On 23 January 2010 14:46, Andrew Dalke <[email protected]> wrote:
> On Jan 23, 2010, at 1:06 PM, Noel O'Boyle wrote:
>> Gotcha. I'll see if that's possible (do you know of any example of a
>> SWIG library that has this?).
>
> I did some searching and experimentation just now.
>
> I think you only need to %include "std_iostream.i" and let SWIG's
> built-in templates handle it for you. Here's a one-line change

That's great Andrew (how did you find this out BTW?).

>
>
> *** ../openbabel-python.i       2010-01-23 15:05:32.000000000 +0100
> --- /Users/dalke/cvses/ob/scripts/openbabel-python.i    2009-11-20 
> 18:09:52.000000000 +0100
> ***************
> *** 49,55 ****
>  %include "std_map.i"
>  %include "std_vector.i"
>  %include "std_string.i"
> - %include "std_iostream.i"
>
>  namespace std {
>
> --- 49,54 ----
>
>
> When that in place, I uncommented the Makefile code which regenerates
> the openbabel_python.cpp from the .i file, rebuilt it, compiled
> (which takes a while), then tested it with the following:
>
>
> [openbabel-2.2.3/scripts/python] dalke% cat use_stdin.py                      
>                                                                       import 
> openbabel as ob
>
> obconversion = ob.OBConversion()
> obconversion.SetInFormat("smi")
> obmol = ob.OBMol()
>
> obconversion.Read(obmol, ob.cvar.cin)
>
> print "title is:", obmol.GetTitle()
>
> [openbabel-2.2.3/scripts/python] dalke% echo "C methane" | env 
> PYTHONPATH=build/lib.macosx-10.6-universal-2.6 
> LD_LIBRARY_PATH=build/lib.macosx-10.6-universal-2.6 python use_stdin.py
> title is: methane
> [openbabel-2.2.3/scripts/python] dalke%
>
>
> The only other change would be the extra %pythoncode
>
> cin = cvar.cin
> cout = cvar.cout
> cerr = cvar.cerr
>
>
>>> dump_smiles mysql://chem:ad...@localhost/test | ob2fps --FP3
>>
>> In that case, why not use the code behind pybel.readstring()? You can
>> read strings from stdin in Python, and pass them to OpenBabel.
>
> Because I want to support all the formats which OpenBabel supports
>
> dump_sdf mysql://chem:ad...@localhost/test | ob2fps --FP3 --in sdf
>
> Including compressed versions, which OB auto-detects
>
> curl 'http://example.com/smiles_data.gz"; | ob2fps --FP2 --in smi
>
> Supporting these all through readstring() would be a lot of
> duplicated work.
>
>> Ok, I see. So you are requesting a global function, GetVersion() or
>> so, that returns the version string.
>
> If such a function doesn't already exist, then yes, I would like it.
>
> It's possible to get the information already, through roundabout means
>
> import openbabel as ob
>
> def GetVersion():
>    obconversion = ob.OBConversion()
>    obconversion.SetInFormat("smi")
>    obconversion.SetOutFormat("pdb")
>    obmol = ob.OBMol()
>
>    obconversion.ReadString(obmol, "C")
>    for line in obconversion.WriteString(obmol).splitlines():
>        if "GENERATED BY OPEN BABEL" in line:
>            return line.split()[-1]
>    return "<unknown>"
>
> print GetVersion()
>
>
> I might just used this if no GetVersion() exists in ob.
>
>
>                                Andrew
>                                [email protected]
>
>
>
> ------------------------------------------------------------------------------
> Throughout its 18-year history, RSA Conference consistently attracts the
> world's best and brightest in the field, creating opportunities for Conference
> attendees to learn about information security's most important issues through
> interactions with peers, luminaries and emerging and established companies.
> http://p.sf.net/sfu/rsaconf-dev2dev
> _______________________________________________
> OpenBabel-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
>

------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
OpenBabel-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss

Reply via email to