mirror of
https://github.com/openbabel/openbabel.git
synced 2025-02-25 18:55:23 -06:00
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:
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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> <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#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> <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, 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="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>
|
||||
|
||||
<!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>
|
||||
Reference in New Issue
Block a user