Skip to content

Commit 870eab0

Browse files
author
Jake Smith
committed
add flag for poorly behaving RASPA2 inputs
1 parent bb33423 commit 870eab0

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

mofdiff/gcmc/gcmc_wrapper.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ def calculate_unit_cells(self, forcefield_cutoff):
139139

140140
def write_out(self, output_path):
141141
with open(output_path, "w") as log_file:
142-
# log_file.write("input file: " + self.sorbent_file + "\n")
143-
# log_file.write("helium_void_fraction: " + str(self.helium_void_fraction) + "\n")
144-
# log_file.write("helium_void_fraction: " + str(self.helium_void_fraction) + "\n")
145142
log_file.write(self.raspa_output)
146143

147144
# assigns charges to the atoms in the simulation file using the MEPO Qeq charge equilibration method
@@ -192,21 +189,18 @@ def run_gcmc_simulation(
192189
initialization_cycles=0,
193190
equilibration_cycles=2000,
194191
production_cycles=2000,
195-
forcefield="UFF-TraPPe",
192+
forcefield="UFF",
196193
forcefield_cutoff=12,
197194
molecule_definitions="TraPPE",
198195
unit_cells=[0, 0, 0],
199196
cleanup=False,
197+
rewrite_raspa_input=False,
200198
):
201199
# copy cif file into parent RASPA folder
202200
shutil.copy(simulation.sorbent_file, raspa_path + "/share/raspa/structures/cif/")
203201
workdir = simulation.rundir / "raspa_output" / simulation.identifier
204202
workdir.mkdir(exist_ok=True, parents=True)
205203

206-
# create and enter temp directory
207-
# os.mkdir(simulation.rundir / "raspa_output" / simulation.identifier)
208-
# os.chdir(os.getcwd() + "/temp/raspa_output/" + simulation.identifier)
209-
210204
sorbent_file = ".".join(simulation.sorbent_file.split("/")[-1].split(".")[:-1])
211205

212206
# calculate number of unit cells needed if not user defined
@@ -299,8 +293,14 @@ def run_gcmc_simulation(
299293
# write out raspa input file
300294
with open(workdir / "simulation.input", "w") as raspa_input:
301295
raspa_input.write(simulation.raspa_config)
296+
297+
# optionally rewrite input file to avoid errors with RASPA reading it
298+
if rewrite_raspa_input:
299+
raspa_input_path = workdir / "simulation.input"
300+
subprocess.run(["mv", raspa_input_path, f"{raspa_input_path}.orig"])
301+
command = f"printf '%s\\n' \"$(cat {raspa_input_path}.orig)\" > {raspa_input_path}"
302+
subprocess.Popen(command, shell = True)
302303

303-
# os.chdir(str(workdir))
304304
# run raspa simulation
305305
subprocess.run([raspa_sim_path, "simulation.input"], cwd=str(workdir))
306306

@@ -313,4 +313,4 @@ def run_gcmc_simulation(
313313

314314
# clear temp directory
315315
if cleanup:
316-
shutil.rmtree(str(workdir))
316+
shutil.rmtree(str(workdir))

mofdiff/gcmc/simulation.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def extract_raspa_output(raspa_output, has_N2=False):
8787

8888
@timeout(36000)
8989
def working_capacity_vacuum_swing(cif_file, calc_charges=True,
90-
rundir='./temp'):
90+
rundir='./temp', rewrite_raspa_input=False):
9191
random.seed(4)
9292
np.random.seed(4)
9393
# adsorption conditions
@@ -102,7 +102,10 @@ def working_capacity_vacuum_swing(cif_file, calc_charges=True,
102102

103103
if calc_charges:
104104
gcmc_wrapper.calculate_mepo_qeq_charges(adsorbed)
105-
gcmc_wrapper.run_gcmc_simulation(adsorbed)
105+
gcmc_wrapper.run_gcmc_simulation(
106+
adsorbed,
107+
rewrite_raspa_input=rewrite_raspa_input,
108+
)
106109

107110
(
108111
adsorbed_CO2,
@@ -124,7 +127,10 @@ def working_capacity_vacuum_swing(cif_file, calc_charges=True,
124127

125128
if calc_charges:
126129
gcmc_wrapper.calculate_mepo_qeq_charges(residual)
127-
gcmc_wrapper.run_gcmc_simulation(residual)
130+
gcmc_wrapper.run_gcmc_simulation(
131+
residual,
132+
rewrite_raspa_input=rewrite_raspa_input,
133+
)
128134

129135
residual_CO2, heat_of_adsorption_CO2_363 = extract_raspa_output(
130136
residual.raspa_output, has_N2=False
@@ -149,4 +155,4 @@ def run_or_fail(cif_path):
149155
return working_capacity_vacuum_swing(cif_path)
150156
except Exception as e:
151157
print(e)
152-
return None
158+
return None

mofdiff/scripts/gcmc_screen.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from p_tqdm import p_umap
1111

1212

13-
def main(input_dir, ncpu=24):
13+
def main(input_dir, ncpu=24, rewrite_raspa_input=False):
1414
rundir = Path(input_dir) / 'gcmc'
1515
rundir.mkdir(exist_ok=True)
1616

@@ -42,7 +42,11 @@ def compute_gcmc(ciffile, max_natom=10000):
4242
info = 'atomic overlap'
4343
else:
4444
adsorption_info = working_capacity_vacuum_swing(
45-
str(ciffile), calc_charges=calc_charges, rundir=rundir)
45+
str(ciffile),
46+
calc_charges=calc_charges,
47+
rundir=rundir,
48+
rewrite_raspa_input=rewrite_raspa_input,
49+
)
4650
info = 'success'
4751
except Exception as e:
4852
print(f'Error in {ciffile}: {e}')
@@ -58,5 +62,7 @@ def compute_gcmc(ciffile, max_natom=10000):
5862
if __name__ == '__main__':
5963
parser = argparse.ArgumentParser()
6064
parser.add_argument('--input', type=str)
65+
parser.add_argument('--rewrite_raspa_input', action='store_true')
66+
parser.set_defaults(rewrite_raspa_input=False)
6167
args = parser.parse_args()
62-
main(args.input)
68+
main(args.input, rewrite_raspa_input=args.rewrite_raspa_input)

0 commit comments

Comments
 (0)