-
Notifications
You must be signed in to change notification settings - Fork 1
/
inputupdate.py
43 lines (37 loc) · 1.43 KB
/
inputupdate.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
import os
import re
import pandas as pd
import numpy as np
import shutil
import subprocess
import multiprocessing
with open(os.path.join('base','input.py')) as infile:
input_file = infile.read()
base_directory = 'binding_energies'
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.
"""
print('start of make input')
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, 'input.py')
with open(out_file,'w') as outfile:
outfile.write(output)
shutil.copy(os.path.join('base','run.sh'), out_dir)
return out_dir
carbon_range = (-7.5, -2.0)
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))