forked from Cell-veto/postlhc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_conf
executable file
·75 lines (65 loc) · 1.68 KB
/
random_conf
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
# write coordinates for a random configuration.
import numpy as np
import os
import sys
from math import pi as M_PI
from math import sqrt
N = 100
rho = .25
argc = len (sys.argv)
i = 1
while i < argc:
if sys.argv[i] == 'eta':
rho = float (sys.argv[i+1]) / M_PI
i += 2
elif sys.argv[i] == 'rho':
rho = float (sys.argv[i+1])
i += 2
elif sys.argv[i] == 'dee':
dee = float (sys.argv[i+1])
i += 2
rho = 1. / M_PI / dee / dee
del dee
elif sys.argv[i] == 'N':
N = int (sys.argv[i+1])
i += 2
elif sys.argv[i] == 'seed':
seed = int (sys.argv[i+1])
np.random.seed (seed)
i += 2
elif sys.argv[i] == '-C':
os.chdir (sys.argv[i+1])
i += 2
else:
abort ("Nope")
def square_lattice (ncells, rho):
"""
construct a perfect square lattice with approximately
N particles, and precise number density rho.
returns (coordinates, slack, box vectors)
"""
N = ncells
A = N / rho
L = np.sqrt (A)
L = [ L, L ]
slack = 0
eta_unit_disks = M_PI * rho # assume unit disks
dee = (M_PI*rho)**-.5
print "actual parameters:", locals ()
XX = np.random.random (size=N) * L[0]
YY = np.random.random (size=N) * L[1]
coords = np.transpose ([XX, YY])
return coords, slack, L
coords, slack, L = square_lattice (N, rho)
N = len (coords)
L = np.array (L)
# canonicalize coordinates into [0; L)
coords += L
coords %= L
mini = np.min (coords, axis=0)
maxi = np.max (coords, axis=0)
assert np.all (mini >= 0.)
assert np.all (maxi < L)
np.savetxt ("coords.dat", coords)
np.savetxt ("periods", (L[0], L[1], 0.))