7 number_of_particles = 10
14 tfn = RMF._get_temporary_file_path(
"motion.rmf3")
20 tf = RMF.TypedFactory(fh)
21 pf = RMF.ParticleFactory(fh)
22 bf = RMF.BondFactory(fh)
23 sf = RMF.SegmentFactory(fh)
24 rf = RMF.RepresentationFactory(fh)
25 scf = RMF.ScoreFactory(fh)
32 def get_distance(v0, r0, v1, r1):
34 ((v0[0] - v1[0]) ** 2 + (v0[1] - v1[1])
35 ** 2 + (v0[1] - v1[1]) ** 2) ** .5 - r0 - r1
39 def intersects(c, r, cs, rs):
40 for oc, orad
in zip(cs, rs):
41 if get_distance(c, r, oc, orad) < 0:
47 def too_far(c, r, oc, orad):
48 d = get_distance(c, r, oc, orad)
54 def random_coordinates():
56 random.uniform(0, box_size),
57 random.uniform(0, box_size))
59 for p
in range(0, number_of_particles):
60 cur = fh.get_root_node().add_child(str(p), RMF.REPRESENTATION)
61 tf.get(cur).set_type_name(str(p % 3))
63 pd.set_static_radius(random.uniform(minimum_radius, maximum_radius))
64 pd.set_static_mass(pd.get_radius())
65 curcoord = random_coordinates()
66 while intersects(curcoord, pd.get_radius(), coords, radii):
67 curcoord = random_coordinates()
68 radii.append(pd.get_radius())
69 coords.append(curcoord)
72 bn = fh.get_root_node().add_child(
"bonds", RMF.ORGANIZATIONAL)
75 print(
"creating bonds")
77 bd0 = random.choice(particles)
78 bd1 = random.choice(particles)
81 bp = (particles.index(bd0), particles.index(bd1))
83 while too_far(coords[bp[0]], radii[bp[0]],
84 coords[bp[1]], radii[bp[1]])\
85 or intersects(coords[bp[0]], radii[bp[0]],
86 coords[:bp[0]] + coords[bp[0] + 1:],
87 radii[:bp[0]] + radii[bp[0] + 1:]):
88 coords[bp[0]] = random_coordinates()
93 b = bn.add_child(
"bond", RMF.BOND)
95 bd.set_static_bonded_0(bd0.get_id().get_index())
96 bd.set_static_bonded_1(bd1.get_id().get_index())
99 coords[bonds[-1][0]] = coords[bonds[-1][1]]
101 print(
"created", len(bonds),
"bonds")
102 fn = fh.get_root_node().add_child(
"restraints", RMF.ORGANIZATIONAL)
105 print(
"creating features")
107 f0 = random.choice(particles)
108 f1 = random.choice(particles)
111 f = fn.add_child(
"r", RMF.FEATURE)
113 rd.set_representation([f0, f1])
114 features.append((particles.index(f0), particles.index(f1)))
115 feature_nodes.append(f)
118 def get_particle_distance(p0, p1):
121 v0 = pd0.get_coordinates()
122 v1 = pd1.get_coordinates()
123 r0 = pd0.get_radius()
124 r1 = pd1.get_radius()
126 ((v0[0] - v1[0]) ** 2 + (v0[1] - v1[1])
127 ** 2 + (v0[1] - v1[1]) ** 2) ** .5 - r0 - r1
130 bn = fh.get_root_node().add_child(
"box", RMF.ORGANIZATIONAL)
146 en = bn.add_child(
"edge", RMF.GEOMETRY)
148 sd.set_static_coordinates_list(e)
151 def write_frame(name):
152 fh.add_frame(name, RMF.FRAME)
153 for c, p
in zip(coords, particles):
155 pd.set_frame_coordinates(c)
156 for f, p
in zip(feature_nodes, features):
157 s = get_particle_distance(particles[p[0]], particles[p[1]])
159 sd.set_frame_score(s)
161 write_frame(
"initial")
163 for i
in range(0, number_of_frames):
164 for i
in range(len(coords)):
167 c[1] + random.uniform(-.2, .2),
168 c[2] + random.uniform(-.2, .2))
169 if intersects(cn, radii[i], coords[:i] + coords[i + 1:], radii[:i] + radii[i + 1:]):
172 for b
in [b
for b
in bonds
if b[0] == i
or b[1] == i]:
175 if too_far(cn, radii[i], coords[b[1]], radii[b[1]]):