def make_mistis_network(): cvX = paths.FunctionCV(name="cvX", f=xval) cvY = paths.FunctionCV(name="cvY", f=yval) cvXprime = paths.FunctionCV(name="cvXprime", f=xprime) x_under_min = paths.CVDefinedVolume(cvX, float("-inf"), -0.35) x_over_max = paths.CVDefinedVolume(cvX, 0.35, float("inf")) y_under_min = paths.CVDefinedVolume(cvY, float("-inf"), -0.35) y_over_max = paths.CVDefinedVolume(cvY, 0.35, float("inf")) stateA = (x_under_min & y_under_min).named("A") stateB = (x_over_max & y_under_min).named("B") stateC = (x_under_min & y_over_max).named("C") interfacesAB = paths.VolumeInterfaceSet( cvX, float("-inf"), [-0.35, -0.3, -0.27, -0.24, -0.2, -0.1] ) interfacesAC = paths.VolumeInterfaceSet( cvY, float("-inf"), [-0.35, -0.3, -0.27, -0.24, -0.2, -0.1, 0.0] ) interfacesBA = paths.VolumeInterfaceSet( cvXprime, float("-inf"), [-0.35, -0.3, -0.27, -0.24, -0.2, -0.1] ) ms_outer = paths.MSOuterTISInterface.from_lambdas( {iface: 0.0 for iface in [interfacesAB, interfacesBA]} ) network = paths.MISTISNetwork( [(stateA, interfacesAB, stateB), (stateA, interfacesAC, stateC), (stateB, interfacesBA, stateA)], ms_outers=ms_outer, strict_sampling=True ).named("mistis") return network
def setup(self): self.cv = paths.FunctionCV("Id", lambda snap: snap.xyz[0][0]) cv_neg = paths.FunctionCV("Neg", lambda snap: -snap.xyz[0][0]) self.stateA = paths.CVDefinedVolume(self.cv, -1.0, 0.0) self.stateB = paths.CVDefinedVolume(self.cv, 1.0, 2.0) self.stateC = paths.CVDefinedVolume(self.cv, 3.0, 4.0) interfacesAB = paths.VolumeInterfaceSet( self.cv, -1.0, [0.0, 0.2, 0.4] ) interfacesBC = paths.VolumeInterfaceSet( self.cv, 1.0, [2.0, 2.2, 2.4] ) interfacesBA = paths.VolumeInterfaceSet( cv_neg, -1.0, [-1.0, -0.8, -0.6] ) network = paths.MISTISNetwork([ (self.stateA, interfacesAB, self.stateB), (self.stateB, interfacesBC, self.stateC), (self.stateB, interfacesBA, self.stateA) ]) self.tisAB = network.input_transitions[(self.stateA, self.stateB)] self.tisBC = network.input_transitions[(self.stateB, self.stateC)] self.tisBA = network.input_transitions[(self.stateB, self.stateA)] self.network = network self.snapA = make_1d_traj([-0.5])[0] self.noforbid_noextra_AB = paths.FullBootstrapping( transition=self.tisAB, snapshot=self.snapA )
def setup(self): # set up the trajectories, ensembles, etc. for this test paths.InterfaceSet._reset() cv_A = paths.FunctionCV('Id', lambda s: s.xyz[0][0]) cv_B = paths.FunctionCV('1-Id', lambda s: 1.0-s.xyz[0][0]) self.cv_x = cv_A self.state_A = paths.CVDefinedVolume(cv_A, float("-inf"), 0.0).named("A") self.state_B = paths.CVDefinedVolume(cv_B, float("-inf"), 0.0).named("B") interfaces_AB = paths.VolumeInterfaceSet(cv_A, float("-inf"), [0.0, 0.1, 0.2]) interfaces_BA = paths.VolumeInterfaceSet(cv_B, float("-inf"), [0.0, 0.1, 0.2]) # trajectory that crosses each interface, one state-to-state self.trajs_AB = [make_tis_traj_fixed_steps(i) for i in [0, 1, 2]] self.trajs_AB += [make_1d_traj([(-0.5 + i) * 0.1 for i in range(12)])] self.trajs_BA = [make_tis_traj_fixed_steps(i, reverse=True) for i in [0, 1, 2]] self.trajs_BA += [make_1d_traj([1.0 - (-0.5 + i) * 0.1 for i in range(12)])] # set up mistis self.mistis = paths.MISTISNetwork([ (self.state_A, interfaces_AB, self.state_B), (self.state_B, interfaces_BA, self.state_A) ]) mover_stub_mistis = MoverWithSignature(self.mistis.all_ensembles, self.mistis.all_ensembles) mistis_ssets = self._make_fake_sampling_sets(self.mistis) self.mistis_steps = self._make_fake_steps(mistis_ssets, mover_stub_mistis) self.mistis_weighted_trajectories = steps_to_weighted_trajectories( self.mistis_steps, self.mistis.sampling_ensembles ) # TODO: set up mstis self.mstis = paths.MSTISNetwork([ (self.state_A, interfaces_AB), (self.state_B, interfaces_BA) ]) mover_stub_mstis = MoverWithSignature(self.mstis.all_ensembles, self.mstis.all_ensembles) mstis_ssets = self._make_fake_sampling_sets(self.mstis) self.mstis_steps = self._make_fake_steps(mstis_ssets, mover_stub_mstis) self.mstis_weighted_trajectories = steps_to_weighted_trajectories( self.mstis_steps, self.mstis.sampling_ensembles )
def setup(self): id_cv = paths.FunctionCV("Id", lambda snap: snap.xyz[0][0]) sin_cv = paths.FunctionCV("sin", lambda snap: np.sin(snap.xyz[0][0])) square_cv = paths.FunctionCV("x^2", lambda snap: snap.xyz[0][0]**2) self.cvs = [id_cv, sin_cv, square_cv] self.left_bin_edges = (0, 0, 0) self.bin_widths = (0.25, 0.5, 0.4) self.traj1 = make_1d_traj([0.1, 0.51, 0.61]) # [(0, 0, 0), (2, 0, 0), (2, 1, 0)] # interpolate: (1, 0, 0) self.traj2 = make_1d_traj([0.6, 0.7])
def setup(self): self.HAS_TQDM = paths.progress.HAS_TQDM paths.progress.HAS_TQDM = False paths.InterfaceSet._reset() cvA = paths.FunctionCV(name="xA", f=lambda s: s.xyz[0][0]) cvB = paths.FunctionCV(name="xB", f=lambda s: -s.xyz[0][0]) state_A = paths.CVDefinedVolume(cvA, float("-inf"), -0.5).named("A") state_B = paths.CVDefinedVolume(cvB, float("-inf"), -0.5).named("B") interfaces_A = paths.VolumeInterfaceSet(cvA, float("-inf"), [-0.5, -0.3]) network = paths.MISTISNetwork([(state_A, interfaces_A, state_B)]) self.scheme = MoveScheme(network) self.scheme.append(OneWayShootingStrategy()) self.scheme.append(NearestNeighborRepExStrategy()) self.scheme.append(OrganizeByMoveGroupStrategy()) root_mover = self.scheme.move_decision_tree() path_sim_mover = paths.PathSimulatorMover(root_mover, None) null_mover = paths.IdentityPathMover(counts_as_trial=False) ens_0 = network.sampling_ensembles[0] ens_1 = network.sampling_ensembles[1] # acc repex ens1-2 # acc fwd ens1 # acc bkwd ens2 # rej bkwd ens1 # rej repex ens1-2 step_info = [(1, True, path_sim_mover, 'repex', [ens_0, ens_1], None), (2, True, path_sim_mover, 'shooting', [ens_0], 0), (3, True, path_sim_mover, 'shooting', [ens_1], 1), (4, False, path_sim_mover, 'shooting', [ens_0], 1), (5, False, path_sim_mover, 'repex', [ens_0, ens_1], None)] self.steps = [_make_acceptance_mock_step(*info) for info in step_info] self.null_mover_6 = _make_null_mover_step(6, path_sim_mover, null_mover) self.null_mover_change_key = [(None, str([path_sim_mover, [None]]))] acceptance_empty = MoveAcceptanceAnalysis(self.scheme) acceptance = MoveAcceptanceAnalysis(self.scheme) acceptance.add_steps(self.steps) acceptance_null = MoveAcceptanceAnalysis(self.scheme) acceptance_null.add_steps(self.steps + [self.null_mover_6]) self.analysis = { 'empty': acceptance_empty, 'normal': acceptance, 'with_null': acceptance_null }
def setup(self): cvA = paths.FunctionCV(name="xA", f=lambda s: s.xyz[0][0]) cvB = paths.FunctionCV(name="xB", f=lambda s: -s.xyz[0][0]) self.stateA = paths.CVDefinedVolume(cvA, float("-inf"), -0.5) self.stateB = paths.CVDefinedVolume(cvB, float("-inf"), -0.5) interfacesA = paths.VolumeInterfaceSet(cvA, float("-inf"), [-0.5, -0.3, -0.1]) interfacesB = paths.VolumeInterfaceSet(cvB, float("-inf"), [-0.5, -0.3, -0.1]) self.network = paths.MSTISNetwork( [(self.stateA, interfacesA), (self.stateB, interfacesB)], ms_outers=paths.MSOuterTISInterface.from_lambdas({ interfacesA: 0.0, interfacesB: 0.0 }))
def setup(self): pes = toys.HarmonicOscillator(A=[1.0], omega=[1.0], x0=[0.0]) topology = toys.Topology(n_spatial=1, masses=[1.0], pes=pes) integrator = toys.LeapfrogVerletIntegrator(0.1) options = { 'integ': integrator, 'n_frames_max': 100000, 'n_steps_per_frame': 2 } self.engine = toys.Engine(options=options, topology=topology) self.snap0 = toys.Snapshot(coordinates=np.array([[0.0]]), velocities=np.array([[1.0]]), engine=self.engine) cv = paths.FunctionCV("Id", lambda snap : snap.coordinates[0][0]) self.cv = cv self.center = paths.CVDefinedVolume(cv, -0.2, 0.2) self.interface = paths.CVDefinedVolume(cv, -0.3, 0.3) self.outside = paths.CVDefinedVolume(cv, 0.6, 0.9) self.extra = paths.CVDefinedVolume(cv, -1.5, -0.9) self.flux_pairs = [(self.center, self.interface)] self.sim = DirectSimulation(storage=None, engine=self.engine, states=[self.center, self.outside], flux_pairs=self.flux_pairs, initial_snapshot=self.snap0)
def setup(self): # As a test system, let's use 1D motion on a flat potential. If the # velocity is positive, you right the state on the right. If it is # negative, you hit the state on the left. pes = toys.LinearSlope(m=[0.0], c=[0.0]) # flat line topology = toys.Topology(n_spatial=1, masses=[1.0], pes=pes) integrator = toys.LeapfrogVerletIntegrator(0.1) options = { 'integ': integrator, 'n_frames_max': 100000, 'n_steps_per_frame': 5 } self.engine = toys.Engine(options=options, topology=topology) self.snap0 = toys.Snapshot(coordinates=np.array([[0.0]]), velocities=np.array([[1.0]]), engine=self.engine) cv = paths.FunctionCV("Id", lambda snap : snap.coordinates[0][0]) self.left = paths.CVDefinedVolume(cv, float("-inf"), -1.0) self.right = paths.CVDefinedVolume(cv, 1.0, float("inf")) self.state_labels = {"Left" : self.left, "Right" : self.right, "None" : ~(self.left | self.right)} randomizer = paths.NoModification() self.filename = data_filename("committor_test.nc") self.storage = paths.Storage(self.filename, mode="w") self.storage.save(self.snap0) self.simulation = CommittorSimulation(storage=self.storage, engine=self.engine, states=[self.left, self.right], randomizer=randomizer, initial_snapshots=self.snap0) self.simulation.output_stream = open(os.devnull, 'w')
def setup(self): # As a test system, let's use 1D motion on a flat potential. If the # velocity is positive, you right the state on the right. If it is # negative, you hit the state on the left. pes = toys.LinearSlope(m=[0.0], c=[0.0]) # flat line topology = toys.Topology(n_spatial=1, masses=[1.0], pes=pes) integrator = toys.LeapfrogVerletIntegrator(0.1) options = { 'integ': integrator, 'n_frames_max': 100000, 'n_steps_per_frame': 5 } self.engine = toys.Engine(options=options, topology=topology) self.snap0 = toys.Snapshot(coordinates=np.array([[0.0]]), velocities=np.array([[1.0]]), engine=self.engine) cv = paths.FunctionCV("Id", lambda snap: snap.coordinates[0][0]) starting_volume = paths.CVDefinedVolume(cv, -0.01, 0.01) forward_ensemble = paths.LengthEnsemble(5) backward_ensemble = paths.LengthEnsemble(3) randomizer = paths.NoModification() self.filename = data_filename("shoot_from_snaps.nc") self.storage = paths.Storage(self.filename, 'w') self.simulation = ShootFromSnapshotsSimulation( storage=self.storage, engine=self.engine, starting_volume=starting_volume, forward_ensemble=forward_ensemble, backward_ensemble=backward_ensemble, randomizer=randomizer, initial_snapshots=self.snap0) self.simulation.output_stream = open(os.devnull, "w")
def test_autonaming(self): assert_equal(self.stateA.name, "A") assert_equal(self.stateB.name, "B") assert_equal(self.stateC.name, "C") # check that (1) given names stay unchanged; (2) code knows to skip # over any default names that have been assigned (i.e., it renames # stateC to "C", not to "A" # force renaming to weirdness self.stateA.name = "B" self.stateB.name = "A" self.stateC._name = "" paths.InterfaceSet._reset() xval = paths.FunctionCV(name="xA", f=lambda s: s.xyz[0][0]) ifacesA = paths.VolumeInterfaceSet(xval, float("-inf"), [-0.5, -0.4, -0.3]) ifacesB = paths.VolumeInterfaceSet(xval, [-0.2, -0.15, -0.1], [0.2, 0.15, 0.1]) ifacesC = paths.VolumeInterfaceSet(xval, [0.5, 0.4, 0.3], float("inf")) new_network = MSTISNetwork([(self.stateA, ifacesA), (self.stateB, ifacesB), (self.stateC, ifacesC)]) assert_equal(self.stateA.name, "B") assert_equal(self.stateB.name, "A") assert_equal(self.stateC.name, "C")
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 setup(self): paths.InterfaceSet._reset() self.cv = paths.FunctionCV("x", lambda x: x.xyz[0][0]) self.state_A = paths.CVDefinedVolume(self.cv, float("-inf"), 0.0) self.state_B = paths.CVDefinedVolume(self.cv, 1.0, float("inf")) pes = paths.engines.toy.LinearSlope([0, 0, 0], 0) integ = paths.engines.toy.LangevinBAOABIntegrator(0.01, 0.1, 2.5) topology = paths.engines.toy.Topology(n_spatial=3, masses=[1.0], pes=pes) self.engine = paths.engines.toy.Engine(options={'integ': integ}, topology=topology) interfaces = paths.VolumeInterfaceSet(self.cv, float("-inf"), [0.0, 0.1, 0.2]) network = paths.MISTISNetwork([(self.state_A, interfaces, self.state_B) ]) init_traj = make_1d_traj([-0.1, 0.2, 0.5, 0.8, 1.1]) scheme = paths.MoveScheme(network) scheme.append([ paths.strategies.OneWayShootingStrategy( selector=paths.UniformSelector(), engine=self.engine), paths.strategies.PathReversalStrategy(), paths.strategies.OrganizeByMoveGroupStrategy() ]) init_cond = scheme.initial_conditions_from_trajectories(init_traj) self.sim = PathSampling(storage=None, move_scheme=scheme, sample_set=init_cond)
def setup(self): self.cv = paths.FunctionCV(name="x", f=lambda s: s.xyz[0][0]) self.increasing_set = paths.PeriodicVolumeInterfaceSet( cv=self.cv, minvals=0.0, maxvals=[100, 150, 200 - 360], period_min=-180, period_max=180)
def _create_selector(func_name): func = { 'gaussian': lambda s: np.exp(-2.0 * (s.xyz[0][0] - 0.25)**2), 'uniform': lambda s: 1 }[func_name] cv = paths.FunctionCV('sel_cv', func) selector = BiasedSelector(cv) return selector
def setup(self): # PES is one-dimensional linear slope (y(x) = x) pes = toys.LinearSlope(m=[-1.0], c=[0.0]) # one particle with mass 1.0 topology = toys.Topology(n_spatial=1, masses=[1.0], pes=pes) integrator = toys.LeapfrogVerletIntegrator(0.02) options = { 'integ': integrator, 'n_frames_max': 1000, 'n_steps_per_frame': 5 } self.engine = toys.Engine(options=options, topology=topology) # test uses three snapshots with different velocities # 0: direction ok, velocity too low => falls back to dividing surface # 1: wrong direction => backward shot towards B # 2: direction ok, velocity high enough => successfull new trajectory self.initial_snapshots = [ toys.Snapshot(coordinates=np.array([[0.0]]), velocities=np.array([[1.0]]), engine=self.engine), toys.Snapshot(coordinates=np.array([[0.0]]), velocities=np.array([[-1.0]]), engine=self.engine), toys.Snapshot(coordinates=np.array([[0.0]]), velocities=np.array([[2.0]]), engine=self.engine) ] # reaction coordinate is just x coordinate rc = paths.FunctionCV("Id", lambda snap: snap.coordinates[0][0]) # state A: [-inf, -1] self.state_A = paths.CVDefinedVolume(rc, float("-inf"), -1.0) # area between A and dividing surface: [-1, 0] self.towards_A = paths.CVDefinedVolume(rc, -1.0, 0.0) # state B: [1, inf] self.state_B = paths.CVDefinedVolume(rc, 1.0, float("inf")) # define state labels self.state_labels = { "A": self.state_A, "B": self.state_B, "ToA": self.towards_A, "None": ~(self.state_A | self.state_B | self.towards_A) } # velocities are not randomized randomizer = paths.NoModification() self.filename = data_filename("rf_test.nc") self.storage = paths.Storage(self.filename, mode="w") self.storage.save(self.initial_snapshots) self.simulation = ReactiveFluxSimulation( storage=self.storage, engine=self.engine, states=[self.state_A, self.state_B], randomizer=randomizer, initial_snapshots=self.initial_snapshots, rc=rc) self.simulation.output_stream = open(os.devnull, 'w')
def setup(self): paths.InterfaceSet._reset() self.cv_inc = paths.FunctionCV(name="inc", f=lambda s: s.xyz[0][0]) self.cv_dec = paths.FunctionCV(name="dec", f=lambda s: 1.0 - s.xyz[0][0]) self.lambdas = [0.0, 0.1, 0.2, 0.3] self.interfaces_inc = paths.VolumeInterfaceSet(cv=self.cv_inc, minvals=float("-inf"), maxvals=self.lambdas) self.interfaces_dec = paths.VolumeInterfaceSet(cv=self.cv_dec, minvals=float("-inf"), maxvals=self.lambdas) self.stateA = paths.CVDefinedVolume(self.cv_inc, float("-inf"), 0.0).named("A") self.stateB = paths.CVDefinedVolume(self.cv_dec, float("-inf"), 0.0).named("B") self.network = paths.MISTISNetwork([ (self.stateA, self.interfaces_inc, self.stateB), (self.stateB, self.interfaces_dec, self.stateA) ]) self.volumes = [ self.interfaces_inc.new_interface(0.5), self.interfaces_dec.new_interface(0.4) ] self.ms_outer_explicit = paths.MSOuterTISInterface( interface_sets=[self.interfaces_inc, self.interfaces_dec], volumes=self.volumes, lambdas=[0.5, 0.4]) self.ms_outer = paths.MSOuterTISInterface.from_lambdas({ self.interfaces_inc: 0.5, self.interfaces_dec: 0.4 }) # TODO: temporary hack until networks working; remove after self.post_network = paths.MSOuterTISInterface.from_lambdas({ t.interfaces: { self.cv_inc: 0.5, self.cv_dec: 0.4 }[t.interfaces.cv] for t in self.network.sampling_transitions })
def setup(self): paths.InterfaceSet._reset() cvA = paths.FunctionCV(name="xA", f=lambda s: s.xyz[0][0]) cvB = paths.FunctionCV(name="xB", f=lambda s: -s.xyz[0][0]) self.stateA = paths.CVDefinedVolume(cvA, float("-inf"), -0.5) self.stateB = paths.CVDefinedVolume(cvB, float("-inf"), -0.5) interfacesA = paths.VolumeInterfaceSet(cvA, float("-inf"), [-0.5, -0.3, -0.1]) interfacesB = paths.VolumeInterfaceSet(cvB, float("-inf"), [-0.5, -0.3, -0.1]) self.network = paths.MSTISNetwork( [(self.stateA, interfacesA), (self.stateB, interfacesB)], ms_outers=paths.MSOuterTISInterface.from_lambdas({ interfacesA: 0.0, interfacesB: 0.0 })) self.basic_scheme = DefaultScheme(self.network) self.root_mover = self.basic_scheme.move_decision_tree()
def test_analysis(self): # check wrong analyze_single_step() argument empty_dict = self.analysis.analyze_single_step(3.1415) assert empty_dict == {} # dictionary with three entries returned assert len(self.analysis) == 3 # run C_AB() in advance, this triggers calculate_averages() cab = self.analysis.C_AB() assert len(cab) == self.l + 1 assert cab.sum() > 0 # get total and per-snapshot results M, Ns, I_Bt, Ns_Bt, hAhB_Bt, sres = self.analysis.calculate_averages() # check total number of generated subtrajectories assert M == 3 * (self.l + 1) # since we did not use a bias Ns_Bt should be 1.0 np.testing.assert_almost_equal(Ns_Bt, 1.0) # now do the same tests on a per-snapshot basis snaps = sres.keys() for snap in snaps: assert sres[snap]["M"] == self.l + 1 np.testing.assert_almost_equal(sres[snap]["Ns_Bt"], 1.0) # check whether time correlation is only filled for case (2), for # case (1) and (3) the array should be empty. if snap.xyz[0][0] == 0.0: np.testing.assert_almost_equal( np.array(sres[snap]["hAhB_Bt"]).sum(), 0) elif snap.xyz[0][0] == 0.1: assert np.array(sres[snap]["hAhB_Bt"]).sum() > 0 elif snap.xyz[0][0] == -0.2: np.testing.assert_almost_equal( np.array(sres[snap]["hAhB_Bt"]).sum(), 0) # run C_AB() afterwards, this triggers another if clause cab = self.analysis.C_AB() assert len(cab) == self.l + 1 assert cab.sum() > 0 # try another analysis with different arguments for complete coverage def dummy_bias(x): return 1.0 cv_b = paths.CoordinateFunctionCV(name="cv_b", f=dummy_bias) rc = paths.FunctionCV("Id", lambda snap: snap.coordinates[0][0]) self.state_S2 = paths.CVDefinedVolume(rc, -0.55, 0.05) self.analysis2 = SShootingAnalysis( steps=self.storage.steps, states=[self.state_A, self.state_B, self.state_S2], bias=cv_b) with pytest.raises(NotImplementedError): self.analysis.committor() with pytest.raises(NotImplementedError): self.analysis.committor_histogram()
def setup(self): op = paths.FunctionCV("Id", lambda snap: snap.coordinates[0][0]) vol1 = paths.CVDefinedVolume(op, 0.1, 0.5) vol2 = paths.CVDefinedVolume(op, -0.1, 0.7) vol3 = paths.CVDefinedVolume(op, 2.0, 2.5) self.stateA = vol1 self.interstitial = vol2 & ~vol1 self.outInterface = ~vol2 & ~vol3 self.stateB = vol3
def test_flux_from_calvinist_dynamics(self): # To check for the multiple interface set case, we need to have two # dimensions. We can hack two "independent" dimensions from a one # dimensional system by making the second CV non-monotonic with the # first. For the full trajectory, we need snapshots `S` (in the # state); `I` (interstitial: outside the state, but not outside # either interface); `X_a` (outside interface alpha, not outside # interface beta); `X_b` (outside interface beta, not outside # interface alpha); and `X_ab` (outside interface alpha and beta). cv1 = self.cv cv2 = paths.FunctionCV("abs_sin", lambda snap : np.abs(np.sin(snap.xyz[0][0]))) state = paths.CVDefinedVolume(cv1, -np.pi/8.0, np.pi/8.0) other_state = paths.CVDefinedVolume(cv1, -5.0/8.0*np.pi, -3.0/8.0*np.pi) alpha = paths.CVDefinedVolume(cv1, float("-inf"), 3.0/8.0*np.pi) beta = paths.CVDefinedVolume(cv2, float("-inf"), np.sqrt(2)/2.0) # approx alpha: x < 1.17 beta: abs(sin(x)) < 0.70 S = 0 # cv1 = 0.00; cv2 = 0.00 I = np.pi/5.0 # cv1 = 0.63; cv2 = 0.59 X_a = np.pi # cv1 = 3.14; cv2 = 0.00 X_b = -np.pi/3.0 # cv1 = -1.05; cv2 = 0.87 X_ab = np.pi/2.0 # cv1 = 1.57; cv2 = 1.00 other = -np.pi/2.0 # cv1 = -1.57; cv2 = 1.00 # That hack is utterly crazy, but I'm kinda proud of it! predetermined = [S, S, I, X_a, # (2) first exit S, X_a, # (4) cross A S, X_ab, # (6) cross A & B I, S, X_b, # (9) cross B S, I, X_b, # (12) cross B other, I, X_b, # (15) cross to other state S, X_b, # (17) first cross B S, X_a, # (19) first cross A S, S, X_ab, # (22) cross A & B I, X_ab, # (24) recrossing test S, I, # (26) false crossing test S, S] engine = CalvinistDynamics(predetermined) init = make_1d_traj([S]) sim = DirectSimulation(storage=None, engine=engine, states=[state, other_state], flux_pairs=[(state, alpha), (state, beta)], initial_snapshot=init[0]) sim.run(len(predetermined)-1) # subtract 1 from the indices in `predetermined`, b/c 0 index of the # traj comes after the found initial step expected_flux_events = { (state, alpha): [(4, 2), (6, 4), (22, 19)], (state, beta): [(9, 6), (12, 9), (22, 17)] } assert_equal(len(sim.flux_events), 2) assert_equal(sim.flux_events[(state, alpha)], expected_flux_events[(state, alpha)]) assert_equal(sim.flux_events[(state, beta)], expected_flux_events[(state, beta)])
def setup(self): super(TestGaussianBiasSelector, self).setup() self.cv = paths.FunctionCV("Id", lambda x: x.xyz[0][0]) self.sel = GaussianBiasSelector(self.cv, alpha=2.0, l_0=0.25) self.f = [ 0.32465246735834974, # = exp(-2.0*(-0.5-0.25)**2) 0.9559974818331, # = exp(-2.0*(0.1-0.25)**2) 0.9950124791926823, # = exp(-2.0*(0.2-0.25)**2) 0.9950124791926823, # = exp(-2.0*(0.3-0.25)**2) 0.8824969025845955, # = exp(-2.0*(0.5-0.25)**2) ]
def setup(self): self.cv = paths.FunctionCV(name="x", f=lambda s: s.xyz[0][0]) self.increasing_set = paths.VolumeInterfaceSet(cv=self.cv, minvals=float("-inf"), maxvals=[0.0, 0.1]) self.decreasing_set = paths.VolumeInterfaceSet(cv=self.cv, minvals=[0.0, -0.1], maxvals=float("inf")) self.weird_set = paths.VolumeInterfaceSet(cv=self.cv, minvals=[-0.1, -0.2], maxvals=[0.1, 0.2])
def setup(self): self.cv = paths.FunctionCV(name="x", f=lambda s: s.xyz[0][0]) self.lambdas = [0.0, 0.1, 0.2, 0.3] self.volumes = paths.VolumeFactory.CVRangeVolumeSet( self.cv, float("-inf"), self.lambdas) self.interface_set = paths.InterfaceSet(self.volumes, self.cv, self.lambdas) self.decreasing = paths.InterfaceSet(list(reversed(self.volumes)), self.cv, list(reversed(self.lambdas))) self.no_lambda_set = paths.InterfaceSet(self.volumes, self.cv)
def test_pickle_cv_with_imports(self): template = make_1d_traj([0.0])[0] def test_cv_func(snap): import math return math.ceil(snap.coordinates[0][0]) cv = paths.FunctionCV("y", test_cv_func) storage = paths.Storage("myfile.nc", "w", template) storage.save(cv) storage.close()
def setup(self): self.cv = paths.FunctionCV("x", lambda x: x.xyz[0][0]) vol_A = paths.CVDefinedVolume(self.cv, 0.0, 1.0).named("A") vol_B = paths.CVDefinedVolume(self.cv, 2.0, 3.0).named("B") vol_C = paths.CVDefinedVolume(self.cv, 4.0, 5.0).named("C") vol_D = paths.CVDefinedVolume(self.cv, 6.0, 7.0).named("D") self.states = [vol_A, vol_B, vol_C, vol_D] self.ensemble = VisitAllStatesEnsemble(self.states, progress='silent') sequence = [-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5] self.state_seq = [[], [vol_A], [], [vol_B], [], [vol_C], [], [vol_D], []] self.traj = make_1d_traj(sequence)
def setup(self): op = paths.FunctionCV("Id", lambda snap: snap.coordinates[0][0]) self.stateA = paths.CVDefinedVolume(op, 0.1, 0.5) self.stateB = paths.CVDefinedVolume(op, 2.0, 2.5) self.transition = paths.FixedLengthTPSTransition(self.stateA, self.stateB, length=4) self.good_traj = self._make_traj("aixb") self.short_traj = self._make_traj("axb") self.long_traj = self._make_traj("aixbb") self.bad_states_traj = self._make_traj("aixx")
def setup(self): op = paths.FunctionCV("Id", lambda snap : snap.coordinates[0][0]) self.vol1 = paths.CVDefinedVolume(op, 0.1, 0.5) self.vol3 = paths.CVDefinedVolume(op, 2.0, 2.5) self.trajectory = make_1d_traj(coordinates=[0.2, 0.3, 0.6, 2.1, 2.2, 0.7, 0.4, 0.35, 2.4, 0.33, 0.32, 0.31], velocities=[0.0]*12) all_in_1 = paths.AllInXEnsemble(self.vol1) self.segments = all_in_1.split(self.trajectory) self.container = paths.TrajectorySegmentContainer(self.segments, dt=0.5)
def setup(self): # PES is one-dimensional zero function (y(x) = 0) pes = toys.LinearSlope(m=[0.0], c=[0.0]) topology = toys.Topology(n_spatial=1, masses=[1.0], pes=pes) integrator = toys.LeapfrogVerletIntegrator(0.02) options = { 'integ' : integrator, 'n_frames_max' : 1000, 'n_steps_per_frame' : 1 } self.engine = toys.Engine(options=options, topology=topology) # test uses snapshots with different velocities self.initial_snapshots = [toys.Snapshot( coordinates=np.array([[0.0]]), velocities=np.array([[1.0]]), engine=self.engine), toys.Snapshot( coordinates=np.array([[0.1]]), velocities=np.array([[-1.0]]), engine=self.engine), toys.Snapshot( coordinates=np.array([[-0.2]]), velocities=np.array([[2.0]]), engine=self.engine)] # trajectory length is set to 100 steps self.l = 100 # reaction coordinate is just x coordinate rc = paths.FunctionCV("Id", lambda snap : snap.coordinates[0][0]) # state S: [-0.5, 0.5] self.state_S = paths.CVDefinedVolume(rc, -0.5, 0.5) # define state labels self.state_labels = { "S" : self.state_S, "NotS" :~self.state_S} # velocities are not randomized randomizer = paths.NoModification() self.filename = data_filename("sshooting_test.nc") self.storage = paths.Storage(self.filename, mode="w") self.storage.save(self.initial_snapshots) self.simulation = SShootingSimulation( storage=self.storage, engine=self.engine, state_S=self.state_S, randomizer=randomizer, initial_snapshots=self.initial_snapshots, trajectory_length=self.l ) self.simulation.output_stream = open(os.devnull, 'w')
def setup(self): paths.InterfaceSet._reset() self.cv = paths.FunctionCV(name="x", f=lambda s: s.xyz[0][0]) self.lambdas = [0.0, 0.1, 0.2, 0.3] min_vals = [float("-inf")] * len(self.lambdas) self.volumes = [ paths.CVDefinedVolume(self.cv, min_v, max_v) for min_v, max_v in zip(min_vals, self.lambdas) ] self.interface_set = paths.InterfaceSet(self.volumes, self.cv, self.lambdas) self.decreasing = paths.InterfaceSet(list(reversed(self.volumes)), self.cv, list(reversed(self.lambdas))) self.no_lambda_set = paths.InterfaceSet(self.volumes, self.cv)
def setup(self): from .test_helpers import CallIdentity xval = paths.FunctionCV("xval", lambda snap: snap.xyz[0][0]) self.stateA = paths.CVDefinedVolume(xval, float("-inf"), -0.5) self.stateB = paths.CVDefinedVolume(xval, -0.1, 0.1) self.stateC = paths.CVDefinedVolume(xval, 0.5, float("inf")) self.states = [self.stateA, self.stateB, self.stateC] self.traj = {} self.traj['AA'] = make_1d_traj([-0.51, -0.49, -0.49, -0.52]) self.traj['AB'] = make_1d_traj([-0.51, -0.25, -0.25, 0.0]) self.traj['BA'] = make_1d_traj([0.0, -0.15, -0.35, -0.52]) self.traj['BB'] = make_1d_traj([0.0, -0.25, 0.25, 0.02]) self.traj['BC'] = make_1d_traj([0.01, 0.16, 0.25, 0.53]) self.traj['CC'] = make_1d_traj([0.51, 0.35, 0.36, 0.55]) self.traj['CA'] = make_1d_traj([0.52, 0.22, -0.22, -0.52])