2007-05-08 Noel O'Boyle <baoilleach@gmail.com>

* 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
This commit is contained in:
Noel O'Boyle
2007-05-08 12:33:05 +00:00
parent 12d2d9d286
commit 8270b862df
8 changed files with 506 additions and 317 deletions

View File

@@ -51,7 +51,7 @@ class Test_readstring(unittest.TestCase):
def testgetprops(self):
"""Get the values of the properties."""
test = { 'dim':0, 'spin':1, 'energy': 0.0,
'charge':0, 'flags':514, 'formula': 'C4H10',
'charge':0, 'formula': 'C4H10',
'mod':0 }
result = {}
for attr in self.mol._getmethods:
@@ -137,6 +137,36 @@ class Test_readfile(unittest.TestCase):
test = ['O=C1C=CC(=O)C=C1C\tNSC 1\n', 'c1cccc2c1nc(SSc1nc3ccccc3s1)s2\tNSC 2\n']
self.assertEqual(filecontents, test)
class Test_data(unittest.TestCase):
def setUp(self):
self.mol = pybel.readfile("sdf", "head.sdf").next()
self.data = self.mol.data
def accesstest(self):
# Should raise KeyError
return self.data['noel']
def testcomment(self):
"""Mess about with the comment field"""
self.assertEqual('Comment' in self.data, True)
self.assertEqual(self.data['Comment'], 'CORINA 2.61 0041 25.10.2001')
self.data['Comment'] = 'New comment'
self.assertEqual(self.data['Comment'], 'New comment')
def testaccess(self):
"""Change the value of a field"""
self.assertRaises(KeyError, self.accesstest)
self.data['noel'] = 'testvalue'
self.assertEqual(self.data['noel'], 'testvalue')
def testglobalaccess(self):
"""Check out the keys"""
self.assertEqual(self.data.has_key('Comment'), True)
self.assertEqual(self.data.has_key('Noel'), False)
self.assertEqual(len(self.data), 2)
for key in self.data:
self.assertEqual(key in ['Comment', 'NSC'], True)
class Test_atoms(unittest.TestCase):
"""Testing some of the atom code"""
def setUp(self):
@@ -187,9 +217,4 @@ class Test_cornercases(unittest.TestCase):
self.assertEqual(atom.atomicnum, 0)
if __name__=="__main__":
testgroups = [Test_readstring, Test_readfile, Test_atoms,
Test_smarts, Test_cornercases, Test_fingerprint]
for testgroup in testgroups:
print "\n=== %s ===" % testgroup.__doc__
suite = unittest.makeSuite(testgroup)
unittest.TextTestRunner(verbosity=2).run(suite)
unittest.main()

View File

