Files
openbabel/scripts/python/pyopenbabel.txt
2006-01-04 15:53:52 +00:00

127 lines
3.9 KiB
Plaintext

Developer's Notes and Design Decisions for pyopenbabel.py
---------------------------------------------------------
The Atom class
==============
To find all of the GetVar() methods of the Atom class:
import openbabel
b = [x for x in openbabel.OBAtom.__dict__.keys() if x.startswith("Get")]
b.sort()
for c in b:
print c
GetAngle "NotImplementedError: No matching function for overloaded 'OBAtom_GetAngle'"
GetAtomicMass == atomicmass
GetAtomicNum == atomicnum
GetBond needs two arguments
GetCIdx == cidx
GetCoordinate replaced by a .coords attribute containing a tuple (x,y,z) (also "Segmentation fault")
GetCoordinateIdx == coordidx
GetData == data
GetDistance "NotImplementedError: No matching function for overloaded 'OBAtom_GetDistance'"
GetExactMass == exactmass
GetFormalCharge == formalcharge
GetHeteroValence == heterovalence
GetHvyValence == heavyvalence (if hetero isn't abbreviated, then neither should heavy)
GetHyb == hyb
GetIdx == idx
GetImplicitValence == implicitvalence
GetIsotope == isotope
GetNewBondVector needs three arguments
GetNextAtom not required (given a Molecule, you can loop through the atoms)
GetPartialCharge == partialcharge
GetResidue "Segmentation fault"
GetSpinMultiplicity == spin
GetType == type
GetValence == valence
GetVector == vector
GetX replaced by a .coords attribute containing a tuple (x,y,z)
GetY replaced by a .coords attribute containing a tuple (x,y,z)
GetZ replaced by a .coords attribute containing a tuple (x,y,z)
All attributes are calculated on-the-fly when you ask for them. They are also initialised when you create the Atom object, so that dir(myatom) gives a useful list of attributes.
The Molecule class
==================
To find all of the GetVar() methods of the Molecule class:
import openbabel
b = [x for x in openbabel.OBMol.__dict__.keys() if x.startswith("Get")]
b.sort()
for c in b:
print c
GetAtom replaced by a .atoms attributes containing a list of Atoms
GetBond (to be)replaced by a .bonds attributes containing a list of Bonds
GetConformer needs two arguments
GetConformers == conformers
GetCoordinates == coords
GetData == data
GetDimension == dim
GetEnergy == energy
GetExactMass == exactmass
GetFirstAtom not required (can use .atoms attribute instead)
GetFlags == flags
GetFormula == formula
GetGIDVector needs two arguments
GetGIVector needs two arguments
GetGTDVector == gtdvector
GetInternalCoord == internalcoord (or internalcoords??)
GetMod == mod
GetMolWt == molwt
GetResidue needs two arguments
GetSSSR == sssr
GetTitle == title
GetTorsion "NotImplementedError: No matching function for overloaded 'OBMol_GetTorsion'"
GetTotalCharge == charge
GetTotalSpinMultiplicity == spin
All attributes are calculated on-the-fly when you ask for them. They are also initialised when you create the Molecule object, so that dir(mymolecule) gives a useful list of attributes.
Added an iterator over the atoms of the molecule so that you can do things like:
for atom in mymol:
print atom
Creating a Molecule from a String
=================================
Replaced:
from openbabel import *
mymol = OBMol()
obConversion = OBConversion()
obConversion.SetInFormat("smi")
obConversion.ReadString(mymol,"C1=CC=CS1")
With:
from pyopenbabel import *
mymol = readstring("smi","C1=CC=CS1")
Reading a Molecule From a File
==============================
TODO
Writing a Molecule To a File (continued from either of the examples above)
============================
Replaced:
obConversion.SetOutFormat("smi")
obConversion.WriteFile(mymol,"tmp.txt")
With:
mymol.write("smi",tmp.txt")
Bug Converting To and From Smiles Strings?
==========================================
from openbabel import *
mymol = OBMol()
obConversion = OBConversion()
obConversion.SetInAndOutFormats("smi","smi")
obConversion.ReadString(mymol,"C1=CC=CS1")
print obConversion.WriteString(mymol)
'c1sccc1\t\n'
-- should remove the \t and \n