Created
May 14, 2015 18:35
-
-
Save ghutchis/b692761252833ccdda5a to your computer and use it in GitHub Desktop.
Print molecule "report" as a CSV file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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