From 68a550fb58a7b6ebf5b253bbd6aab1a2b172bfbc Mon Sep 17 00:00:00 2001 From: Sky2Luke Date: Tue, 9 Jul 2024 18:57:39 -0300 Subject: [PATCH 1/2] Improves error handling with descriptive error messages as warnings. --- .../multi_component_hydrogen_bond_propensity_report.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 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 1737d98..eb4e4e1 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 @@ -358,10 +358,12 @@ def main(structure, work_directory, failure_directory, library, csdrefcode): tdata = get_mc_scores(propensities, crystal.identifier) json.dump(tdata, file) mc_dictionary[coformer_name] = get_mc_scores(propensities, crystal.identifier) - except RuntimeError: + except RuntimeError as error_message: print("Propensity calculation failure for %s!" % coformer_name) + error_string = f"{coformer_name}: {error_message}" + warnings.warn(error_string) mc_dictionary[coformer_name] = ["N/A", "N/A", "N/A", "N/A", "N/A", crystal.identifier] - failures.append(coformer_name) + failures.append(error_string) # 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 8ba409fab4c5cc38f152c004df1352a0eb825d93 Mon Sep 17 00:00:00 2001 From: Sky2Luke Date: Tue, 9 Jul 2024 18:57:39 -0300 Subject: [PATCH 2/2] This raises an exception when the input_structure is disordered it doesn't totally fixes #58 but improves it somewhat. There doesn't seem to be any consistent ways to check for disorder in the different structure files supported. --- ...ulti_component_hydrogen_bond_propensity_report.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 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 eb4e4e1..c49fffe 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, failure_directory, library, csdrefcode): +def main(structure, work_directory, failure_directory, library, csdrefcode, force_run): # This loads up the CSD if a refcode is requested, otherwise loads the structural file supplied if csdrefcode: try: @@ -322,6 +322,10 @@ def main(structure, work_directory, failure_directory, library, csdrefcode): except RuntimeError: print('Error! %s is not in the database!' % structure) quit() + if io.CrystalReader('CSD').entry(structure).has_disorder and not force_run: + raise RuntimeError("Disorder can cause undefined behaviour. It is not advisable to run this " + "script on disordered entries.\n To force this script to run on disordered entries" + " use the flag --force_run_disordered.") else: crystal = io.CrystalReader(structure)[0] @@ -413,6 +417,9 @@ def main(structure, work_directory, failure_directory, library, csdrefcode): parser.add_argument('-f', '--failure_directory', type=str, help='The location where the failures file should be generated') + parser.add_argument('--force_run_disordered', action="store_true", + help='Forces running the script on disordered entries. (NOT RECOMMENDED)', default=False) + args = parser.parse_args() refcode = False args.directory = os.path.abspath(args.directory) @@ -426,4 +433,5 @@ def main(structure, work_directory, failure_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.failure_directory, args.coformer_library, refcode) + main(args.input_structure, args.directory, args.failure_directory, args.coformer_library, refcode, + args.force_run_disordered)