Commit b16155f7 authored by Ask Hjorth Larsen's avatar Ask Hjorth Larsen
Browse files

fix array lengths when same thing is parsed multiple times

parent c39af793
...@@ -29,16 +29,20 @@ def siesta_energy(title, meta, **kwargs): ...@@ -29,16 +29,20 @@ def siesta_energy(title, meta, **kwargs):
def ArraySM(header, row, build, **kwargs): def ArraySM(header, row, build, **kwargs):
lines = []
def addrow(parser): class LineBuf:
line = parser.fIn.readline() def __init__(self):
lines.append(line) self.lines = []
def _build_array(parser): def addrow(self, parser):
build(parser.backend.superBackend, lines) line = parser.fIn.readline()
self.lines.append(line)
def _build_array(self, parser):
build(parser.backend.superBackend, self.lines)
self.lines = []
linebuf = LineBuf()
sm = SM(header, sm = SM(header,
name=kwargs.pop('name', 'startarray'), name=kwargs.pop('name', 'startarray'),
required=True, required=True,
...@@ -46,8 +50,8 @@ def ArraySM(header, row, build, **kwargs): ...@@ -46,8 +50,8 @@ def ArraySM(header, row, build, **kwargs):
subMatchers=[ subMatchers=[
SM(row, name='array', repeats=True, SM(row, name='array', repeats=True,
forwardMatch=True, forwardMatch=True,
adHoc=addrow, required=True), adHoc=linebuf.addrow, required=True),
SM(r'', endReStr='', adHoc=_build_array, name='endarray', SM(r'', endReStr='', adHoc=linebuf._build_array, name='endarray',
forwardMatch=True) forwardMatch=True)
], ],
**kwargs) **kwargs)
...@@ -184,45 +188,52 @@ infoFileDescription = SM( ...@@ -184,45 +188,52 @@ infoFileDescription = SM(
r'\s*[0-9]+\s+\S+\s+\S+\s+\S+', r'\s*[0-9]+\s+\S+\s+\S+\s+\S+',
get_forces, name='forces-in-opt-step'), get_forces, name='forces-in-opt-step'),
SM(r'Target enthalpy', name='end-singleconfig'), SM(r'Target enthalpy', name='end-singleconfig'),
SM(r'', weak=True, name='After singleconfigs', # As we get past the last singleconfig, we need to add all the stuff
subFlags=SM.SubFlags.Sequenced, # that pertains only to the last one, basically eigs and occs.
subMatchers=[ # Therefore we read a bit past the last config and try to trigger
# this as appropriate.
#SM(r'outcoor: Relaxed atomic coordinates',
# adHoc=read_eigenvalues),
#])
SM(r'', weak=True, name='After singleconfigs',
subFlags=SM.SubFlags.Sequenced,
subMatchers=[
# There is a stupid header in the middle of nowhere which is # There is a stupid header in the middle of nowhere which is
# equal to a later header, so we swallow it here: # equal to a later header, so we swallow it here:
#SM(r'siesta: Atomic forces \(eV/Ang\):'), #SM(r'siesta: Atomic forces \(eV/Ang\):'),
ArraySM(r'siesta: Atomic forces \(eV/Ang\):', ArraySM(r'siesta: Atomic forces \(eV/Ang\):',
r'siesta:\s*[0-9]+\s+\S+\s+\S+\s+\S+', r'siesta:\s*[0-9]+\s+\S+\s+\S+\s+\S+',
get_forces, name='forces-in-single-calc'), get_forces, name='forces-in-single-calc'),
SM(r'siesta: Program\'s energy decomposition \(eV\):', SM(r'siesta: Program\'s energy decomposition \(eV\):',
name='energy header 1', name='energy header 1',
weak=True, weak=True,
subMatchers=[ subMatchers=[
siesta_energy('FreeEng', 'energy_free') siesta_energy('FreeEng', 'energy_free')
]), ]),
SM(r'siesta: Final energy \(eV\):', SM(r'siesta: Final energy \(eV\):',
name='energy header 2', name='energy header 2',
subMatchers=[ subMatchers=[
siesta_energy('Band Struct\.', 'energy_sum_eigenvalues'), siesta_energy('Band Struct\.', 'energy_sum_eigenvalues'),
siesta_energy('Kinetic', 'electronic_kinetic_energy'), siesta_energy('Kinetic', 'electronic_kinetic_energy'),
siesta_energy('Hartree', 'energy_electrostatic'), siesta_energy('Hartree', 'energy_electrostatic'),
#siesta_energy('Ext\. field', ''), #siesta_energy('Ext\. field', ''),
siesta_energy('Exch\.-corr\.', 'energy_XC'), siesta_energy('Exch\.-corr\.', 'energy_XC'),
#siesta_energy('Ion-electron', ''), #siesta_energy('Ion-electron', ''),
#siesta_energy('Ion-Ion', ''), #siesta_energy('Ion-Ion', ''),
#siesta_energy('Ekinion', ''), #siesta_energy('Ekinion', ''),
siesta_energy('Total', 'energy_total'), siesta_energy('Total', 'energy_total'),
]), ]),
ArraySM(r'siesta: Stress tensor \(static\) \(eV/Ang\*\*3\):', ArraySM(r'siesta: Stress tensor \(static\) \(eV/Ang\*\*3\):',
r'siesta:\s*\S+\s+\S+\s+\S+', r'siesta:\s*\S+\s+\S+\s+\S+',
get_stress), get_stress),
ArraySM(r'siesta: Electric dipole \(Debye\)\s*=', ArraySM(r'siesta: Electric dipole \(Debye\)\s*=',
r'siesta: Electric dipole \(Debye\)\s*=', r'siesta: Electric dipole \(Debye\)\s*=',
get_dipole, get_dipole,
forwardMatch=True), forwardMatch=True),
# The purpose of the following matcher is to parse all lines # The purpose of the following matcher is to parse all lines
SM(r'x^', name='end') SM(r'x^', name='end')
]) ])
]), ])
]) ])
class SiestaContext(object): class SiestaContext(object):
......
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