Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
parser-cp2k
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nomad-lab
parser-cp2k
Commits
0622015a
Commit
0622015a
authored
9 years ago
by
Himanen, Lauri (himanel1)
Browse files
Options
Downloads
Patches
Plain Diff
Better documentation.
parent
b988039e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cp2kparser/generics/nomadparser.py
+45
-19
45 additions, 19 deletions
cp2kparser/generics/nomadparser.py
cp2kparser/implementation/parser.py
+5
-2
5 additions, 2 deletions
cp2kparser/implementation/parser.py
with
50 additions
and
21 deletions
cp2kparser/generics/nomadparser.py
+
45
−
19
View file @
0622015a
...
...
@@ -3,13 +3,29 @@
import
json
import
os
import
time
from
abc
import
ABCMeta
,
abstractmethod
from
cp2kparser.generics.util
import
*
#===============================================================================
class
NomadParser
(
object
):
"""
The base class for a NoMaD parser.
This class should be inherited by the python based parsers. It provides
general utility methods and a single interface for input and output.
The utilities that this class provides and the inherited classes should NOT
do:
- Converting results to JSON
- Converting units to SI
- Timing
- Caching of results
- Providing file contents, sizes and handles
This class also defines some absract methods that each parser must
implement.
"""
__metaclass__
=
ABCMeta
def
__init__
(
self
,
input_json_string
):
self
.
input_json_string
=
input_json_string
...
...
@@ -27,7 +43,10 @@ class NomadParser(object):
self
.
results
=
{}
def
get_file_contents
(
self
,
file_id
):
"""
Get the contents for the file with the given id. Uses cached result
if available. Does not cache files that are bigger than a certain
limit.
"""
cache_limit
=
10000
contents
=
self
.
file_contents
.
get
(
file_id
)
if
not
contents
:
...
...
@@ -39,7 +58,9 @@ class NomadParser(object):
return
contents
def
get_file_size
(
self
,
file_id
):
"""
Get the size of a file with the given id. Uses cached result
if available.
"""
size
=
self
.
file_sizes
.
get
(
file_id
)
if
not
size
:
fh
=
self
.
file_handles
[
file_id
]
...
...
@@ -49,10 +70,11 @@ class NomadParser(object):
return
size
def
get_file_handle
(
self
,
file_id
):
"""
Get the handle for a file with the given id. Uses cached result
if available.
"""
handle
=
self
.
file_handles
.
get
(
file_id
)
if
not
handle
:
path
=
self
.
file_ids
[
file_id
]
try
:
handle
=
open
(
path
,
"
r
"
)
...
...
@@ -64,7 +86,8 @@ class NomadParser(object):
return
handle
def
analyse_input_json
(
self
):
"""
Analyze the JSON given as input.
"""
# Try to decode
self
.
input_json_object
=
json
.
loads
(
self
.
input_json_string
)
...
...
@@ -80,17 +103,6 @@ class NomadParser(object):
# See if the metainfos exist
def
setup_version
(
self
):
"""
Setup a correct implementation for this version of CP2K.
"""
pass
def
determine_file_ids
(
self
):
"""
If the files have not been given an id, try to determine the
correct ids by looking at the input file, contents and file extensions.
"""
pass
def
get_quantity
(
self
,
name
):
"""
Given a unique quantity id which is present in the metainfo
declaration, parses the corresponding quantity (if available) and
...
...
@@ -122,16 +134,30 @@ class NomadParser(object):
print_debug
(
"
Elapsed time: {} ms
"
.
format
((
stop
-
start
)
*
1000
))
return
result
@abstractmethod
def
setup_version
(
self
):
"""
Setup a correct implementation for this version.
"""
pass
@abstractmethod
def
determine_file_ids
(
self
):
"""
If the files have not been given an id, try to determine the
correct ids by looking at the input file, contents and file extensions.
"""
pass
@abstractmethod
def
parse_quantity
(
self
,
name
):
"""
Override this function in an actual implementation
"""
"""
Parse a quantity from the given files.
"""
pass
@abstractmethod
def
check_quantity_availability
(
self
,
name
):
"""
Check quantity availability.
-Check the list of available quantities declared in interface.
-Check if the run type actually produces the quantity
-Check if the quantity is allowed by the
'
metainfoToKeep
'
and
'
metainfoToSkip
'
"""
return
True
pass
This diff is collapsed.
Click to expand it.
cp2kparser/implementation/parser.py
+
5
−
2
View file @
0622015a
...
...
@@ -13,7 +13,8 @@ from cp2kparser.engines.cp2kinputengine import CP2KInputEngine
#===============================================================================
class
CP2KParser
(
NomadParser
):
"""
The interface to a NoMaD CP2K parser.
"""
The interface for a NoMaD CP2K parser. All parsing actions will go
through this class.
"""
def
__init__
(
self
,
input_json_string
):
...
...
@@ -167,9 +168,11 @@ class CP2KImplementation(object):
xc_shortcut
=
self
.
inputengine
.
get_subsection
(
"
FORCE_EVAL/DFT/XC/XC_FUNCTIONAL
"
).
get_parameter
()
return
{
'
B3LYP
'
:
"
HYB_GGA_XC_B3LYP
"
,
'
BEEFVDW
'
:
""
,
'
BLYP
'
:
""
,
'
PADE
'
:
"
LDA_XC_TETER93
"
,
'
PBE
'
:
"
GGA_X_PBE
"
,
'
B3LYP
'
:
"
HYB_GGA_XC_B3LYP
"
,
}.
get
(
xc_shortcut
,
None
)
def
particle_forces
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment