forked from SSAGESLabs/PySAGES
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_gsd.py
56 lines (40 loc) · 1.42 KB
/
gen_gsd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import sys
import gsd
import gsd.hoomd
import numpy as np
class System:
def __init__(self):
self.L = 5
self.N = 200
def post_process_pos(snapshot):
box_size = snapshot.configuration.box[:3]
snapshot.particles.image = np.rint(snapshot.particles.position / box_size)
snapshot.particles.position -= snapshot.particles.image * box_size
return snapshot
def get_snap(system):
L = system.L
snapshot = gsd.hoomd.Frame()
snapshot.configuration.box = [L, L, L, 0, 0, 0]
snapshot.particles.N = N = system.N
snapshot.particles.types = ["A"]
snapshot.particles.position = np.zeros((N, 3))
snapshot.particles.velocity = np.random.standard_normal((N, 3))
snapshot.particles.image = np.zeros((N, 3), dtype=int)
snapshot.particles.typeid = np.zeros(N, dtype=int)
rng = np.random.default_rng()
for particle in range(N):
snapshot.particles.position[particle, 0] = rng.random() * L - L / 2
snapshot.particles.position[particle, 1] = rng.random() * L - L / 2
snapshot.particles.position[particle, 2] = rng.random() * L - L / 2
return snapshot
def main(argv):
if len(argv) != 1:
print("Usage: ./gen_gsd.py")
system = System()
snap = get_snap(system)
snap = post_process_pos(snap)
snap.particles.validate()
with gsd.hoomd.open("start.gsd", "w") as f:
f.append(snap)
if __name__ == "__main__":
main(sys.argv)