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 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 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 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 test_mdtraj_trajectory(self): snap_1 = omm_engine.snapshot_from_testsystem(self.test_system, periodic=False) assert_is(snap_1.box_vectors, None) traj_1 = snap_1.md assert_equal(len(traj_1), 1) assert_is_not(traj_1.xyz, None) assert_is(traj_1.unitcell_vectors, None) snap_2 = self.test_snap traj_2 = snap_2.md assert_equal(len(traj_2), 1) assert_is_not(traj_2.xyz, None) assert_is_not(traj_2.unitcell_vectors, None)
def test_mdtraj_trajectory(self): snap_1 = omm_engine.snapshot_from_testsystem(self.test_system, periodic=False) assert_is(snap_1.box_vectors, None) traj_1 = snap_1.md assert_equal(len(traj_1), 1) assert_is_not(traj_1.xyz, None) assert_is(traj_1.unitcell_vectors, None) snap_2 = self.engine.current_snapshot traj_2 = snap_2.md assert_equal(len(traj_2), 1) assert_is_not(traj_2.xyz, None) assert_is_not(traj_2.unitcell_vectors, None)
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 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 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_with_openmm_snapshot(self): # note: this is only a smoke test; correctness depends on OpenMM's # tests of its constraint approaches. 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 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)
def test_copy_with_replacement_openmm(self): # test an openmm snapshot sys = omt.testsystems.AlanineDipeptideVacuum() omm_snap = omm_engine.snapshot_from_testsystem(sys) rep_vel = omm_snap.velocities * 2.0 omm_copy = omm_snap.copy_with_replacement(velocities=rep_vel) npt.assert_allclose(omm_copy.velocities, rep_vel) assert (hex(id(omm_snap.kinetics)) != hex(id(omm_copy.kinetics))) assert (hex(id(omm_snap.statics)) == hex(id(omm_copy.statics))) omm_copy = omm_snap.copy_with_replacement( coordinates=[1.0, 2.0, 3.0] * u.nanometer, box_vectors=[1.0, 1.0, 1.0] * u.nanometer) assert (hex(id(omm_snap.kinetics)) == hex(id(omm_copy.kinetics))) assert (hex(id(omm_snap.statics)) != hex(id(omm_copy.statics)))
def test_copy_with_replacement_openmm(self): # test an openmm snapshot sys = omt.testsystems.AlanineDipeptideVacuum() omm_snap = omm_engine.snapshot_from_testsystem(sys) rep_vel = omm_snap.velocities * 2.0 omm_copy = omm_snap.copy_with_replacement( velocities=rep_vel) npt.assert_allclose(omm_copy.velocities, rep_vel) assert(hex(id(omm_snap.kinetics)) != hex(id(omm_copy.kinetics))) assert(hex(id(omm_snap.statics)) == hex(id(omm_copy.statics))) omm_copy = omm_snap.copy_with_replacement( coordinates=[1.0, 2.0, 3.0] * u.nanometer, box_vectors=[1.0, 1.0, 1.0] * u.nanometer) assert(hex(id(omm_snap.kinetics)) == hex(id(omm_copy.kinetics))) assert(hex(id(omm_snap.statics)) != hex(id(omm_copy.statics)))
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 )
print( 'System does not use periodic boundary conditions; skipping equilibration.' ) # Create test system from collections import namedtuple LocalTestSystem = namedtuple('LocalTestSystem', ['name', 'system', 'topology', 'positions']) testsystem = LocalTestSystem(name='CB7:B2', system=system, topology=topology, positions=positions) # Generate an OpenPathSampling template. print('Creating template...') template = engine.snapshot_from_testsystem(testsystem) print('Creating an integrator...') integrator = VVVRIntegrator(temperature, collision_rate, timestep) integrator.setConstraintTolerance(1.0e-6) 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,
integrator.step(nsteps) positions = context.getState(getPositions=True).getPositions(asNumpy=True) box_vectors = context.getState().getPeriodicBoxVectors() system.setDefaultPeriodicBoxVectors(*box_vectors) del context, integrator, system_with_barostat else: print('System does not use periodic boundary conditions; skipping equilibration.') # Create test system from collections import namedtuple LocalTestSystem = namedtuple('LocalTestSystem', ['name', 'system', 'topology', 'positions']) testsystem = LocalTestSystem(name='CB7:B2', system=system, topology=topology, positions=positions) # Generate an OpenPathSampling template. print('Creating template...') template = engine.snapshot_from_testsystem(testsystem) print('Creating an integrator...') integrator = VVVRIntegrator(temperature, collision_rate, timestep) integrator.setConstraintTolerance(1.0e-6) 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,