mirror of
https://github.com/openbabel/openbabel.git
synced 2025-02-25 18:55:23 -06:00
* scripting interfaces: added a method to cast OBGenericData to OBPairData * pybel: added dictionary-like support for accessing molecule data, and updated the tests and the API documentation
369 lines
22 KiB
HTML
369 lines
22 KiB
HTML
|
|
<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<html><head><title>Python: module pybel</title>
|
|
</head><body bgcolor="#f0f0f8">
|
|
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
|
|
<tr bgcolor="#7799ee">
|
|
<td valign=bottom> <br>
|
|
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>pybel</strong></big></big></font></td
|
|
><td align=right valign=bottom
|
|
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:///C|/python24/lib/site-packages/pybel.py">c:\python24\lib\site-packages\pybel.py</a></font></td></tr></table>
|
|
<p></p>
|
|
<p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#aa55cc">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#fffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
|
|
|
|
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
|
|
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="openbabel.html">openbabel</a><br>
|
|
</td><td width="25%" valign=top><a href="os.html">os</a><br>
|
|
</td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ee77aa">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
|
|
|
|
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
|
|
<td width="100%"><dl>
|
|
<dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a>
|
|
</font></dt><dd>
|
|
<dl>
|
|
<dt><font face="helvetica, arial"><a href="pybel.html#Atom">Atom</a>
|
|
</font></dt><dt><font face="helvetica, arial"><a href="pybel.html#Fingerprint">Fingerprint</a>
|
|
</font></dt><dt><font face="helvetica, arial"><a href="pybel.html#Molecule">Molecule</a>
|
|
</font></dt><dt><font face="helvetica, arial"><a href="pybel.html#MoleculeData">MoleculeData</a>
|
|
</font></dt><dt><font face="helvetica, arial"><a href="pybel.html#Outputfile">Outputfile</a>
|
|
</font></dt><dt><font face="helvetica, arial"><a href="pybel.html#Smarts">Smarts</a>
|
|
</font></dt></dl>
|
|
</dd>
|
|
</dl>
|
|
<p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ffc8d8">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#000000" face="helvetica, arial"><a name="Atom">class <strong>Atom</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
|
|
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
|
<td colspan=2><tt>Represent a Pybel atom.<br>
|
|
<br>
|
|
Optional parameters:<br>
|
|
OBAtom -- an Open Babel <a href="#Atom">Atom</a> (default is None)<br>
|
|
index -- the index of the atom in the molecule (default is None)<br>
|
|
<br>
|
|
An empty <a href="#Atom">Atom</a> is created if an Open Babel atom is not provided.<br>
|
|
<br>
|
|
Attributes:<br>
|
|
atomicmass, atomicnum, cidx, coords, coordidx, exactmass,<br>
|
|
formalcharge, heavyvalence, heterovalence, hyb, idx,<br>
|
|
implicitvalence, index, isotope, partialcharge, spin, type,<br>
|
|
valence, vector.<br>
|
|
<br>
|
|
(refer to the Open Babel library documentation for more info).<br>
|
|
<br>
|
|
The original Open Babel atom can be accessed using the attribute:<br>
|
|
OBAtom<br> </tt></td></tr>
|
|
<tr><td> </td>
|
|
<td width="100%">Methods defined here:<br>
|
|
<dl><dt><a name="Atom-__getattr__"><strong>__getattr__</strong></a>(self, attr)</dt></dl>
|
|
|
|
<dl><dt><a name="Atom-__init__"><strong>__init__</strong></a>(self, OBAtom<font color="#909090">=None</font>, index<font color="#909090">=None</font>)</dt></dl>
|
|
|
|
<dl><dt><a name="Atom-__str__"><strong>__str__</strong></a>(self)</dt><dd><tt>Create a string representation of the atom.<br>
|
|
<br>
|
|
>>> a = <a href="#Atom">Atom</a>()<br>
|
|
>>> print a<br>
|
|
<a href="#Atom">Atom</a>: 0 (0.0, 0.0, 0.0)</tt></dd></dl>
|
|
|
|
<hr>
|
|
Data and other attributes defined here:<br>
|
|
<dl><dt><strong>__dict__</strong> = <dictproxy object><dd><tt>dictionary for instance variables (if defined)</tt></dl>
|
|
|
|
<dl><dt><strong>__weakref__</strong> = <attribute '__weakref__' of 'Atom' objects><dd><tt>list of weak references to the <a href="__builtin__.html#object">object</a> (if defined)</tt></dl>
|
|
|
|
</td></tr></table> <p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ffc8d8">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#000000" face="helvetica, arial"><a name="Fingerprint">class <strong>Fingerprint</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
|
|
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
|
<td colspan=2><tt>A Molecular <a href="#Fingerprint">Fingerprint</a>.<br>
|
|
<br>
|
|
Required parameters:<br>
|
|
obFingerprint -- a vector calculated by OBFingerprint.FindFingerprint()<br>
|
|
<br>
|
|
Attributes:<br>
|
|
fp -- the original obFingerprint<br>
|
|
bits -- a list of bits set in the <a href="#Fingerprint">Fingerprint</a><br>
|
|
<br>
|
|
Methods:<br>
|
|
The "|" operator can be used to calculate the Tanimoto coeff. For example,<br>
|
|
given two Fingerprints 'a', and 'b', the Tanimoto coefficient is given by:<br>
|
|
tanimoto = a | b<br> </tt></td></tr>
|
|
<tr><td> </td>
|
|
<td width="100%">Methods defined here:<br>
|
|
<dl><dt><a name="Fingerprint-__getattr__"><strong>__getattr__</strong></a>(self, attr)</dt></dl>
|
|
|
|
<dl><dt><a name="Fingerprint-__init__"><strong>__init__</strong></a>(self, obFingerprint)</dt></dl>
|
|
|
|
<dl><dt><a name="Fingerprint-__or__"><strong>__or__</strong></a>(self, other)</dt></dl>
|
|
|
|
<dl><dt><a name="Fingerprint-__str__"><strong>__str__</strong></a>(self)</dt></dl>
|
|
|
|
<hr>
|
|
Data and other attributes defined here:<br>
|
|
<dl><dt><strong>__dict__</strong> = <dictproxy object><dd><tt>dictionary for instance variables (if defined)</tt></dl>
|
|
|
|
<dl><dt><strong>__weakref__</strong> = <attribute '__weakref__' of 'Fingerprint' objects><dd><tt>list of weak references to the <a href="__builtin__.html#object">object</a> (if defined)</tt></dl>
|
|
|
|
</td></tr></table> <p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ffc8d8">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#000000" face="helvetica, arial"><a name="Molecule">class <strong>Molecule</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
|
|
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
|
<td colspan=2><tt>Represent a Pybel molecule.<br>
|
|
<br>
|
|
Optional parameters:<br>
|
|
OBMol -- an Open Babel molecule (default is None)<br>
|
|
<br>
|
|
An empty <a href="#Molecule">Molecule</a> is created if an Open Babel molecule is not provided.<br>
|
|
<br>
|
|
Attributes:<br>
|
|
atoms, charge, data, dim, energy, exactmass, flags, formula, <br>
|
|
mod, molwt, spin, sssr, title.<br>
|
|
(refer to the Open Babel library documentation for more info).<br>
|
|
<br>
|
|
Methods:<br>
|
|
<a href="#Molecule-write">write</a>(), <a href="#Molecule-calcfp">calcfp</a>()<br>
|
|
<br>
|
|
The original Open Babel molecule can be accessed using the attribute:<br>
|
|
OBMol<br> </tt></td></tr>
|
|
<tr><td> </td>
|
|
<td width="100%">Methods defined here:<br>
|
|
<dl><dt><a name="Molecule-__getattr__"><strong>__getattr__</strong></a>(self, attr)</dt><dd><tt>Return the value of an attribute<br>
|
|
<br>
|
|
Note: The values are calculated on-the-fly. You may want to store the value in<br>
|
|
a variable if you repeatedly access the same attribute.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="Molecule-__init__"><strong>__init__</strong></a>(self, OBMol<font color="#909090">=None</font>)</dt></dl>
|
|
|
|
<dl><dt><a name="Molecule-__iter__"><strong>__iter__</strong></a>(self)</dt><dd><tt>Iterate over the Atoms of the <a href="#Molecule">Molecule</a>.<br>
|
|
<br>
|
|
This allows constructions such as the following:<br>
|
|
for atom in mymol:<br>
|
|
print atom</tt></dd></dl>
|
|
|
|
<dl><dt><a name="Molecule-__str__"><strong>__str__</strong></a>(self)</dt></dl>
|
|
|
|
<dl><dt><a name="Molecule-calcfp"><strong>calcfp</strong></a>(self, fptype<font color="#909090">=''</font>)</dt><dd><tt>Calculate a molecular fingerprint.<br>
|
|
<br>
|
|
Optional parameters:<br>
|
|
fptype -- the name of the Open Babel fingerprint type.<br>
|
|
<br>
|
|
If fptype is not specified, the default Open Babel fingerprint<br>
|
|
type is used. See the Open Babel library documentation for more<br>
|
|
details.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="Molecule-write"><strong>write</strong></a>(self, format<font color="#909090">='SMI'</font>, filename<font color="#909090">=None</font>, overwrite<font color="#909090">=False</font>)</dt><dd><tt>Write the molecule to a file or return a string.<br>
|
|
<br>
|
|
Optional parameters:<br>
|
|
format -- default is "SMI"<br>
|
|
filename -- default is None<br>
|
|
overwite -- default is False<br>
|
|
<br>
|
|
If a filename is specified, the result is written to a file.<br>
|
|
Otherwise, a string is returned containing the result.<br>
|
|
The overwrite flag is ignored if a filename is not specified.<br>
|
|
It controls whether to overwrite an existing file.</tt></dd></dl>
|
|
|
|
<hr>
|
|
Data and other attributes defined here:<br>
|
|
<dl><dt><strong>__dict__</strong> = <dictproxy object><dd><tt>dictionary for instance variables (if defined)</tt></dl>
|
|
|
|
<dl><dt><strong>__weakref__</strong> = <attribute '__weakref__' of 'Molecule' objects><dd><tt>list of weak references to the <a href="__builtin__.html#object">object</a> (if defined)</tt></dl>
|
|
|
|
</td></tr></table> <p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ffc8d8">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#000000" face="helvetica, arial"><a name="MoleculeData">class <strong>MoleculeData</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
|
|
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
|
<td colspan=2><tt>Store molecule data in a dictionary-type <a href="__builtin__.html#object">object</a><br>
|
|
<br>
|
|
Required parameters:<br>
|
|
obmol -- an Open Babel OBMol <br>
|
|
<br>
|
|
Methods and accessor methods are like those of a dictionary except<br>
|
|
that the data is retrieved on-the-fly from the underlying OBMol.<br>
|
|
<br>
|
|
Example:<br>
|
|
>>> mol = <a href="#-readfile">readfile</a>("sdf", 'head.sdf').next()<br>
|
|
>>> data = mol.data<br>
|
|
>>> print data<br>
|
|
{'Comment': 'CORINA 2.61 0041 25.10.2001', 'NSC': '1'}<br>
|
|
>>> print len(data), data.<a href="#MoleculeData-keys">keys</a>(), data.<a href="#MoleculeData-has_key">has_key</a>("Second comment")<br>
|
|
2 ['Comment', 'NSC'] False<br>
|
|
>>> print data['Comment']<br>
|
|
CORINA 2.61 0041 25.10.2001<br>
|
|
>>> data['Comment'] = 'This is a new comment'<br>
|
|
>>> for k,v in data.<a href="#MoleculeData-iteritems">iteritems</a>():<br>
|
|
... print k, "-->", v<br>
|
|
Comment --> This is a new comment<br>
|
|
NSC --> 1<br> </tt></td></tr>
|
|
<tr><td> </td>
|
|
<td width="100%">Methods defined here:<br>
|
|
<dl><dt><a name="MoleculeData-__contains__"><strong>__contains__</strong></a>(self, key)</dt></dl>
|
|
|
|
<dl><dt><a name="MoleculeData-__getitem__"><strong>__getitem__</strong></a>(self, key)</dt></dl>
|
|
|
|
<dl><dt><a name="MoleculeData-__init__"><strong>__init__</strong></a>(self, obmol)</dt></dl>
|
|
|
|
<dl><dt><a name="MoleculeData-__iter__"><strong>__iter__</strong></a>(self)</dt></dl>
|
|
|
|
<dl><dt><a name="MoleculeData-__len__"><strong>__len__</strong></a>(self)</dt></dl>
|
|
|
|
<dl><dt><a name="MoleculeData-__repr__"><strong>__repr__</strong></a>(self)</dt></dl>
|
|
|
|
<dl><dt><a name="MoleculeData-__setitem__"><strong>__setitem__</strong></a>(self, key, value)</dt></dl>
|
|
|
|
<dl><dt><a name="MoleculeData-has_key"><strong>has_key</strong></a>(self, key)</dt></dl>
|
|
|
|
<dl><dt><a name="MoleculeData-items"><strong>items</strong></a>(self)</dt></dl>
|
|
|
|
<dl><dt><a name="MoleculeData-iteritems"><strong>iteritems</strong></a>(self)</dt></dl>
|
|
|
|
<dl><dt><a name="MoleculeData-keys"><strong>keys</strong></a>(self)</dt></dl>
|
|
|
|
<dl><dt><a name="MoleculeData-values"><strong>values</strong></a>(self)</dt></dl>
|
|
|
|
<hr>
|
|
Data and other attributes defined here:<br>
|
|
<dl><dt><strong>__dict__</strong> = <dictproxy object><dd><tt>dictionary for instance variables (if defined)</tt></dl>
|
|
|
|
<dl><dt><strong>__weakref__</strong> = <attribute '__weakref__' of 'MoleculeData' objects><dd><tt>list of weak references to the <a href="__builtin__.html#object">object</a> (if defined)</tt></dl>
|
|
|
|
</td></tr></table> <p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ffc8d8">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#000000" face="helvetica, arial"><a name="Outputfile">class <strong>Outputfile</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
|
|
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
|
<td colspan=2><tt>Represent a file to which *output* is to be sent.<br>
|
|
<br>
|
|
Although it's possible to write a single molecule to a file by<br>
|
|
calling the <a href="#Outputfile-write">write</a>() method of a molecule, if multiple molecules<br>
|
|
are to be written to the same file you should use the <a href="#Outputfile">Outputfile</a><br>
|
|
class.<br>
|
|
<br>
|
|
Required parameters:<br>
|
|
format<br>
|
|
filename<br>
|
|
Optional parameters:<br>
|
|
overwrite (default is False) -- if the output file already exists,<br>
|
|
should it be overwritten?<br>
|
|
Methods:<br>
|
|
<a href="#Outputfile-write">write</a>(molecule)<br> </tt></td></tr>
|
|
<tr><td> </td>
|
|
<td width="100%">Methods defined here:<br>
|
|
<dl><dt><a name="Outputfile-__init__"><strong>__init__</strong></a>(self, format, filename, overwrite<font color="#909090">=False</font>)</dt></dl>
|
|
|
|
<dl><dt><a name="Outputfile-close"><strong>close</strong></a>(self)</dt><dd><tt>Close the <a href="#Outputfile">Outputfile</a> to further writing.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="Outputfile-write"><strong>write</strong></a>(self, molecule)</dt><dd><tt>Write a molecule to the output file.<br>
|
|
<br>
|
|
Required parameters:<br>
|
|
molecule</tt></dd></dl>
|
|
|
|
<hr>
|
|
Data and other attributes defined here:<br>
|
|
<dl><dt><strong>__dict__</strong> = <dictproxy object><dd><tt>dictionary for instance variables (if defined)</tt></dl>
|
|
|
|
<dl><dt><strong>__weakref__</strong> = <attribute '__weakref__' of 'Outputfile' objects><dd><tt>list of weak references to the <a href="__builtin__.html#object">object</a> (if defined)</tt></dl>
|
|
|
|
</td></tr></table> <p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ffc8d8">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#000000" face="helvetica, arial"><a name="Smarts">class <strong>Smarts</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
|
|
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
|
<td colspan=2><tt>A <a href="#Smarts">Smarts</a> Pattern Matcher<br>
|
|
<br>
|
|
Required parameters:<br>
|
|
smartspattern<br>
|
|
<br>
|
|
Methods:<br>
|
|
<a href="#Smarts-findall">findall</a>()<br>
|
|
<br>
|
|
Example:<br>
|
|
>>> mol = <a href="#-readstring">readstring</a>("smi","CCN(CC)CC") # triethylamine<br>
|
|
>>> smarts = <a href="#Smarts">Smarts</a>("[#6][#6]") # Matches an ethyl group<br>
|
|
>>> print smarts.<a href="#Smarts-findall">findall</a>(mol) <br>
|
|
[(1, 2), (4, 5), (6, 7)]<br> </tt></td></tr>
|
|
<tr><td> </td>
|
|
<td width="100%">Methods defined here:<br>
|
|
<dl><dt><a name="Smarts-__init__"><strong>__init__</strong></a>(self, smartspattern)</dt><dd><tt>Initialise with a SMARTS pattern.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="Smarts-findall"><strong>findall</strong></a>(self, molecule)</dt><dd><tt>Find all matches of the SMARTS pattern to a particular molecule.<br>
|
|
<br>
|
|
Required parameters:<br>
|
|
molecule</tt></dd></dl>
|
|
|
|
<hr>
|
|
Data and other attributes defined here:<br>
|
|
<dl><dt><strong>__dict__</strong> = <dictproxy object><dd><tt>dictionary for instance variables (if defined)</tt></dl>
|
|
|
|
<dl><dt><strong>__weakref__</strong> = <attribute '__weakref__' of 'Smarts' objects><dd><tt>list of weak references to the <a href="__builtin__.html#object">object</a> (if defined)</tt></dl>
|
|
|
|
</td></tr></table></td></tr></table><p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#eeaa77">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
|
|
|
|
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
|
|
<td width="100%"><dl><dt><a name="-findbits"><strong>findbits</strong></a>(fp, bitsperint)</dt><dd><tt>Find which bits are set in a list/vector.<br>
|
|
<br>
|
|
This function is used by the <a href="#Fingerprint">Fingerprint</a> class.<br>
|
|
<br>
|
|
>>> <a href="#-findbits">findbits</a>([13, 71], 8)<br>
|
|
[1, 3, 4, 9, 10, 11, 15]</tt></dd></dl>
|
|
<dl><dt><a name="-readfile"><strong>readfile</strong></a>(format, filename)</dt><dd><tt>Iterate over the molecules in a file.<br>
|
|
<br>
|
|
Required parameters:<br>
|
|
format<br>
|
|
filename<br>
|
|
<br>
|
|
You can access the first molecule in a file using:<br>
|
|
mol = <a href="#-readfile">readfile</a>("smi", "myfile.smi").next()<br>
|
|
<br>
|
|
You can make a list of the molecules in a file using:<br>
|
|
mols = [mol for mol in <a href="#-readfile">readfile</a>("smi", "myfile.smi")]<br>
|
|
<br>
|
|
You can iterate over the molecules in a file as shown in the<br>
|
|
following code snippet...<br>
|
|
<br>
|
|
>>> atomtotal = 0<br>
|
|
>>> for mol in <a href="#-readfile">readfile</a>("sdf","head.sdf"):<br>
|
|
... atomtotal += len(mol.atoms)<br>
|
|
...<br>
|
|
>>> print atomtotal<br>
|
|
43</tt></dd></dl>
|
|
<dl><dt><a name="-readstring"><strong>readstring</strong></a>(format, string)</dt><dd><tt>Read in a molecule from a string.<br>
|
|
<br>
|
|
Required parameters:<br>
|
|
format<br>
|
|
string<br>
|
|
<br>
|
|
>>> input = "C1=CC=CS1"<br>
|
|
>>> mymol = <a href="#-readstring">readstring</a>("smi",input)<br>
|
|
>>> len(mymol.atoms)<br>
|
|
5</tt></dd></dl>
|
|
</td></tr></table>
|
|
</body></html> |