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 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): # set up the trajectory that we'll annotate in the tests self.traj = make_1d_traj( [-1, 1, 4, 3, 6, 11, 22, 33, 23, 101, 205, 35, 45]) # set up some states to test later # this system is designed under the assumption that the "states" are # defined by how many digits are in the x-coordinate (and I'll # intentionally fail to identify some of them) self.cv = paths.CoordinateFunctionCV("x", lambda s: s.xyz[0][0]) self.state_1 = paths.CVDefinedVolume(self.cv, 0, 9) self.state_2 = paths.CVDefinedVolume(self.cv, 10, 99) self.state_3 = paths.CVDefinedVolume(self.cv, 100, 999) # create the annotations self.annotation_1 = Annotation(state="1-digit", begin=1, end=4) self.annotation_2 = Annotation(state="2-digit", begin=6, end=8) self.annotation_3 = Annotation(state="3-digit", begin=10, end=10) self.annotation_4 = Annotation(state="2-digit", begin=11, end=12) self.states = { "1-digit": self.state_1, "2-digit": self.state_2, "3-digit": self.state_3 } self.annotated = AnnotatedTrajectory(self.traj) self.annotations = [ self.annotation_1, self.annotation_2, self.annotation_3, self.annotation_4 ]
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): 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): 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): cv = paths.CoordinateFunctionCV('x', lambda x: x.xyz[0][0]) vol_A = paths.CVDefinedVolume(cv, float("-inf"), 0.0) vol_B = paths.CVDefinedVolume(cv, 1.0, float("inf")) ensembles = [ paths.LengthEnsemble(1).named("len1"), paths.LengthEnsemble(3).named("len3"), paths.SequentialEnsemble([ paths.LengthEnsemble(1) & paths.AllInXEnsemble(vol_A), paths.AllOutXEnsemble(vol_A | vol_B), paths.LengthEnsemble(1) & paths.AllInXEnsemble(vol_A) ]).named('return'), paths.SequentialEnsemble([ paths.LengthEnsemble(1) & paths.AllInXEnsemble(vol_A), paths.AllOutXEnsemble(vol_A | vol_B), paths.LengthEnsemble(1) & paths.AllInXEnsemble(vol_B) ]).named('transition'), ] self.ensembles = {ens.name: ens for ens in ensembles} self.traj_vals = [-0.1, 1.1, 0.5, -0.2, 0.1, -0.3, 0.4, 1.4, -1.0] self.trajectory = make_1d_traj(self.traj_vals) self.engine = CalvinistDynamics(self.traj_vals) self.satisfied_when_traj_len = { "len1": 1, "len3": 3, "return": 6, "transition": 8, } self.conditions = EnsembleSatisfiedContinueConditions(ensembles)
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 test_fluxes(self): left_interface = paths.CVDefinedVolume(self.cv, -0.3, float("inf")) right_interface = paths.CVDefinedVolume(self.cv, float("-inf"), 0.3) sim = DirectSimulation(storage=None, engine=self.engine, states=[self.center, self.outside], flux_pairs=[(self.center, left_interface), (self.center, right_interface)], initial_snapshot=self.snap0) fake_flux_events = { (self.center, right_interface): [(15, 3), (23, 15), (48, 23)], (self.center, left_interface): [(97, 34), (160, 97)] } sim.flux_events = fake_flux_events n_flux_events = { (self.center, right_interface): 3, (self.center, left_interface): 2 } assert_equal(sim.n_flux_events, n_flux_events) expected_fluxes = { (self.center, right_interface): 1.0 / (((15 - 3) + (23 - 15) + (48 - 23)) / 3.0), (self.center, left_interface): 1.0 / (((97 - 34) + (160 - 97)) / 2.0) } for p in expected_fluxes: assert_almost_equal(sim.fluxes[p], expected_fluxes[p])
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): # 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): 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): 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): 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): 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 unidirectional_tis_network(): r"""Fixture for unidirectional TIS with the default (RETIS) scheme. This has states defined as initial state :math:`x < 0` and final state :math:`x \ge 10`. The interfaces are at :math:`x=0`, :math:`x=3`, and :math:`x=6`. """ paths.InterfaceSet._reset() state_A = paths.CVDefinedVolume(DEFAULT_CV, float("-inf"), 0) state_B = paths.CVDefinedVolume(DEFAULT_CV, 10, float("inf")) interfaces = paths.VolumeInterfaceSet(DEFAULT_CV, float("-inf"), [0, 3, 6]) network = paths.MISTISNetwork([(state_A, interfaces, state_B)]) return network
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): xval = paths.CoordinateFunctionCV(name="xA", f=lambda s: s.xyz[0][0]) self.stateA = paths.CVDefinedVolume(xval, -1.0, -0.5).named("A") self.stateB = paths.CVDefinedVolume(xval, 0.5, float("inf")).named("B") self.ifacesA = paths.VolumeInterfaceSet(xval, -1.0, [-0.5, -0.4, -0.3, -0.2]) self.ifacesB = paths.VolumeInterfaceSet(xval, [0.5, 0.4, 0.3, 0.2], 1.0) self.tcp_A = paths.numerics.LookupFunction( ordinate=[-0.5, -0.4, -0.3, -0.2, -0.1], abscissa=[1.0, 0.5, 0.25, 0.125, 0.0625]) self.tcp_B = paths.numerics.LookupFunction( ordinate=[0.5, 0.4, 0.3, 0.2, 0.1], abscissa=[1.0, 0.2, 0.04, 0.008, 0.0016])
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 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): 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])
def setup(self): self.HAS_TQDM = paths.progress.HAS_TQDM paths.progress.HAS_TQDM = False # taken from the TestCommittorSimulation import openpathsampling.engines.toy as toys pes = toys.LinearSlope(m=[0.0], c=[0.0]) # flat line topology = toys.Topology(n_spatial=1, masses=[1.0], pes=pes) descriptor = peng.SnapshotDescriptor.construct( toys.Snapshot, { 'n_atoms': 1, 'n_spatial': 1 } ) engine = peng.NoEngine(descriptor) self.snap0 = toys.Snapshot(coordinates=np.array([[0.0]]), velocities=np.array([[1.0]]), engine=engine) self.snap1 = toys.Snapshot(coordinates=np.array([[0.1]]), velocities=np.array([[1.0]]), engine=engine) integrator = toys.LeapfrogVerletIntegrator(0.1) options = { 'integ': integrator, 'n_frames_max': 10000, 'n_steps_per_frame': 5 } self.engine = toys.Engine(options=options, topology=topology) self.cv = paths.FunctionCV("Id", lambda snap: snap.coordinates[0][0]) self.left = paths.CVDefinedVolume(self.cv, float("-inf"), -1.0) self.right = paths.CVDefinedVolume(self.cv, 1.0, float("inf")) randomizer = paths.NoModification() self.filename = data_filename("shooting_analysis.nc") self.storage = paths.Storage(self.filename, mode="w") self.simulation = paths.CommittorSimulation( storage=self.storage, engine=self.engine, states=[self.left, self.right], randomizer=randomizer, initial_snapshots=[self.snap0, self.snap1] ) self.simulation.output_stream = open(os.devnull, 'w') self.simulation.run(20) # set up the analysis object self.analyzer = ShootingPointAnalysis(self.storage.steps, [self.left, self.right])
def setup(self): cv = paths.FunctionCV("Id", lambda snap: snap.xyz[0][0]) self.state_A = paths.CVDefinedVolume(cv, -0.1, 0.1) self.state_B = ~paths.CVDefinedVolume(cv, -1.0, 1.0) nml_increasing = paths.CVDefinedVolume(cv, 0.1, 1.0) nml_decreasing = paths.CVDefinedVolume(cv, -1.0, -0.1) increasing = paths.AllInXEnsemble(nml_increasing) decreasing = paths.AllInXEnsemble(nml_decreasing) self.ensemble = paths.SequentialEnsemble([ paths.LengthEnsemble(1) & paths.AllInXEnsemble(self.state_A), paths.AllOutXEnsemble(self.state_A | self.state_B), paths.LengthEnsemble(1) & paths.AllInXEnsemble(self.state_B) ]) self.incr_1 = self._make_active([0.0, 0.5, 1.1]) self.incr_2 = self._make_active([0.05, 0.6, 1.2]) self.decr_1 = self._make_active([0.0, -0.5, -1.1]) self.both_1 = self._make_active([0.0, 0.5, -0.5, 1.1]) self.both_2 = self._make_active([0.0, -0.4, 0.4, -1.1]) self.none_1 = self._make_active([0.0, 1.1]) self.none_2 = self._make_active([0.0, -1.1]) self.channels = {'incr': increasing, 'decr': decreasing} # used in simplest tests of relabeling self.toy_results = { 'a': [(0, 5), (8, 10)], 'b': [(3, 9)], 'c': [(7, 9)] } self.results_with_none = { 'a': [(0, 2), (6, 9)], 'b': [(5, 7), (9, 10)], None: [(2, 5)] } self.set_a = frozenset(['a']) self.set_b = frozenset(['b']) self.set_c = frozenset(['c']) self.toy_expanded_results = [(0, 5, self.set_a), (3, 9, self.set_b), (7, 9, self.set_c), (8, 10, self.set_a)] self.expanded_results_simultaneous_ending = [(0, 5, self.set_a), (3, 9, self.set_b), (7, 10, self.set_c), (8, 10, self.set_a)] self.expanded_oldest_skips_internal = [(0, 5, self.set_a), (3, 9, self.set_b), (7, 8, self.set_c), (8, 10, self.set_a), (10, 11, self.set_b)]
def test_load_results(self): left_interface = paths.CVDefinedVolume(self.cv, -0.3, float("inf")) right_interface = paths.CVDefinedVolume(self.cv, float("-inf"), 0.3) fake_transition_count = [ (self.center, 1), (self.outside, 4), (self.center, 7), (self.extra, 10), (self.center, 12), (self.outside, 14) ] fake_flux_events = {(self.center, right_interface): [(15, 3), (23, 15), (48, 23)], (self.center, left_interface): [(97, 34), (160, 97)]} results = {'transition_count': fake_transition_count, 'flux_events': fake_flux_events} self.sim.load_results(results) assert_equal(self.sim.transition_count, fake_transition_count) assert_equal(self.sim.flux_events, fake_flux_events)
def test_make_ensemble_with_forbidden(self): forbidden = paths.CVDefinedVolume(self.cv_inc, 0.55, 0.65) transitions = self.network.sampling_transitions # TODO: switch once network is working ensemble = self.post_network.make_ensemble(transitions, forbidden) #ensemble = self.ms_outer.make_ensemble(transitions, forbidden) test_AA = make_1d_traj([-0.1, 0.2, -0.2]) test_AXA = make_1d_traj([-0.1, 0.7, -0.2]) test_AFA = make_1d_traj([-0.1, 0.6, -0.2]) test_BB = make_1d_traj([1.1, 0.9, 1.2]) test_BXB = make_1d_traj([1.1, 0.5, 1.2]) test_BFB = make_1d_traj([1.1, 0.6, 1.2]) test_AXB = make_1d_traj([-0.1, 0.7, 1.1]) test_AFB = make_1d_traj([-0.1, 0.6, 1.1]) test_BXA = make_1d_traj([1.1, 0.5, -0.1]) test_BFA = make_1d_traj([1.1, 0.6, -0.1]) assert_equal(ensemble(test_AA), False) assert_equal(ensemble(test_AXA), True) assert_equal(ensemble(test_BB), False) assert_equal(ensemble(test_BXB), True) assert_equal(ensemble(test_BXA), True) assert_equal(ensemble(test_AXB), True) assert_equal(ensemble(test_AFA), False) assert_equal(ensemble(test_BFB), False) assert_equal(ensemble(test_AFB), False) assert_equal(ensemble(test_BFA), False)
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 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.stateB = vol3 self.interfaceA0 = vol2 self.stateX = ~vol1 & ~vol3 transition = paths.TPSTransition(self.stateA, self.stateB) self.analyzer = paths.TrajectoryTransitionAnalysis(transition, dt=0.1) self.traj_str = "aaaxaxxbxaxababaxbbbbbxxxxxxa" # frame numbers "0 5 0 5 0 5 8" self.trajectory = self._make_traj(self.traj_str)
def from_dict(dct): interface_set = VolumeInterfaceSet.__new__(VolumeInterfaceSet) interface_set._load_from_dict(dct) volume_func = lambda minv, maxv: paths.CVDefinedVolume( interface_set.cv, minv, maxv) super(InterfaceSet, interface_set).__init__() interface_set._set_volume_func(volume_func) return interface_set
def test_default_state_progress_report(): cv = paths.FunctionCV("x", lambda x: x.xyz[0][0]) vol_A = paths.CVDefinedVolume(cv, 0.0, 1.0).named("A") vol_B = paths.CVDefinedVolume(cv, 2.0, 3.0).named("B") vol_C = paths.CVDefinedVolume(cv, 4.0, 5.0).named("C") vol_D = paths.CVDefinedVolume(cv, 6.0, 7.0).named("D") n_steps = 100 found_vol = [vol_A, vol_B] all_vol = [vol_A, vol_B, vol_C, vol_D] tstep = 0.5 f = default_state_progress_report # keep on one line assert f(n_steps, found_vol, all_vol) == \ "Ran 100 frames. Found states [A,B]. Looking for [C,D]." assert f(n_steps, found_vol, all_vol, tstep) == \ "Ran 100 frames [50.0]. Found states [A,B]. Looking for [C,D]."