It is a bit of a hack, but for certain applications where I know it is
likely fine, I use networkx to do subgraph isomorphism while considering
only the elements and not looking at the order of the bonds. I can
trivially draw a molecule where this does the wrong thing, but the majority
of the time, it does the right thing.

For the system you are discussing, here's an example using the attached
script:

$ ./isomorph.py 1PE_model.sdf 1kf6_1pe.pdb
[{0: 0,
  1: 1,
  2: 2,
  3: 3,
  4: 4,
  5: 5,
  6: 6,
  7: 7,
  8: 8,
  9: 9,
  10: 10,
  11: 11,
  12: 12,
  13: 13,
  14: 14,
  15: 15},
 {0: 15,
  1: 13,
  2: 14,
  3: 12,
  4: 11,
  5: 10,
  6: 9,
  7: 8,
  8: 7,
  9: 6,
  10: 5,
  11: 4,
  12: 3,
  13: 1,
  14: 2,
  15: 0}]

Since 1PE is symmetric, it outputs the forward ordering of the 1st -> 1st,
2nd -> 2nd, etc. and reverse ordering of 1st->16th, 2nd  -> 15th.

Hopefully the attached script gives an idea of how to incorporate this idea
into your code.


On Wed, Aug 31, 2016 at 4:51 PM, Sam Tonddast-Navaei <s.tondd...@gmail.com>
wrote:

> I am trying to read a small molecule from PDB file and match its atom
> numbers to the same molecule in a SDF file. I have tried both matching
> SMART patterns and using OBIsomorphismMapper, both work for 70% of cases.
> However there are cases for which OpenBabel can not simply get the right
> SMILES from just the PDB file (e.g.  adds extra double bonds or miss ones). 
> For
> example in PDB ID 1KF6 and ligand name IPE, if you generate SMILES from PDB
> you will get OCCO/C=C/OCCO/C=C/O/C=C/O while the correct one should be
> OCCOCCOCCOCCOCCO. I would appreciate if someone can give me some advise on
> this.
>
> Thanks,
> Sam
>
> ------------------------------------------------------------
> ------------------
>
> _______________________________________________
> OpenBabel-discuss mailing list
> OpenBabel-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
>
>
#!/usr/bin/env python
# Copyright 2016 Acpharis Inc, All Rights Reserved
import pprint
import networkx
from networkx.algorithms import isomorphism
import argparse
import pybel
import openbabel

parser = argparse.ArgumentParser()
parser.add_argument('sdf')
parser.add_argument('pdb')
args = parser.parse_args()


mol1 = pybel.readfile('sdf', args.sdf).next()
mol2 = pybel.readfile('pdb', args.pdb).next()


G1 = networkx.Graph()
G2 = networkx.Graph()

for index, atom in enumerate(mol1):
    G1.add_node(index, type=atom.atomicnum)

for bond in openbabel.OBMolBondIter(mol1.OBMol):
    G1.add_edge(bond.GetBeginAtomIdx()-1, bond.GetEndAtomIdx()-1)

for index, atom in enumerate(mol2):
    G2.add_node(index, type=atom.atomicnum)

for bond in openbabel.OBMolBondIter(mol2.OBMol):
    G2.add_edge(bond.GetBeginAtomIdx()-1, bond.GetEndAtomIdx()-1)

class GraphMatcherLocal(isomorphism.GraphMatcher):
    def semantic_feasibility(self, G1_node, G2_node):
        return self.G1.node[G1_node]['type'] == self.G2.node[G2_node]['type']

GM = GraphMatcherLocal(G1, G2)
gen_isms = GM.subgraph_isomorphisms_iter()

# networkx gives us a generator, we need a list that we can iterate over
# multiple times
isms = []
for ism in gen_isms:
    isms.append(ism)

pprint.pprint(isms)
------------------------------------------------------------------------------
_______________________________________________
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss

Reply via email to