Commit 005ba93a authored by Ask Hjorth Larsen's avatar Ask Hjorth Larsen
Browse files

get forces. Improve array matcher

parent 6677991a
......@@ -22,48 +22,13 @@ metaInfoEnv, warnings = loadJsonFile(filePath=metaInfoPath,
parser_info = {'name':'siesta-parser', 'version': '1.0'}
def siesta_energy(title, meta):
return SM(r'siesta:\s*%s\s*=\s*(?P<%s__eV>\S*)' % (title, meta),
name=meta)
def array_matcher():
def getarray():
pass
sm = SM()
return sm
#class ArrayParser(SM):
# def __init__(self, *args, **kwargs):
# SM.__init__(self, *args, adHoc=get_ar**kwargs)
#def array_line_matcher(*args, **kwargs):
# def
# sm = SimpleMatcher(*args, repeats=True, **kwargs)
# return sm
def get_positions_and_labels(parser):
rows = []
atomic_numbers = []
line = parser.fIn.readline()
while line.startswith('siesta:'):
tokens = line.split()
rows.append([float(x) for x in tokens[1:4]])
atomic_numbers.append(int(tokens[4]))
line = parser.fIn.readline()
rows = np.array(rows, float)
labels = np.array([chemical_symbols[Z] for Z in atomic_numbers])
b = parser.backend.superBackend
b.addArrayValues('atom_positions', convert_unit(rows, 'bohr'))
b.addArrayValues('atom_labels', labels)
#def get_cell(parser):
#
def siesta_energy(title, meta, **kwargs):
return SM(r'siesta:\s*%s\s*=\s*(?P<%s__eV>\S*)' % (title, meta),
name=meta, **kwargs)
def ArraySM(header, row, end, build):
def ArraySM(header, row, build, **kwargs):
lines = []
def addrow(parser):
......@@ -73,6 +38,7 @@ def ArraySM(header, row, end, build):
def _build_array(parser):
build(parser.backend.superBackend, lines)
sm = SM(header,
name='startarray',
required=True,
......@@ -81,15 +47,21 @@ def ArraySM(header, row, end, build):
SM(row, name='array', repeats=True,
forwardMatch=True,
adHoc=addrow, required=True),
SM(end, name='endarray', required=True),
SM(r'', adHoc=_build_array, name='dummy', forwardMatch=True)
])
SM(r'', endReStr='', adHoc=_build_array, name='endarray',
forwardMatch=True)
],
**kwargs)
return sm
def build_cell(backend, lines):
cell = np.array([[float(x) for x in line.split()] for line in lines])
backend.addArrayValues('simulation_cell', convert_unit(cell, 'angstrom'))
def get_forces(backend, lines):
arr = np.array([line.split() for line in lines], object)
forces = arr[:, 1:].astype(float)
backend.addArrayValues('atom_forces', convert_unit(forces, 'eV/angstrom'))
def add_positions_and_labels(backend, lines):
matrix = np.array([line.split() for line in lines], object)
positions = matrix[:, 1:4].astype(float)
......@@ -106,18 +78,27 @@ infoFileDescription = SM(
subFlags=SM.SubFlags.Sequenced, # sequenced or not?
subMatchers=[
SM(r'Siesta Version: (?P<program_name>siesta)-(?P<program_version>\S*)',
name='name&version'),
name='name&version', required=True),
ArraySM(r'siesta: Atomic coordinates \(Bohr\) and species',
r'siesta:', r'', add_positions_and_labels),
r'siesta:\s*\S+\s+\S+\s+\S+\s+\S+\s+\S+',
add_positions_and_labels),
SM(r'\s*Single-point calculation',
name='singleconfig',
sections=['section_single_configuration_calculation'],
subFlags=SM.SubFlags.Sequenced,
subMatchers=[
ArraySM(r'outcell: Unit cell vectors \(Ang\):',
r'\s*\S+\s*\S+\s*\S+',
r'\s*', build_cell),
build_cell),
SM(r'\s*scf:\s*iscf', name='scf', required=True),
SM(r'siesta: Program\'s energy decomposition \(eV\):',
name='energy header 1',
weak=True,
subMatchers=[
siesta_energy('FreeEng', 'energy_free')
]),
SM(r'siesta: Final energy \(eV\):',
name='energy_header',
name='energy header 2',
subMatchers=[
siesta_energy('Band Struct\.', 'energy_sum_eigenvalues'),
siesta_energy('Kinetic', 'electronic_kinetic_energy'),
......@@ -127,13 +108,16 @@ infoFileDescription = SM(
#siesta_energy('Ion-electron', ''),
#siesta_energy('Ion-Ion', ''),
#siesta_energy('Ekinion', ''),
siesta_energy('Total', 'energy_total')
])
siesta_energy('Total', 'energy_total'),
]),
ArraySM(r'siesta: Atomic forces \(eV/Ang\):',
r'siesta:\s*[0-9]+\s+\S+\s+\S+\s+\S+',
get_forces, weak=True)
])
])
class SiestaContext(object):
def startedParsing(self, *args, **kwargs):
def startedParsing(self, fname, parser):
pass
mainFunction(mainFileDescription=infoFileDescription,
......
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