def test_unbonded_edge(self): sim = Simulation() sim.set_kernel("SingleCPU") sim.box_size = common.Vec(10, 10, 10) np.testing.assert_equal(sim.kernel_supports_topologies(), True) sim.register_particle_type("T", 1.0, .5, flavor=ParticleTypeFlavor.TOPOLOGY) sim.register_particle_type("D", 1.0, .5, flavor=ParticleTypeFlavor.TOPOLOGY) sim.configure_topology_bond_potential("T", "T", 10., 11.) 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(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 chain_decay(self, kernel): sim = Simulation() sim.set_kernel(kernel) sim.box_size = common.Vec(10, 10, 10) sim.register_topology_type("TA") np.testing.assert_equal(sim.kernel_supports_topologies(), True) sim.register_particle_type("B", 1.0, ParticleTypeFlavor.NORMAL) sim.register_particle_type("Topology A", 1.0, ParticleTypeFlavor.TOPOLOGY) sim.configure_topology_bond_potential("Topology A", "Topology A", 10, 10) 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.register_structural_topology_reaction("TA", self._get_decay_reaction()) sim.register_structural_topology_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_scheme_readdy(True).evaluate_topology_reactions().configure_and_run(int(500), float(1.0)) np.testing.assert_equal(0, len(sim.current_topologies()))
def test_sanity(self): sim = Simulation() sim.set_kernel("SingleCPU") sim.box_size = common.Vec(10, 10, 10) np.testing.assert_equal(sim.kernel_supports_topologies(), True) sim.register_topology_type("TA") sim.register_particle_type("T", 1.0, flavor=ParticleTypeFlavor.TOPOLOGY) sim.configure_topology_bond_potential("T", "T", 10., 11.) particles = [ sim.create_topology_particle("T", common.Vec(x, 0, 0)) for x in range(4) ] 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) np.testing.assert_equal(len(graph.get_vertices()), 4) for v in graph.get_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_scheme_readdy(True).configure_and_run(0, 1)
def test_unconnected_graph(self): sim = Simulation() sim.set_kernel("SingleCPU") sim.register_topology_type("TA") sim.box_size = common.Vec(10, 10, 10) np.testing.assert_equal(sim.kernel_supports_topologies(), True) sim.register_particle_type("T", 1.0, flavor=ParticleTypeFlavor.TOPOLOGY) sim.configure_topology_bond_potential("T", "T", 10., 11.) particles = [sim.create_topology_particle("T", common.Vec(0, 0, 0)) for _ in range(4)] top = sim.add_topology("TA", particles) graph = top.get_graph() graph.add_edge(0, 1) graph.add_edge(1, 2) with (np.testing.assert_raises(ValueError)): top.configure()
def run(self, time_steps, out_file): sim = Simulation() sim.set_kernel(self.kernel) sim.box_size = common.Vec(60, 20, 20) sim.periodic_boundary = [True, True, True] typeid_b = sim.register_particle_type("B", 1.0, 1.0, ParticleTypeFlavor.NORMAL) sim.register_particle_type("Topology A", .5, .5, ParticleTypeFlavor.TOPOLOGY) sim.register_potential_harmonic_repulsion("Topology A", "Topology A", 10) sim.register_potential_harmonic_repulsion("Topology A", "B", 10) sim.register_potential_harmonic_repulsion("B", "B", 10) sim.configure_topology_bond_potential("Topology A", "Topology A", 10, 1.) sim.configure_topology_angle_potential("Topology A", "Topology A", "Topology A", 10, np.pi) # sim.configure_topology_dihedral_potential("Topology A", "Topology A", "Topology A", "Topology A", 1, 1, -np.pi) n_elements = 50. particles = [ sim.create_topology_particle("Topology A", common.Vec(-25. + i, 0, 0)) for i in range(int(n_elements)) ] topology = sim.add_topology(particles) for i in range(int(n_elements - 1)): topology.get_graph().add_edge(i, i + 1) topology.add_reaction(self._get_decay_reaction(typeid_b)) topology.add_reaction(self._get_split_reaction()) traj_handle = sim.register_observable_flat_trajectory(1) with closing( io.File(out_file, io.FileAction.CREATE, io.FileFlag.OVERWRITE)) as f: traj_handle.enable_write_to_file(f, u"", 50) sim.run_scheme_readdy(True)\ .evaluate_topology_reactions()\ .write_config_to_file(f)\ .configure_and_run(time_steps, self.time_step) print("currently %s topologies" % len(sim.current_topologies()))
def test_sanity(self): sim = Simulation() sim.set_kernel("SingleCPU") sim.box_size = common.Vec(10, 10, 10) np.testing.assert_equal(sim.kernel_supports_topologies(), True) sim.register_particle_type("T", 1.0, .5, flavor=ParticleTypeFlavor.TOPOLOGY) sim.configure_topology_bond_potential("T", "T", 10., 11.) particles = [ sim.create_topology_particle("T", common.Vec(0, 0, 0)) for _ in range(4) ] labels = ["%s" % i for i in range(4)] top = sim.add_topology(particles, labels) graph = top.get_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.get_vertices(): if v.label == "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.label == "1": 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.label == "2": 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.label == "3": 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_scheme_readdy(True).configure_and_run(0, 1)
def chain_decay(self, kernel): sim = Simulation() sim.set_kernel(kernel) sim.box_size = common.Vec(10, 10, 10) sim.register_topology_type("TA") np.testing.assert_equal(sim.kernel_supports_topologies(), True) sim.register_particle_type("B", 1.0, ParticleTypeFlavor.NORMAL) sim.register_particle_type("Topology A", 1.0, ParticleTypeFlavor.TOPOLOGY) sim.configure_topology_bond_potential("Topology A", "Topology A", 10, 10) 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.register_structural_topology_reaction("TA", self._get_decay_reaction()) sim.register_structural_topology_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_scheme_readdy( True).evaluate_topology_reactions().configure_and_run( int(500), float(1.0)) np.testing.assert_equal(0, len(sim.current_topologies()))
def test_sanity(self): sim = Simulation() sim.set_kernel("SingleCPU") sim.box_size = common.Vec(10, 10, 10) np.testing.assert_equal(sim.kernel_supports_topologies(), True) sim.register_topology_type("TA") sim.register_particle_type("T", 1.0, flavor=ParticleTypeFlavor.TOPOLOGY) sim.configure_topology_bond_potential("T", "T", 10., 11.) particles = [sim.create_topology_particle("T", common.Vec(x, 0, 0)) for x in range(4)] 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) np.testing.assert_equal(len(graph.get_vertices()), 4) for v in graph.get_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_scheme_readdy(True).configure_and_run(0, 1)
def run(self, time_steps, out_file): sim = Simulation() sim.set_kernel(self.kernel) sim.box_size = common.Vec(60, 20, 20) sim.periodic_boundary = [True, True, True] typeid_b = sim.register_particle_type("B", 1.0, 1.0, ParticleTypeFlavor.NORMAL) sim.register_particle_type("Topology A", .5, .5, ParticleTypeFlavor.TOPOLOGY) sim.register_potential_harmonic_repulsion("Topology A", "Topology A", 10) sim.register_potential_harmonic_repulsion("Topology A", "B", 10) sim.register_potential_harmonic_repulsion("B", "B", 10) sim.configure_topology_bond_potential("Topology A", "Topology A", 10, 1.) sim.configure_topology_angle_potential("Topology A", "Topology A", "Topology A", 10, np.pi) # sim.configure_topology_dihedral_potential("Topology A", "Topology A", "Topology A", "Topology A", 1, 1, -np.pi) n_elements = 50. particles = [sim.create_topology_particle("Topology A", common.Vec(-25. + i, 0, 0)) for i in range(int(n_elements))] topology = sim.add_topology(particles) for i in range(int(n_elements - 1)): topology.get_graph().add_edge(i, i + 1) topology.add_reaction(self._get_decay_reaction(typeid_b)) topology.add_reaction(self._get_split_reaction()) traj_handle = sim.register_observable_flat_trajectory(1) with closing(io.File(out_file, io.FileAction.CREATE, io.FileFlag.OVERWRITE)) as f: traj_handle.enable_write_to_file(f, u"", 50) sim.run_scheme_readdy(True)\ .evaluate_topology_reactions()\ .write_config_to_file(f)\ .configure_and_run(time_steps, self.time_step) print("currently %s topologies" % len(sim.current_topologies()))