Skip to content

Commit 37e7144

Browse files
Brandon Duane WalkerBrandon Duane Walker
authored andcommitted
extract protein and ligand in same workflow step
1 parent 6539626 commit 37e7144

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

examples/scripts/topology_check.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import signal
23
from rdkit import Chem
34
from rdkit.Chem.rdchem import Atom, Mol
45

@@ -14,11 +15,19 @@ def map_atoms(mol1: Mol, mol2: Mol) -> dict:
1415
Returns:
1516
dict: Mapping of atoms from mol1 to mol2.
1617
"""
17-
match_atoms = mol1.GetSubstructMatch(mol2)
18+
mol1_num_atoms = mol1.GetNumAtoms()
19+
mol2_num_atoms = mol2.GetNumAtoms()
20+
# if the mol being mapped has less atom then a match won't be found
21+
if mol1_num_atoms > mol2_num_atoms:
22+
match_atoms = mol1.GetSubstructMatch(mol2)
23+
mol2_index_to_mol1_index = {mol2_index: mol1_index for mol2_index, mol1_index in enumerate(match_atoms)}
24+
mol1_index_to_mol2_index = {k: v for v, k in mol2_index_to_mol1_index.items()}
25+
else:
26+
match_atoms = mol2.GetSubstructMatch(mol1)
27+
mol1_index_to_mol2_index = {mol1_index: mol2_index for mol1_index, mol2_index in enumerate(match_atoms)}
1828
if len(match_atoms) == 0:
1929
raise ValueError("No atoms matched between the two molecules.")
20-
mol2_index_to_mol1_index = {mol2_index: mol1_index for mol2_index, mol1_index in enumerate(match_atoms)}
21-
mol1_index_to_mol2_index = {k: v for v, k in mol2_index_to_mol1_index.items()}
30+
2231
return mol1_index_to_mol2_index
2332

2433

@@ -126,8 +135,11 @@ def main() -> None:
126135
args = parser.parse_args()
127136
mol1 = Chem.MolFromPDBFile(args.file1, removeHs=False, sanitize=False)
128137
mol2 = Chem.MolFromPDBFile(args.file2, removeHs=False, sanitize=False)
129-
138+
signal.alarm(60)
130139
mol1_index_to_mol2_index = map_atoms(mol1, mol2)
140+
# Cancel the alarm if the code executed within the timeout duration
141+
signal.alarm(0)
142+
131143
atom_differences = compare_atoms(mol1, mol2, mol1_index_to_mol2_index, intended_changes=args.intended_changes)
132144
if atom_differences:
133145
for mol1_idx, diff in atom_differences.items():

0 commit comments

Comments
 (0)