@@ -59,9 +59,9 @@ def get_writer(outfile_base):
59
59
global file_count
60
60
61
61
if not writer :
62
- writer = Chem .SDWriter (outfile_base + '_' + f'{ file_count :04 } ' + '.sdf' )
62
+ writer = Chem .SDWriter (outfile_base + '_' + f'{ file_count :03 } ' + '.sdf' )
63
63
64
- if write_count < chunk_size :
64
+ if write_count <= chunk_size :
65
65
# print(' Using existing writer for', id, writer)
66
66
return writer
67
67
@@ -73,7 +73,7 @@ def get_writer(outfile_base):
73
73
writer .close ()
74
74
file_count += 1
75
75
76
- writer = Chem .SDWriter (outfile_base + '_' + f'{ file_count :04 } ' + '.sdf' )
76
+ writer = Chem .SDWriter (outfile_base + '_' + f'{ file_count :03 } ' + '.sdf' )
77
77
#print(' Using new writer for', id, writer)
78
78
return writer
79
79
@@ -361,11 +361,89 @@ def minimize_mol(mol, target, molMatch, targetMatch, algMap, getForceField):
361
361
rms = AlignMol (mol , target , atomMap = algMap )
362
362
mol .SetDoubleProp ('EmbedRMS' , rms )
363
363
364
+ def find_best_mcs (hit , mol ):
365
+ best_score = 0
366
+ mcs = rdFMCS .FindMCS ([hit , mol ], completeRingsOnly = True , ringMatchesRingOnly = True ,
367
+ atomCompare = rdFMCS .AtomCompare .CompareElements , bondCompare = rdFMCS .BondCompare .CompareOrder )
368
+ score = score_mcs (hit , mol , mcs )
369
+ if score > best_score :
370
+ best_score = score
371
+ best_mcs = mcs
372
+ best_index = 1
373
+ mcs = rdFMCS .FindMCS ([hit , mol ], completeRingsOnly = True , ringMatchesRingOnly = False ,
374
+ atomCompare = rdFMCS .AtomCompare .CompareElements , bondCompare = rdFMCS .BondCompare .CompareOrder )
375
+ score = score_mcs (hit , mol , mcs )
376
+ if score > best_score :
377
+ best_score = score
378
+ best_mcs = mcs
379
+ best_index = 2
380
+ mcs = rdFMCS .FindMCS ([hit , mol ], completeRingsOnly = False , ringMatchesRingOnly = True ,
381
+ atomCompare = rdFMCS .AtomCompare .CompareElements , bondCompare = rdFMCS .BondCompare .CompareOrder )
382
+ score = score_mcs (hit , mol , mcs )
383
+ if score > best_score :
384
+ best_score = score
385
+ best_mcs = mcs
386
+ best_index = 3
387
+ mcs = rdFMCS .FindMCS ([hit , mol ], completeRingsOnly = False , ringMatchesRingOnly = False ,
388
+ atomCompare = rdFMCS .AtomCompare .CompareElements , bondCompare = rdFMCS .BondCompare .CompareOrder )
389
+ score = score_mcs (hit , mol , mcs )
390
+ if score > best_score :
391
+ best_score = score
392
+ best_mcs = mcs
393
+ best_index = 4
394
+
395
+ mcs = rdFMCS .FindMCS ([hit , mol ], completeRingsOnly = True , ringMatchesRingOnly = True ,
396
+ atomCompare = rdFMCS .AtomCompare .CompareAny , bondCompare = rdFMCS .BondCompare .CompareAny )
397
+ score = score_mcs (hit , mol , mcs )
398
+ if score > best_score :
399
+ best_score = score
400
+ best_mcs = mcs
401
+ best_index = 5
402
+ mcs = rdFMCS .FindMCS ([hit , mol ], completeRingsOnly = True , ringMatchesRingOnly = False ,
403
+ atomCompare = rdFMCS .AtomCompare .CompareAny , bondCompare = rdFMCS .BondCompare .CompareAny )
404
+ score = score_mcs (hit , mol , mcs )
405
+ if score > best_score :
406
+ best_score = score
407
+ best_mcs = mcs
408
+ best_index = 6
409
+ mcs = rdFMCS .FindMCS ([hit , mol ], completeRingsOnly = False , ringMatchesRingOnly = True ,
410
+ atomCompare = rdFMCS .AtomCompare .CompareAny , bondCompare = rdFMCS .BondCompare .CompareAny )
411
+ score = score_mcs (hit , mol , mcs )
412
+ if score > best_score :
413
+ best_score = score
414
+ best_mcs = mcs
415
+ best_index = 7
416
+ mcs = rdFMCS .FindMCS ([hit , mol ], completeRingsOnly = False , ringMatchesRingOnly = False ,
417
+ atomCompare = rdFMCS .AtomCompare .CompareAny , bondCompare = rdFMCS .BondCompare .CompareAny )
418
+ score = score_mcs (hit , mol , mcs )
419
+ if score > best_score :
420
+ best_score = score
421
+ best_mcs = mcs
422
+ best_index = 8
423
+ print (" Best MCS is" , best_index , 'with score' , best_score )
424
+ return best_mcs
425
+
426
+ def score_mcs (hit , mol , mcs ):
427
+ smartsMol = Chem .MolFromSmarts (mcs .smartsString )
428
+ hitMatches = hit .GetSubstructMatch (smartsMol )
429
+ molMatches = mol .GetSubstructMatch (smartsMol )
430
+ # print(' Matches:', hitMatches, molMatches)
431
+ score = 0
432
+ for hitMatch , molMatch in zip (hitMatches , molMatches ):
433
+ score += 1
434
+ if hit .GetAtomWithIdx (hitMatch ).GetAtomicNum () == mol .GetAtomWithIdx (molMatch ).GetAtomicNum ():
435
+ score += 1
436
+ if mol .GetAtomWithIdx (molMatch ).IsInRing ():
437
+ score += 1
438
+ print (' Score:' , score )
439
+ return score
364
440
365
441
def execute (smi , hit_molfile , outfile_base , min_ph = None , max_ph = None , max_inputs = 0 , max_outputs = 0 , modulus = 0 , timout_embed_secs = 5 ):
366
442
367
443
global write_count
368
444
445
+ GetFF = lambda x ,confId = - 1 :AllChem .MMFFGetMoleculeForceField (x ,AllChem .MMFFGetMoleculeProperties (x ),confId = confId )
446
+
369
447
hit = Chem .MolFromMolFile (hit_molfile )
370
448
371
449
num_mols = 0
@@ -395,6 +473,8 @@ def execute(smi, hit_molfile, outfile_base, min_ph=None, max_ph=None, max_inputs
395
473
num_processed += 1
396
474
num_added = 0
397
475
476
+ w = get_writer (outfile_base )
477
+
398
478
print ('Processing' , num_mols , num_processed , smiles , Chem .MolToSmiles (hit ))
399
479
400
480
try :
@@ -406,14 +486,19 @@ def execute(smi, hit_molfile, outfile_base, min_ph=None, max_ph=None, max_inputs
406
486
else :
407
487
enumerated_mols = [mol ]
408
488
409
- # mcs0 = rdFMCS.FindMCS([hit, mol], completeRingsOnly=True, matchValences=False, ringMatchesRingOnly=True,
410
- # atomCompare=rdFMCS.AtomCompare.CompareAny, bondCompare=rdFMCS.BondCompare.CompareAny)
411
- mcs0 = rdFMCS .FindMCS ([hit , mol ], completeRingsOnly = True , ringMatchesRingOnly = True )
489
+ mcs0 = rdFMCS .FindMCS ([hit , mol ], completeRingsOnly = False , ringMatchesRingOnly = False ,
490
+ atomCompare = rdFMCS .AtomCompare .CompareAny , bondCompare = rdFMCS .BondCompare .CompareAny )
491
+ # mcs0 = rdFMCS.FindMCS([hit, mol], completeRingsOnly=False, ringMatchesRingOnly=False)
492
+ # score_mcs(hit, mol, mcs0)
493
+
494
+ # mcs0 = find_best_mcs(hit, mol)
495
+
412
496
mcsQuery = Chem .MolFromSmarts (mcs0 .smartsString )
413
497
414
498
count = 0
415
499
for ligand in enumerated_mols :
416
500
molh = Chem .AddHs (ligand )
501
+ # mol_match_tuple = MultiConstrainedEmbed(molh, queryMol, getForceField=GetFF)
417
502
mol_match_tuple = multi_constrained_embed (molh , hit , mcsQuery , timout_embed_secs = timout_embed_secs )
418
503
print (' ' , len (mol_match_tuple ), 'mols tethered' )
419
504
@@ -429,10 +514,8 @@ def execute(smi, hit_molfile, outfile_base, min_ph=None, max_ph=None, max_inputs
429
514
t_mol .SetProp ('TETHERED ATOMS' , tethers )
430
515
# print(' Tethers: ', tethers)
431
516
432
- w = get_writer (outfile_base )
433
517
w .write (t_mol )
434
518
write_count += 1
435
- print (' Write count =' , write_count )
436
519
num_outputs += 1
437
520
num_added += 1
438
521
@@ -455,7 +538,7 @@ def execute(smi, hit_molfile, outfile_base, min_ph=None, max_ph=None, max_inputs
455
538
def main ():
456
539
"""
457
540
Example usage:
458
- python -m pipelines.xchem.prepare_tether --smi ../../data/mpro/Mpro-x0387_0.smi --mol ../../data/mpro/Mpro-x0387_0.mol -o TETHERED --max-inputs 500 --chunk-size 100
541
+ python -m pipelines.xchem.prepare_tether_2 --smi ../../data/mpro/Mpro-x0387_0.smi --mol ../../data/mpro/Mpro-x0387_0.mol -o TETHERED --max-inputs 500 --chunk-size 100
459
542
460
543
:return:
461
544
"""
0 commit comments