Skip to content

PR to verify disorders on input structure and improve error handling #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -314,14 +314,18 @@ 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:
crystal = io.CrystalReader('CSD').crystal(structure)
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,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)
@@ -411,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)
@@ -424,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)
Loading
Oops, something went wrong.