Skip to content

Commit d3359eb

Browse files
committed
Fixed Failures and added a json with the mc_scores for it to be able to save the state of the MCHBP. This was done so a report can be compiled even if the software crashes. This will allow for example stopping the software and re-running it and skipping the already calculated regressions.
1 parent 116f36c commit d3359eb

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

scripts/multi_component_hydrogen_bond_propensity/multi_component_hydrogen_bond_propensity_report.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import argparse
2121
import tempfile
2222
import subprocess
23+
import json
2324

2425
import matplotlib
2526

@@ -344,16 +345,24 @@ def main(structure, work_directory, library, csdrefcode):
344345
crystal = crystal_reader[0]
345346

346347
directory = os.path.join(os.path.abspath(work_directory), crystal.identifier)
347-
348-
try:
349-
propensities, donors, acceptors = propensity_calc(crystal, directory)
350-
coordination_scores = coordination_scores_calc(crystal, directory)
351-
pair_output(crystal.identifier, propensities, donors, acceptors, coordination_scores, directory)
352-
mc_dictionary[coformer_name] = get_mc_scores(propensities, crystal.identifier)
353-
354-
except RuntimeError:
355-
print("Propensity calculation failure for %s!" % coformer_name)
356-
mc_dictionary[coformer_name] = ["N/A", "N/A", "N/A", "N/A", "N/A", crystal.identifier]
348+
if os.path.exists(os.path.join(directory, "success.json")):
349+
with open(os.path.join(directory, "success.json"), "r") as file:
350+
tloaded = json.load(file)
351+
mc_dictionary[coformer_name] = tloaded
352+
else:
353+
try:
354+
propensities, donors, acceptors = propensity_calc(crystal, directory)
355+
coordination_scores = coordination_scores_calc(crystal, directory)
356+
pair_output(crystal.identifier, propensities, donors, acceptors, coordination_scores, directory)
357+
with open(os.path.join(directory, "success.json"), "w") as file:
358+
tdata = get_mc_scores(propensities, crystal.identifier)
359+
json.dump(tdata, file)
360+
mc_dictionary[coformer_name] = get_mc_scores(propensities, crystal.identifier)
361+
print(get_mc_scores(propensities, crystal.identifier))
362+
except RuntimeError:
363+
print("Propensity calculation failure for %s!" % coformer_name)
364+
mc_dictionary[coformer_name] = ["N/A", "N/A", "N/A", "N/A", "N/A", crystal.identifier]
365+
failures.append(coformer_name)
357366

358367
# Make sense of the outputs of all the calculations
359368
mc_hbp_screen = sorted(mc_dictionary.items(), key=lambda e: 0 if e[1][0] == 'N/A' else e[1][0], reverse=True)

0 commit comments

Comments
 (0)