def chain_decay(self, kernel): sim = Simulation(kernel) sim.context.box_size = [10., 10., 10.] sim.context.topologies.add_type("TA") np.testing.assert_equal(sim.kernel_supports_topologies(), True) sim.context.particle_types.add("B", 1.0, ParticleTypeFlavor.NORMAL) sim.context.particle_types.add("Topology A", 1.0, ParticleTypeFlavor.TOPOLOGY) sim.context.topologies.configure_bond_potential("Topology A", "Topology A", BondedPotentialConfiguration(10, 10, "harmonic")) n_elements = 50. particles = [sim.create_topology_particle("Topology A", common.Vec(-5. + i * 10. / n_elements, 0, 0)) for i in range(int(n_elements))] topology = sim.add_topology("TA", particles) for i in range(int(n_elements - 1)): topology.get_graph().add_edge(i, i + 1) sim.context.topologies.add_structural_reaction("TA", self._get_decay_reaction()) sim.context.topologies.add_structural_reaction("TA", self._get_split_reaction()) # h = sim.register_observable_n_particles(1, [], lambda x: print("n particles=%s" % x)) np.testing.assert_equal(1, len(sim.current_topologies)) sim.run(500, 1.) np.testing.assert_equal(0, len(sim.current_topologies))
def test_unbonded_edge(self): context = Context() context.box_size = [10., 10., 10.] context.topologies.add_type("TA") context.particle_types.add("T", 1.0, flavor=ParticleTypeFlavor.TOPOLOGY) context.particle_types.add("D", 1.0, flavor=ParticleTypeFlavor.TOPOLOGY) context.topologies.configure_bond_potential( "T", "T", BondedPotentialConfiguration(10., 11., "harmonic")) sim = Simulation("SingleCPU", context) np.testing.assert_equal(sim.kernel_supports_topologies(), True) particles = [ sim.create_topology_particle("T", common.Vec(0, 0, 0)) for _ in range(3) ] particles.append(sim.create_topology_particle("D", common.Vec(0, 0, 0))) top = sim.add_topology("TA", particles) graph = top.get_graph() graph.add_edge(0, 1) graph.add_edge(1, 2) graph.add_edge(2, 3) with (np.testing.assert_raises(ValueError)): top.configure()
def test_sanity(self): context = Context() context.box_size = [10., 10., 10.] context.topologies.add_type("TA") context.particle_types.add("T", 1.0, flavor=ParticleTypeFlavor.TOPOLOGY) context.topologies.configure_bond_potential( "T", "T", BondedPotentialConfiguration(10., 11., "harmonic")) sim = Simulation("SingleCPU", context) np.testing.assert_equal(sim.kernel_supports_topologies(), True) particles = [ sim.create_topology_particle("T", common.Vec(x, 0, 0)) for x in range(4) ] top = sim.add_topology("TA", particles) graph = top.graph graph.add_edge(0, 1) graph.add_edge(1, 2) graph.add_edge(2, 3) np.testing.assert_equal(len(graph.get_vertices()), 4) for v in graph.vertices: if v.particle_index == 0: np.testing.assert_equal(top.position_of_vertex(v), common.Vec(0, 0, 0)) np.testing.assert_equal(len(v.neighbors()), 1) np.testing.assert_equal( 1 in [vv.get().particle_index for vv in v], True) if v.particle_index == 1: np.testing.assert_equal(top.position_of_vertex(v), common.Vec(1, 0, 0)) np.testing.assert_equal(len(v.neighbors()), 2) np.testing.assert_equal( 0 in [vv.get().particle_index for vv in v], True) np.testing.assert_equal( 2 in [vv.get().particle_index for vv in v], True) if v.particle_index == 2: np.testing.assert_equal(top.position_of_vertex(v), common.Vec(2, 0, 0)) np.testing.assert_equal(len(v.neighbors()), 2) np.testing.assert_equal( 1 in [vv.get().particle_index for vv in v], True) np.testing.assert_equal( 3 in [vv.get().particle_index for vv in v], True) if v.particle_index == 3: np.testing.assert_equal(top.position_of_vertex(v), common.Vec(3, 0, 0)) np.testing.assert_equal(len(v.neighbors()), 1) np.testing.assert_equal( 2 in [vv.get().particle_index for vv in v], True) top.configure() sim.run(0, 1)