Skip to content

Commit 1099975

Browse files
committed
Added ignore_intra flag, removed duplicated call NO_JIRA
1 parent 7803c92 commit 1099975

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

scripts/multi_component_hydrogen_bond_propensity/multi_component_hydrogen_bond_propensity_report.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def calculate(self):
8181
print(self.hbp.functional_groups)
8282

8383
# Generate Training Dataset
84-
self.hbp.match_fitting_data(count=500) # set to 500 for better representation of functional groups
84+
self.hbp.match_fitting_data(count=50) # set to 500 for better representation of functional groups
8585

8686
self.hbp.analyse_fitting_data()
8787

@@ -190,13 +190,16 @@ def format_scores(scores, das, d_type):
190190
return formatted_scores
191191

192192

193-
def get_mc_scores(propensities, identifier):
193+
def get_mc_scores(propensities, identifier, ignore_intra:bool):
194194
# Calculates the multi-component scores from the individual HBP calculation
195195
AA_propensities = []
196196
BB_propensities = []
197197
AB_propensities = []
198198
BA_propensities = []
199199

200+
if ignore_intra is True:
201+
propensities = [p for p in propensities if p.is_intermolecular]
202+
200203
for p in propensities:
201204
t = "%s_d" % p.donor_label.split(" ")[0], "%s_a" % p.acceptor_label.split(" ")[0]
202205
if '_A_' in t[0] and '_A_' in t[1]:
@@ -323,7 +326,7 @@ def make_mc_report(identifier, results, directory, diagram_file, chart_file):
323326
launch_word_processor(output_file)
324327

325328

326-
def main(structure, work_directory, failure_directory, library, csdrefcode, force_run):
329+
def main(structure, work_directory, failure_directory, library, csdrefcode, ignore_intra, force_run):
327330
# This loads up the CSD if a refcode is requested, otherwise loads the structural file supplied
328331
if csdrefcode:
329332
try:
@@ -371,10 +374,9 @@ def main(structure, work_directory, failure_directory, library, csdrefcode, forc
371374
propensities, donors, acceptors = hbp_calculator.calculate()
372375
coordination_scores = coordination_scores_calc(crystal, directory)
373376
pair_output(crystal.identifier, propensities, donors, acceptors, coordination_scores, directory)
377+
mc_dictionary[coformer_name] = get_mc_scores(propensities, crystal.identifier, ignore_intra)
374378
with open(os.path.join(directory, "success.json"), "w") as file:
375-
tdata = get_mc_scores(propensities, crystal.identifier)
376-
json.dump(tdata, file)
377-
mc_dictionary[coformer_name] = get_mc_scores(propensities, crystal.identifier)
379+
json.dump(mc_dictionary[coformer_name], file)
378380
except Exception as error_message:
379381
print("Propensity calculation failure for %s!" % coformer_name)
380382
error_string = f"{coformer_name}: {error_message}"
@@ -429,7 +431,8 @@ def main(structure, work_directory, failure_directory, library, csdrefcode, forc
429431
default=ccdc_coformers_dir)
430432
parser.add_argument('-f', '--failure_directory', type=str,
431433
help='The location where the failures file should be generated')
432-
434+
parser.add_argument('-i', '--ignore_intra', action='store_true', default='False',
435+
help='Ignore intramolecular hydrogen bonds when ranking pairs')
433436
parser.add_argument('--force_run_disordered', action="store_true",
434437
help='Forces running the script on disordered entries. (NOT RECOMMENDED)', default=False)
435438

@@ -447,4 +450,4 @@ def main(structure, work_directory, failure_directory, library, csdrefcode, forc
447450
parser.error('%s - library not found.' % args.coformer_library)
448451

449452
main(args.input_structure, args.directory, args.failure_directory, args.coformer_library, refcode,
450-
args.force_run_disordered)
453+
args.ignore_intra, args.force_run_disordered)

0 commit comments

Comments
 (0)