-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunchR.py
101 lines (75 loc) · 3.42 KB
/
launchR.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
"""
Module launchR launches simulations of interacting Brownian rotors.
"""
from active_work.exponents import float_to_letters
from active_work.init import get_env
from numpy.random import randint
from os import path
from subprocess import Popen, DEVNULL
# FUNCTIONS AND CLASSES
def filename(N, Dr, g, launch):
"""
Name of simulation output files.
Parameters
----------
N : int
Number of rotors in the system.
Dr : float
Rotational diffusivity.
g : float
Aligning torque parameter.
launch : int
Launch identifier.
Returns
-------
name : str
File name.
"""
return 'N%s_R%s_G%s_E%s.datR' % tuple(map(float_to_letters,
(N, Dr, g, launch)))
# DEFAULT VARIABLES
_N = 10 # default number of rotors in the system
_Dr = 1./2. # default rotational diffusivity
_seed = randint(1e7) # default random seed
_dt = 1e-3 # default time step
_Niter = 5e4 # default number of iterations
_launch = 0 # default launch identifier
_nOrder = 0 # default number of frames on which to sum the order parameter
_dump = 1 # default boolean to indicate to dump orientations to output file
_period = 1 # default period of dumping of orientations in number of frames
_exec_dir = path.join(path.dirname(path.realpath(__file__)), 'build') # default executable directory
_exec_name = 'rotors' # default executable name
_out_dir = _exec_dir # default simulation output directory
# SCRIPT
if __name__ == '__main__':
# VARIABLE DEFINITIONS
# SYSTEM PARAMETERS
N = get_env('N', default=_N, vartype=int) # number of particles in the system
Dr = get_env('DR', default=_Dr, vartype=float) # rotational diffusivity
g = get_env('G', default=-Dr/2, vartype=float) # aligning torque parameter
# SIMULATION PARAMETERS
seed = get_env('SEED', default=_seed, vartype=int) # random seed
dt = get_env('DT', default=_dt, vartype=float) # time step
Niter = get_env('NITER', default=_Niter, vartype=int) # number of iterations
# NAMING PARAMETERS
launch = get_env('LAUNCH', default=_launch, vartype=float) # launch identifier
# OUTPUT PARAMETERS
nOrder = get_env('NORDER', default=_nOrder, vartype=int) # number of frames on which to sum the order parameter
dump = get_env('DUMP', default=_dump, vartype=int) # boolean to indicate to dump orientations to output file
period = get_env('PERIOD', default=_period, vartype=int) # period of dumping of orientations in number of frames
# EXECUTABLE PARAMETERS
exec_dir = get_env('EXEC_DIR', default=_exec_dir, vartype=str) # executable directory
exec_name = get_env('EXEC_NAME', default=_exec_name, vartype=str) # executable name
# OUTPUT FILE PARAMETERS
out_dir = get_env('OUT_DIR', default=_out_dir, vartype=str) # simulation output directory
out_file = filename(N, Dr, g, launch) # simulation output file name
# LAUNCH
proc = Popen(
['{ %s; }' % str(' ').join(['setsid', path.join(exec_dir, exec_name)])],
stdout=DEVNULL, shell=True, env={
'N': str(N), 'DR': str(Dr), 'G': str(g),
'SEED': str(seed),
'FILE': path.join(out_dir, out_file),
'DT': str(dt), 'NITER': str(Niter),
'NORDER': str(nOrder), 'DUMP': str(dump), 'PERIOD': str(period)})
proc.wait()