def setup(self): pes = paths.engines.toy.Gaussian(1, [1.0, 1.0], [0.0, 0.0]) integ = paths.engines.toy.LangevinBAOABIntegrator(0.01, 0.1, 2.5) topology = paths.engines.toy.Topology(n_spatial=2, n_atoms=1, masses=[1.0], pes=pes) self.engine = paths.engines.toy.Engine( options={ 'n_frames_max': 1000, 'n_steps_per_frame': 10, 'integ': integ }, topology=topology).named("engine") self.other_engine = paths.engines.toy.Engine(options={ 'n_frames_max': 5000, 'n_steps_per_frame': 1, 'integ': integ }, topology=topology) self.cv = paths.FunctionCV("x", lambda x: x.xyz[0][0]) self.state_A = paths.CVDefinedVolume(self.cv, float("-inf"), 0).named("A") self.state_B = paths.CVDefinedVolume(self.cv, 10, float("inf")).named("B") self.network = paths.TPSNetwork(self.state_A, self.state_B).named('network') self.scheme = paths.OneWayShootingMoveScheme( self.network, paths.UniformSelector(), self.engine).named("scheme") self.other_scheme = paths.OneWayShootingMoveScheme( self.network, paths.UniformSelector(), self.other_engine) self.tempdir = tempfile.mkdtemp()
def tps_main(engine, states, init_traj, output_storage, n_steps): network = paths.TPSNetwork(initial_states=states, final_states=states) scheme = paths.OneWayShootingMoveScheme(network, engine=engine) initial_conditions = \ scheme.initial_conditions_from_trajectories(init_traj) simulation = paths.PathSampling( storage=output_storage, move_scheme=scheme, sample_set=initial_conditions ) simulation.run(n_steps) output_storage.tags['final_conditions'] = simulation.sample_set return simulation.sample_set, simulation
def _wc_hg_TPS_network(self, topology): # separated for readability, not re-usability d_WC = paths.MDTrajFunctionCV("d_WC", md.compute_distances, topology, atom_pairs=[[275, 494]]) d_HG = paths.MDTrajFunctionCV("d_HG", md.compute_distances, topology, atom_pairs=[[275, 488]]) d_bp = paths.MDTrajFunctionCV("d_bp", md.compute_distances, topology, atom_pairs=[[274, 491]]) state_WC = (paths.CVDefinedVolume(d_WC, 0.0, 0.35) & paths.CVDefinedVolume(d_bp, 0.0, 0.35)).named("WC") state_HG = (paths.CVDefinedVolume(d_HG, 0.0, 0.35) & paths.CVDefinedVolume(d_bp, 0.0, 0.35)).named("HG") network = paths.TPSNetwork(state_WC, state_HG) return network
def two_state_tps(wizard, fixed_length=False): import openpathsampling as paths wizard.requirements['state'] = ('volumes', 2, 2) intro = [ _FIRST_STATE.format(n_states_string=2), "Let's start with your initial state.", _VOL_DESC, ] initial_state = volumes(wizard, context={'intro': intro}) wizard.register(initial_state, 'initial state', 'states') pause.section(wizard) intro = ["Next let's define your final state.", _VOL_DESC] final_state = volumes(wizard, context={'intro': intro}) wizard.register(final_state, 'final state', 'states') if fixed_length: ... # no-cov (will add this later) else: network = paths.TPSNetwork(initial_state, final_state) scheme = tps_scheme(wizard, network=network) return scheme
def test_non_shooting_steps(self): network = paths.TPSNetwork(self.left, self.right) init_traj = make_1d_traj([-1.1, 0.0, 1.1]) ensemble = network.all_ensembles[0] mover = paths.PathReversalMover(ensemble) scheme = paths.LockedMoveScheme(mover, network) init_conds = scheme.initial_conditions_from_trajectories([init_traj]) assert_equal(len(init_conds), 1) self.storage.close() self.storage = paths.Storage(self.filename, "w") assert_equal(init_conds[ensemble].trajectory, init_traj) sim = paths.PathSampling(storage=self.storage, move_scheme=scheme, sample_set=init_conds) sim.output_stream = open(os.devnull, "w") sim.run(1) step0 = self.storage.steps[0] step1 = self.storage.steps[1] assert_equal(self.analyzer.step_key(step0), None) assert_equal(self.analyzer.step_key(step1), None) assert_equal(self.analyzer.analyze_single_step(step0), []) assert_equal(self.analyzer.analyze_single_step(step1), [])
print(engine.name) # ## TPS # # As always, the process for setting up a simulation is: # # 1. Create a `network` # 2. Create a `move_scheme` # 3. Set up `initial_conditions` # 4. Create the `PathSampling` object and run it. # # Since we already created all the input to these when we set up the first trajectory, we can load use the versions we loaded above. # In[5]: network = paths.TPSNetwork(C_7eq, alpha_R) # In[6]: scheme = paths.OneWayShootingMoveScheme(network, selector=paths.UniformSelector(), engine=engine) # In[7]: initial_conditions = scheme.initial_conditions_from_trajectories(traj) # In[8]: storage = paths.Storage("alanine_dipeptide_tps.nc", "w", template) sampler = paths.PathSampling(storage=storage,
def tps_network(): cv = paths.CoordinateFunctionCV('x', lambda s: s.xyz[0][0]) state_A = paths.CVDefinedVolume(cv, float("-inf"), 0).named("A") state_B = paths.CVDefinedVolume(cv, 0, float("inf")).named("B") network = paths.TPSNetwork(state_A, state_B).named('tps-network') return network
def tps_network_and_traj(cv_and_states, transition_traj): _, state_A, state_B = cv_and_states network = paths.TPSNetwork(state_A, state_B) return network, transition_traj
def two_state_tps_network(): state_A = paths.CVDefinedVolume(DEFAULT_CV, float("-inf"), 0) state_B = paths.CVDefinedVolume(DEFAULT_CV, 10, float("inf")) network = paths.TPSNetwork(state_A, state_B) return network
topology=topology, groups=groups, image_molecules=False, mass_weighted=False, cv_time_reversible=True, cv_wrap_numpy_array=True).with_diskcache() # Defining the states rmax = 4.5 * unit.nanometer rmin = -2.5 * unit.nanometer entrance = paths.CVDefinedVolume(cv_r_p, lambda_min=-2.5, lambda_max=-0.5).named("entrance") exit = paths.CVDefinedVolume(cv_r_p, lambda_min=2.0, lambda_max=4.5).named("exit") # Setting up the transition network and move scheme network = paths.TPSNetwork(entrance, exit) scheme = paths.OneWayShootingMoveScheme(network, selector=paths.UniformSelector(), engine=engine) mdtraj_t = md.load('../../arg/smd.nc', top=topology) ops_trajectory = trajectory_from_mdtraj(mdtraj_t) # take the subtrajectory matching the ensemble (only one ensemble, only one subtraj) subtrajectories = [] for ens in network.analysis_ensembles: subtrajectories += ens.split(ops_trajectory) init_cond = scheme.initial_conditions_from_trajectories( trajectories=subtrajectories) sim = paths.PathSampling(storage=paths.Storage("one-way-shooting.nc", "w",
from __future__ import print_function import openpathsampling as paths from openpathsampling.tests.test_helpers import make_1d_traj import os def xval(snap): return snap.coordinates[0][0] cv = paths.FunctionCV("x", xval) left = paths.CVDefinedVolume(cv, float("-inf"), 0.0).named("left") right = paths.CVDefinedVolume(cv, 10.0, float("inf")).named("right") tps_network = paths.TPSNetwork(left, right) tps_ensemble = tps_network.sampling_ensembles[0] def shooting_move_info(): t0 = make_1d_traj( [-0.1, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.1]) t1 = make_1d_traj([-0.11, 2.1]) t2 = make_1d_traj([5.2, 7.2, 9.2, 10.12]) t3 = make_1d_traj([-0.13, 2.3, 5.3, 8.3]) t4 = make_1d_traj([-0.14, 2.4, 4.4, 6.4]) out1 = paths.Trajectory(t1 + t0[4:]) out2 = paths.Trajectory(out1[0:3] + t2) out3 = paths.Trajectory(t3 + out2[5:]) # REJECT THIS out4 = paths.Trajectory(t4 + out2[4:])
print('Creating network...') mistis = paths.MISTISNetwork([(bound, interfaces, unbound)]) initial_trajectory_method = 'bootstrap' if initial_trajectory_method == 'high-temperature': # We are starting in the bound state, so # generate high-temperature trajectory that reaches the unbound state print('Generating high-temperature trajectory...') #ensemble = not (paths.ExitsXEnsemble(bound) & paths.EntersXEnsemble(unbound)) unbinding_ensemble = paths.AllOutXEnsemble(unbound) bridging_ensemble = paths.AllOutXEnsemble(bound) & paths.AllOutXEnsemble( unbound) initial_trajectories = list() minus_trajectories = list() tmp_network = paths.TPSNetwork(bound, unbound) attempt = 0 while (len(initial_trajectories) == 0) or (len(minus_trajectories) == 0): print('Attempt %d' % attempt) long_trajectory = engine_hot.generate(initial_snapshot_hot, [unbinding_ensemble]) print('long trajectory:') print(long_trajectory) distances = np.array([cv(snapshot) for snapshot in long_trajectory]) print(distances) # split out the subtrajectory of interest initial_trajectories = tmp_network.all_ensembles[0].split( long_trajectory) print('initial trajectories:') print(initial_trajectories) if len(initial_trajectories) > 0:
'n_frames_max': 5000, 'n_steps_per_frame': 10}, topology) template = toys.Snapshot(coordinates=np.array([[0.0, 0.0]]), velocities=np.array([[0.0, 0.0]]), engine=engine) def val(snapshot, index): return snapshot.xyz[0][index] cv_x = paths.FunctionCV("xval", val, index=0) cv_y = paths.FunctionCV("yval", val, index=1) stateA = paths.CVDefinedVolume(cv_x, float("-inf"), -0.6).named("A") stateB = paths.CVDefinedVolume(cv_x, 0.6, float("inf")).named("B") network = paths.TPSNetwork(stateA, stateB) scheme = paths.OneWayShootingMoveScheme(network=network, engine=engine) # I'll fake an initial trajectory trajectory = paths.Trajectory([ toys.Snapshot(coordinates=np.array([[-.65+k*0.1, 0.0]]), velocities=np.array([[0.1, 0.0]]), engine=engine) for k in range(14) ]) initial_conditions = scheme.initial_conditions_from_trajectories(trajectory) # use this for debugging the equilibration # equil_store = paths.Storage('equil.nc', 'w') equil_store = None
openmm_properties=openmm_properties, options=engine_options ) engine.name = '300K' # ## Equilibrate TPS # # This is, again, a simple path sampling setup. We use the same `TPSNetwork` we'll use later, and only shooting moves. One the initial conditions are correctly set up, we run one step at a time until the initial trajectory is decorrelated. # # This setup of a path sampler always consists of defining a `network` and a `move_scheme`. See toy model notebooks for further discussion. # In[14]: network = paths.TPSNetwork(initial_states=C_7eq, final_states=alpha_R) scheme = paths.OneWayShootingMoveScheme(network, selector=paths.UniformSelector(), engine=engine) # In[15]: # make subtrajectories into initial conditions (trajectories become a sampleset) initial_conditions = scheme.initial_conditions_from_trajectories(subtrajectories) # In[16]: