Planned maintenance on Wednesday, 2021-01-20, 17:00-18:00. Expect some interruptions during that time

Commit d6e15e4b authored by Carl Poelking's avatar Carl Poelking

Cross-references in backend topology.

parent 11db537f
......@@ -12,8 +12,8 @@ from contextlib import contextmanager
from libDlPolyParser import *
try:
from momo import osio, endl, flush
#osio.ConnectToFile('dl_poly.log')
from libMomo import osio, endl, flush
osio.ConnectToFile('parser.osio.log')
green = osio.mg
except:
osio = endl = flush = None
......@@ -27,8 +27,9 @@ parser_info = {
}
# LOGGING
def log(msg, highlight=osio.ww, enter=endl):
def log(msg, highlight=None, enter=endl):
if osio:
if highlight==None: hightlight = osio.ww
osio << highlight << msg << enter
return
......@@ -36,7 +37,7 @@ def log(msg, highlight=osio.ww, enter=endl):
@contextmanager
def open_section(p, name):
gid = p.openSection(name)
yield
yield gid
p.closeSection(name, gid)
def push(jbe, terminal, key1, fct=lambda x: x.As(), key2=None):
......@@ -45,6 +46,10 @@ def push(jbe, terminal, key1, fct=lambda x: x.As(), key2=None):
jbe.addValue(key1, value)
return value
def push_value(jbe, value, key):
jbe.addValue(key, value)
return value
def parse(output_file_name):
jbe = JsonParseEventsWriterBackend(meta_info_env)
jbe.startedParsingSession(output_file_name, parser_info)
......@@ -54,13 +59,12 @@ def parse(output_file_name):
terminal_ctrls = DlPolyControls(osio)
terminal_ctrls.ParseControls(ctrl_file_name)
# PARSE OUTPUT / TOPOLOGY ...
output_file_name = 'OUTPUT'
terminal = DlPolyParser(osio)
terminal.ParseOutput(output_file_name)
# PARSE TRAJECTORY ...
cfg_file_name = 'CONFIG'
terminal_trj = DlPolyConfig(osio)
terminal_trj.ParseConfig(cfg_file_name)
terminal_trj.ParseConfig(cfg_file_name)
# SUMMARIZE KEY-TABLE DEFAULTS ...
terminal.SummarizeKeyDefaults()
terminal.topology.SummarizeKeyDefaults()
......@@ -72,7 +76,7 @@ def parse(output_file_name):
top = terminal.topology
trj = terminal_trj
ofs = open('keys.log', 'w')
ofs = open('parser.keys.log', 'w')
terminals = [ctr, out, top, trj]
for t in terminals:
keys = sorted(t.data.keys())
......@@ -82,35 +86,74 @@ def parse(output_file_name):
ofs.close()
# PUSH TO BACKEND
with open_section(jbe, 'section_run'):
with open_section(jbe, 'section_run') as gid_run:
push(jbe, out, 'program_name')
push(jbe, out, 'program_version')
push(jbe, out, 'program_info', key2='program_version_date')
with open_section(jbe, 'section_topology'):
# TOPOLOGY SECTION
with open_section(jbe, 'section_topology') as gid_top:
# Cross-referencing is done on-the-fly (as gid's become available)
# a) <molecule_to_molecule_type> : shape=(number_of_topology_molecules, [<gid>])
# b) <atom_in_molecule_to_atom_type_ref> : shape=(number_of_atoms_in_molecule, [<gid>])
# c) <atom_to_molecule> : shape=(number_of_topology_atoms, [<molidx>, <atomidx>])
push(jbe, top, 'number_of_topology_molecules', lambda s: s.As(int))
push(jbe, top, 'number_of_topology_atoms', lambda s: s.As(int))
# Molecule types
for mol in top.molecules:
with open_section(jbe, 'section_molecule_type'):
push(jbe, mol, 'molecule_type_name')
push(jbe, mol, 'number_of_atoms_in_molecule', lambda s: s.As(int))
# TODO settings_atom_... is abstract type => set atom_in_molecule_charge via list,
# TODO same for atom_in_molecule_name
# TODO atom_to_molecule, molecule_to_molecule_type, atom_in_molecule_to_atom_type_ref
for atom in mol.atoms:
with open_section(jbe, 'settings_atom_in_molecule'):
push(jbe, atom, 'atom_in_molecule_charge', lambda s: s.As(float), 'atom_charge')
push(jbe, atom, 'atom_in_molecule_name', lambda s: s.As(), 'atom_name')
push(jbe, top, 'number_of_topology_atoms', lambda s: s.As(int))
# Atom types
mol_type_atom_type_id_to_atom_type_gid = {}
for mol in top.molecules:
mol_name = mol['molecule_type_name'].As()
mol_type_atom_type_id_to_atom_type_gid[mol_name] = {}
for atom in mol.atoms:
with open_section(jbe, 'section_atom_type'):
# Add type
with open_section(jbe, 'section_atom_type') as gid_atom:
atom_id = atom['atom_id'].As(int)
mol_type_atom_type_id_to_atom_type_gid[mol_name][atom_id] = gid_atom
push(jbe, atom, 'atom_type_name', lambda s: s.As(), 'atom_name')
push(jbe, atom, 'atom_type_mass', lambda s: s.As(float), 'atom_mass')
push(jbe, atom, 'atom_type_charge', lambda s: s.As(float), 'atom_charge')
push(jbe, atom, 'atom_type_charge', lambda s: s.As(float), 'atom_charge')
# Molecule types
molecule_type_name_to_type_gid = {}
for mol in top.molecules:
mol_name = mol['molecule_type_name'].As()
# Extract references of atoms to atom types
atom_type_id_to_atom_type_gid = mol_type_atom_type_id_to_atom_type_gid[mol_name]
atom_gid_list = []
for atom in mol.atoms:
atom_id = atom['atom_id'].As(int)
atom_gid_list.append(atom_type_id_to_atom_type_gid[atom_id])
# Add molecule
with open_section(jbe, 'section_molecule_type') as gid_mol:
molecule_type_name_to_type_gid[mol['molecule_type_name'].As()] = gid_mol
push(jbe, mol, 'molecule_type_name')
push(jbe, mol, 'number_of_atoms_in_molecule', lambda s: s.As(int))
push(jbe, mol, 'atom_in_molecule_name')
push(jbe, mol, 'atom_in_molecule_charge')
push_value(jbe, atom_gid_list, 'atom_in_molecule_to_atom_type_ref')
# Global molecule type map
molecule_to_molecule_type = []
for mol in top.molecules:
type_name_this_mol = mol['molecule_type_name'].As()
type_gid_this_mol = molecule_type_name_to_type_gid[type_name_this_mol]
n_this_mol = mol['number_of_molecules'].As(int)
for i in range(n_this_mol):
molecule_to_molecule_type.append(type_gid_this_mol)
push_value(jbe, molecule_to_molecule_type, 'molecule_to_molecule_type_map')
# Global atom map
atoms_to_molidx_atomidx = []
molidx = 0
for mol in top.molecules:
n_mol = mol['number_of_molecules'].As(int)
for i in range(n_mol):
atomidx = 0
for atom in mol.atoms:
molidx_atomidx = [ molidx, atomidx ]
atoms_to_molidx_atomidx.append(molidx_atomidx)
atomidx += 1
molidx += 1
push_value(jbe, atoms_to_molidx_atomidx, 'atom_to_molecule')
# SAMPLING-METHOD SECTION
with open_section(jbe, 'section_sampling_method'):
# Ensemble
ensemble = push(jbe, out, 'ensemble_type', lambda s: s.As().split()[0].upper())
......@@ -127,7 +170,8 @@ def parse(output_file_name):
push(jbe, out, 'barostat_target_pressure', lambda s: s.As(float))
push(jbe, out, 'barostat_tau', lambda s: s.As(float))
pass
# FRAME-SEQUENCE SECTION
with open_section(jbe, 'section_frame_sequence'):
pass
......@@ -150,9 +194,7 @@ if __name__ == '__main__':
extraArgsHandling=InfoKindEl.ADD_EXTRA_ARGS,
uri=None)
log("Parsing ...", green)
output_file_name = sys.argv[1]
parse(output_file_name)
log("... Done.", green)
parse(output_file_name)
......@@ -404,7 +404,7 @@ class DlPolyControls(DlPolyParser):
return
def ParseControls(self, ctrl_file):
if self.log:
self.log << self.log.endl << self.log.mg << "Start controls ..." << self.log.endl
self.log << self.log.mg << "Start controls ..." << self.log.endl
ifs = FileStream(ctrl_file)
while not ifs.all_read():
ln = ifs.ln()
......@@ -575,6 +575,11 @@ class DlPolyMolecule(DlPolyParser):
break
assert atom_count == n_atoms
atom_charges = [ atom['atom_charge'].As(float) for atom in self.atoms ]
atom_names = [ atom['atom_name'].As() for atom in self.atoms ]
self.Set('atom_in_molecule_charge', atom_charges)
self.Set('atom_in_molecule_name', atom_names)
# TODO Parse interactions
return
......@@ -582,7 +587,7 @@ class DlPolyMolecule(DlPolyParser):
class DlPolyAtom(DlPolyParser):
def __init__(self, atom_properties, atom_property_labels, parser):
super(DlPolyAtom, self).__init__(parser.log)
if not self.log.debug: self.log = None
if self.log and not self.log.debug: self.log = None
self.logtag = 'atm'
for value, label in zip(atom_properties, atom_property_labels):
self.Set(label, value)
......
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