First version of Gaussian parser including geometry

parent 51277673
import setup_paths
from nomadcore.simple_parser import mainFunction, SimpleMatcher as SM
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
import os, sys, json
from nomadcore.caching_backend import CachingLevel
import os, sys, json, logging
import numpy as np
# description of the input
mainFileDescription = SM(
......@@ -10,14 +12,40 @@ mainFileDescription = SM(
startReStr = "",
subMatchers = [
SM(name = 'newRun',
startReStr = r"\s*# SampleParser #\s*",
startReStr = r"\s*Entering Link 1 ",
repeats = True,
required = True,
forwardMatch = True,
sections = ['section_run'],
sections = ['section_run','section_method'],
subMatchers = [
SM(name = 'header',
startReStr = r"\s*# SampleParser #\s*")
startReStr = r"\s*Entering Link 1 ",
subMatchers = [
SM(r"\s*Cite this work as:"),
SM(r"\s*Gaussian [0-9]+, Revision [A-Za-z0-9.]*,"),
SM(r"\s\*\*\*\*\*\*\*\*\*\*\*\**"),
SM(r"\s*(?P<program_name>Gaussian)\s*(?P<program_version>[0-9]*:\s.*)")
]
),
SM(name = 'globalparams',
startReStr = r"\s*%\w*=",
subFlags = SM.SubFlags.Unordered,
forwardMatch = True,
subMatchers = [
SM(r"\s*%[Cc]hk=(?P<gaussian_chk_file>[A-Za-z0-9.]*)"),
SM(r"\s*%[Mm]em=(?P<gaussian_memory>[A-Za-z0-9.]*)"),
SM(r"\s*%[Nn][Pp]roc=(?P<gaussian_number_of_processors>[A-Za-z0-9.]*)"),
]
),
SM(name = 'geometry_charge_multiplicity',
sections = ['section_system_description','gaussian_section_geometry'],
startReStr = r"\s*Symbolic Z-matrix:",
subMatchers = [
SM(r"\s*Charge =\s*(?P<total_charge>[-+0-9]+) Multiplicity =\s*(?P<target_multiplicity>[0-9]+)"),
SM(r"\s*(?P<gaussian_atom_label>\w+)\s+(?P<gaussian_atom_x_coord__angstrom>[-+0-9EeDd.]+)\s+(?P<gaussian_atom_y_coord__angstrom>[-+0-9EeDd.]+)\s+(?P<gaussian_atom_z_coord__angstrom>[-+0-9EeDd.]+)",
repeats = True)
]),
SM(r"\s*NAtoms=")
])
])
......@@ -33,23 +61,36 @@ parserInfo = {
class GaussianParserContext(object):
"""main place to keep the parser status, open ancillary files,..."""
def __init__(self):
self.scfIterNr = 0
# just examples, you probably want to remove the following two triggers
pass
def onClose_section_single_configuration_calculation(self, backend, gIndex, section):
"""trigger called when section_single_configuration_calculation is closed"""
#backend.addValue("", self.scfIterNr)
logging.getLogger("nomadcore.parsing").info("closing section_single_configuration_calculation gIndex %d %s", gIndex, section.simpleValues)
self.scfIterNr = 0
def startedParsing(self, path, parser):
self.parser = parser
def onClose_section_scf_iteration(self, backend, gIndex, section):
"""trigger called when section_scf_iteration is closed"""
logging.getLogger("nomadcore.parsing").info("closing section_scf_iteration bla gIndex %d %s", gIndex, section.simpleValues)
self.scfIterNr += 1
def onClose_gaussian_section_geometry(self, backend, gIndex, section):
xCoord = section["gaussian_atom_x_coord"]
yCoord = section["gaussian_atom_y_coord"]
zCoord = section["gaussian_atom_z_coord"]
labels = section["gaussian_atom_label"]
logging.error("x:%s",xCoord)
logging.error("y:%s",yCoord)
logging.error("z:%s",zCoord)
logging.error("labels:%s",labels)
atom_positions = np.zeros((len(xCoord),3), dtype=float)
for i in range(len(xCoord)):
atom_positions[i,0] = xCoord[i]
atom_positions[i,1] = yCoord[i]
atom_positions[i,2] = zCoord[i]
backend.addArrayValues("atom_position", atom_positions)
backend.addValue("atom_label", labels)
# which values to cache or forward (mapping meta name -> CachingLevel)
cachingLevelForMetaName = {}
cachingLevelForMetaName = {
"gaussian_atom_x_coord": CachingLevel.Cache,
"gaussian_atom_y_coord": CachingLevel.Cache,
"gaussian_atom_z_coord": CachingLevel.Cache,
"gaussian_atom_label": CachingLevel.Cache,
"gaussian_section_geometry": CachingLevel.Ignore,
}
if __name__ == "__main__":
mainFunction(mainFileDescription, metaInfoEnv, parserInfo,
......
%mem=24000000
#B1B95/6-31G**
atom calc
casno=7429905
method=55
basis=3
0 2
Al
This diff is collapsed.
%chk=ZnO10pbe
%mem=1500mb
%nproc=12
#p pbepbe/6-31G* td(singlets,nstates=10)
ZnO 10
0 1
O 3.25422625 1.27930585 -2.54529614
Zn 2.24859735 -0.44790645 -2.74547013
O 3.22448354 -2.01425234 -3.19002709
Zn 3.40374636 -1.80554341 -5.20959503
O 5.25270943 -2.29560427 -5.24774549
Zn 5.99419054 -0.54286846 -5.22935256
O 6.28848283 -0.42881245 -3.16157625
Zn 5.12324614 -1.93265943 -3.19033674
Zn 4.96040891 0.94341796 -3.28777063
O 5.13698492 1.15172617 -5.30695890
Zn 0.60201850 -0.16611529 -5.28308763
O 2.30611968 -0.50267796 -6.02913818
Zn 3.31139087 1.22419605 -5.82287052
O -0.72661336 1.20584185 -5.41057105
Zn -0.43367086 1.32094499 -3.34238586
O 0.42394706 -0.37365245 -3.26432151
Zn 2.15599088 2.58444037 -3.36102890
O 0.30716576 3.07376050 -3.32446397
Zn 0.43812201 2.71026983 -5.38146546
O 2.33665319 2.79214294 -5.38100795
This diff is collapsed.
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