@@ -79,7 +79,7 @@ class Outputfile(object):
self.format = format
self.filename = filename
if not overwrite and os.path.isfile(self.filename):
raise IOError, "%s already exists. Use 'overwrite=False' to overwrite it." % self.filename
raise IOError, "%s already exists. Use 'overwrite=True' to overwrite it." % self.filename
self.obConversion = ob.OBConversion()
formatok = self.obConversion.SetOutFormat(self.format)
if not formatok:
@@ -115,7 +115,7 @@ class Molecule(object):
An empty Molecule is created if an Open Babel molecule is not provided.
Attributes:
atoms, charge, dim, energy, exactmass, flags, formula,
atoms, charge, data, dim, energy, exactmass, flags, formula,
mod, molwt, spin, sssr, title.
(refer to the Open Babel library documentation for more info).
@@ -159,6 +159,9 @@ class Molecule(object):
if attr == "atoms":
# Create an atoms attribute on-the-fly
return [ Atom(self.OBMol.GetAtom(i+1),i+1) for i in range(self.OBMol.NumAtoms()) ]
elif attr == "data":
# Create a data attribute on-the-fly
return MoleculeData(self.OBMol)
elif attr in self._getmethods:
# Call the OB Method to find the attribute value
return getattr(self.OBMol, self._getmethods[attr])()
@@ -213,7 +216,7 @@ class Molecule(object):
if filename:
if not overwrite and os.path.isfile(filename):
raise IOError, "%s already exists. Use 'overwrite=False' to overwrite it." % filename
raise IOError, "%s already exists. Use 'overwrite=True' to overwrite it." % filename
obconversion.WriteFile(self.OBMol,filename)
else:
return obconversion.WriteString(self.OBMol)
@@ -365,7 +368,72 @@ class Smarts(object):
self.obsmarts.Match(molecule.OBMol)
return [x for x in self.obsmarts.GetUMapList()]
class MoleculeData(object):
"""Store molecule data in a dictionary-type object
Required parameters:
obmol -- an Open Babel OBMol
Methods and accessor methods are like those of a dictionary except
that the data is retrieved on-the-fly from the underlying OBMol.
Example:
>>> mol = readfile("sdf", 'head.sdf').next()
>>> data = mol.data
>>> print data
{'Comment': 'CORINA 2.61 0041 25.10.2001', 'NSC': '1'}
>>> print len(data), data.keys(), data.has_key("Second comment")
2 ['Comment', 'NSC'] False
>>> print data['Comment']
CORINA 2.61 0041 25.10.2001
>>> data['Comment'] = 'This is a new comment'
>>> for k,v in data.iteritems():
... print k, "-->", v
Comment --> This is a new comment
NSC --> 1
"""
def __init__(self, obmol):
self._mol = obmol
def _data(self):
return [ob.toPairData(x) for x in self._mol.GetData()]
def _testforkey(self, key):
if not key in self:
raise KeyError, "'%s'" % key
def keys(self):
return [x.GetAttribute() for x in self._data()]
def values(self):
return [x.GetValue() for x in self._data()]
def items(self):
return zip(self.keys(), self.values())
def __iter__(self):
return iter(self.keys())
def iteritems(self):
return iter(self.items())
def __len__(self):
return self._mol.GetData().size()
def __contains__(self, key):
return self._mol.HasData(key)
#def __delitem__(self, key):
#self._testforkey(key)
#self._mol.DeleteData(self._mol.GetData(key))
def has_key(self, key):
return key in self
def __getitem__(self, key):
self._testforkey(key)
return ob.toPairData(self._mol.GetData(key)).GetValue()
def __setitem__(self, key, value):
if key in self:
pairdata = ob.toPairData(self._mol.GetData(key))
pairdata.SetValue(value)
else:
pairdata = ob.OBPairData()
pairdata.SetAttribute(key)
pairdata.SetValue(value)
pairdata.thisown = 0 # So that SWIG Proxy will not delete pairdata
self._mol.SetData(pairdata)
def __repr__(self):
return dict(self.iteritems()).__repr__()
if __name__=="__main__":
import doctest
doctest.testmod()

View File

