def serialise_system(self): """Create the OpenMM system; parametrise using frost; serialise the system.""" # Load the molecule using openforcefield pdb_file = app.PDBFile(f'{self.molecule.name}.pdb') # Now we need the connection info try using smiles string from rdkit rdkit = RDKit() molecule = Molecule.from_smiles( rdkit.get_smiles(f'{self.molecule.name}.pdb')) # Make the openMM system omm_topology = pdb_file.topology off_topology = Topology.from_openmm(omm_topology, unique_molecules=[molecule]) # Load the smirnoff99Frosst force field. forcefield = ForceField('test_forcefields/smirnoff99Frosst.offxml') # Parametrize the topology and create an OpenMM System. system = forcefield.create_openmm_system(off_topology) # Serialise the OpenMM system into the xml file with open('serialised.xml', 'w+') as out: out.write(XmlSerializer.serializeSystem(system))
def write_system_xml(self, file_name): """ Method that writes the OpenMM system stored in the `system` attribute to an XML file. Parameters ---------- file_name : str Name of the XML file to be written. Returns ------- `True` if file was closed successfully. `False` otherwise. """ from simtk.openmm import XmlSerializer logging.info( "Writing serialized system to XML file {}.".format(file_name)) serialized_system = XmlSerializer.serializeSystem(self.system) outfile = open(file_name, 'w') outfile.write(serialized_system) outfile.close() return outfile.close()
def serialise_system(self): """Serialise the amber style files into an openmm object.""" prmtop = app.AmberPrmtopFile(self.prmtop) system = prmtop.createSystem(nonbondedMethod=app.NoCutoff, constraints=None) with open('serialised.xml', 'w+') as out: out.write(XmlSerializer.serializeSystem(system))
def _serialise_system(self, system: System) -> None: """ Serialise a openMM system to file so that the parameters can be gathered. Args: system: A parameterised OpenMM system. """ xml = XmlSerializer.serializeSystem(system) with open("serialised.xml", "w+") as out: out.write(xml)
def serialise_system(self): """Serialise the input XML system using openmm.""" pdb = app.PDBFile(f'{self.molecule.name}.pdb') modeller = app.Modeller(pdb.topology, pdb.positions) forcefield = app.ForceField(self.xml) system = forcefield.createSystem(modeller.topology, nonbondedMethod=app.NoCutoff, constraints=None) xml = XmlSerializer.serializeSystem(system) with open('serialised.xml', 'w+') as out: out.write(xml)
def serialise_system(self): """Serialise the input XML system using openmm.""" pdb = app.PDBFile(f"{self.molecule.name}.pdb") modeller = app.Modeller(pdb.topology, pdb.positions) # if the user want the general qube forcefield make it here. if self.xml == "QUBE_general_pi.xml": qube_general() forcefield = app.ForceField(self.xml) system = forcefield.createSystem(modeller.topology, nonbondedMethod=app.NoCutoff, constraints=None) xml = XmlSerializer.serializeSystem(system) with open("serialised.xml", "w+") as out: out.write(xml)
def serialise_system(self): """Serialise the input XML system using openmm.""" pdb = app.PDBFile(f'{self.molecule.name}.pdb') modeller = app.Modeller(pdb.topology, pdb.positions) if self.input_file: forcefield = app.ForceField(self.input_file) else: try: forcefield = app.ForceField(self.molecule.name + '.xml') except FileNotFoundError: raise FileNotFoundError('No .xml type file found.') system = forcefield.createSystem(modeller.topology, nonbondedMethod=app.NoCutoff, constraints=None) xml = XmlSerializer.serializeSystem(system) with open('serialised.xml', 'w+') as out: out.write(xml)
def serialise_system(self): """Serialise the input XML system using openmm.""" pdb = app.PDBFile(f'{self.molecule.name}.pdb') modeller = app.Modeller(pdb.topology, pdb.positions) forcefield = app.ForceField(self.xml) # Check for virtual sites try: system = forcefield.createSystem(modeller.topology, nonbondedMethod=app.NoCutoff, constraints=None) except ValueError: print('Virtual sites were found in the xml file') modeller.addExtraParticles(forcefield) system = forcefield.createSystem(modeller.topology, nonbondedMethod=app.NoCutoff, constraints=None) xml = XmlSerializer.serializeSystem(system) with open('serialised.xml', 'w+') as out: out.write(xml)
def serialise_system(self): """Serialise the input XML system using openmm.""" modeller = app.Modeller(self.molecule.to_openmm_topology(), self.molecule.openmm_coordinates()) forcefield = app.ForceField(self.xml) # Check for virtual sites try: system = forcefield.createSystem(modeller.topology, nonbondedMethod=app.NoCutoff, constraints=None) except ValueError: print("Virtual sites were found in the xml file") modeller.addExtraParticles(forcefield) system = forcefield.createSystem(modeller.topology, nonbondedMethod=app.NoCutoff, constraints=None) xml = XmlSerializer.serializeSystem(system) with open("serialised.xml", "w+") as out: out.write(xml)
def serialise_system(self): """Create the OpenMM system; parametrise using frost; serialise the system.""" # Create an openFF molecule from the rdkit molecule off_molecule = Molecule.from_rdkit(self.molecule.rdkit_mol, allow_undefined_stereo=True) # Make the OpenMM system off_topology = off_molecule.to_topology() forcefield = ForceField("openff_unconstrained-1.0.0.offxml") try: # Parametrise the topology and create an OpenMM System. system = forcefield.create_openmm_system(off_topology) except ( UnassignedValenceParameterException, UnassignedBondParameterException, UnassignedProperTorsionParameterException, UnassignedAngleParameterException, UnassignedMoleculeChargeException, TypeError, ): # If this does not work then we have a molecule that is not in SMIRNOFF so we must add generics # and remove the charge handler to get some basic parameters for the moleucle new_bond = BondHandler.BondType( smirks="[*:1]~[*:2]", length="0 * angstrom", k="0.0 * angstrom**-2 * mole**-1 * kilocalorie", ) new_angle = AngleHandler.AngleType( smirks="[*:1]~[*:2]~[*:3]", angle="0.0 * degree", k="0.0 * mole**-1 * radian**-2 * kilocalorie", ) new_torsion = ProperTorsionHandler.ProperTorsionType( smirks="[*:1]~[*:2]~[*:3]~[*:4]", periodicity1="1", phase1="0.0 * degree", k1="0.0 * mole**-1 * kilocalorie", periodicity2="2", phase2="180.0 * degree", k2="0.0 * mole**-1 * kilocalorie", periodicity3="3", phase3="0.0 * degree", k3="0.0 * mole**-1 * kilocalorie", periodicity4="4", phase4="180.0 * degree", k4="0.0 * mole**-1 * kilocalorie", idivf1="1.0", idivf2="1.0", idivf3="1.0", idivf4="1.0", ) new_vdw = vdWHandler.vdWType( smirks="[*:1]", epsilon=0 * unit.kilocalories_per_mole, sigma=0 * unit.angstroms, ) new_generics = { "Bonds": new_bond, "Angles": new_angle, "ProperTorsions": new_torsion, "vdW": new_vdw, } for key, val in new_generics.items(): forcefield.get_parameter_handler(key).parameters.insert(0, val) # This has to be removed as sqm will fail with unknown elements del forcefield._parameter_handlers["ToolkitAM1BCC"] del forcefield._parameter_handlers["Electrostatics"] # Parametrize the topology and create an OpenMM System. system = forcefield.create_openmm_system(off_topology) # This will tag the molecule so run.py knows that generics have been used. self.fftype = "generics" # Serialise the OpenMM system into the xml file with open("serialised.xml", "w+") as out: out.write(XmlSerializer.serializeSystem(system))
def serialise_system(self): """Create the OpenMM system; parametrise using frost; serialise the system.""" # Create an openFF molecule from the rdkit molecule off_molecule = Molecule.from_rdkit(self.molecule.rdkit_mol, allow_undefined_stereo=True) # Make the OpenMM system off_topology = off_molecule.to_topology() # Load the smirnoff99Frosst force field. forcefield = ForceField('test_forcefields/smirnoff99Frosst.offxml') try: # Parametrize the topology and create an OpenMM System. system = forcefield.create_openmm_system(off_topology) except (UnassignedValenceParameterException, TypeError, UnassignedValenceParameterException): # If this does not work then we have a moleucle that is not in SMIRNOFF so we must add generics # and remove the charge handler to get some basic parameters for the moleucle new_bond = BondHandler.BondType( smirks='[*:1]~[*:2]', length="0 * angstrom", k="0.0 * angstrom**-2 * mole**-1 * kilocalorie") new_angle = AngleHandler.AngleType( smirks='[*:1]~[*:2]~[*:3]', angle="0.0 * degree", k="0.0 * mole**-1 * radian**-2 * kilocalorie") new_torsion = ProperTorsionHandler.ProperTorsionType( smirks='[*:1]~[*:2]~[*:3]~[*:4]', periodicity1="1", phase1="0.0 * degree", k1="0.0 * mole**-1 * kilocalorie", periodicity2="2", phase2="180.0 * degree", k2="0.0 * mole**-1 * kilocalorie", periodicity3="3", phase3="0.0 * degree", k3="0.0 * mole**-1 * kilocalorie", periodicity4="4", phase4="180.0 * degree", k4="0.0 * mole**-1 * kilocalorie", idivf1="1.0", idivf2="1.0", idivf3="1.0", idivf4="1.0") new_vdw = vdWHandler.vdWType(smirks='[*:1]', epsilon=0 * unit.kilocalories_per_mole, sigma=0 * unit.angstroms) new_generics = { 'Bonds': new_bond, 'Angles': new_angle, 'ProperTorsions': new_torsion, 'vdW': new_vdw } for key, val in new_generics.items(): forcefield.get_parameter_handler(key).parameters.insert(0, val) # This has to be removed as sqm will fail with unknown elements del forcefield._parameter_handlers['ToolkitAM1BCC'] # Parametrize the topology and create an OpenMM System. system = forcefield.create_openmm_system(off_topology) # This will tag the molecule so run.py knows that generics have been used. self.fftype = 'generics' # Serialise the OpenMM system into the xml file with open('serialised.xml', 'w+') as out: out.write(XmlSerializer.serializeSystem(system))