Commit 8341d560 authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Fixes and an example on how to use NomadParser.

parent 78d6f663
......@@ -13,6 +13,8 @@ class AtomsEngine(object):
Reading is primarily done by ASE or MDAnalysis, but in some cases own
implementation had to be made.
Returns all coordinates as numpy arrays.
formats = {
"xyz": "",
......@@ -86,9 +88,6 @@ class AtomsEngine(object):
if format == "pdb-cp2k":
iterator = self.parser.csvengine.iread(contents, columns=[3, 4, 5], comments=["TITLE", "AUTHOR", "REMARK", "CRYST"], separator="END")
return iterator
if format == "xyz":
iterator = self.parser.csvengine.iread(contents, columns=[-3, -2, -1], comments=["^i ="], separator="^\s*\d+$")
return iterator
def ase_wrapper(self, iterator):
"""Used to wrap an iterator returned by so that it returns
......@@ -88,7 +88,9 @@ class CSVEngine(object):
# Start iterating
configuration = []
for line in contents: # This actually reads line by line and only keeps the current line in memory
print line
# If separator encountered, yield the stored configuration
if is_separator(line):
......@@ -261,6 +261,7 @@ class NomadParser(object):
section_id = self.backend.openSection(name)
for value in value_iterable:
print value
# Save to backend
self.input_value_to_backend(name, value, unit, dtypestr, shape)
self.backend.closeSection(name, section_id)
......@@ -198,10 +198,10 @@ if __name__ == '__main__':
# unittest.main()
suites = []
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestForces))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestFunctionals))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestTrajectory))
alltests = unittest.TestSuite(suites)
......@@ -153,25 +153,31 @@ class MyParserImplementation2(MyParserImplementation1):
result.value = "2.0"
return result
MyParser could be now used as follows:
An example of the JSON file given to the NomadParser contructor:
"metaInfoFile": "metainfo.json"),
"tmpDir": "/home",
"metainfoToKeep": [],
"metainfoToSkip": [],
"files": {
"": "forces",
"": "positions",
input_json = """{
"metaInfoFile": "metainfo.json",
"tmpDir": "/home",
"metainfoToKeep": [],
"metainfoToSkip": [],
"files": {": "forces",
"": "positions"
parser = MyParser(json.dumps(input_json))
The 'metaInfoFile' contains the metainfo definitions used by the parser. From
this file the parser can determine the type and shape and excistence of
metainfo definitions.
The input JSON string is used to initialize the parser. The 'metaInfoFile'
attribute contains the metainfo definitions used by the parser. From this file
the parser can determine the type and shape and existence of metainfo
The 'files' object contains all the files that are given to the parser. The
attribute names are the file paths and their values are optional id's. The id's
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment