pybel
index
/home/vmware/Tools/openbabel/scripts/python/pybel.py

 
Modules
       
openbabel
os

 
Classes
       
__builtin__.object
Atom
Molecule
Outputfile
Smarts

 
class Atom(__builtin__.object)
    Represent a Pybel atom.
 
Optional parameters:
   OBAtom -- an Open Babel Atom (default is None)
   index -- the index of the atom in the molecule (default is None)
 
An empty Atom is created if an Open Babel atom is not provided.
 
Attributes:
   atomicmass, atomicnum, cidx, coords, coordidx, exactmass,
   formalcharge, heavyvalence, heterovalence, hyb, idx,
   implicitvalence, index, isotope, partialcharge, spin, type,
   valence, vector.
 
(refer to the Open Babel library documentation for more info).
 
The original Open Babel atom can be accessed using the attribute:
   OBAtom
 
  Methods defined here:
__getattr__(self, attr)
__init__(self, OBAtom=None, index=None)
__str__(self)
Create a string representation of the atom.
 
>>> a = Atom()
>>> print a
Atom: 0 (0.0, 0.0, 0.0)

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Atom' objects>
list of weak references to the object (if defined)

 
class Molecule(__builtin__.object)
    Represent a Pybel molecule.
 
Optional parameters:
   OBMol -- an Open Babel molecule (default is None)
 
An empty Molecule is created if an Open Babel molecule is not provided.
 
Attributes:
   atoms, charge, dim, energy, exactmass, flags, formula, 
   mod, molwt, spin, sssr, title.
(refer to the Open Babel library documentation for more info).
 
Methods:
   write()
  
The original Open Babel molecule can be accessed using the attribute:
   OBMol
 
  Methods defined here:
__getattr__(self, attr)
Return the value of an attribute
 
Note: The values are calculated on-the-fly. You may want to store the value in
a variable if you repeatedly access the same attribute.
__init__(self, OBMol=None)
__iter__(self)
Iterate over the Atoms of the Molecule.
 
This allows constructions such as the following:
   for atom in mymol:
       print atom
__str__(self)
write(self, format='SMI', filename=None, overwrite=False)
Write the molecule to a file or return a string.
 
Optional parameters:
   format -- default is "SMI"
   filename -- default is None
   overwite -- default is False
 
If a filename is specified, the result is written to a file.
Otherwise, a string is returned containing the result.
The overwrite flag is ignored if a filename is not specified.
It controls whether to overwrite an existing file.

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Molecule' objects>
list of weak references to the object (if defined)

 
class Outputfile(__builtin__.object)
    Represent a file to which *output* is to be sent.
 
Although it's possible to write a single molecule to a file by
calling the write() method of a molecule, if multiple molecules
are to be written to the same file you should use the Outputfile
class.
 
Required parameters:
   format
   filename
Optional parameters:
   overwrite (default is False) -- if the output file already exists,
                                   should it be overwritten?
Methods:
   write(molecule)
   close()
 
  Methods defined here:
__init__(self, format, filename, overwrite=False)
close(self)
Close the Outputfile to further writing.
write(self, molecule)
Write a molecule to the output file.
 
Required parameters:
   molecule

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Outputfile' objects>
list of weak references to the object (if defined)

 
class Smarts(__builtin__.object)
    Smarts Pattern Matcher
 
Required parameters:
   smartspattern
 
Methods:
   findall()
 
Example:
>>> mol = readstring("smi","CCN(CC)CC") # triethylamine
>>> smarts = Smarts("[#6][#6]") # Matches an ethyl group
>>> print smarts.findall(mol) 
[(1, 2), (4, 5), (6, 7)]
 
  Methods defined here:
__init__(self, smartspattern)
Initialise with a SMARTS pattern.
findall(self, molecule)
Find all matches of the SMARTS pattern to a particular molecule.
 
Required parameters:
   molecule

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Smarts' objects>
list of weak references to the object (if defined)

 
Functions
       
readfile(format, filename)
Iterate over the molecules in a file.
 
Required parameters:
   format
   filename
 
You can access the first molecule in a file using:
    mol = readfile("smi", "myfile.smi").next()
    
You can make a list of the molecules in a file using:
    mols = [mol for mol in readfile("smi", "myfile.smi")]
    
You can iterate over the molecules in a file as shown in the
following code snippet...
 
>>> atomtotal = 0
>>> for mol in readfile("sdf","head.sdf"):
...     atomtotal += len(mol.atoms)
...
>>> print atomtotal
43
readstring(format, string)
Read in a molecule from a string.
 
Required parameters:
   format
   string
 
>>> input = "C1=CC=CS1"
>>> mymol = readstring("smi",input)
>>> len(mymol.atoms)
5