Source code for Scripts.DatabankLib.openmm_parser

from xml.etree import ElementTree as etree


[docs] def openmm_input(input, type): if type == "inp": return read_inp_input(input) elif type == "xml": return read_xml_input(input)
[docs] def read_inp_input(input): try: filename = open(input, "r") print(filename.name) except FileNotFoundError: print("File does not exist") with open(filename.name, "r") as f: tmp_type = [] tmp_value = [] for line in f: split = line.split() if len(split) > 2: tmp_type.append(split[0]) tmp_value.append(split[2]) return [tmp_type, tmp_value]
[docs] def read_xml_input(input): try: filename = open(input, "r") except FileNotFoundError: print("File does not exist") tree = etree.parse(filename.name) temp = [ value for key, value in tree.getroot()[1].attrib.items() if "temperature" in key.lower() ] return (["temp"], [temp])
[docs] class OpenMMParser: def __init__(self, filename, type): [properties, values] = openmm_input(filename, type) print(properties) self.temperature = float(values[properties.index("temp")]) # self.pressure = values[properties.index('p_ref')] # self.ptype = values[properties.index('p_type')] # self.dt = values[properties.index('dt')]
[docs] def set_tempurature(self, temp): self.temperature = temp
[docs] def set_pressure(self, pressure): self.pressure = pressure
[docs] def set_ptype(self, ptype): self.ptype = ptype
[docs] def set_dt(self, dt): self.dt = dt