@@ -1,307 +1,369 @@
<!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#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#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="Fingerprint">class <strong>Fingerprint</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;Molecular&nbsp;<a href="#Fingerprint">Fingerprint</a>.<br>
&nbsp;<br>
Required&nbsp;parameters:<br>
&nbsp;&nbsp;&nbsp;obFingerprint&nbsp;--&nbsp;a&nbsp;vector&nbsp;calculated&nbsp;by&nbsp;OBFingerprint.FindFingerprint()<br>
&nbsp;<br>
Attributes:<br>
&nbsp;&nbsp;&nbsp;fp&nbsp;--&nbsp;the&nbsp;original&nbsp;obFingerprint<br>
&nbsp;&nbsp;&nbsp;bits&nbsp;--&nbsp;a&nbsp;list&nbsp;of&nbsp;bits&nbsp;set&nbsp;in&nbsp;the&nbsp;<a href="#Fingerprint">Fingerprint</a><br>
&nbsp;<br>
Methods:<br>
&nbsp;&nbsp;&nbsp;The&nbsp;"|"&nbsp;operator&nbsp;can&nbsp;be&nbsp;used&nbsp;to&nbsp;calculate&nbsp;the&nbsp;Tanimoto&nbsp;coeff.&nbsp;For&nbsp;example,<br>
&nbsp;&nbsp;&nbsp;given&nbsp;two&nbsp;Fingerprints&nbsp;'a',&nbsp;and&nbsp;'b',&nbsp;the&nbsp;Tanimoto&nbsp;coefficient&nbsp;is&nbsp;given&nbsp;by:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tanimoto&nbsp;=&nbsp;a&nbsp;|&nbsp;b<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</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> = &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 'Fingerprint' 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>(),&nbsp;<a href="#Molecule-calcfp">calcfp</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-calcfp"><strong>calcfp</strong></a>(self, fptype<font color="#909090">=''</font>)</dt><dd><tt>Calculate&nbsp;a&nbsp;molecular&nbsp;fingerprint.<br>
&nbsp;<br>
Optional&nbsp;parameters:<br>
&nbsp;&nbsp;&nbsp;fptype&nbsp;--&nbsp;the&nbsp;name&nbsp;of&nbsp;the&nbsp;Open&nbsp;Babel&nbsp;fingerprint&nbsp;type.<br>
&nbsp;<br>
If&nbsp;fptype&nbsp;is&nbsp;not&nbsp;specified,&nbsp;the&nbsp;default&nbsp;Open&nbsp;Babel&nbsp;fingerprint<br>
type&nbsp;is&nbsp;used.&nbsp;See&nbsp;the&nbsp;Open&nbsp;Babel&nbsp;library&nbsp;documentation&nbsp;for&nbsp;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&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-close"><strong>close</strong></a>(self)</dt><dd><tt>Close&nbsp;the&nbsp;<a href="#Outputfile">Outputfile</a>&nbsp;to&nbsp;further&nbsp;writing.</tt></dd></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="-findbits"><strong>findbits</strong></a>(fp, bitsperint)</dt><dd><tt>Find&nbsp;which&nbsp;bits&nbsp;are&nbsp;set&nbsp;in&nbsp;a&nbsp;list/vector.<br>
&nbsp;<br>
This&nbsp;function&nbsp;is&nbsp;used&nbsp;by&nbsp;the&nbsp;<a href="#Fingerprint">Fingerprint</a>&nbsp;class.<br>
&nbsp;<br>
&gt;&gt;&gt;&nbsp;<a href="#-findbits">findbits</a>([13,&nbsp;71],&nbsp;8)<br>
[1,&nbsp;3,&nbsp;4,&nbsp;9,&nbsp;10,&nbsp;11,&nbsp;15]</tt></dd></dl>
<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>
<!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:///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>&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#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>&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="Fingerprint">class <strong>Fingerprint</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;Molecular&nbsp;<a href="#Fingerprint">Fingerprint</a>.<br>
&nbsp;<br>
Required&nbsp;parameters:<br>
&nbsp;&nbsp;&nbsp;obFingerprint&nbsp;--&nbsp;a&nbsp;vector&nbsp;calculated&nbsp;by&nbsp;OBFingerprint.FindFingerprint()<br>
&nbsp;<br>
Attributes:<br>
&nbsp;&nbsp;&nbsp;fp&nbsp;--&nbsp;the&nbsp;original&nbsp;obFingerprint<br>
&nbsp;&nbsp;&nbsp;bits&nbsp;--&nbsp;a&nbsp;list&nbsp;of&nbsp;bits&nbsp;set&nbsp;in&nbsp;the&nbsp;<a href="#Fingerprint">Fingerprint</a><br>
&nbsp;<br>
Methods:<br>
&nbsp;&nbsp;&nbsp;The&nbsp;"|"&nbsp;operator&nbsp;can&nbsp;be&nbsp;used&nbsp;to&nbsp;calculate&nbsp;the&nbsp;Tanimoto&nbsp;coeff.&nbsp;For&nbsp;example,<br>
&nbsp;&nbsp;&nbsp;given&nbsp;two&nbsp;Fingerprints&nbsp;'a',&nbsp;and&nbsp;'b',&nbsp;the&nbsp;Tanimoto&nbsp;coefficient&nbsp;is&nbsp;given&nbsp;by:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tanimoto&nbsp;=&nbsp;a&nbsp;|&nbsp;b<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</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> = &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 'Fingerprint' 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;data,&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>(),&nbsp;<a href="#Molecule-calcfp">calcfp</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-calcfp"><strong>calcfp</strong></a>(self, fptype<font color="#909090">=''</font>)</dt><dd><tt>Calculate&nbsp;a&nbsp;molecular&nbsp;fingerprint.<br>
&nbsp;<br>
Optional&nbsp;parameters:<br>
&nbsp;&nbsp;&nbsp;fptype&nbsp;--&nbsp;the&nbsp;name&nbsp;of&nbsp;the&nbsp;Open&nbsp;Babel&nbsp;fingerprint&nbsp;type.<br>
&nbsp;<br>
If&nbsp;fptype&nbsp;is&nbsp;not&nbsp;specified,&nbsp;the&nbsp;default&nbsp;Open&nbsp;Babel&nbsp;fingerprint<br>
type&nbsp;is&nbsp;used.&nbsp;See&nbsp;the&nbsp;Open&nbsp;Babel&nbsp;library&nbsp;documentation&nbsp;for&nbsp;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&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="MoleculeData">class <strong>MoleculeData</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>Store&nbsp;molecule&nbsp;data&nbsp;in&nbsp;a&nbsp;dictionary-type&nbsp;<a href="__builtin__.html#object">object</a><br>
&nbsp;<br>
Required&nbsp;parameters:<br>
&nbsp;&nbsp;obmol&nbsp;--&nbsp;an&nbsp;Open&nbsp;Babel&nbsp;OBMol&nbsp;<br>
&nbsp;<br>
Methods&nbsp;and&nbsp;accessor&nbsp;methods&nbsp;are&nbsp;like&nbsp;those&nbsp;of&nbsp;a&nbsp;dictionary&nbsp;except<br>
that&nbsp;the&nbsp;data&nbsp;is&nbsp;retrieved&nbsp;on-the-fly&nbsp;from&nbsp;the&nbsp;underlying&nbsp;OBMol.<br>
&nbsp;<br>
Example:<br>
&gt;&gt;&gt;&nbsp;mol&nbsp;=&nbsp;<a href="#-readfile">readfile</a>("sdf",&nbsp;'head.sdf').next()<br>
&gt;&gt;&gt;&nbsp;data&nbsp;=&nbsp;mol.data<br>
&gt;&gt;&gt;&nbsp;print&nbsp;data<br>
{'Comment':&nbsp;'CORINA&nbsp;2.61&nbsp;0041&nbsp;&nbsp;25.10.2001',&nbsp;'NSC':&nbsp;'1'}<br>
&gt;&gt;&gt;&nbsp;print&nbsp;len(data),&nbsp;data.<a href="#MoleculeData-keys">keys</a>(),&nbsp;data.<a href="#MoleculeData-has_key">has_key</a>("Second&nbsp;comment")<br>
2&nbsp;['Comment',&nbsp;'NSC']&nbsp;False<br>
&gt;&gt;&gt;&nbsp;print&nbsp;data['Comment']<br>
CORINA&nbsp;2.61&nbsp;0041&nbsp;&nbsp;25.10.2001<br>
&gt;&gt;&gt;&nbsp;data['Comment']&nbsp;=&nbsp;'This&nbsp;is&nbsp;a&nbsp;new&nbsp;comment'<br>
&gt;&gt;&gt;&nbsp;for&nbsp;k,v&nbsp;in&nbsp;data.<a href="#MoleculeData-iteritems">iteritems</a>():<br>
...&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;k,&nbsp;"--&gt;",&nbsp;v<br>
Comment&nbsp;--&gt;&nbsp;This&nbsp;is&nbsp;a&nbsp;new&nbsp;comment<br>
NSC&nbsp;--&gt;&nbsp;1<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</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> = &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 'MoleculeData' 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-close"><strong>close</strong></a>(self)</dt><dd><tt>Close&nbsp;the&nbsp;<a href="#Outputfile">Outputfile</a>&nbsp;to&nbsp;further&nbsp;writing.</tt></dd></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="-findbits"><strong>findbits</strong></a>(fp, bitsperint)</dt><dd><tt>Find&nbsp;which&nbsp;bits&nbsp;are&nbsp;set&nbsp;in&nbsp;a&nbsp;list/vector.<br>
&nbsp;<br>
This&nbsp;function&nbsp;is&nbsp;used&nbsp;by&nbsp;the&nbsp;<a href="#Fingerprint">Fingerprint</a>&nbsp;class.<br>
&nbsp;<br>
&gt;&gt;&gt;&nbsp;<a href="#-findbits">findbits</a>([13,&nbsp;71],&nbsp;8)<br>
[1,&nbsp;3,&nbsp;4,&nbsp;9,&nbsp;10,&nbsp;11,&nbsp;15]</tt></dd></dl>
<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>