3

I want to read sdf file (containing many molecules) and return the weighted adjacency matrix of the molecule. Atoms should be treated as vertices and bond as edges. If i and j vertex are connected by single, double, or triple bond then corresponding entries in the adjacency matrix should be 1,2, and 3 respectively. I need to further obtain a distance vector for each vertex which list the number of vertices at different distance.

Are there any python package available to do this?

DurgaDatta
  • 3,952
  • 4
  • 27
  • 34

3 Answers3

3

I would recommend Pybel for reading and manipulating SDF files in Python. To get the bonding information, you will probably need to also use the more full-featured but less pythonic openbabel module, which can be used in concert with Pybel (as pybel.ob).

To start with, you would write something like this:

import pybel

for mol in pybel.readfile('sdf', 'many_molecules.sdf'):
  for atom in mol:
    coords = atom.coords
    for neighbor in pybel.ob.OBAtomAtomIter(atom.OBAtom):
      neighbor_coords = pybel.atom(neighbor).coords
vamin
  • 2,178
  • 6
  • 26
  • 30
1

Why not use the most commonly used package rdkit to process the SDF chemical file? It is really fast and convenient.

suppl = Chem.SDMolSupplier('xxx.sdf') # name the path of the SDF file 
for mol in supply:
    print(mol.GetNumAtoms()) # give the number of atoms in each molecule
    ......                   # do whatever kind of operations you want 
Fang WU
  • 180
  • 2
  • 7
0

See

http://code.google.com/p/cinfony/

However for your exact problem you will need to consult the documentation.

beginner_
  • 7,230
  • 18
  • 70
  • 127