mirror of
https://github.com/openbabel/openbabel.git
synced 2025-02-25 18:55:23 -06:00
.close() method to the Outputfile class of Pybel. This uses the CloseOutFile() method added by Chris Morley in r1606. This is necessary to ensure that all tests pass on Windows.
256 lines
15 KiB
HTML
256 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> <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:/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> <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#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> <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="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, 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>()<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-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="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>
|
|
<a href="#Outputfile-close">close</a>()<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="-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> |