From 116f36c8bc9dcf438d8b10a7c0fe63855738a176 Mon Sep 17 00:00:00 2001 From: Luke2Sky Date: Mon, 2 Oct 2023 15:07:25 -0300 Subject: [PATCH 1/3] Added a file to note every failure that happened during the running of multi_component_hydrogen_bond_propensity_report.py --- .../multi_component_hydrogen_bond_propensity_report.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/multi_component_hydrogen_bond_propensity/multi_component_hydrogen_bond_propensity_report.py b/scripts/multi_component_hydrogen_bond_propensity/multi_component_hydrogen_bond_propensity_report.py index 70d413e..34da4ba 100644 --- a/scripts/multi_component_hydrogen_bond_propensity/multi_component_hydrogen_bond_propensity_report.py +++ b/scripts/multi_component_hydrogen_bond_propensity/multi_component_hydrogen_bond_propensity_report.py @@ -334,6 +334,7 @@ def main(structure, work_directory, library, csdrefcode): coformer_files = glob.glob(os.path.join(library, '*.mol2')) tempdir = tempfile.mkdtemp() mc_dictionary = {} + failures = [] # for each coformer in the library, make a pair file for the api/coformer and run a HBP calculation for i, f in enumerate(coformer_files): @@ -359,6 +360,11 @@ def main(structure, work_directory, library, csdrefcode): diagram_file = make_diagram(api_molecule, work_directory) chart_file = make_mc_chart(mc_hbp_screen, directory, api_molecule) make_mc_report(structure, mc_hbp_screen, work_directory, diagram_file, chart_file) + with open("failures.txt", 'w') as file: + # Iterate through the array + for element in failures: + # Write each element to the file followed by a newline character + file.write(element + '\n') if __name__ == '__main__': From d3359eb53b792fe051723cad25dfd3d332e612ec Mon Sep 17 00:00:00 2001 From: Luke2Sky Date: Mon, 2 Oct 2023 15:16:43 -0300 Subject: [PATCH 2/3] 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. --- ...mponent_hydrogen_bond_propensity_report.py | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/scripts/multi_component_hydrogen_bond_propensity/multi_component_hydrogen_bond_propensity_report.py b/scripts/multi_component_hydrogen_bond_propensity/multi_component_hydrogen_bond_propensity_report.py index 34da4ba..c980a88 100644 --- a/scripts/multi_component_hydrogen_bond_propensity/multi_component_hydrogen_bond_propensity_report.py +++ b/scripts/multi_component_hydrogen_bond_propensity/multi_component_hydrogen_bond_propensity_report.py @@ -20,6 +20,7 @@ import argparse import tempfile import subprocess +import json import matplotlib @@ -344,16 +345,24 @@ def main(structure, work_directory, library, csdrefcode): crystal = crystal_reader[0] directory = os.path.join(os.path.abspath(work_directory), crystal.identifier) - - try: - propensities, donors, acceptors = propensity_calc(crystal, directory) - coordination_scores = coordination_scores_calc(crystal, directory) - pair_output(crystal.identifier, propensities, donors, acceptors, coordination_scores, directory) - mc_dictionary[coformer_name] = get_mc_scores(propensities, crystal.identifier) - - except RuntimeError: - print("Propensity calculation failure for %s!" % coformer_name) - mc_dictionary[coformer_name] = ["N/A", "N/A", "N/A", "N/A", "N/A", crystal.identifier] + if os.path.exists(os.path.join(directory, "success.json")): + with open(os.path.join(directory, "success.json"), "r") as file: + tloaded = json.load(file) + mc_dictionary[coformer_name] = tloaded + else: + try: + propensities, donors, acceptors = propensity_calc(crystal, directory) + coordination_scores = coordination_scores_calc(crystal, directory) + pair_output(crystal.identifier, propensities, donors, acceptors, coordination_scores, directory) + with open(os.path.join(directory, "success.json"), "w") as file: + tdata = get_mc_scores(propensities, crystal.identifier) + json.dump(tdata, file) + mc_dictionary[coformer_name] = get_mc_scores(propensities, crystal.identifier) + print(get_mc_scores(propensities, crystal.identifier)) + except RuntimeError: + print("Propensity calculation failure for %s!" % coformer_name) + mc_dictionary[coformer_name] = ["N/A", "N/A", "N/A", "N/A", "N/A", crystal.identifier] + failures.append(coformer_name) # Make sense of the outputs of all the calculations mc_hbp_screen = sorted(mc_dictionary.items(), key=lambda e: 0 if e[1][0] == 'N/A' else e[1][0], reverse=True) From 0ec9d2686486be1cdcb40a55922a5da22d6c3e11 Mon Sep 17 00:00:00 2001 From: Luke2Sky Date: Tue, 3 Oct 2023 12:29:56 -0300 Subject: [PATCH 3/3] Added --failure_directory argument --- ...i_component_hydrogen_bond_propensity_report.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/scripts/multi_component_hydrogen_bond_propensity/multi_component_hydrogen_bond_propensity_report.py b/scripts/multi_component_hydrogen_bond_propensity/multi_component_hydrogen_bond_propensity_report.py index c980a88..af167ff 100644 --- a/scripts/multi_component_hydrogen_bond_propensity/multi_component_hydrogen_bond_propensity_report.py +++ b/scripts/multi_component_hydrogen_bond_propensity/multi_component_hydrogen_bond_propensity_report.py @@ -314,7 +314,7 @@ def make_mc_report(identifier, results, directory, diagram_file, chart_file): launch_word_processor(output_file) -def main(structure, work_directory, library, csdrefcode): +def main(structure, work_directory, failure_directory, library, csdrefcode): # This loads up the CSD if a refcode is requested, otherwise loads the structural file supplied if csdrefcode: try: @@ -369,11 +369,9 @@ def main(structure, work_directory, library, csdrefcode): diagram_file = make_diagram(api_molecule, work_directory) chart_file = make_mc_chart(mc_hbp_screen, directory, api_molecule) make_mc_report(structure, mc_hbp_screen, work_directory, diagram_file, chart_file) - with open("failures.txt", 'w') as file: - # Iterate through the array - for element in failures: - # Write each element to the file followed by a newline character - file.write(element + '\n') + if failure_directory is not None: + with open(os.path.join(failure_directory, 'failures.txt'), 'w', encoding='utf-8', newline='') as file: + file.write('\n'.join(map(str, failures))) if __name__ == '__main__': @@ -411,9 +409,10 @@ def main(structure, work_directory, library, csdrefcode): parser.add_argument('-c', '--coformer_library', type=str, help='the directory of the desired coformer library', default=ccdc_coformers_dir) + parser.add_argument('-f', '--failure_directory', type=str, + help='The location where the failures file should be generated') args = parser.parse_args() - refcode = False if not os.path.isfile(args.input_structure): @@ -428,4 +427,4 @@ def main(structure, work_directory, library, csdrefcode): if not os.path.isdir(args.coformer_library): parser.error('%s - library not found.' % args.coformer_library) - main(args.input_structure, args.directory, args.coformer_library, refcode) + main(args.input_structure, args.directory, args.failure_directory, args.coformer_library, refcode)