def setup(self): import openpathsampling.engines.toy as toys # applies one delta_v to all atoms self.toy_modifier_all = GeneralizedDirectionModifier(1.5) # defines delta_v per atom, including those not in the mask self.toy_modifier_long_dv = GeneralizedDirectionModifier( delta_v=[0.5, 1.0, 2.0], subset_mask=[1, 2]) # defines delta_v per atom in the subset mask self.toy_modifier = GeneralizedDirectionModifier(delta_v=[1.0, 2.0], subset_mask=[1, 2]) self.toy_engine = toys.Engine(topology=toys.Topology( n_spatial=2, n_atoms=3, pes=None, masses=[1.0, 1.5, 4.0]), options={}) self.toy_snapshot = toys.Snapshot(coordinates=np.array([[0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]), velocities=np.array([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0]]), engine=self.toy_engine) # create the OpenMM versions u_vel = old_div(u.nanometer, u.picosecond) self.openmm_modifier = GeneralizedDirectionModifier(1.2 * u_vel) ad_vacuum = omt.testsystems.AlanineDipeptideVacuum(constraints=None) self.test_snap = omm_engine.snapshot_from_testsystem(ad_vacuum) self.openmm_engine = omm_engine.Engine( topology=self.test_snap.topology, system=ad_vacuum.system, integrator=omt.integrators.VVVRIntegrator()) self.openmm_snap = self.test_snap.copy_with_replacement( engine=self.openmm_engine)
def setup(self): import openpathsampling.engines.toy as toys self.toy_modifier = SingleAtomVelocityDirectionModifier( delta_v=[1.0, 2.0], subset_mask=[1, 2], remove_linear_momentum=False) self.toy_engine = toys.Engine( topology=toys.Topology(n_spatial=2, n_atoms=3, pes=None, masses=np.array([1.0, 1.5, 4.0])), options={}) self.toy_snapshot = toys.Snapshot(coordinates=np.array([[0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]), velocities=np.array([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0]]), engine=self.toy_engine) u_vel = old_div(u.nanometer, u.picosecond) self.openmm_modifier = SingleAtomVelocityDirectionModifier( delta_v=1.2 * u_vel, remove_linear_momentum=False) ad_vacuum = omt.testsystems.AlanineDipeptideVacuum(constraints=None) self.test_snap = omm_engine.snapshot_from_testsystem(ad_vacuum) self.openmm_engine = omm_engine.Engine( topology=self.test_snap.topology, system=ad_vacuum.system, integrator=omt.integrators.VVVRIntegrator()) self.openmm_snap = self.test_snap.copy_with_replacement( engine=self.openmm_engine, velocities=np.ones(shape=self.test_snap.velocities.shape) * u_vel)
def build_engine(self): """Builds the OpenMMEngine.""" from simtk.openmm import app import simtk.openmm as mm from simtk import unit kinase = self.kinase #### SET UP THE OPENMM STUFF ####################################### # taken from builder.openmm.org forcefield = app.ForceField('amber99sbildn.xml', 'amber99_obc.xml') system = forcefield.createSystem(app.PDBFile(kinase['pdb']).topology, nonbondedMethod=app.NoCutoff, constraints=app.HBonds) integrator = mm.LangevinIntegrator(300 * unit.kelvin, 1.0 / unit.picoseconds, 2.0 * unit.femtoseconds) integrator.setConstraintTolerance(0.00001) #### OPENPATHSAMPLING-SPECIFIC SETUP ############################### options = {'nsteps_per_frame': 50, 'n_frames_max': 1500} template = omm_eng.tools.snapshot_from_pdb(kinase['pdb']) engine = omm_eng.Engine(template=template, system=system, integrator=integrator, options=options) return engine
def setup(self): # OpenMM Integrator integrator = mm.LangevinIntegrator( 300*u.kelvin, old_div(1.0,u.picoseconds), 2.0*u.femtoseconds ) integrator.setConstraintTolerance(0.00001) # Engine options options = { 'n_steps_per_frame': 2, 'n_frames_max': 5 } self.engine = peng.Engine( template.topology, system, integrator, options=options ) self.engine.initialize('CPU') context = self.engine.simulation.context zero_array = np.zeros((template.topology.n_atoms, 3)) context.setPositions(template.coordinates) context.setVelocities(u.Quantity(zero_array, old_div(u.nanometers, u.picoseconds)))
def test_verify_snapshot_constraints(self): ad_vacuum_constr = omt.testsystems.AlanineDipeptideVacuum() constrained_engine = omm_engine.Engine( topology=self.test_snap.topology, system=ad_vacuum_constr.system, integrator=omt.integrators.VVVRIntegrator()) constr_snap = self.test_snap.copy_with_replacement( engine=constrained_engine) self.openmm_modifier._verify_snapshot(constr_snap)
def setup(self): test_system = omt.testsystems.AlanineDipeptideVacuum() self.template = omm_engine.snapshot_from_testsystem(test_system) self.engine = omm_engine.Engine( topology=self.template.topology, system=test_system.system, integrator=omt.integrators.VVVRIntegrator()) self.n_atoms = self.engine.topology.n_atoms self.engine.current_snapshot = self.template
def test_verify_snapshot_box_vectors(self): ad_explicit = omt.testsystems.AlanineDipeptideExplicit( constraints=None, rigid_water=False) ad_explicit_tmpl = omm_engine.snapshot_from_testsystem(ad_explicit) explicit_engine = omm_engine.Engine( topology=ad_explicit_tmpl.topology, system=ad_explicit.system, integrator=omt.integrators.VVVRIntegrator()) ad_explicit_snap = ad_explicit_tmpl.copy_with_replacement( engine=explicit_engine) self.openmm_modifier._verify_snapshot(ad_explicit_snap)
def test_has_constraints(self, has_constraints): omt = pytest.importorskip('openmmtools') constraints = app.HBonds if has_constraints else None system = omt.testsystems.AlanineDipeptideVacuum( constraints=constraints ) template = peng.snapshot_from_testsystem(system) engine = peng.Engine( topology=template.topology, system=system.system, integrator=omt.integrators.VVVRIntegrator() ) assert engine.has_constraints() == has_constraints
def setup(self): if not openmm: raise SkipTest("OpenMM not installed") if not omt: raise SkipTest("OpenMMTools not installed; required for OpenMM " "tests.") self.test_system = omt.testsystems.AlanineDipeptideVacuum() self.template = omm_engine.snapshot_from_testsystem(self.test_system) self.engine = omm_engine.Engine( topology=self.template.topology, system=self.test_system.system, integrator=omt.integrators.VVVRIntegrator() ) self.n_atoms = self.engine.topology.n_atoms self.engine.current_snapshot = self.template
def run_steps(steps): template = peng.snapshot_from_pdb( "/Users/jan-hendrikprinz/Studium/git/openpathsampling/examples/data/Alanine_solvated.pdb") topology = peng.to_openmm_topology(template) # Generated using OpenMM Script Builder # http://builder.openmm.org forcefield = mm.app.ForceField( 'amber96.xml', # solute FF 'tip3p.xml' # solvent FF ) # OpenMM System system = forcefield.createSystem( topology, nonbondedMethod=mm.app.PME, nonbondedCutoff=1.0*u.nanometers, constraints=mm.app.HBonds, ewaldErrorTolerance=0.0005 ) # OpenMM Integrator integrator = mm.LangevinIntegrator( 300 * u.kelvin, 1.0 / u.picoseconds, 2.0 * u.femtoseconds ) integrator.setConstraintTolerance(0.00001) # Engine options options = { 'n_steps_per_frame': 2, 'n_frames_max': 5 } engine = peng.Engine( template.topology, system, integrator, options=options ) engine.initialize('CPU') traj = engine.generate(template, paths.LengthEnsemble(steps).can_append) return traj
def test_with_openmm_snapshot(self): # note: this is only a smoke test; correctness depends on OpenMM's # tests of its constraint approaches. if not omt: raise SkipTest("Requires OpenMMTools (not installed)") test_system = omt.testsystems.AlanineDipeptideVacuum() template = omm_engine.snapshot_from_testsystem(test_system) engine = omm_engine.Engine( topology=template.topology, system=test_system.system, integrator=omt.integrators.VVVRIntegrator() ) beta = old_div(1.0, (300.0 * u.kelvin * u.BOLTZMANN_CONSTANT_kB)) # when the engine doesn't have an existing snapshot randomizer = RandomVelocities(beta=beta, engine=engine) new_snap = randomizer(template) # coordinates stayed the same assert_array_almost_equal(template.coordinates, new_snap.coordinates) # velocities changed assert_equal(np.isclose(template.velocities, new_snap.velocities).all(), False) engine.generate(new_snap, [lambda x, foo: len(x) <= 4]) # when the engine does have an existing snapshot zeros = np.zeros((engine.n_atoms, engine.n_spatial)) zero_snap = paths.engines.openmm.Snapshot.construct( coordinates=zeros * u.nanometer, velocities=zeros * u.nanometer / u.picosecond, box_vectors=template.box_vectors, engine=engine ) engine.current_snapshot = zero_snap randomizer = RandomVelocities(beta=beta, engine=engine) new_snap = randomizer(template) # coordinates stayed the same assert_array_almost_equal(template.coordinates, new_snap.coordinates) # velocities changed assert_equal(np.isclose(template.velocities, new_snap.velocities).all(), False) # internal snapshot unchanged assert_equal(engine.current_snapshot, zero_snap) engine.generate(new_snap, [lambda x, foo: len(x) <= 4])
def test_verify_engine_constraints(self): ad_vacuum_constr = omt.testsystems.AlanineDipeptideVacuum() constrained_engine = omm_engine.Engine( topology=self.test_snap.topology, system=ad_vacuum_constr.system, integrator=omt.integrators.VVVRIntegrator()) modifier = GeneralizedDirectionModifier(1.2 * u.nanometer / u.picosecond, engine=constrained_engine) # this is a hack because ndofs not defined in TestsystemEngine self.openmm_engine.current_snapshot = self.test_snap snap = self.openmm_engine.current_snapshot # when it checks based on the engine, it should be fine self.openmm_modifier._verify_snapshot(snap) # when modifier overrides snap.engine, it errors with pytest.raises(RuntimeError, match="constraints"): modifier._verify_snapshot(snap)
def setup(self): if not openmm: raise SkipTest("OpenMM not installed") if not omt: raise SkipTest("OpenMMTools not installed; required for OpenMM " "tests.") self.test_system = omt.testsystems.AlanineDipeptideVacuum() self.template = omm_engine.snapshot_from_testsystem(self.test_system) self.engine = omm_engine.Engine( topology=self.template.topology, system=self.test_system.system, integrator=omt.integrators.VVVRIntegrator()) self.n_atoms = self.engine.topology.n_atoms self.test_snap = omm_engine.Snapshot.construct( coordinates=self.template.coordinates, box_vectors=self.template.box_vectors, velocities=self.template.velocities, engine=self.engine)
pdb = app.PDBFile('../../porin-ligand.pdb') integrator = openmm.LangevinIntegrator(310 * unit.kelvin, 1.0 / unit.picoseconds, 4 * unit.femtosecond) with open('../../arg/openmm_system_tps.xml', 'r') as infile: openmm_system = XmlSerializer.deserialize(infile.read()) template = ops_load_trajectory('../../porin-ligand.pdb')[0] openmm_properties = {'CUDAPrecision': 'mixed'} engine_options = {'n_steps_per_frame': 500, 'n_frames_max': 10000} engine = omm.Engine(template.topology, openmm_system, integrator, openmm_properties=openmm_properties, options=engine_options).named("arg_engine") topology = md.Topology.from_openmm(pdb.topology) bottom_atoms = [1396, 5018, 3076] top_atoms = [6241, 3325, 1626] selection = '(residue 422) and (mass > 3.0)' ligand_atoms = topology.select(selection) groups = [bottom_atoms] + [top_atoms] + [ligand_atoms] # Defining the CVs cv_r_p = FunctionCV('r_p', r_parallel, topology=topology, groups=groups,
print("Selecting a platform...") platform_name = 'CUDA' platform = openmm.Platform.getPlatformByName(platform_name) openmm_properties = {'OpenCLPrecision': 'mixed'} # Create an engine print('Creating engine...') engine_options = { 'n_frames_max': 1000, 'platform': platform_name, 'n_steps_per_frame': 50 } engine = engine.Engine(template.topology, system, integrator, openmm_properties=openmm_properties, options=engine_options) engine.name = 'default' # Create a hot engine for generating an initial unbinding path print('Creating a "hot" engine...') integrator_hot = VVVRIntegrator(temperature_hot, collision_rate, timestep) integrator_hot.setConstraintTolerance(1.0e-6) engine_hot = engine.from_new_options(integrator=integrator_hot) engine_hot.name = 'hot' # Select engine mover paths.EngineMover.engine = engine # Create storage