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
80587fd9
Commit
80587fd9
authored
Jan 21, 2016
by
Lauri Himanen
Browse files
Moved package one level deeper, can't use mainFunction anymore so next creating my own...
parent
a3c66ab1
Changes
30
Hide whitespace changes
Inline
Side-by-side
parser/parsercp2k/parser.py
→
parser/parser
-
cp2k/
cp2kparser/parsing/
parser.py
View file @
80587fd9
import
re
import
re
import
logging
import
logging
import
parsercp2k.setup_paths
from
cp2kparser.utils.baseclasses
import
Parser
from
parsercp2k.utils.baseclasses
import
Parser
from
cp2kparser.parsing.implementations
import
*
from
parsercp2k.parsing.implementations
import
*
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -71,10 +70,3 @@ class CP2KParser(Parser):
...
@@ -71,10 +70,3 @@ class CP2KParser(Parser):
the nomadtoolkit.
the nomadtoolkit.
"""
"""
return
"cp2k.nomadmetainfo.json"
return
"cp2k.nomadmetainfo.json"
#===============================================================================
# This is what gets run when the scala layer calls for this parser
if
__name__
==
"__main__"
:
cp2kparser
=
CP2KParser
()
cp2kparser
.
scala_main_function
()
parser/parser-cp2k/cp2kparser/scalainterface.py
0 → 100644
View file @
80587fd9
"""
This is the access point to the parser for the scala layer in the nomad project.
"""
import
os
from
cp2kparser
import
CP2KParser
from
nomadcore.local_meta_info
import
loadJsonFile
,
InfoKindEl
from
nomadcore.simple_parser
import
mainFunction
# This is what gets run when the scala layer calls for this parser. Currently
# only the outputparser is used because the scala layer doesn't support
# auxiliary files. Also the version identification is skipped and the structure
# used in CP2K 2.6.2 is assumed.
if
__name__
==
"__main__"
:
cp2kparser
=
CP2KParser
()
# Get the outputparser class
outputparser
=
globals
()[
"CP2KOutputParser{}"
.
format
(
"262"
)](
None
,
None
)
# Setup the metainfos
metaInfoPath
=
os
.
path
.
normpath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
"../../../../nomad-meta-info/meta_info/nomad_meta_info/{}"
.
format
(
cp2kparser
.
get_metainfo_filename
())))
metaInfoEnv
,
warnings
=
loadJsonFile
(
filePath
=
metaInfoPath
,
dependencyLoader
=
None
,
extraArgsHandling
=
InfoKindEl
.
ADD_EXTRA_ARGS
,
uri
=
None
)
# Parser info
parserInfo
=
{
'name'
:
'cp2k-parser'
,
'version'
:
'1.0'
}
# Adjust caching of metadata
cachingLevelForMetaName
=
outputparser
.
cachingLevelForMetaName
# Supercontext is where the objet where the callback functions for
# section closing are found
superContext
=
outputparser
# Main file description is the SimpleParser tree
mainFileDescription
=
outputparser
.
outputstructure
# Use the main function from nomadcore
mainFunction
(
mainFileDescription
,
metaInfoEnv
,
parserInfo
,
superContext
=
superContext
,
cachingLevelForMetaName
=
cachingLevelForMetaName
,
onClose
=
{})
parser/parsercp2k/utils/__init__.py
→
parser/parser
-
cp2k/
cp2kparser/
utils/__init__.py
View file @
80587fd9
File moved
parser/parsercp2k/utils/baseclasses.py
→
parser/parser
-
cp2k/
cp2kparser/
utils/baseclasses.py
View file @
80587fd9
...
@@ -3,11 +3,8 @@ import sys
...
@@ -3,11 +3,8 @@ import sys
import
logging
import
logging
import
StringIO
import
StringIO
from
abc
import
ABCMeta
,
abstractmethod
from
abc
import
ABCMeta
,
abstractmethod
from
parsercp2k.parsing.outputparsing
import
*
from
nomadcore.simple_parser
import
SimpleParserBuilder
,
defaultParseFile
,
extractOnCloseTriggers
from
nomadcore.simple_parser
import
SimpleParserBuilder
,
defaultParseFile
,
extractOnCloseTriggers
from
nomadcore.local_meta_info
import
loadJsonFile
,
InfoKindEl
from
nomadcore.caching_backend
import
CachingLevel
,
ActiveBackend
from
nomadcore.caching_backend
import
CachingLevel
,
ActiveBackend
from
nomadcore.simple_parser
import
mainFunction
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -16,8 +13,11 @@ class Parser(object):
...
@@ -16,8 +13,11 @@ class Parser(object):
"""A base class for nomad parsers.
"""A base class for nomad parsers.
Attributes:
Attributes:
self.
implementation: an object that actually does the parsing and is
implementation: an object that actually does the parsing and is
setup by this class based on the given contents.
setup by this class based on the given contents.
parser_context: A wrapper class for all the parser related information.
This is contructed here and then passed onto the different
implementations.
"""
"""
__metaclass__
=
ABCMeta
__metaclass__
=
ABCMeta
parser_name
=
None
parser_name
=
None
...
@@ -97,39 +97,12 @@ class Parser(object):
...
@@ -97,39 +97,12 @@ class Parser(object):
logger
.
error
(
"No parser implementation has been setup."
)
logger
.
error
(
"No parser implementation has been setup."
)
# Write the starting bracket
# Write the starting bracket
self
.
backend
.
fileOut
.
write
(
"["
)
self
.
implementation
.
backend
.
fileOut
.
write
(
"["
)
self
.
implementation
.
parse
()
self
.
implementation
.
parse
()
# Write the ending bracket
# Write the ending bracket
self
.
backend
.
fileOut
.
write
(
"]
\n
"
)
self
.
implementation
.
backend
.
fileOut
.
write
(
"]
\n
"
)
def
scala_main_function
(
self
):
"""This function gets called when the scala calls for a parser.
"""
# Get the outputparser class
outputparser
=
globals
()[
"CP2KOutputParser{}"
.
format
(
"262"
)](
None
,
None
)
# Setup the metainfos
metaInfoPath
=
os
.
path
.
normpath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
"../../../../nomad-meta-info/meta_info/nomad_meta_info/{}"
.
format
(
self
.
get_metainfo_filename
())))
metaInfoEnv
,
warnings
=
loadJsonFile
(
filePath
=
metaInfoPath
,
dependencyLoader
=
None
,
extraArgsHandling
=
InfoKindEl
.
ADD_EXTRA_ARGS
,
uri
=
None
)
# Parser info
parserInfo
=
{
'name'
:
'cp2k-parser'
,
'version'
:
'1.0'
}
# Adjust caching of metadata
cachingLevelForMetaName
=
outputparser
.
cachingLevelForMetaName
# Supercontext is where the objet where the callback functions for
# section closing are found
superContext
=
outputparser
# Main file description is the SimpleParser tree
mainFileDescription
=
outputparser
.
outputstructure
# Use the main function from nomadcore
mainFunction
(
mainFileDescription
,
metaInfoEnv
,
parserInfo
,
superContext
=
superContext
,
cachingLevelForMetaName
=
cachingLevelForMetaName
,
onClose
=
{})
#===============================================================================
#===============================================================================
...
...
parser/parsercp2k/utils/logconfig.py
→
parser/parser
-
cp2k/
cp2kparser/
utils/logconfig.py
View file @
80587fd9
File moved
parser/parsercp2k/utils/testing.py
→
parser/parser
-
cp2k/
cp2kparser/
utils/testing.py
View file @
80587fd9
File moved
parser/setup.py
→
parser/
parser-cp2k/
setup.py
View file @
80587fd9
...
@@ -5,7 +5,7 @@ from setuptools import setup, find_packages
...
@@ -5,7 +5,7 @@ from setuptools import setup, find_packages
def
main
():
def
main
():
# Start package setup
# Start package setup
setup
(
setup
(
name
=
"
p
arser
cp2k
"
,
name
=
"
cp2k
arser"
,
version
=
"0.1"
,
version
=
"0.1"
,
include_package_data
=
True
,
include_package_data
=
True
,
package_data
=
{
package_data
=
{
...
@@ -15,7 +15,7 @@ def main():
...
@@ -15,7 +15,7 @@ def main():
author
=
"Lauri Himanen"
,
author
=
"Lauri Himanen"
,
author_email
=
"lauri.himanen@gmail.com"
,
author_email
=
"lauri.himanen@gmail.com"
,
license
=
"GPL3"
,
license
=
"GPL3"
,
packages
=
[
"parser
cp2k
"
],
packages
=
[
"
cp2k
parser"
],
install_requires
=
[
install_requires
=
[
'pint'
,
'pint'
,
'numpy'
,
'numpy'
,
...
...
parser/parsercp2k/__init__.py
deleted
100644 → 0
View file @
a3c66ab1
import
parsercp2k.utils.logconfig
from
parsercp2k.parser
import
CP2KParser
parser/parsercp2k/parsing/autoparser.py
deleted
100644 → 0
View file @
a3c66ab1
import
sys
import
os
import
cStringIO
from
parsercp2k.implementation.cp2kparserversioner
import
CP2KParserVersioner
from
parsercp2k.generics.testing
import
get_parser
#===============================================================================
def
parse_path
(
path
,
metainfo_to_keep
=
[],
metainfo_to_skip
=
[],
dump
=
False
):
"""Generates a cp2k parser using the tools defined in testing.py and parses
the contents in the given path
"""
# If a dump is requested, the results will be saved to a file under the
# current folder
if
dump
:
stream
=
cStringIO
.
StringIO
()
else
:
stream
=
sys
.
stdout
parserbuilder
=
CP2KParserVersioner
metainfopath
=
os
.
path
.
normpath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
"../../../nomad-meta-info/meta_info/nomad_meta_info/cp2k.nomadmetainfo.json"
))
parser
=
get_parser
(
path
,
metainfopath
,
parserbuilder
,
metainfo_to_keep
,
metainfo_to_skip
,
stream
)
parser
.
parse
()
if
dump
:
outputfile
=
open
(
path
+
"/parseroutput.json"
,
"w"
)
outputfile
.
write
(
stream
.
getvalue
())
parser/parsercp2k/setup_paths.py
deleted
100644 → 0
View file @
a3c66ab1
import
sys
import
os
baseDir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
commonDir
=
os
.
path
.
normpath
(
os
.
path
.
join
(
baseDir
,
"../../../../python-common/common/python"
))
if
os
.
path
.
exists
(
commonDir
):
if
not
commonDir
in
sys
.
path
:
sys
.
path
.
insert
(
0
,
commonDir
)
Prev
1
2
Next
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