Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
parser-cp2k
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nomad-lab
parser-cp2k
Commits
35a90bed
Commit
35a90bed
authored
Oct 18, 2017
by
Lauri Himanen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Started using the new way of giving the input file to the parser.
parent
31ca2e00
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
26 additions
and
26 deletions
+26
-26
parser/parser-cp2k/cp2kparser/parser.py
parser/parser-cp2k/cp2kparser/parser.py
+1
-1
parser/parser-cp2k/cp2kparser/versions/cp2k262/commonparser.py
...r/parser-cp2k/cp2kparser/versions/cp2k262/commonparser.py
+2
-2
parser/parser-cp2k/cp2kparser/versions/cp2k262/geooptparser.py
...r/parser-cp2k/cp2kparser/versions/cp2k262/geooptparser.py
+2
-2
parser/parser-cp2k/cp2kparser/versions/cp2k262/inputparser.py
...er/parser-cp2k/cp2kparser/versions/cp2k262/inputparser.py
+8
-8
parser/parser-cp2k/cp2kparser/versions/cp2k262/mdparser.py
parser/parser-cp2k/cp2kparser/versions/cp2k262/mdparser.py
+2
-2
parser/parser-cp2k/cp2kparser/versions/cp2k262/singlepointforceparser.py
...p2k/cp2kparser/versions/cp2k262/singlepointforceparser.py
+4
-4
parser/parser-cp2k/cp2kparser/versions/cp2k262/singlepointparser.py
...ser-cp2k/cp2kparser/versions/cp2k262/singlepointparser.py
+4
-4
regtests/regtests.py
regtests/regtests.py
+3
-3
No files found.
parser/parser-cp2k/cp2kparser/parser.py
View file @
35a90bed
...
@@ -153,4 +153,4 @@ class CP2KParser(ParserInterface):
...
@@ -153,4 +153,4 @@ class CP2KParser(ParserInterface):
)
)
raise
raise
self
.
main_parser
=
parser_class
(
self
.
parser_context
.
main_file
,
self
.
parser_context
)
self
.
main_parser
=
parser_class
(
self
.
parser_context
)
parser/parser-cp2k/cp2kparser/versions/cp2k262/commonparser.py
View file @
35a90bed
...
@@ -445,8 +445,8 @@ class CP2KCommonParser(CommonParser):
...
@@ -445,8 +445,8 @@ class CP2KCommonParser(CommonParser):
# If the input file is available, parse it
# If the input file is available, parse it
filepath
=
self
.
file_service
.
get_file_by_id
(
"input"
)
filepath
=
self
.
file_service
.
get_file_by_id
(
"input"
)
if
filepath
is
not
None
:
if
filepath
is
not
None
:
input_parser
=
CP2KInputParser
(
filepath
,
self
.
parser_context
)
input_parser
=
CP2KInputParser
(
self
.
parser_context
)
input_parser
.
parse
()
input_parser
.
parse
(
filepath
)
else
:
else
:
logger
.
warning
(
"The input file of the calculation could not be found."
)
logger
.
warning
(
"The input file of the calculation could not be found."
)
...
...
parser/parser-cp2k/cp2kparser/versions/cp2k262/geooptparser.py
View file @
35a90bed
...
@@ -16,10 +16,10 @@ class CP2KGeoOptParser(MainHierarchicalParser):
...
@@ -16,10 +16,10 @@ class CP2KGeoOptParser(MainHierarchicalParser):
"""Used to parse the CP2K calculation with run types:
"""Used to parse the CP2K calculation with run types:
-GEO_OPT/GEOMETRY_OPTIMIZATION
-GEO_OPT/GEOMETRY_OPTIMIZATION
"""
"""
def
__init__
(
self
,
file_path
,
parser_context
):
def
__init__
(
self
,
parser_context
):
"""
"""
"""
"""
super
(
CP2KGeoOptParser
,
self
).
__init__
(
file_path
,
parser_context
)
super
(
CP2KGeoOptParser
,
self
).
__init__
(
parser_context
)
self
.
setup_common_matcher
(
CP2KCommonParser
(
parser_context
))
self
.
setup_common_matcher
(
CP2KCommonParser
(
parser_context
))
self
.
traj_iterator
=
None
self
.
traj_iterator
=
None
self
.
energy_reeval_quickstep
=
None
self
.
energy_reeval_quickstep
=
None
...
...
parser/parser-cp2k/cp2kparser/versions/cp2k262/inputparser.py
View file @
35a90bed
...
@@ -28,7 +28,7 @@ class CP2KInputParser(AbstractBaseParser):
...
@@ -28,7 +28,7 @@ class CP2KInputParser(AbstractBaseParser):
supports variables. This is currently not supported, but may be added at
supports variables. This is currently not supported, but may be added at
some point.
some point.
"""
"""
def
__init__
(
self
,
file_path
,
parser_context
):
def
__init__
(
self
,
parser_context
):
"""
"""
Attributes:
Attributes:
input_tree: The input structure for this version of CP2K. The
input_tree: The input structure for this version of CP2K. The
...
@@ -38,7 +38,7 @@ class CP2KInputParser(AbstractBaseParser):
...
@@ -38,7 +38,7 @@ class CP2KInputParser(AbstractBaseParser):
variables have been stated explicitly and the additional input files have
variables have been stated explicitly and the additional input files have
been merged.
been merged.
"""
"""
super
(
CP2KInputParser
,
self
).
__init__
(
file_path
,
parser_context
)
super
(
CP2KInputParser
,
self
).
__init__
(
parser_context
)
self
.
input_tree
=
None
self
.
input_tree
=
None
self
.
input_lines
=
None
self
.
input_lines
=
None
self
.
unit_mapping
=
{
self
.
unit_mapping
=
{
...
@@ -68,16 +68,16 @@ class CP2KInputParser(AbstractBaseParser):
...
@@ -68,16 +68,16 @@ class CP2KInputParser(AbstractBaseParser):
self
.
cache_service
.
add
(
"traj_add_last"
)
self
.
cache_service
.
add
(
"traj_add_last"
)
# self.cache_service.add("electronic_structure_method")
# self.cache_service.add("electronic_structure_method")
def
parse
(
self
):
def
parse
(
self
,
filepath
):
#=======================================================================
#=======================================================================
# Preprocess to spell out variables and to include stuff from other
# Preprocess to spell out variables and to include stuff from other
# files
# files
self
.
preprocess_input
()
self
.
preprocess_input
(
filepath
)
#=======================================================================
#=======================================================================
# Gather the information from the input file
# Gather the information from the input file
self
.
fill_input_tree
(
self
.
file_
path
)
self
.
fill_input_tree
(
file
path
)
#=======================================================================
#=======================================================================
# Parse everything in the input to cp2k specific metadata
# Parse everything in the input to cp2k specific metadata
...
@@ -459,14 +459,14 @@ class CP2KInputParser(AbstractBaseParser):
...
@@ -459,14 +459,14 @@ class CP2KInputParser(AbstractBaseParser):
input_tree_pickle_file
=
open
(
pickle_path
,
'rb'
)
input_tree_pickle_file
=
open
(
pickle_path
,
'rb'
)
self
.
input_tree
=
pickle
.
load
(
input_tree_pickle_file
)
self
.
input_tree
=
pickle
.
load
(
input_tree_pickle_file
)
def
preprocess_input
(
self
):
def
preprocess_input
(
self
,
filepath
):
"""Preprocess the input file. Concatenate .inc files into the main
"""Preprocess the input file. Concatenate .inc files into the main
input file and explicitly state all variables.
input file and explicitly state all variables.
"""
"""
# Read the input file into memory. It shouldn't be that big so we can
# Read the input file into memory. It shouldn't be that big so we can
# do this easily
# do this easily
input_lines
=
[]
input_lines
=
[]
with
open
(
self
.
file_
path
,
"r"
)
as
f
:
with
open
(
file
path
,
"r"
)
as
f
:
for
line
in
f
:
for
line
in
f
:
input_lines
.
append
(
line
.
strip
())
input_lines
.
append
(
line
.
strip
())
...
@@ -477,7 +477,7 @@ class CP2KInputParser(AbstractBaseParser):
...
@@ -477,7 +477,7 @@ class CP2KInputParser(AbstractBaseParser):
if
line
.
startswith
(
"@INCLUDE"
)
or
line
.
startswith
(
"@include"
):
if
line
.
startswith
(
"@INCLUDE"
)
or
line
.
startswith
(
"@include"
):
split
=
line
.
split
(
None
,
1
)
split
=
line
.
split
(
None
,
1
)
includepath
=
split
[
1
]
includepath
=
split
[
1
]
basedir
=
os
.
path
.
dirname
(
self
.
file_
path
)
basedir
=
os
.
path
.
dirname
(
file
path
)
filepath
=
os
.
path
.
join
(
basedir
,
includepath
)
filepath
=
os
.
path
.
join
(
basedir
,
includepath
)
filepath
=
os
.
path
.
abspath
(
filepath
)
filepath
=
os
.
path
.
abspath
(
filepath
)
if
not
os
.
path
.
isfile
(
filepath
):
if
not
os
.
path
.
isfile
(
filepath
):
...
...
parser/parser-cp2k/cp2kparser/versions/cp2k262/mdparser.py
View file @
35a90bed
...
@@ -18,10 +18,10 @@ class CP2KMDParser(MainHierarchicalParser):
...
@@ -18,10 +18,10 @@ class CP2KMDParser(MainHierarchicalParser):
-MD
-MD
-MOLECULAR_DYNAMICS
-MOLECULAR_DYNAMICS
"""
"""
def
__init__
(
self
,
file_path
,
parser_context
):
def
__init__
(
self
,
parser_context
):
"""
"""
"""
"""
super
(
CP2KMDParser
,
self
).
__init__
(
file_path
,
parser_context
)
super
(
CP2KMDParser
,
self
).
__init__
(
parser_context
)
self
.
setup_common_matcher
(
CP2KCommonParser
(
parser_context
))
self
.
setup_common_matcher
(
CP2KCommonParser
(
parser_context
))
self
.
traj_iterator
=
None
self
.
traj_iterator
=
None
self
.
vel_iterator
=
None
self
.
vel_iterator
=
None
...
...
parser/parser-cp2k/cp2kparser/versions/cp2k262/singlepointforceparser.py
View file @
35a90bed
...
@@ -9,13 +9,13 @@ class CP2KSinglePointForceParser(AbstractBaseParser):
...
@@ -9,13 +9,13 @@ class CP2KSinglePointForceParser(AbstractBaseParser):
calculation. It is not exactly an ZYX file, so here we define separate
calculation. It is not exactly an ZYX file, so here we define separate
parser.
parser.
"""
"""
def
__init__
(
self
,
file_path
,
parser_context
):
def
__init__
(
self
,
parser_context
):
super
(
CP2KSinglePointForceParser
,
self
).
__init__
(
file_path
,
parser_context
)
super
(
CP2KSinglePointForceParser
,
self
).
__init__
(
parser_context
)
def
parse
(
self
):
def
parse
(
self
,
filepath
):
start
=
False
start
=
False
forces
=
[]
forces
=
[]
with
open
(
self
.
file_
path
)
as
f
:
with
open
(
file
path
)
as
f
:
for
line
in
f
:
for
line
in
f
:
if
line
.
startswith
(
" # Atom"
):
if
line
.
startswith
(
" # Atom"
):
start
=
True
start
=
True
...
...
parser/parser-cp2k/cp2kparser/versions/cp2k262/singlepointparser.py
View file @
35a90bed
...
@@ -13,10 +13,10 @@ class CP2KSinglePointParser(MainHierarchicalParser):
...
@@ -13,10 +13,10 @@ class CP2KSinglePointParser(MainHierarchicalParser):
-ENERGY
-ENERGY
-ENERGY_FORCE
-ENERGY_FORCE
"""
"""
def
__init__
(
self
,
file_path
,
parser_context
):
def
__init__
(
self
,
parser_context
):
"""
"""
"""
"""
super
(
CP2KSinglePointParser
,
self
).
__init__
(
file_path
,
parser_context
)
super
(
CP2KSinglePointParser
,
self
).
__init__
(
parser_context
)
self
.
setup_common_matcher
(
CP2KCommonParser
(
parser_context
))
self
.
setup_common_matcher
(
CP2KCommonParser
(
parser_context
))
#=======================================================================
#=======================================================================
...
@@ -54,8 +54,8 @@ class CP2KSinglePointParser(MainHierarchicalParser):
...
@@ -54,8 +54,8 @@ class CP2KSinglePointParser(MainHierarchicalParser):
if
section
[
"atom_forces"
]
is
None
:
if
section
[
"atom_forces"
]
is
None
:
force_file
=
self
.
file_service
.
get_file_by_id
(
"force_file_single_point"
)
force_file
=
self
.
file_service
.
get_file_by_id
(
"force_file_single_point"
)
if
force_file
is
not
None
:
if
force_file
is
not
None
:
force_parser
=
CP2KSinglePointForceParser
(
force_file
,
self
.
parser_context
)
force_parser
=
CP2KSinglePointForceParser
(
self
.
parser_context
)
force_parser
.
parse
()
force_parser
.
parse
(
force_file
)
else
:
else
:
logger
.
warning
(
"The file containing the forces printed by ENERGY_FORCE calculation could not be found."
)
logger
.
warning
(
"The file containing the forces printed by ENERGY_FORCE calculation could not be found."
)
...
...
regtests/regtests.py
View file @
35a90bed
...
@@ -17,8 +17,8 @@ def get_result(folder, metaname=None):
...
@@ -17,8 +17,8 @@ def get_result(folder, metaname=None):
"""
"""
dirname
=
os
.
path
.
dirname
(
__file__
)
dirname
=
os
.
path
.
dirname
(
__file__
)
filename
=
os
.
path
.
join
(
"cp2k_{}"
.
format
(
VERSION
),
dirname
,
folder
,
"unittest.out"
)
filename
=
os
.
path
.
join
(
"cp2k_{}"
.
format
(
VERSION
),
dirname
,
folder
,
"unittest.out"
)
parser
=
CP2KParser
(
filename
,
None
,
debug
=
True
,
log_level
=
logging
.
CRITICAL
)
parser
=
CP2KParser
(
None
,
debug
=
True
,
log_level
=
logging
.
CRITICAL
)
results
=
parser
.
parse
()
results
=
parser
.
parse
(
filename
)
if
metaname
is
None
:
if
metaname
is
None
:
return
results
return
results
...
@@ -32,7 +32,7 @@ class TestErrors(unittest.TestCase):
...
@@ -32,7 +32,7 @@ class TestErrors(unittest.TestCase):
def
test_no_file
(
self
):
def
test_no_file
(
self
):
"""File is not no present.
"""File is not no present.
"""
"""
with
self
.
assertRaises
(
IO
Error
):
with
self
.
assertRaises
(
Value
Error
):
get_result
(
"errors/no_file"
,
"XC_functional"
)
get_result
(
"errors/no_file"
,
"XC_functional"
)
def
test_invalid_file
(
self
):
def
test_invalid_file
(
self
):
...
...
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