Skip to content

Commit 2be0c35

Browse files
authored
Merge pull request #78 from ccdc-opensource/intra_flag
Added intra flag, removed duplicated call NO_JIRA
2 parents debf7d7 + 5ec4aa4 commit 2be0c35

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

scripts/multi_component_hydrogen_bond_propensity/multi_component_hydrogen_bond_propensity_report.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,27 @@ 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 = []
199+
AA_intra_propensities = []
200+
BB_intra_propensities = []
199201

200202
for p in propensities:
203+
if ignore_intra and not p.is_intermolecular:
204+
continue
201205
t = "%s_d" % p.donor_label.split(" ")[0], "%s_a" % p.acceptor_label.split(" ")[0]
202206
if '_A_' in t[0] and '_A_' in t[1]:
203207
AA_propensities.append(p.propensity)
208+
if not p.is_intermolecular:
209+
AA_intra_propensities.append(p.propensity)
204210
elif '_B_' in t[0] and '_B_' in t[1]:
205211
BB_propensities.append(p.propensity)
212+
if not p.is_intermolecular:
213+
BB_intra_propensities.append(p.propensity)
206214
elif '_A_' in t[0] and '_B_' in t[1]:
207215
AB_propensities.append(p.propensity)
208216
elif '_B_' in t[0] and '_A_' in t[1]:
@@ -212,10 +220,12 @@ def get_mc_scores(propensities, identifier):
212220
max_AB = max(AB_propensities) if len(AB_propensities) > 0 else 0.0
213221
max_BA = max(BA_propensities) if len(BA_propensities) > 0 else 0.0
214222
max_list = [max_AA, max_BB, max_AB, max_BA]
215-
max_keys = ['A:A', 'B:B', 'A:B', 'B:A']
216223
max_mc = max(max_list[2], max_list[3])
217224
max_sc = max(max_list[0], max_list[1])
218225

226+
max_keys = ['A:A*', 'B:B*', 'A:B', 'B:A'] if max_sc in AA_intra_propensities or max_sc in BB_intra_propensities \
227+
else ['A:A', 'B:B', 'A:B', 'B:A']
228+
219229
return [round((max_mc - max_sc), 2),
220230
max_keys[max_list.index(max(max_list))],
221231
round(max_mc, 2),
@@ -323,7 +333,7 @@ def make_mc_report(identifier, results, directory, diagram_file, chart_file):
323333
launch_word_processor(output_file)
324334

325335

326-
def main(structure, work_directory, failure_directory, library, csdrefcode, force_run):
336+
def main(structure, work_directory, failure_directory, library, csdrefcode, ignore_intra, force_run):
327337
# This loads up the CSD if a refcode is requested, otherwise loads the structural file supplied
328338
if csdrefcode:
329339
try:
@@ -371,10 +381,9 @@ def main(structure, work_directory, failure_directory, library, csdrefcode, forc
371381
propensities, donors, acceptors = hbp_calculator.calculate()
372382
coordination_scores = coordination_scores_calc(crystal, directory)
373383
pair_output(crystal.identifier, propensities, donors, acceptors, coordination_scores, directory)
384+
mc_dictionary[coformer_name] = get_mc_scores(propensities, crystal.identifier, ignore_intra)
374385
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)
386+
json.dump(mc_dictionary[coformer_name], file)
378387
except Exception as error_message:
379388
print("Propensity calculation failure for %s!" % coformer_name)
380389
error_string = f"{coformer_name}: {error_message}"
@@ -429,7 +438,8 @@ def main(structure, work_directory, failure_directory, library, csdrefcode, forc
429438
default=ccdc_coformers_dir)
430439
parser.add_argument('-f', '--failure_directory', type=str,
431440
help='The location where the failures file should be generated')
432-
441+
parser.add_argument('-i', '--ignore_intra', type=bool, action='store_true', default=False,
442+
help='Ignore intramolecular hydrogen bonds when ranking pairs')
433443
parser.add_argument('--force_run_disordered', action="store_true",
434444
help='Forces running the script on disordered entries. (NOT RECOMMENDED)', default=False)
435445

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

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

0 commit comments

Comments
 (0)