Skip to content

Commit 26f61a2

Browse files
committed
Move functions.
1 parent b2f2ccd commit 26f61a2

File tree

2 files changed

+38
-37
lines changed

2 files changed

+38
-37
lines changed

mmtbx/ligands/rdkit_utils.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,41 @@
1818
match_mol_indices: Match atom indices of different mols
1919
"""
2020

21+
def get_rdkit_bond_type(cif_order):
22+
"""
23+
Maps CCTBX CIF bond orders to RDKit BondType enum.
24+
"""
25+
if not cif_order: return Chem.BondType.SINGLE
26+
order = cif_order.lower()
27+
if 'sing' in order: return Chem.BondType.SINGLE
28+
if 'doub' in order: return Chem.BondType.DOUBLE
29+
if 'trip' in order: return Chem.BondType.TRIPLE
30+
if 'deloc' in order or 'arom' in order: return Chem.BondType.AROMATIC
31+
return Chem.BondType.SINGLE
32+
33+
def is_amide_bond(mol, bond):
34+
"""
35+
Checks if a bond is a C-N amide bond to prevent cutting peptides.
36+
"""
37+
a1 = bond.GetBeginAtom()
38+
a2 = bond.GetEndAtom()
39+
40+
c_atom, n_atom = None, None
41+
if a1.GetSymbol() == 'C' and a2.GetSymbol() == 'N':
42+
c_atom, n_atom = a1, a2
43+
elif a2.GetSymbol() == 'C' and a1.GetSymbol() == 'N':
44+
c_atom, n_atom = a2, a1
45+
46+
if c_atom is None: return False
47+
48+
for nbr in c_atom.GetNeighbors():
49+
if nbr.GetIdx() == n_atom.GetIdx(): continue
50+
if nbr.GetSymbol() == 'O':
51+
bond_to_o = mol.GetBondBetweenAtoms(c_atom.GetIdx(), nbr.GetIdx())
52+
if bond_to_o is not None and bond_to_o.GetBondType() == Chem.BondType.DOUBLE:
53+
return True
54+
return False
55+
2156
def get_prop_safe(rd_obj, prop):
2257
if prop not in rd_obj.GetPropNames(): return False
2358
return rd_obj.GetProp(prop)

mmtbx/regression/tst_rdkit_utils_fragmentation.py

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from rdkit import Chem
77
from rdkit.Chem import Lipinski, rdmolops
88
from scitbx.array_family import flex
9+
import mmtbx.ligands.rdkit_utils as rdkit_utils
910

1011
# ------------------------------------------------------------------------------
1112

@@ -102,7 +103,7 @@ def run_fragmentation(ligand_isel, model):
102103
rd_j = name_to_rdkit[atom_2]
103104
# Check existing to prevent duplicates
104105
if mol.GetBondBetweenAtoms(rd_i, rd_j) is None:
105-
mol.AddBond(rd_i, rd_j, get_rdkit_bond_type(order_str))
106+
mol.AddBond(rd_i, rd_j, rdkit_utils.get_rdkit_bond_type(order_str))
106107

107108
# 4. Sanitize (Important for implicit valence calculation)
108109
try:
@@ -122,7 +123,7 @@ def run_fragmentation(ligand_isel, model):
122123
if bond is None: continue
123124

124125
# Filter 1: Protect Amides
125-
if is_amide_bond(mol, bond): continue
126+
if rdkit_utils.is_amide_bond(mol, bond): continue
126127

127128
bidx = bond.GetIdx()
128129

@@ -170,41 +171,6 @@ def run_fragmentation(ligand_isel, model):
170171

171172
return cctbx_rigid_components
172173

173-
def get_rdkit_bond_type(cif_order):
174-
"""
175-
Maps CCTBX CIF bond orders to RDKit BondType enum.
176-
"""
177-
if not cif_order: return Chem.BondType.SINGLE
178-
order = cif_order.lower()
179-
if 'sing' in order: return Chem.BondType.SINGLE
180-
if 'doub' in order: return Chem.BondType.DOUBLE
181-
if 'trip' in order: return Chem.BondType.TRIPLE
182-
if 'deloc' in order or 'arom' in order: return Chem.BondType.AROMATIC
183-
return Chem.BondType.SINGLE
184-
185-
def is_amide_bond(mol, bond):
186-
"""
187-
Checks if a bond is a C-N amide bond to prevent cutting peptides.
188-
"""
189-
a1 = bond.GetBeginAtom()
190-
a2 = bond.GetEndAtom()
191-
192-
c_atom, n_atom = None, None
193-
if a1.GetSymbol() == 'C' and a2.GetSymbol() == 'N':
194-
c_atom, n_atom = a1, a2
195-
elif a2.GetSymbol() == 'C' and a1.GetSymbol() == 'N':
196-
c_atom, n_atom = a2, a1
197-
198-
if c_atom is None: return False
199-
200-
for nbr in c_atom.GetNeighbors():
201-
if nbr.GetIdx() == n_atom.GetIdx(): continue
202-
if nbr.GetSymbol() == 'O':
203-
bond_to_o = mol.GetBondBetweenAtoms(c_atom.GetIdx(), nbr.GetIdx())
204-
if bond_to_o is not None and bond_to_o.GetBondType() == Chem.BondType.DOUBLE:
205-
return True
206-
return False
207-
208174
# ------------------------------------------------------------------------------
209175

210176
pdb_str_01 = '''

0 commit comments

Comments
 (0)