-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_cantera_simulations.py
48 lines (43 loc) · 1.68 KB
/
update_cantera_simulations.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
import os
import re
import pandas as pd
import numpy as np
import shutil
import subprocess
import multiprocessing
with open(os.path.join('rh', 'simulations.py')) as infile:
input_file = infile.read()
base_directory = 'large-grid'
def directory(carbon,oxygen):
return os.path.join(base_directory, "c{:.3f}o{:.3f}".format(carbon,oxygen))
def make_input(binding_energies):
"""
Make an input file for the given (carbon,oxygen) tuple (or iterable) of binding energies
and return the name of the directory in which it is saved.
"""
carbon, oxygen = binding_energies
output = input_file
out_dir = directory(carbon, oxygen)
carbon_string = "'C':({:f}, 'eV/molecule')".format(carbon)
output = re.sub("'C':\(.*?, 'eV/molecule'\)", carbon_string, output)
oxygen_string = "'O':({:f}, 'eV/molecule')".format(oxygen)
output = re.sub("'O':\(.*?, 'eV/molecule'\)", oxygen_string, output)
os.path.exists(out_dir) or os.makedirs(out_dir)
out_file = os.path.join(out_dir, 'simulations.py')
with open(out_file,'w') as outfile:
outfile.write(output)
shutil.copy(os.path.join('base','runsimulations.sh'), out_dir)
return out_dir
carbon_range = (-7.5, -2)
oxygen_range = (-6.5, -1.5)
grid_size = 9
mesh = np.mgrid[carbon_range[0]:carbon_range[1]:grid_size*1j, oxygen_range[0]:oxygen_range[1]:grid_size*1j]
experiments = mesh.reshape((2,-1)).T
list(map(make_input, experiments))
base_directory = 'small-grid'
carbon_range = (-7.5, -5.5)
oxygen_range = (-5.25, -3.25)
grid_size = 9
mesh = np.mgrid[carbon_range[0]:carbon_range[1]:grid_size*1j, oxygen_range[0]:oxygen_range[1]:grid_size*1j]
experiments = mesh.reshape((2,-1)).T
list(map(make_input, experiments))