Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CHARMM files parsing and system building #23

Merged
merged 7 commits into from
Oct 20, 2022
49 changes: 24 additions & 25 deletions gamd/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def assign_tag(root, tagname, value, attributes=None):
xmlTag.text = str(value)
for attribute in attributes:
xmlTag.set(attribute, attributes[attribute])

return

class SystemConfig:
Expand All @@ -31,7 +31,7 @@ def __init__(self):
self.nonbonded_cutoff = 0.9*unit.nanometer
self.constraints = "HBonds"
return

def serialize(self, root):
assign_tag(root, "nonbonded-method", self.nonbonded_method)
assign_tag(root, "nonbonded-cutoff", self.nonbonded_cutoff.value_in_unit(unit.nanometers))
Expand All @@ -43,7 +43,7 @@ def __init__(self):
self.pressure = 1.0 * unit.bar
self.frequency = 25
return

def serialize(self, root):
assign_tag(root, "pressure", self.pressure.value_in_unit(unit.bar))
assign_tag(root, "frequency", self.frequency)
Expand All @@ -54,7 +54,7 @@ def __init__(self):
self.primary = 6.0 * unit.kilocalories_per_mole
self.secondary = 6.0 * unit.kilocalories_per_mole
return

def serialize(self, root):
assign_tag(root, "primary", self.primary.value_in_unit(unit.kilocalories_per_mole))
assign_tag(root, "secondary", self.secondary.value_in_unit(unit.kilocalories_per_mole))
Expand All @@ -70,7 +70,7 @@ def __init__(self):
self.total_simulation_length = 0
self.averaging_window_interval = 0
return

def serialize(self, root):
assign_tag(root, "conventional-md-prep", self.conventional_md_prep)
assign_tag(root, "conventional-md", self.conventional_md)
Expand All @@ -80,7 +80,7 @@ def serialize(self, root):
#assign_tag(root, "total-simulation-length", self.total_simulation_length)
assign_tag(root, "averaging-window-interval", self.averaging_window_interval)
return

def compute_total_simulation_length(self):
self.total_simulation_length = self.conventional_md \
+ self.gamd_equilibration + self.gamd_production
Expand All @@ -95,7 +95,7 @@ def __init__(self):
self.friction_coefficient = 1.0 * unit.picoseconds ** -1
self.number_of_steps = IntegratorNumberOfStepsConfig()
return

def serialize(self, root):
assign_tag(root, "algorithm", self.algorithm)
assign_tag(root, "boost-type", self.boost_type)
Expand All @@ -114,26 +114,25 @@ def __init__(self):
self.coordinates = ""
self.coordinates_filetype = ""
return

def serialize(self, root):
assign_tag(root, "topology", self.topology)
assign_tag(root, "coordinates", self.coordinates, {"type": self.coordinates_filetype})
return


class CharmmConfig:
def __init__(self):
self.topology = ""
self.coordinates = ""
self.parameters = []
self.parameters = ""
self.box_vector = ""
return

def serialize(self, root):
assign_tag(root, "topology", self.topology)
assign_tag(root, "coordinates", self.coordinates)
xmlParams = ET.SubElement(root, 'parameters')
for params_filename in self.parameters:
assign_tag(xmlParams, "file", params_filename)
assign_tag(root, "parameters", self.parameters)
assign_tag(root, "box_vector", self.box_vector)
return

class GromacsConfig:
Expand All @@ -142,7 +141,7 @@ def __init__(self):
self.coordinates = ""
self.include_dir = ""
return

def serialize(self, root):
assign_tag(root, "topology", self.topology)
assign_tag(root, "coordinates", self.coordinates)
Expand All @@ -155,7 +154,7 @@ def __init__(self):
self.forcefield_list_native = []
self.forcefield_list_external = []
return

def serialize(self, root):
assign_tag(root, "coordinates", self.coordinates)
xmlForcefields = ET.SubElement(root, "forcefields")
Expand All @@ -174,7 +173,7 @@ def __init__(self):
self.gromacs = None
self.forcefield = None
return

def serialize(self, root):
if self.amber is not None:
xml_amber_tags = ET.SubElement(root, "amber")
Expand All @@ -198,13 +197,13 @@ def __init__(self):
self.restart_checkpoint_interval = 50000
self.statistics_interval = 500
return

mdpoleto marked this conversation as resolved.
Show resolved Hide resolved
def compute_chunk_size(self):
gcd = np.gcd.reduce(
[self.energy_interval, self.coordinates_interval,
self.restart_checkpoint_interval, self.statistics_interval])
return gcd

def serialize(self, root):
xml_energy_tags = ET.SubElement(root, "energy")
assign_tag(xml_energy_tags, "interval", self.energy_interval)
Expand All @@ -220,7 +219,7 @@ def __init__(self):
self.overwrite_output = True
self.reporting = OutputsReportingConfig()
return

def serialize(self, root):
assign_tag(root, "directory", self.directory)
assign_tag(root, "overwrite-output", self.overwrite_output)
Expand All @@ -231,15 +230,15 @@ def serialize(self, root):
class Config:
def __init__(self):
# set all the default values

self.temperature = 298.15 * unit.kelvin
self.system = SystemConfig()
self.barostat = None #BarostatConfig()
self.run_minimization = True
self.integrator = IntegratorConfig()
self.input_files = InputFilesConfig()
self.outputs = OutputsConfig()

def serialize(self, filename):
root = ET.Element('gamd')
assign_tag(root, "temperature", self.temperature.value_in_unit(unit.kelvin))
Expand All @@ -255,13 +254,13 @@ def serialize(self, filename):
self.input_files.serialize(xml_input_files)
xml_outputs = ET.SubElement(root, "outputs")
self.outputs.serialize(xml_outputs)

xmlstr = minidom.parseString(ET.tostring(root)).toprettyxml(
indent=" ")
our_file=open(filename, 'w')
our_file.write(xmlstr)
our_file.close()


if __name__ == "__main__":
pass
pass
Loading