forked from AchillesGen/Achilles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_nuchic_params.py
58 lines (41 loc) · 1.51 KB
/
run_nuchic_params.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
""" Run nuchic over a range of parameters. """
import os
import subprocess
import shutil
from string import Template
import numpy as np
from nuchic.qe_data import QuasielasticData
PARAMETERS = ['beam_energy', 'angle']
def get_data():
qe_data = QuasielasticData(str('12C'))
values = qe_data.data.groupby(['Energy', 'Angle']).groups.keys()
return values
def create_run(parameters):
""" Create a run card from a dictionary of parameters. """
template = open('run_template.yml')
src = Template(template.read())
template.close()
result = src.substitute(parameters)
with open('run.yml', 'w') as run_card:
for line in result:
run_card.write(line)
def main():
""" Loop over all the parameters and generate results. """
if not os.path.exists('Results'):
os.mkdir('Results')
values = get_data()
for value in values:
energy = int(np.rint(value[0]*1000))
angle = np.rint(value[1]*100)/100
print(energy, angle)
create_run({PARAMETERS[0]: energy, PARAMETERS[1]: angle})
subprocess.call('nuchic')
shutil.move('omega.png',
os.path.join('Results',
'omega_{}_{}.png'.format(energy, angle)))
shutil.move('before_cascade.png',
os.path.join('Results',
'before_cascade_{}_{}.png'.format(energy,
angle)))
if __name__ == '__main__':
main()