From df7115d41c41f48239469784153ed0046461b25c Mon Sep 17 00:00:00 2001 From: Sky2Luke Date: Tue, 9 Jul 2024 18:57:39 -0300 Subject: [PATCH 1/3] This raises an exception when the input_structure it doesn't totally fixes #58 but improves it somewhat. There doesn't seem to be any consistent ways to check for disorder --- ...component_hydrogen_bond_propensity_report.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 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..0423237 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] @@ -358,10 +362,11 @@ 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) + print(error_message) mc_dictionary[coformer_name] = ["N/A", "N/A", "N/A", "N/A", "N/A", crystal.identifier] - failures.append(coformer_name) + failures.append(f"coformer_name: {error_message}") # 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) @@ -411,6 +416,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) @@ -424,4 +432,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) From 6e1fce27e285e730ee05f93940ad5b13c9f6f112 Mon Sep 17 00:00:00 2001 From: Sky2Luke Date: Tue, 9 Jul 2024 19:23:11 -0300 Subject: [PATCH 2/3] Verifies if mol2 files have 3d coordinates to avoid running if there are no 3d coordinates and gives out a warning. --- .../multi_component_hydrogen_bond_propensity_report.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 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 0423237..c1877f8 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 @@ -21,6 +21,7 @@ import tempfile import subprocess import json +import warnings import matplotlib @@ -32,8 +33,6 @@ from ccdc.descriptors import CrystalDescriptors try: - import warnings - with warnings.catch_warnings(): warnings.simplefilter("ignore", category=DeprecationWarning) import docxtpl @@ -344,6 +343,11 @@ def main(structure, work_directory, failure_directory, library, csdrefcode, forc # 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): molecule_file, coformer_name = make_pair_file(api_molecule, tempdir, f, i + 1) + if not io.CrystalReader(f)[0].molecule.is_3d: + failure_warning = f"Could not run for {coformer_name} no 3d coordinates present." + failures.append(failure_warning) + warnings.warn(failure_warning) + continue print(coformer_name) crystal_reader = io.CrystalReader(molecule_file) crystal = crystal_reader[0] @@ -366,7 +370,7 @@ def main(structure, work_directory, failure_directory, library, csdrefcode, forc print("Propensity calculation failure for %s!" % coformer_name) print(error_message) mc_dictionary[coformer_name] = ["N/A", "N/A", "N/A", "N/A", "N/A", crystal.identifier] - failures.append(f"coformer_name: {error_message}") + failures.append(f"{coformer_name}: {error_message}") # 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 39fe60fdd53d1bb46b514680746a04e8d6e7f4d6 Mon Sep 17 00:00:00 2001 From: Sky2Luke Date: Tue, 9 Jul 2024 19:32:59 -0300 Subject: [PATCH 3/3] Update ReadMe.md --- scripts/multi_component_hydrogen_bond_propensity/ReadMe.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/multi_component_hydrogen_bond_propensity/ReadMe.md b/scripts/multi_component_hydrogen_bond_propensity/ReadMe.md index b7d6092..1dbf78a 100644 --- a/scripts/multi_component_hydrogen_bond_propensity/ReadMe.md +++ b/scripts/multi_component_hydrogen_bond_propensity/ReadMe.md @@ -44,6 +44,8 @@ optional arguments: the directory of the desired coformer library -f FAILURE_DIRECTORY, --failure_directory FAILURE_DIRECTORY The location where the failures file should be generated + --force_run_disordered + Forces running the script on disordered entries. (NOT RECOMMENDED) ``` The default coformer library is the one supplied with your Mercury install