def setUp(self): self.pdb = app.PDBFile('systems/alanine-dipeptide-implicit.pdb') self.forcefield = app.ForceField('amber99sbildn.xml') self.system = self.forcefield.createSystem( self.pdb.topology, nonbondedMethod=app.CutoffNonPeriodic, constraints=app.HBonds)
def test_local_coord_sites(): """Make sure that the internal prep of vs positions matches that given by OpenMM.""" # make a system mol = app.PDBFile(os.path.join("files", "vs_mol.pdb")) modeller = app.Modeller(topology=mol.topology, positions=mol.positions) forcefield = app.ForceField( os.path.join("files", "forcefield", "vs_mol.xml")) modeller.addExtraParticles(forcefield) system = forcefield.createSystem(modeller.topology, constraints=None) integrator = mm.VerletIntegrator(1.0 * unit.femtoseconds) platform = mm.Platform.getPlatformByName("Reference") simulation = app.Simulation(modeller.topology, system, integrator, platform) simulation.context.setPositions(modeller.positions) # update the site positions simulation.context.computeVirtualSites() # one vs and it should be last vs_pos = simulation.context.getState(getPositions=True).getPositions( asNumpy=True)[-1] # now compute and compare vsinfo = PrepareVirtualSites(system=system) new_pos = ResetVirtualSites_fast(positions=modeller.positions, vsinfo=vsinfo)[-1] assert np.allclose(vs_pos._value, np.array([new_pos.x, new_pos.y, new_pos.z]))
def simulate(pdbcode, pdb_filename): from openmm import app import openmm.openmm as mm from openmm import unit from sys import stdout # Load the PDB file. pdb = app.PDBFile(pdb_filename) # Set up implicit solvent forcefield. #forcefield = app.ForceField('amber99sbildn.xml') forcefield = app.ForceField('amber10.xml') # Create the system. system = forcefield.createSystem(pdb.topology, nonbondedMethod=app.NoCutoff, constraints=app.HBonds) # Create an integrator. integrator = mm.LangevinIntegrator(300 * unit.kelvin, 91.0 / unit.picoseconds, 1.0 * unit.femtoseconds) # Create a context. context = mm.Context(system, integrator) context.setPositions(pdb.positions) # Check to make sure energy is finite. state = context.getState(getEnergy=True) potential = state.getPotentialEnergy() / unit.kilocalories_per_mole if numpy.isnan(potential): raise Exception("Initial energy for %s is NaN." % pdbcode) # Minimize. tolerance = 1.0 * unit.kilocalories_per_mole / unit.angstroms maxIterations = 50 mm.LocalEnergyMinimizer.minimize(context, tolerance, maxIterations) # Check to make sure energy is finite. state = context.getState(getEnergy=True) potential = state.getPotentialEnergy() / unit.kilocalories_per_mole if numpy.isnan(potential): raise Exception("Energy for %s is NaN after minimization." % pdbcode) # Simulate. nsteps = 500 integrator.step(nsteps) # Check to make sure energy is finite. state = context.getState(getEnergy=True) potential = state.getPotentialEnergy() / unit.kilocalories_per_mole if numpy.isnan(potential): raise Exception("Energy for %s is NaN after simulation." % pdbcode) del context, integrator print("Simulation completed: potential = %.3f kcal/mol" % potential) return
def setUp(self): with open('systems/alanine-dipeptide-implicit.pdb') as f: pdb = app.PDBFile(f) forcefield = app.ForceField('amber99sbildn.xml') system = forcefield.createSystem(pdb.topology, nonbondedMethod=app.CutoffNonPeriodic, nonbondedCutoff=1.0*unit.nanometers, constraints=app.HBonds) self.simulation = app.Simulation(pdb.topology, system, mm.VerletIntegrator(0.002*unit.picoseconds)) self.simulation.context.setPositions(pdb.positions)
def testLongTrajectory(self): """Test writing a trajectory that has more than 2^31 steps.""" fname = tempfile.mktemp(suffix='.dcd') pdbfile = app.PDBFile('systems/alanine-dipeptide-implicit.pdb') natom = len(list(pdbfile.topology.atoms())) with open(fname, 'wb') as f: dcd = app.DCDFile(f, pdbfile.topology, 0.001, interval=1000000000) for i in range(5): dcd.writeModel([ mm.Vec3(random(), random(), random()) for j in range(natom) ] * unit.angstroms) os.remove(fname)
def test_dcd(self): """ Test the DCD file """ fname = tempfile.mktemp(suffix='.dcd') pdbfile = app.PDBFile('systems/alanine-dipeptide-implicit.pdb') natom = len(list(pdbfile.topology.atoms())) with open(fname, 'wb') as f: dcd = app.DCDFile(f, pdbfile.topology, 0.001) for i in range(5): dcd.writeModel([ mm.Vec3(random(), random(), random()) for j in range(natom) ] * unit.angstroms) os.remove(fname)
def _configure_amber_implicit( pdb_file: PathLike, top_file: Optional[PathLike], dt_ps: float, temperature_kelvin: float, heat_bath_friction_coef: float, platform: "openmm.Platform", platform_properties: dict, ) -> Tuple["app.Simulation", Optional["app.PDBFile"]]: # Configure system if top_file is not None: pdb = None top = app.AmberPrmtopFile(str(top_file)) system = top.createSystem( nonbondedMethod=app.CutoffNonPeriodic, nonbondedCutoff=1.0 * u.nanometer, constraints=app.HBonds, implicitSolvent=app.OBC1, ) else: pdb = app.PDBFile(str(pdb_file)) top = pdb.topology forcefield = app.ForceField("amber99sbildn.xml", "amber99_obc.xml") system = forcefield.createSystem( top, nonbondedMethod=app.CutoffNonPeriodic, nonbondedCutoff=1.0 * u.nanometer, constraints=app.HBonds, ) # Configure integrator integrator = openmm.LangevinIntegrator( temperature_kelvin * u.kelvin, heat_bath_friction_coef / u.picosecond, dt_ps * u.picosecond, ) integrator.setConstraintTolerance(0.00001) sim = app.Simulation(top, system, integrator, platform, platform_properties) # Returning the pdb file object for later use to reduce I/O. # If a topology file is passed, the pdb variable is None. return sim, pdb
def test_mutate_1(): fixer = pdbfixer.PDBFixer(pdbid='1VII') fixer.applyMutations(["ALA-57-GLY"], "A") fixer.findMissingResidues() fixer.findMissingAtoms() fixer.addMissingAtoms() fixer.addMissingHydrogens(7.0) with tempfile.NamedTemporaryFile(mode='w+') as temp_pdb: app.PDBFile.writeFile(fixer.topology, fixer.positions, temp_pdb) temp_pdb.flush() pdb = app.PDBFile(temp_pdb.name) new_residue57 = list(fixer.topology.residues())[16] assert new_residue57.name == "GLY", "Name of mutated residue did not change correctly!" assert len(list( new_residue57.atoms())) == 7, "Should have 7 atoms in GLY 56" atom_names = set([atom.name for atom in new_residue57.atoms()]) desired_atom_names = set(["N", "CA", "C", "O", "H", "HA3", "HA2"]) assert atom_names == desired_atom_names, "Atom Names did not match for GLY 56"
def testAppend(self): """Test appending to an existing trajectory.""" fname = tempfile.mktemp(suffix='.dcd') pdb = app.PDBFile('systems/alanine-dipeptide-implicit.pdb') ff = app.ForceField('amber99sb.xml', 'tip3p.xml') system = ff.createSystem(pdb.topology) # Create a simulation and write some frames to a DCD file. integrator = mm.VerletIntegrator(0.001 * unit.picoseconds) simulation = app.Simulation(pdb.topology, system, integrator, mm.Platform.getPlatformByName('Reference')) dcd = app.DCDReporter(fname, 2) simulation.reporters.append(dcd) simulation.context.setPositions(pdb.positions) simulation.context.setVelocitiesToTemperature(300 * unit.kelvin) simulation.step(10) self.assertEqual(5, dcd._dcd._modelCount) del simulation del dcd len1 = os.stat(fname).st_size # Create a new simulation and have it append some more frames. integrator = mm.VerletIntegrator(0.001 * unit.picoseconds) simulation = app.Simulation(pdb.topology, system, integrator, mm.Platform.getPlatformByName('Reference')) dcd = app.DCDReporter(fname, 2, append=True) simulation.reporters.append(dcd) simulation.context.setPositions(pdb.positions) simulation.context.setVelocitiesToTemperature(300 * unit.kelvin) simulation.step(10) self.assertEqual(10, dcd._dcd._modelCount) len2 = os.stat(fname).st_size self.assertTrue(len2 - len1 > 3 * 4 * 5 * system.getNumParticles()) del simulation del dcd os.remove(fname)
def create_openmm_system(sim_openmm, model, anchor, frame=0, load_state_file=None): """ Create an openmm System() object. """ building_directory = os.path.join(model.anchor_rootdir, anchor.directory, anchor.building_directory) box_vectors = None num_frames = 0 positions_obj = None if anchor.__class__.__name__ in ["MMVT_toy_anchor", "Elber_toy_anchor"]: if load_state_file is not None: positions = None num_frames = 1 elif anchor.starting_positions is not None: positions_frames = np.array(anchor.starting_positions) \ * openmm.unit.nanometers positions = positions_frames[frame] num_frames = len(positions_frames) else: raise Exception( "No starting state or starting positions provided.") else: if anchor.amber_params is not None: prmtop_filename = os.path.join(building_directory, anchor.amber_params.prmtop_filename) prmtop = openmm_app.AmberPrmtopFile(prmtop_filename) #assert anchor.amber_params.pdb_coordinates_filename is not None if anchor.amber_params.pdb_coordinates_filename is None \ or anchor.amber_params.pdb_coordinates_filename == "": positions_obj = None positions = None sim_openmm.try_to_load_state = True else: pdb_coordinates_filename = os.path.join( building_directory, anchor.amber_params.pdb_coordinates_filename) positions_obj = openmm_app.PDBFile(pdb_coordinates_filename) #assert anchor.amber_params.box_vectors is not None box_vectors = anchor.amber_params.box_vectors topology = prmtop.topology elif anchor.forcefield_params is not None: forcefield_filenames = [] for forcefield_filename in \ anchor.forcefield_params.built_in_forcefield_filenames: forcefield_filenames.append(forcefield_filename) for forcefield_filename in \ anchor.forcefield_params.custom_forcefield_filenames: forcefield_filenames.append( os.path.join(building_directory, forcefield_filename)) print("anchor.forcefield_params.pdb_filename:", anchor.forcefield_params.pdb_coordinates_filename) pdb_filename = os.path.join( building_directory, anchor.forcefield_params.pdb_coordinates_filename) print("pdb_filename:", pdb_filename) pdb = openmm_app.PDBFile(pdb_filename) forcefield = openmm_app.ForceField(*forcefield_filenames) box_vectors = anchor.forcefield_params.box_vectors topology = pdb.topology positions_obj = pdb positions = None elif anchor.charmm_params is not None: raise Exception("Charmm systems not yet implemented") else: raise Exception("No Amber or Charmm input settings detected.") #assert box_vectors is not None, "No source of box vectors provided." nonbonded_method = model.openmm_settings.nonbonded_method.lower() if nonbonded_method == "pme": nonbondedMethod = openmm_app.PME elif nonbonded_method == "nocutoff": nonbondedMethod = openmm_app.NoCutoff elif nonbonded_method == "cutoffnonperiodic": nonbondedMethod = openmm_app.CutoffNonPeriodic elif nonbonded_method == "cutoffperiodic": nonbondedMethod = openmm_app.CutoffPeriodic elif nonbonded_method == "ewald": nonbondedMethod = openmm_app.Ewald else: raise Exception("nonbonded method not found: %s", model.openmm_settings.nonbonded_method) if model.openmm_settings.constraints is None: constraints_str = None else: constraints_str = model.openmm_settings.constraints if constraints_str is None: constraints = None elif constraints_str.lower() == "none": constraints = None elif constraints_str.lower() == "hbonds": constraints = openmm_app.HBonds elif constraints_str.lower() == "allbonds": constraints = openmm_app.AllBonds elif constraints_str.lower() == "hangles": constraints = openmm_app.HAngles else: raise Exception("constraints not found: %s", model.openmm_settings.constraints) if model.openmm_settings.hydrogenMass is not None: hydrogenMass = model.openmm_settings.hydrogenMass * openmm.unit.amu else: hydrogenMass = None rigidWater = model.openmm_settings.rigidWater if anchor.__class__.__name__ in ["MMVT_toy_anchor", "Elber_toy_anchor"]: system, topology = make_toy_system_object(model) else: if anchor.amber_params is not None: system = prmtop.createSystem( nonbondedMethod=nonbondedMethod, nonbondedCutoff=model.openmm_settings.nonbonded_cutoff, constraints=constraints, hydrogenMass=hydrogenMass, rigidWater=rigidWater) elif anchor.forcefield_params is not None: system = forcefield.createSystem( pdb.topology, nonbondedMethod=nonbondedMethod, nonbondedCutoff=model.openmm_settings.nonbonded_cutoff, constraints=constraints, hydrogenMass=hydrogenMass, rigidWater=rigidWater) elif anchor.charmm_params is not None: raise Exception("Charmm input settings not yet implemented") else: print("Settings for Amber or Charmm simulations not found") if positions_obj is not None: positions = positions_obj.getPositions(frame=frame) assert frame >= 0, "Cannot have negative frame index" assert frame < positions_obj.getNumFrames(), \ "Frame index {} out of range.".format(frame) num_frames = positions_obj.getNumFrames() return system, topology, positions, box_vectors, num_frames
def configure_simulation( pdb_file: PathLike, top_file: Optional[PathLike], solvent_type: str, gpu_index: int, dt_ps: float, temperature_kelvin: float, heat_bath_friction_coef: float, explicit_barostat: str = "MonteCarloBarostat", run_minimization: bool = True, set_positions: bool = True, set_velocities: bool = True, ) -> "app.Simulation": """Configure an OpenMM amber simulation. Parameters ---------- pdb_file : PathLike The PDB file to initialize the positions (and topology if `top_file` is not present and the `solvent_type` is `implicit`). top_file : Optional[PathLike] The topology file to initialize the systems topology. solvent_type : str Solvent type can be either `implicit` or `explicit`, if `explicit` then `top_file` must be present. gpu_index : int The GPU index to use for the simulation. dt_ps : float The timestep to use for the simulation. temperature_kelvin : float The temperature to use for the simulation. heat_bath_friction_coef : float The heat bath friction coefficient to use for the simulation. explicit_barostat : str, optional The barostat used for an `explicit` solvent simulation can be either "MonteCarloBarostat" by deafult, or "MonteCarloAnisotropicBarostat". run_minimization : bool, optional Whether or not to run energy minimization, by default True. set_positions : bool, optional Whether or not to set positions (Loads the PDB file), by default True. set_velocities : bool, optional Whether or not to set velocities to temperature, by default True. Returns ------- app.Simulation Configured OpenMM Simulation object. """ # Configure hardware try: platform = openmm.Platform_getPlatformByName("CUDA") platform_properties = { "DeviceIndex": str(gpu_index), "CudaPrecision": "mixed" } except Exception: try: platform = openmm.Platform_getPlatformByName("OpenCL") platform_properties = {"DeviceIndex": str(gpu_index)} except Exception: platform = openmm.Platform_getPlatformByName("CPU") platform_properties = {} # Select implicit or explicit solvent configuration if solvent_type == "implicit": sim, pdb = _configure_amber_implicit( pdb_file, top_file, dt_ps, temperature_kelvin, heat_bath_friction_coef, platform, platform_properties, ) else: assert solvent_type == "explicit" assert top_file is not None pdb = None sim = _configure_amber_explicit( top_file, dt_ps, temperature_kelvin, heat_bath_friction_coef, platform, platform_properties, explicit_barostat, ) # Set the positions if set_positions: if pdb is None: pdb = app.PDBFile(str(pdb_file)) sim.context.setPositions(pdb.getPositions()) # Minimize energy and equilibrate if run_minimization: sim.minimizeEnergy() # Set velocities to temperature if set_velocities: sim.context.setVelocitiesToTemperature(temperature_kelvin * u.kelvin, random.randint(1, 10000)) return sim
def runOneTest(testName, options): """Perform a single benchmarking simulation.""" explicit = (testName not in ('gbsa', 'amoebagk')) amoeba = (testName in ('amoebagk', 'amoebapme')) apoa1 = testName.startswith('apoa1') amber = (testName.startswith('amber')) hydrogenMass = None print() if amoeba: print('Test: %s (epsilon=%g)' % (testName, options.epsilon)) elif testName == 'pme': print('Test: pme (cutoff=%g)' % options.cutoff) else: print('Test: %s' % testName) print('Ensemble: %s' % options.ensemble) platform = mm.Platform.getPlatformByName(options.platform) # Create the System. temperature = 300 * unit.kelvin if explicit: friction = 1 * (1 / unit.picoseconds) else: friction = 91 * (1 / unit.picoseconds) if amoeba: constraints = None epsilon = float(options.epsilon) if explicit: ff = app.ForceField('amoeba2009.xml') pdb = app.PDBFile('5dfr_solv-cube_equil.pdb') cutoff = 0.7 * unit.nanometers vdwCutoff = 0.9 * unit.nanometers system = ff.createSystem(pdb.topology, nonbondedMethod=app.PME, nonbondedCutoff=cutoff, vdwCutoff=vdwCutoff, constraints=constraints, ewaldErrorTolerance=0.00075, mutualInducedTargetEpsilon=epsilon, polarization=options.polarization) else: ff = app.ForceField('amoeba2009.xml', 'amoeba2009_gk.xml') pdb = app.PDBFile('5dfr_minimized.pdb') cutoff = 2.0 * unit.nanometers vdwCutoff = 1.2 * unit.nanometers system = ff.createSystem(pdb.topology, nonbondedMethod=app.NoCutoff, constraints=constraints, mutualInducedTargetEpsilon=epsilon, polarization=options.polarization) for f in system.getForces(): if isinstance(f, mm.AmoebaMultipoleForce) or isinstance( f, mm.AmoebaVdwForce) or isinstance( f, mm.AmoebaGeneralizedKirkwoodForce) or isinstance( f, mm.AmoebaWcaDispersionForce): f.setForceGroup(1) dt = 0.002 * unit.picoseconds if options.ensemble == 'NVE': integ = mm.MTSIntegrator(dt, [(0, 2), (1, 1)]) else: integ = mm.MTSLangevinIntegrator(temperature, friction, dt, [(0, 2), (1, 1)]) positions = pdb.positions elif amber: dirname = downloadAmberSuite() names = { 'amber20-dhfr': 'JAC', 'amber20-factorix': 'FactorIX', 'amber20-cellulose': 'Cellulose', 'amber20-stmv': 'STMV' } fileName = names[testName] prmtop = app.AmberPrmtopFile( os.path.join(dirname, f'PME/Topologies/{fileName}.prmtop')) inpcrd = app.AmberInpcrdFile( os.path.join(dirname, f'PME/Coordinates/{fileName}.inpcrd')) topology = prmtop.topology positions = inpcrd.positions dt = 0.004 * unit.picoseconds method = app.PME cutoff = options.cutoff constraints = app.HBonds system = prmtop.createSystem(nonbondedMethod=method, nonbondedCutoff=cutoff, constraints=constraints) if options.ensemble == 'NVE': integ = mm.VerletIntegrator(dt) else: integ = mm.LangevinMiddleIntegrator(temperature, friction, dt) else: if apoa1: ff = app.ForceField('amber14/protein.ff14SB.xml', 'amber14/lipid17.xml', 'amber14/tip3p.xml') pdb = app.PDBFile('apoa1.pdb') if testName == 'apoa1pme': method = app.PME cutoff = options.cutoff elif testName == 'apoa1ljpme': method = app.LJPME cutoff = options.cutoff else: method = app.CutoffPeriodic cutoff = 1 * unit.nanometers hydrogenMass = 1.5 * unit.amu elif explicit: ff = app.ForceField('amber99sb.xml', 'tip3p.xml') pdb = app.PDBFile('5dfr_solv-cube_equil.pdb') if testName == 'pme': method = app.PME cutoff = options.cutoff else: method = app.CutoffPeriodic cutoff = 1 * unit.nanometers else: ff = app.ForceField('amber99sb.xml', 'amber99_obc.xml') pdb = app.PDBFile('5dfr_minimized.pdb') method = app.CutoffNonPeriodic cutoff = 2 * unit.nanometers if options.heavy: dt = 0.005 * unit.picoseconds constraints = app.AllBonds hydrogenMass = 4 * unit.amu if options.ensemble == 'NVE': integ = mm.VerletIntegrator(dt) else: integ = mm.LangevinIntegrator(temperature, friction, dt) else: dt = 0.004 * unit.picoseconds constraints = app.HBonds if options.ensemble == 'NVE': integ = mm.VerletIntegrator(dt) else: integ = mm.LangevinMiddleIntegrator(temperature, friction, dt) positions = pdb.positions system = ff.createSystem(pdb.topology, nonbondedMethod=method, nonbondedCutoff=cutoff, constraints=constraints, hydrogenMass=hydrogenMass) if options.ensemble == 'NPT': system.addForce(mm.MonteCarloBarostat(1 * unit.bar, temperature, 100)) print('Step Size: %g fs' % dt.value_in_unit(unit.femtoseconds)) properties = {} initialSteps = 5 if options.device is not None and platform.getName() in ('CUDA', 'OpenCL'): properties['DeviceIndex'] = options.device if ',' in options.device or ' ' in options.device: initialSteps = 250 if options.precision is not None and platform.getName() in ('CUDA', 'OpenCL'): properties['Precision'] = options.precision # Run the simulation. integ.setConstraintTolerance(1e-5) if len(properties) > 0: context = mm.Context(system, integ, platform, properties) else: context = mm.Context(system, integ, platform) context.setPositions(positions) if amber: if inpcrd.boxVectors is not None: context.setPeriodicBoxVectors(*inpcrd.boxVectors) mm.LocalEnergyMinimizer.minimize( context, 100 * unit.kilojoules_per_mole / unit.nanometer) context.setVelocitiesToTemperature(temperature) steps = 20 while True: time = timeIntegration(context, steps, initialSteps) if time >= 0.5 * options.seconds: break if time < 0.5: steps = int( steps * 1.0 / time ) # Integrate enough steps to get a reasonable estimate for how many we'll need. else: steps = int(steps * options.seconds / time) print('Integrated %d steps in %g seconds' % (steps, time)) print('%g ns/day' % (dt * steps * 86400 / time).value_in_unit(unit.nanoseconds))
def create_openmm_system(sim_openmm, model, anchor): """ Create an openmm System() object. """ building_directory = os.path.join(model.anchor_rootdir, anchor.directory, anchor.building_directory) box_vectors = None if anchor.amber_params is not None: prmtop_filename = os.path.join(building_directory, anchor.amber_params.prmtop_filename) prmtop = openmm_app.AmberPrmtopFile(prmtop_filename) assert anchor.amber_params.pdb_coordinates_filename is not None pdb_coordinates_filename = os.path.join( building_directory, anchor.amber_params.pdb_coordinates_filename) positions = openmm_app.PDBFile(pdb_coordinates_filename) #assert anchor.amber_params.box_vectors is not None box_vectors = anchor.amber_params.box_vectors topology = prmtop elif anchor.forcefield_params is not None: forcefield_filenames = [] for forcefield_filename in \ anchor.forcefield_params.built_in_forcefield_filenames: forcefield_filenames.append(forcefield_filename) for forcefield_filename in \ anchor.forcefield_params.custom_forcefield_filenames: forcefield_filenames.append( os.path.join(building_directory, forcefield_filename)) pdb_filename = os.path.join(building_directory, anchor.forcefield_params.pdb_filename) pdb = openmm_app.PDBFile(pdb_filename) forcefield = openmm_app.ForceField(*forcefield_filenames) box_vectors = anchor.forcefield_params.box_vectors topology = pdb positions = pdb elif anchor.charmm_params is not None: raise Exception("Charmm systems not yet implemented") else: raise Exception("No Amber or Charmm input settings detected.") #assert box_vectors is not None, "No source of box vectors provided." nonbonded_method = model.openmm_settings.nonbonded_method.lower() if nonbonded_method == "pme": nonbondedMethod = openmm_app.PME elif nonbonded_method == "nocutoff": nonbondedMethod = openmm_app.NoCutoff elif nonbonded_method == "cutoffnonperiodic": nonbondedMethod = openmm_app.CutoffNonPeriodic elif nonbonded_method == "cutoffperiodic": nonbondedMethod = openmm_app.CutoffPeriodic elif nonbonded_method == "ewald": nonbondedMethod = openmm_app.Ewald else: raise Exception("nonbonded method not found: %s", model.openmm_settings.nonbonded_method) if model.openmm_settings.constraints is None: constraints_str = None else: constraints_str = model.openmm_settings.constraints if constraints_str is None: constraints = None elif constraints_str.lower() == "none": constraints = None elif constraints_str.lower() == "hbonds": constraints = openmm_app.HBonds elif constraints_str.lower() == "allbonds": constraints = openmm_app.AllBonds elif constraints_str.lower() == "hangles": constraints = openmm_app.HAngles else: raise Exception("constraints not found: %s", model.openmm_settings.constraints) if model.openmm_settings.hydrogenMass: hydrogenMass = model.openmm_settings.hydrogenMass * openmm.unit.amu else: hydrogenMass = model.openmm_settings.hydrogenMass rigidWater = model.openmm_settings.rigidWater if anchor.amber_params is not None: system = prmtop.createSystem( nonbondedMethod=nonbondedMethod, nonbondedCutoff=model.openmm_settings.nonbonded_cutoff, constraints=constraints, hydrogenMass=hydrogenMass, rigidWater=rigidWater) elif anchor.forcefield_params is not None: system = forcefield.createSystem( pdb.topology, nonbondedMethod=nonbondedMethod, nonbondedCutoff=model.openmm_settings.nonbonded_cutoff, constraints=constraints, hydrogenMass=hydrogenMass, rigidWater=rigidWater) elif anchor.charmm_params is not None: raise Exception("Charmm input settings not yet implemented") else: print("Settings for Amber or Charmm simulations not found") return system, topology, positions, box_vectors