Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
parser-cp2k
Commits
2091f384
Commit
2091f384
authored
Mar 12, 2016
by
Lauri Himanen
Browse files
Added profiling tools, disabled CP2K input information loading for now.
parent
c8ab8bd0
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
parser/parser-cp2k/cp2kparser/parsing/versions/cp2k262/implementation.py
View file @
2091f384
...
...
@@ -2,7 +2,7 @@ import re
import
os
import
logging
from
cp2kparser.parsing.csvparsing
import
CSVParser
from
.inputparsing
import
CP2KInputParser
#
from .inputparsing import CP2KInputParser
from
.outputparser
import
CP2KOutputParser
# from cp2kparser.parsing.cp2kinputenginedata.input_tree import CP2KInput
from
cp2kparser.utils.baseclasses
import
ParserImplementation
...
...
@@ -23,14 +23,14 @@ class CP2KImplementation(ParserImplementation):
# know the version id.
self
.
csvengine
=
CSVParser
(
self
)
self
.
atomsengine
=
CoordinateReader
()
self
.
inputparser
=
CP2KInputParser
()
self
.
inputparser
.
setup_version
(
self
.
version_id
)
#
self.inputparser = CP2KInputParser()
#
self.inputparser.setup_version(self.version_id)
self
.
input_tree
=
None
self
.
extended_input
=
None
self
.
determine_file_ids_pre_setup
()
self
.
input_preprocessor
()
self
.
determine_file_ids_post_setup
()
#
self.input_preprocessor()
#
self.determine_file_ids_post_setup()
def
determine_file_ids_pre_setup
(
self
):
"""Resolve the input and output files based on extension and the
...
...
@@ -151,71 +151,71 @@ class CP2KImplementation(ParserImplementation):
input_variables_replaced
.
append
(
new_line
)
self
.
extended_input
=
'
\n
'
.
join
(
input_variables_replaced
)
self
.
input_tree
=
self
.
inputparser
.
parse
(
self
.
extended_input
)
#
self.input_tree = self.inputparser.parse(self.extended_input)
def
determine_file_ids_post_setup
(
self
):
"""Determines the file id's after the CP2K verion has been set
up. This includes force files, coordinate files, cell files, etc.
"""
# Determine the presence of force file
force_path
=
self
.
input_tree
.
get_keyword
(
"FORCE_EVAL/PRINT/FORCES/FILENAME"
)
project_name
=
self
.
input_tree
.
get_keyword
(
"GLOBAL/PROJECT_NAME"
)
if
force_path
is
not
None
and
force_path
!=
"__STD_OUT__"
:
# The force path is not typically exactly as written in input
if
force_path
.
startswith
(
"="
):
logger
.
debug
(
"Using single force file."
)
force_path
=
force_path
[
1
:]
elif
re
.
match
(
r
".?/"
,
force_path
):
logger
.
debug
(
"Using separate force file for each step."
)
force_path
=
"{}-1_0.xyz"
.
format
(
force_path
)
else
:
logger
.
debug
(
"Using separate force file for each step."
)
force_path
=
"{}-{}-1_0.xyz"
.
format
(
project_name
,
force_path
)
force_path
=
os
.
path
.
basename
(
force_path
)
# Check against the given files
file_path
=
self
.
search_file
(
force_path
)
self
.
file_storage
.
setup_file_id
(
file_path
,
"forces"
)
# Determine the presence of an initial coordinate file
init_coord_file
=
self
.
input_tree
.
get_keyword
(
"FORCE_EVAL/SUBSYS/TOPOLOGY/COORD_FILE_NAME"
)
if
init_coord_file
is
not
None
:
logger
.
debug
(
"Initial coordinate file found."
)
# Check against the given files
file_path
=
self
.
search_file
(
init_coord_file
)
self
.
file_storage
.
setup_file_id
(
file_path
,
"initial_coordinates"
)
# Determine the presence of a trajectory file
traj_file
=
self
.
input_tree
.
get_keyword
(
"MOTION/PRINT/TRAJECTORY/FILENAME"
)
if
traj_file
is
not
None
and
traj_file
!=
"__STD_OUT__"
:
file_format
=
self
.
input_tree
.
get_keyword
(
"MOTION/PRINT/TRAJECTORY/FORMAT"
)
extension
=
{
"PDB"
:
"pdb"
,
"XYZ"
:
"xyz"
,
"XMOL"
:
"xyz"
,
"ATOMIC"
:
"xyz"
,
"DCD"
:
"dcd"
,
}[
file_format
]
logger
.
debug
(
"Trajectory file found."
)
normalized_path
=
self
.
normalize_cp2k_path
(
traj_file
,
extension
,
"pos"
)
file_path
=
self
.
search_file
(
normalized_path
)
self
.
file_storage
.
setup_file_id
(
file_path
,
"trajectory"
)
# Determine the presence of a cell output file
cell_motion_file
=
self
.
input_tree
.
get_keyword
(
"MOTION/PRINT/CELL/FILENAME"
)
if
cell_motion_file
is
not
None
:
logger
.
debug
(
"Cell file found."
)
extension
=
"cell"
normalized_path
=
self
.
normalize_cp2k_path
(
cell_motion_file
,
extension
)
file_path
=
self
.
search_file
(
normalized_path
)
self
.
file_storage
.
setup_file_id
(
file_path
,
"cell_output"
)
# Determine the presence of a cell input file
cell_input_file
=
self
.
input_tree
.
get_keyword
(
"FORCE_EVAL/SUBSYS/CELL/CELL_FILE_NAME"
)
if
cell_input_file
is
not
None
:
file_path
=
self
.
search_file
(
cell_input_file
)
self
.
file_storage
.
setup_file_id
(
file_path
,
"cell_input"
)
#
def determine_file_ids_post_setup(self):
#
"""Determines the file id's after the CP2K verion has been set
#
up. This includes force files, coordinate files, cell files, etc.
#
"""
#
#
Determine the presence of force file
#
force_path = self.input_tree.get_keyword("FORCE_EVAL/PRINT/FORCES/FILENAME")
#
project_name = self.input_tree.get_keyword("GLOBAL/PROJECT_NAME")
#
if force_path is not None and force_path != "__STD_OUT__":
#
#
The force path is not typically exactly as written in input
#
if force_path.startswith("="):
#
logger.debug("Using single force file.")
#
force_path = force_path[1:]
#
elif re.match(r".?/", force_path):
#
logger.debug("Using separate force file for each step.")
#
force_path = "{}-1_0.xyz".format(force_path)
#
else:
#
logger.debug("Using separate force file for each step.")
#
force_path = "{}-{}-1_0.xyz".format(project_name, force_path)
#
force_path = os.path.basename(force_path)
#
#
Check against the given files
#
file_path = self.search_file(force_path)
#
self.file_storage.setup_file_id(file_path, "forces")
#
#
Determine the presence of an initial coordinate file
#
init_coord_file = self.input_tree.get_keyword("FORCE_EVAL/SUBSYS/TOPOLOGY/COORD_FILE_NAME")
#
if init_coord_file is not None:
#
logger.debug("Initial coordinate file found.")
#
#
Check against the given files
#
file_path = self.search_file(init_coord_file)
#
self.file_storage.setup_file_id(file_path, "initial_coordinates")
#
#
Determine the presence of a trajectory file
#
traj_file = self.input_tree.get_keyword("MOTION/PRINT/TRAJECTORY/FILENAME")
#
if traj_file is not None and traj_file != "__STD_OUT__":
#
file_format = self.input_tree.get_keyword("MOTION/PRINT/TRAJECTORY/FORMAT")
#
extension = {
#
"PDB": "pdb",
#
"XYZ": "xyz",
#
"XMOL": "xyz",
#
"ATOMIC": "xyz",
#
"DCD": "dcd",
#
}[file_format]
#
logger.debug("Trajectory file found.")
#
normalized_path = self.normalize_cp2k_path(traj_file, extension, "pos")
#
file_path = self.search_file(normalized_path)
#
self.file_storage.setup_file_id(file_path, "trajectory")
#
#
Determine the presence of a cell output file
#
cell_motion_file = self.input_tree.get_keyword("MOTION/PRINT/CELL/FILENAME")
#
if cell_motion_file is not None:
#
logger.debug("Cell file found.")
#
extension = "cell"
#
normalized_path = self.normalize_cp2k_path(cell_motion_file, extension)
#
file_path = self.search_file(normalized_path)
#
self.file_storage.setup_file_id(file_path, "cell_output")
#
#
Determine the presence of a cell input file
#
cell_input_file = self.input_tree.get_keyword("FORCE_EVAL/SUBSYS/CELL/CELL_FILE_NAME")
#
if cell_input_file is not None:
#
file_path = self.search_file(cell_input_file)
#
self.file_storage.setup_file_id(file_path, "cell_input")
def
normalize_cp2k_path
(
self
,
path
,
extension
,
name
=
""
):
"""The paths in CP2K input can be given in many ways. This function
...
...
parser/parser-cp2k/cp2kparser/utils/baseclasses.py
View file @
2091f384
...
...
@@ -393,7 +393,7 @@ class MainParser(HierarchicalParser):
process just override this method.
"""
# Initialize the parser builder
parserBuilder
=
SimpleParserBuilder
(
self
.
root_matcher
,
self
.
backend
.
metaInfoEnv
(),
self
.
metainfo_to_keep
)
parserBuilder
=
SimpleParserBuilder
(
self
.
root_matcher
,
self
.
backend
.
metaInfoEnv
(),
self
.
metainfo_to_keep
,
units
=
self
.
parser_context
.
units
)
# Verify the metainfo
if
not
parserBuilder
.
verifyMetaInfo
(
sys
.
stderr
):
...
...
@@ -416,6 +416,7 @@ class MainParser(HierarchicalParser):
defaultSectionCachingLevel
=
self
.
default_section_caching_level
,
onClose
=
onClose
,
superBackend
=
self
.
backend
)
self
.
caching_backend
.
units
=
self
.
parser_context
.
units
# Compile the SimpleMatcher tree
parserBuilder
.
compile
()
...
...
@@ -451,9 +452,10 @@ class MainParser(HierarchicalParser):
class
ParserContext
(
object
):
"""Contains everything needed to instantiate a parser implementation.
"""
def
__init__
(
self
,
files
=
None
,
metainfo_to_keep
=
None
,
backend
=
None
,
version_id
=
None
,
main_file
=
None
):
def
__init__
(
self
,
files
=
None
,
metainfo_to_keep
=
None
,
backend
=
None
,
version_id
=
None
,
main_file
=
None
,
units
=
None
):
self
.
files
=
files
self
.
version_id
=
version_id
self
.
metainfo_to_keep
=
metainfo_to_keep
self
.
backend
=
backend
self
.
main_file
=
main_file
self
.
units
=
units
test/unittests/cp2k_2.6.2/run_tests.py
View file @
2091f384
...
...
@@ -40,6 +40,8 @@ def get_result(folder, metaname):
#===============================================================================
class
TestXCFunctional
(
unittest
.
TestCase
):
"""Tests that the XC functionals can be properly parsed.
"""
def
test_pade
(
self
):
xc
=
get_result
(
"XC_functional/pade"
,
"XC_functional"
)
...
...
@@ -59,10 +61,12 @@ class TestXCFunctional(unittest.TestCase):
#===============================================================================
class
TestSectionSingleConfigurationCalculation
(
unittest
.
TestCase
):
class
TestEnergyForce
(
unittest
.
TestCase
):
"""Tests for a CP2K calculation with RUN_TYPE ENERGY_FORCE.
"""
def
setUp
(
self
):
self
.
results
=
get_results
(
"
section_single_configuration_calculation"
,
"section_single_configuration_calculatio
n"
)
self
.
results
=
get_results
(
"
energy_force"
,
"section_ru
n"
)
def
test_energy_total_scf_iteration
(
self
):
energy_total
=
self
.
results
[
"energy_total_scf_iteration"
]
...
...
@@ -91,13 +95,6 @@ class TestSectionSingleConfigurationCalculation(unittest.TestCase):
)
self
.
assertTrue
(
np
.
array_equal
(
atomic_forces
,
expected_result
))
#===============================================================================
class
TestSectionSystemDescription
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
results
=
get_results
(
"section_system_description"
,
"section_system_description"
)
def
test_atom_label
(
self
):
atom_labels
=
self
.
results
[
"atom_label"
]
expected_labels
=
np
.
array
(
8
*
[
"Si"
])
...
...
@@ -130,7 +127,6 @@ if __name__ == '__main__':
suites
=
[]
suites
.
append
(
unittest
.
TestLoader
().
loadTestsFromTestCase
(
TestXCFunctional
))
suites
.
append
(
unittest
.
TestLoader
().
loadTestsFromTestCase
(
TestSectionSingleConfigurationCalculation
))
suites
.
append
(
unittest
.
TestLoader
().
loadTestsFromTestCase
(
TestSectionSystemDescription
))
suites
.
append
(
unittest
.
TestLoader
().
loadTestsFromTestCase
(
TestEnergyForce
))
alltests
=
unittest
.
TestSuite
(
suites
)
unittest
.
TextTestRunner
(
verbosity
=
0
).
run
(
alltests
)
test/unittests/cp2k_2.6.2/section_single_configuration_calculation/si_bulk8.out
deleted
100644 → 0
View file @
c8ab8bd0
This diff is collapsed.
Click to expand it.
test/unittests/cp2k_2.6.2/section_system_description/si_bulk8.out
deleted
100644 → 0
View file @
c8ab8bd0
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment