Files
openbabel/scripts/python/pybelapi.html
Noel O'Boyle 71b835bcad * scripts/python/setup.py, pyopenbabel.py, testpyopenbabel.py,
pyopenbabelapi.html: Changed all references to pyopenbabel to 
pybel
        (new name). Also, corrected minor typo in docstring in pybel.py.
2006-11-18 13:31:04 +00:00

253 lines
15 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>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<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:/home/vmware/Tools/openbabel/scripts/python/pybel.py">/home/vmware/Tools/openbabel/scripts/python/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>&nbsp;<br>
<font color="#fffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</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>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</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#Molecule">Molecule</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>&nbsp;<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>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>Represent&nbsp;a&nbsp;Pybel&nbsp;atom.<br>
&nbsp;<br>
Optional&nbsp;parameters:<br>
&nbsp;&nbsp;&nbsp;OBAtom&nbsp;--&nbsp;an&nbsp;Open&nbsp;Babel&nbsp;<a href="#Atom">Atom</a>&nbsp;(default&nbsp;is&nbsp;None)<br>
&nbsp;&nbsp;&nbsp;index&nbsp;--&nbsp;the&nbsp;index&nbsp;of&nbsp;the&nbsp;atom&nbsp;in&nbsp;the&nbsp;molecule&nbsp;(default&nbsp;is&nbsp;None)<br>
&nbsp;<br>
An&nbsp;empty&nbsp;<a href="#Atom">Atom</a>&nbsp;is&nbsp;created&nbsp;if&nbsp;an&nbsp;Open&nbsp;Babel&nbsp;atom&nbsp;is&nbsp;not&nbsp;provided.<br>
&nbsp;<br>
Attributes:<br>
&nbsp;&nbsp;&nbsp;atomicmass,&nbsp;atomicnum,&nbsp;cidx,&nbsp;coords,&nbsp;coordidx,&nbsp;exactmass,<br>
&nbsp;&nbsp;&nbsp;formalcharge,&nbsp;heavyvalence,&nbsp;heterovalence,&nbsp;hyb,&nbsp;idx,<br>
&nbsp;&nbsp;&nbsp;implicitvalence,&nbsp;index,&nbsp;isotope,&nbsp;partialcharge,&nbsp;spin,&nbsp;type,<br>
&nbsp;&nbsp;&nbsp;valence,&nbsp;vector.<br>
&nbsp;<br>
(refer&nbsp;to&nbsp;the&nbsp;Open&nbsp;Babel&nbsp;library&nbsp;documentation&nbsp;for&nbsp;more&nbsp;info).<br>
&nbsp;<br>
The&nbsp;original&nbsp;Open&nbsp;Babel&nbsp;atom&nbsp;can&nbsp;be&nbsp;accessed&nbsp;using&nbsp;the&nbsp;attribute:<br>
&nbsp;&nbsp;&nbsp;OBAtom<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</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&nbsp;a&nbsp;string&nbsp;representation&nbsp;of&nbsp;the&nbsp;atom.<br>
&nbsp;<br>
&gt;&gt;&gt;&nbsp;a&nbsp;=&nbsp;<a href="#Atom">Atom</a>()<br>
&gt;&gt;&gt;&nbsp;print&nbsp;a<br>
<a href="#Atom">Atom</a>:&nbsp;0&nbsp;(0.0,&nbsp;0.0,&nbsp;0.0)</tt></dd></dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>__dict__</strong> = &lt;dictproxy object&gt;<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dl>
<dl><dt><strong>__weakref__</strong> = &lt;attribute '__weakref__' of 'Atom' objects&gt;<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;(if&nbsp;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>&nbsp;<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>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>Represent&nbsp;a&nbsp;Pybel&nbsp;molecule.<br>
&nbsp;<br>
Optional&nbsp;parameters:<br>
&nbsp;&nbsp;&nbsp;OBMol&nbsp;--&nbsp;an&nbsp;Open&nbsp;Babel&nbsp;molecule&nbsp;(default&nbsp;is&nbsp;None)<br>
&nbsp;<br>
An&nbsp;empty&nbsp;<a href="#Molecule">Molecule</a>&nbsp;is&nbsp;created&nbsp;if&nbsp;an&nbsp;Open&nbsp;Babel&nbsp;molecule&nbsp;is&nbsp;not&nbsp;provided.<br>
&nbsp;<br>
Attributes:<br>
&nbsp;&nbsp;&nbsp;atoms,&nbsp;charge,&nbsp;dim,&nbsp;energy,&nbsp;exactmass,&nbsp;flags,&nbsp;formula,&nbsp;<br>
&nbsp;&nbsp;&nbsp;mod,&nbsp;molwt,&nbsp;spin,&nbsp;sssr,&nbsp;title.<br>
(refer&nbsp;to&nbsp;the&nbsp;Open&nbsp;Babel&nbsp;library&nbsp;documentation&nbsp;for&nbsp;more&nbsp;info).<br>
&nbsp;<br>
Methods:<br>
&nbsp;&nbsp;&nbsp;<a href="#Molecule-write">write</a>()<br>
&nbsp;&nbsp;<br>
The&nbsp;original&nbsp;Open&nbsp;Babel&nbsp;molecule&nbsp;can&nbsp;be&nbsp;accessed&nbsp;using&nbsp;the&nbsp;attribute:<br>
&nbsp;&nbsp;&nbsp;OBMol<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Molecule-__getattr__"><strong>__getattr__</strong></a>(self, attr)</dt><dd><tt>Return&nbsp;the&nbsp;value&nbsp;of&nbsp;an&nbsp;attribute<br>
&nbsp;<br>
Note:&nbsp;The&nbsp;values&nbsp;are&nbsp;calculated&nbsp;on-the-fly.&nbsp;You&nbsp;may&nbsp;want&nbsp;to&nbsp;store&nbsp;the&nbsp;value&nbsp;in<br>
a&nbsp;variable&nbsp;if&nbsp;you&nbsp;repeatedly&nbsp;access&nbsp;the&nbsp;same&nbsp;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&nbsp;over&nbsp;the&nbsp;Atoms&nbsp;of&nbsp;the&nbsp;<a href="#Molecule">Molecule</a>.<br>
&nbsp;<br>
This&nbsp;allows&nbsp;constructions&nbsp;such&nbsp;as&nbsp;the&nbsp;following:<br>
&nbsp;&nbsp;&nbsp;for&nbsp;atom&nbsp;in&nbsp;mymol:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;atom</tt></dd></dl>
<dl><dt><a name="Molecule-__str__"><strong>__str__</strong></a>(self)</dt></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&nbsp;the&nbsp;molecule&nbsp;to&nbsp;a&nbsp;file&nbsp;or&nbsp;return&nbsp;a&nbsp;string.<br>
&nbsp;<br>
Optional&nbsp;parameters:<br>
&nbsp;&nbsp;&nbsp;format&nbsp;--&nbsp;default&nbsp;is&nbsp;"SMI"<br>
&nbsp;&nbsp;&nbsp;filename&nbsp;--&nbsp;default&nbsp;is&nbsp;None<br>
&nbsp;&nbsp;&nbsp;overwite&nbsp;--&nbsp;default&nbsp;is&nbsp;False<br>
&nbsp;<br>
If&nbsp;a&nbsp;filename&nbsp;is&nbsp;specified,&nbsp;the&nbsp;result&nbsp;is&nbsp;written&nbsp;to&nbsp;a&nbsp;file.<br>
Otherwise,&nbsp;a&nbsp;string&nbsp;is&nbsp;returned&nbsp;containing&nbsp;the&nbsp;result.<br>
The&nbsp;overwrite&nbsp;flag&nbsp;is&nbsp;ignored&nbsp;if&nbsp;a&nbsp;filename&nbsp;is&nbsp;not&nbsp;specified.<br>
It&nbsp;controls&nbsp;whether&nbsp;to&nbsp;overwrite&nbsp;an&nbsp;existing&nbsp;file.</tt></dd></dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>__dict__</strong> = &lt;dictproxy object&gt;<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dl>
<dl><dt><strong>__weakref__</strong> = &lt;attribute '__weakref__' of 'Molecule' objects&gt;<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;(if&nbsp;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>&nbsp;<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>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>Represent&nbsp;a&nbsp;file&nbsp;to&nbsp;which&nbsp;*output*&nbsp;is&nbsp;to&nbsp;be&nbsp;sent.<br>
&nbsp;<br>
Although&nbsp;it's&nbsp;possible&nbsp;to&nbsp;write&nbsp;a&nbsp;single&nbsp;molecule&nbsp;to&nbsp;a&nbsp;file&nbsp;by<br>
calling&nbsp;the&nbsp;<a href="#Outputfile-write">write</a>()&nbsp;method&nbsp;of&nbsp;a&nbsp;molecule,&nbsp;if&nbsp;multiple&nbsp;molecules<br>
are&nbsp;to&nbsp;be&nbsp;written&nbsp;to&nbsp;the&nbsp;same&nbsp;file&nbsp;you&nbsp;should&nbsp;use&nbsp;the&nbsp;<a href="#Outputfile">Outputfile</a><br>
class.<br>
&nbsp;<br>
Required&nbsp;parameters:<br>
&nbsp;&nbsp;&nbsp;format<br>
&nbsp;&nbsp;&nbsp;filename<br>
Optional&nbsp;parameters:<br>
&nbsp;&nbsp;&nbsp;overwrite&nbsp;(default&nbsp;is&nbsp;False)&nbsp;--&nbsp;if&nbsp;the&nbsp;output&nbsp;file&nbsp;already&nbsp;exists,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;should&nbsp;it&nbsp;be&nbsp;overwritten?<br>
Methods:<br>
&nbsp;&nbsp;&nbsp;<a href="#Outputfile-write">write</a>(molecule)<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</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-write"><strong>write</strong></a>(self, molecule)</dt><dd><tt>Write&nbsp;a&nbsp;molecule&nbsp;to&nbsp;the&nbsp;output&nbsp;file.<br>
&nbsp;<br>
Required&nbsp;parameters:<br>
&nbsp;&nbsp;&nbsp;molecule</tt></dd></dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>__dict__</strong> = &lt;dictproxy object&gt;<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dl>
<dl><dt><strong>__weakref__</strong> = &lt;attribute '__weakref__' of 'Outputfile' objects&gt;<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;(if&nbsp;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>&nbsp;<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>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>A&nbsp;<a href="#Smarts">Smarts</a>&nbsp;Pattern&nbsp;Matcher<br>
&nbsp;<br>
Required&nbsp;parameters:<br>
&nbsp;&nbsp;&nbsp;smartspattern<br>
&nbsp;<br>
Methods:<br>
&nbsp;&nbsp;&nbsp;<a href="#Smarts-findall">findall</a>()<br>
&nbsp;<br>
Example:<br>
&gt;&gt;&gt;&nbsp;mol&nbsp;=&nbsp;<a href="#-readstring">readstring</a>("smi","CCN(CC)CC")&nbsp;#&nbsp;triethylamine<br>
&gt;&gt;&gt;&nbsp;smarts&nbsp;=&nbsp;<a href="#Smarts">Smarts</a>("[#6][#6]")&nbsp;#&nbsp;Matches&nbsp;an&nbsp;ethyl&nbsp;group<br>
&gt;&gt;&gt;&nbsp;print&nbsp;smarts.<a href="#Smarts-findall">findall</a>(mol)&nbsp;<br>
[(1,&nbsp;2),&nbsp;(4,&nbsp;5),&nbsp;(6,&nbsp;7)]<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Smarts-__init__"><strong>__init__</strong></a>(self, smartspattern)</dt><dd><tt>Initialise&nbsp;with&nbsp;a&nbsp;SMARTS&nbsp;pattern.</tt></dd></dl>
<dl><dt><a name="Smarts-findall"><strong>findall</strong></a>(self, molecule)</dt><dd><tt>Find&nbsp;all&nbsp;matches&nbsp;of&nbsp;the&nbsp;SMARTS&nbsp;pattern&nbsp;to&nbsp;a&nbsp;particular&nbsp;molecule.<br>
&nbsp;<br>
Required&nbsp;parameters:<br>
&nbsp;&nbsp;&nbsp;molecule</tt></dd></dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>__dict__</strong> = &lt;dictproxy object&gt;<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dl>
<dl><dt><strong>__weakref__</strong> = &lt;attribute '__weakref__' of 'Smarts' objects&gt;<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;(if&nbsp;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>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt><a name="-readfile"><strong>readfile</strong></a>(format, filename)</dt><dd><tt>Iterate&nbsp;over&nbsp;the&nbsp;molecules&nbsp;in&nbsp;a&nbsp;file.<br>
&nbsp;<br>
Required&nbsp;parameters:<br>
&nbsp;&nbsp;&nbsp;format<br>
&nbsp;&nbsp;&nbsp;filename<br>
&nbsp;<br>
You&nbsp;can&nbsp;access&nbsp;the&nbsp;first&nbsp;molecule&nbsp;in&nbsp;a&nbsp;file&nbsp;using:<br>
&nbsp;&nbsp;&nbsp;&nbsp;mol&nbsp;=&nbsp;<a href="#-readfile">readfile</a>("smi",&nbsp;"myfile.smi").next()<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
You&nbsp;can&nbsp;make&nbsp;a&nbsp;list&nbsp;of&nbsp;the&nbsp;molecules&nbsp;in&nbsp;a&nbsp;file&nbsp;using:<br>
&nbsp;&nbsp;&nbsp;&nbsp;mols&nbsp;=&nbsp;[mol&nbsp;for&nbsp;mol&nbsp;in&nbsp;<a href="#-readfile">readfile</a>("smi",&nbsp;"myfile.smi")]<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
You&nbsp;can&nbsp;iterate&nbsp;over&nbsp;the&nbsp;molecules&nbsp;in&nbsp;a&nbsp;file&nbsp;as&nbsp;shown&nbsp;in&nbsp;the<br>
following&nbsp;code&nbsp;snippet...<br>
&nbsp;<br>
&gt;&gt;&gt;&nbsp;atomtotal&nbsp;=&nbsp;0<br>
&gt;&gt;&gt;&nbsp;for&nbsp;mol&nbsp;in&nbsp;<a href="#-readfile">readfile</a>("sdf","head.sdf"):<br>
...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;atomtotal&nbsp;+=&nbsp;len(mol.atoms)<br>
...<br>
&gt;&gt;&gt;&nbsp;print&nbsp;atomtotal<br>
43</tt></dd></dl>
<dl><dt><a name="-readstring"><strong>readstring</strong></a>(format, string)</dt><dd><tt>Read&nbsp;in&nbsp;a&nbsp;molecule&nbsp;from&nbsp;a&nbsp;string.<br>
&nbsp;<br>
Required&nbsp;parameters:<br>
&nbsp;&nbsp;&nbsp;format<br>
&nbsp;&nbsp;&nbsp;string<br>
&nbsp;<br>
&gt;&gt;&gt;&nbsp;input&nbsp;=&nbsp;"C1=CC=CS1"<br>
&gt;&gt;&gt;&nbsp;mymol&nbsp;=&nbsp;<a href="#-readstring">readstring</a>("smi",input)<br>
&gt;&gt;&gt;&nbsp;len(mymol.atoms)<br>
5</tt></dd></dl>
</td></tr></table>
</body></html>