def setup_viologen_implicit(): """ Set up viologen in implicit solvent """ viologen = SystemSetup() viologen.temperature = 300.0 * unit.kelvin viologen.pressure = 1.0 * unit.atmospheres viologen.timestep = 1.0 * unit.femtoseconds viologen.collision_rate = 1.0 / unit.picoseconds viologen.pH = 7.0 testsystems = get_test_data("viologen", "testsystems") viologen.ffxml_files = os.path.join(testsystems, "viologen-protons.ffxml") viologen.gaff = os.path.join(testsystems, "gaff.xml") viologen.forcefield = ForceField(viologen.gaff, "gaff-obc2.xml", viologen.ffxml_files) viologen.pdbfile = app.PDBFile( os.path.join(testsystems, "viologen-vacuum.pdb")) viologen.topology = viologen.pdbfile.topology viologen.positions = viologen.pdbfile.getPositions(asNumpy=True) viologen.constraint_tolerance = 1.0e-7 viologen.integrator = openmm.LangevinIntegrator( viologen.temperature, viologen.collision_rate, viologen.timestep) viologen.integrator.setConstraintTolerance( viologen.constraint_tolerance) viologen.system = viologen.forcefield.createSystem( viologen.topology, nonbondedMethod=app.NoCutoff, constraints=app.HBonds) viologen.cooh1 = { # indices in topology of the first cooh group "HO": 56, "OH": 0, "CO": 1, "OC": 2, "R": 3, } viologen.cooh2 = { # indices in topology of the second cooh group "HO": 57, "OH": 27, "CO": 25, "OC": 26, "R": 24, } viologen.simulation = app.Simulation( viologen.topology, viologen.system, viologen.integrator, TestCarboxylicAcid.platform, ) viologen.simulation.context.setPositions(viologen.positions) viologen.context = viologen.simulation.context viologen.perturbations_per_trial = 10 viologen.propagations_per_step = 1 return viologen
def test_modeller(self): """Test addition of hydrogens to a PDB file using modeller.""" pdb = app.PDBFile( get_test_data("glu_ala_his_noH.pdb", "testsystems/tripeptides/")) forcefield = app.ForceField("amber10-constph.xml", "ions_tip3p.xml", "tip3p.xml") modeller = app.Modeller(pdb.topology, pdb.positions) modeller.addHydrogens(forcefield) # Should have 59 hydrogens after adding them assert modeller.topology.getNumAtoms() == 59 system = forcefield.createSystem(modeller.topology)
def xml_to_topology(topology_elem: etree.Element) -> app.Topology: """From a TopologyFile xml element, create a topology""" text = topology_elem.text fileio = StringIO(text) topo_format = topology_elem.attrib["format"].lower() if topo_format == "pdbx": loaded = app.PDBxFile(fileio) elif topo_format == "pdb": loaded = app.PDBFile(fileio) else: raise ValueError(f"Unsupported topology format: '{topo_format}'.") return loaded.getTopology()
def setup_amino_acid_water(three_letter_code): """ Set up glutamic acid in water """ if three_letter_code not in ["glh", "ash"]: raise ValueError("Amino acid not available.") aa = SystemSetup() aa.temperature = 300.0 * unit.kelvin aa.pressure = 1.0 * unit.atmospheres aa.timestep = 1.0 * unit.femtoseconds aa.collision_rate = 1.0 / unit.picoseconds aa.pH = 7.0 testsystems = get_test_data("amino_acid", "testsystems") aa.ffxml_files = "amber10-constph.xml" aa.forcefield = ForceField(aa.ffxml_files, "tip3p.xml") aa.pdbfile = app.PDBFile( os.path.join(testsystems, "{}.pdb".format(three_letter_code))) aa.topology = aa.pdbfile.topology aa.positions = aa.pdbfile.getPositions(asNumpy=True) aa.constraint_tolerance = 1.0e-7 aa.integrator = create_compound_gbaoab_integrator(aa) aa.integrator.setConstraintTolerance(aa.constraint_tolerance) aa.system = aa.forcefield.createSystem( aa.topology, nonbondedMethod=app.PME, nonbondedCutoff=1.0 * unit.nanometers, constraints=app.HBonds, rigidWater=True, ewaldErrorTolerance=0.0005, ) aa.system.addForce( openmm.MonteCarloBarostat(aa.pressure, aa.temperature, 25)) aa.simulation = app.Simulation(aa.topology, aa.system, aa.integrator, TestCarboxylicAcid.platform) aa.simulation.context.setPositions(aa.positions) aa.context = aa.simulation.context aa.perturbations_per_trial = 1000 aa.propagations_per_step = 1 return aa
def setup_peptide_implicit(name: str, minimize=True, createsim=True): """ Set up implicit solvent peptide name - name of the peptide file. The folder "name_implicit" needs to exist, and "name".pdb needs to exist in the folder. minimize = Minimize the system before running (recommended) Works only if simulation is created createsim - instantiate simulation class If False, minimization is not performed. """ peptide = SystemSetup() peptide.temperature = 300.0 * unit.kelvin # hahaha.pressure = 1.0 * unit.atmospheres peptide.timestep = 2.0 * unit.femtoseconds peptide.collision_rate = 1.0 / unit.picoseconds peptide.pH = 7.0 peptide.perturbations_per_trial = 0 # instantaneous monte carlo peptide.propagations_per_step = 1 testsystems = get_test_data("{}_implicit".format(name), "testsystems") peptide.ffxml_files = os.path.join("amber10-constph.xml") peptide.forcefield = ForceField(peptide.ffxml_files, "amber10-constph-obc2.xml") peptide.pdbfile = app.PDBFile(os.path.join(testsystems, "{}.pdb".format(name))) peptide.topology = peptide.pdbfile.topology peptide.positions = peptide.pdbfile.getPositions(asNumpy=True) # Quick fix for histidines in topology # Openmm relabels them HIS, which leads to them not being detected as # titratable. Renaming them fixes this. for residue in peptide.topology.residues(): if residue.name == "HIS": residue.name = "HIP" peptide.constraint_tolerance = 1.0e-7 peptide.integrator = create_compound_gbaoab_integrator(peptide) peptide.system = peptide.forcefield.createSystem( peptide.topology, nonbondedMethod=app.NoCutoff, constraints=app.HBonds ) peptide.drive = ForceFieldProtonDrive( peptide.temperature, peptide.topology, peptide.system, peptide.forcefield, peptide.ffxml_files, perturbations_per_trial=peptide.perturbations_per_trial, propagations_per_step=peptide.propagations_per_step, residues_by_name=None, residues_by_index=None, ) if createsim: peptide.simulation = app.ConstantPHSimulation( peptide.topology, peptide.system, peptide.integrator, peptide.drive, platform=TestSAMS.platform, ) peptide.simulation.context.setPositions(peptide.positions) peptide.context = peptide.simulation.context if minimize: peptide.simulation.minimizeEnergy() return peptide
# coding=utf-8 """ Adds hydrogens to 2HYY-noH.pdb """ from protons import app from simtk.openmm import openmm from simtk.unit import * from protons.app.integrators import GBAOABIntegrator # Load relevant template definitions for modeller, forcefield and topology app.Modeller.loadHydrogenDefinitions('imatinib-hydrogens.xml') forcefield = app.ForceField('amber10-constph.xml', 'gaff.xml', 'imatinib.xml', 'tip3p.xml', 'ions_tip3p.xml') pdb = app.PDBFile('2HYY-noH.pdb') modeller = app.Modeller(pdb.topology, pdb.positions) # The pdb contains solvent but not the right ions. # This would mean we need to equilibrate again even if we just add new ions. # In this case its easiest to just delete and re-add the solvent with the right amount of ions modeller.deleteWater() ions = [ atom for atom in modeller.topology.atoms() if atom.element.symbol in ['Cl', 'Na'] ] modeller.delete(ions) modeller.addHydrogens(forcefield=forcefield) modeller.addSolvent(forcefield, model='tip3p', padding=1.0*nanometers, positiveIon='Na+', negativeIon='Cl-', ionicStrength=120*millimolar, neutralize=True)
def setup_viologen_water(): """ Set up viologen in water """ viologen = SystemSetup() viologen.temperature = 300.0 * unit.kelvin viologen.pressure = 1.0 * unit.atmospheres viologen.timestep = 1.0 * unit.femtoseconds viologen.collision_rate = 1.0 / unit.picoseconds viologen.pH = 7.0 testsystems = get_test_data("viologen", "testsystems") viologen.ffxml_files = os.path.join(testsystems, "viologen-protons-cooh.ffxml") viologen.gaff = os.path.join(testsystems, "gaff.xml") viologen.forcefield = ForceField(viologen.gaff, viologen.ffxml_files, "tip3p.xml") viologen.pdbfile = app.PDBFile( os.path.join(testsystems, "viologen-solvated.pdb")) viologen.topology = viologen.pdbfile.topology viologen.positions = viologen.pdbfile.getPositions(asNumpy=True) viologen.constraint_tolerance = 1.0e-7 viologen.integrator = create_compound_gbaoab_integrator(viologen) viologen.integrator.setConstraintTolerance( viologen.constraint_tolerance) viologen.system = viologen.forcefield.createSystem( viologen.topology, nonbondedMethod=app.PME, nonbondedCutoff=1.0 * unit.nanometers, constraints=app.HBonds, rigidWater=True, ewaldErrorTolerance=0.0005, ) viologen.system.addForce( openmm.MonteCarloBarostat(viologen.pressure, viologen.temperature, 25)) viologen.cooh1 = { # indices in topology of the first cooh group "HO": 56, "OH": 1, "CO": 0, "OC": 2, "R": 3, } viologen.cooh2 = { # indices in topology of the second cooh group "HO": 57, "OH": 27, "CO": 25, "OC": 26, "R": 24, } viologen.simulation = app.Simulation( viologen.topology, viologen.system, viologen.integrator, TestCarboxylicAcid.platform, ) viologen.simulation.context.setPositions(viologen.positions) viologen.context = viologen.simulation.context viologen.perturbations_per_trial = 1000 viologen.propagations_per_step = 1 return viologen