Skip to content

Instantly share code, notes, and snippets.

@ghutchis
Created May 14, 2015 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ghutchis/b692761252833ccdda5a to your computer and use it in GitHub Desktop.
Save ghutchis/b692761252833ccdda5a to your computer and use it in GitHub Desktop.
Print molecule "report" as a CSV file
#!/usr/bin/env python
import sys, os
import pybel
# don't need to reimport openbabel
ob = pybel.ob
for argument in sys.argv[1:]:
filename, extension = os.path.splitext(argument)
# read the molecule from the supplied file
mol = next(pybel.readfile(extension[1:], argument))
# iterate through all atoms
for atom in mol.atoms:
print "Atom %d, %8.4f" % (atom.idx, atom.partialcharge)
# iterate through all bonds
for bond in ob.OBMolBondIter(mol.OBMol):
print "Bond %d-%d, %8.4f" % (bond.GetBeginAtomIdx(), bond.GetEndAtomIdx(), bond.GetLength())
# iterate through all angles
for angle in ob.OBMolAngleIter(mol.OBMol):
a = (angle[0] + 1)
b = mol.OBMol.GetAtom(angle[1] + 1)
c = (angle[2] + 1)
print "Angle %d-%d-%d, %8.3f" % (a, b.GetIdx(), c, b.GetAngle(a, c))
# iterate through all torsions
for torsion in ob.OBMolTorsionIter(mol.OBMol):
a = (torsion[0] + 1)
b = (torsion[1] + 1)
c = (torsion[2] + 1)
d = (torsion[3] + 1)
print "Torsion %d-%d-%d-%d, %8.3f" % (a, b, c, d, mol.OBMol.GetTorsion(a, b, c, d))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment