Hi Jean-Paul,
On Sat, Jan 28, 2012 at 3:18 PM, JP <[email protected]> wrote:
>
> I would like to use ForwardSDMolSupplier to read directly from standard in.
>
> This is possible using the normal SDMolSupplier by using something like:
>
> supp = Chem.SDMolSupplier()
> data = sys.stdin.read()
> ## NB This is not the nicest way to do it - especially if the file is
> massive (it is held in variable data) - but will do.
> suppl.SetData(data, sanitize = True)
> data = None # <- do this last step to free up memory in case the file is
> large
>
> Can the empty constructor and SetData be added to ForwardSDMolSupplier ?
> (possibly this is common behaviour across all Suppliers... and its righteous
> place is in the superclass)
All you need to do is construct a ForwardSDMolSupplier using sys.stdin.
Here's an example:
~/Projects/Benchmarks > cat mols_from_stdin.py
from rdkit import Chem
import sys
nGood=0
nBad=0
for mol in Chem.ForwardSDMolSupplier(sys.stdin):
if mol is None:
nBad+=1
else:
nGood+=1
print '%d good, %d bad'%(nGood,nBad)
~/Projects/Benchmarks > python mols_from_stdin.py < PubChemBackground.sdf
10000 good, 0 bad
Best,
-greg
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Rdkit-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss