Skip to content

Commit df7115d

Browse files
committed
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
1 parent 74a5289 commit df7115d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

scripts/multi_component_hydrogen_bond_propensity/multi_component_hydrogen_bond_propensity_report.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,18 @@ def make_mc_report(identifier, results, directory, diagram_file, chart_file):
314314
launch_word_processor(output_file)
315315

316316

317-
def main(structure, work_directory, failure_directory, library, csdrefcode):
317+
def main(structure, work_directory, failure_directory, library, csdrefcode, force_run):
318318
# This loads up the CSD if a refcode is requested, otherwise loads the structural file supplied
319319
if csdrefcode:
320320
try:
321321
crystal = io.CrystalReader('CSD').crystal(structure)
322322
except RuntimeError:
323323
print('Error! %s is not in the database!' % structure)
324324
quit()
325+
if io.CrystalReader('CSD').entry(structure).has_disorder and not force_run:
326+
raise RuntimeError("Disorder can cause undefined behaviour. It is not advisable to run this "
327+
"script on disordered entries.\n To force this script to run on disordered entries"
328+
" use the flag --force_run_disordered.")
325329
else:
326330
crystal = io.CrystalReader(structure)[0]
327331

@@ -358,10 +362,11 @@ def main(structure, work_directory, failure_directory, library, csdrefcode):
358362
tdata = get_mc_scores(propensities, crystal.identifier)
359363
json.dump(tdata, file)
360364
mc_dictionary[coformer_name] = get_mc_scores(propensities, crystal.identifier)
361-
except RuntimeError:
365+
except RuntimeError as error_message:
362366
print("Propensity calculation failure for %s!" % coformer_name)
367+
print(error_message)
363368
mc_dictionary[coformer_name] = ["N/A", "N/A", "N/A", "N/A", "N/A", crystal.identifier]
364-
failures.append(coformer_name)
369+
failures.append(f"coformer_name: {error_message}")
365370

366371
# Make sense of the outputs of all the calculations
367372
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):
411416
parser.add_argument('-f', '--failure_directory', type=str,
412417
help='The location where the failures file should be generated')
413418

419+
parser.add_argument('--force_run_disordered', action="store_true",
420+
help='Forces running the script on disordered entries. (NOT RECOMMENDED)', default=False)
421+
414422
args = parser.parse_args()
415423
refcode = False
416424
args.directory = os.path.abspath(args.directory)
@@ -424,4 +432,5 @@ def main(structure, work_directory, failure_directory, library, csdrefcode):
424432
if not os.path.isdir(args.coformer_library):
425433
parser.error('%s - library not found.' % args.coformer_library)
426434

427-
main(args.input_structure, args.directory, args.failure_directory, args.coformer_library, refcode)
435+
main(args.input_structure, args.directory, args.failure_directory, args.coformer_library, refcode,
436+
args.force_run_disordered)

0 commit comments

Comments
 (0)