Here's an example with MNA, a simpler format in some respects:

C:\Tools>python
Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pybel
>>> mol = pybel.readstring("smi", "CCCCC(=O)Cl")
>>> conv = pybel.ob.OBConversion()
>>> conv.SetOutFormat("mna")
True
>>> conv.WriteString(mol.OBMol)
'# Title = \n-C(-H(-C)-H(-C)-H(-C)-C(-H-H-C-C))\n-C(-H(-C)-H(-C)-C(-H-H-H-C)-C(-
H-H-C-C))\n-C(-H(-C)-H(-C)-C(-H-H-C-C)-C(-H-H-C-C))\n-C(-H(-C)-H(-C)-C(-H-H-C-C)
-C(-C-O-Cl))\n-C(-C(-H-H-C-C)-O(-C)-Cl(-C))\n-O(-C(-C-O-Cl))\n-Cl(-C(-C-O-Cl))\n
-H(-C(-H-H-H-C))\n-H(-C(-H-H-H-C))\n-H(-C(-H-H-H-C))\n-H(-C(-H-H-C-C))\n-H(-C(-H
-H-C-C))\n-H(-C(-H-H-C-C))\n-H(-C(-H-H-C-C))\n-H(-C(-H-H-C-C))\n-H(-C(-H-H-C-C))
\n'
>>> conv.AddOption("L", conv.OUTOPTIONS, "0")
>>> conv.IsOption("L")
'0'
>>> conv.WriteString(mol.OBMol)
'# Title = \n-C\n-C\n-C\n-C\n-C\n-O\n-Cl\n-H\n-H\n-H\n-H\n-H\n-H\n-H\n-H\n-H\n'
>>>

Note the use of "IsOption" to get the option value.

Maybe you didn't have write permissions on that file for some reason.

- Noel

On 29 June 2011 05:27, A. Heifets <[email protected]> wrote:
> I'm trying to duplicate commandline behavior of obabel via Python.
> I'd appreciate any help.
>
> When I run (using today's subversion checkout)
>       obabel -imol junk.mol  -osvg -Ojunk.svg -xc1 -xr1 -xd
> I get an SVG with the nice resizing javascript.  I can't seem to
> generate the same behavior with Python.  I don't get any errors but
> the SVG does not resize:
>
> $ python
> Python 2.4.3 (#1, May  5 2011, 16:39:10)
> [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import pybel
>>>> import openbabel as ob
>>>> x=pybel.readstring("smi", "n1ccccc1")
>>>> c = ob.OBConversion()
>>>> c.SetOutFormat("svg")
> True
>>>> c.AddOption("d", c.OUTOPTIONS, "")
>>>> c.AddOption("r", c.OUTOPTIONS, "1")
>>>> c.AddOption("c", c.OUTOPTIONS, "1")
>>>> c.WriteFile(x.OBMol, "./junk.svg")
> False
>
> I tried to investigate whether the options I thought I was setting are
> the right ones.  I expected that the "c" option should take one
> parameter but, as you can see, something's not right:
>>>> c.GetOptionParams("c", c.OUTOPTIONS)
> 0
>>>> c.GetOptionParams("c", c.INOPTIONS)
> 0
>>>> c.GetOptionParams("c", c.GENOPTIONS)
> 0
>>>> c.GetOptionParams("c", c.ALL)
> Segmentation fault
>
> --
> A. Heifets
> http://www.cs.toronto.edu/~aheifets/
>
> ------------------------------------------------------------------------------
> All of the data generated in your IT infrastructure is seriously valuable.
> Why? It contains a definitive record of application performance, security
> threats, fraudulent activity, and more. Splunk takes this data and makes
> sense of it. IT sense. And common sense.
> http://p.sf.net/sfu/splunk-d2d-c2
> _______________________________________________
> OpenBabel-scripting mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/openbabel-scripting
>

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
OpenBabel-scripting mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbabel-scripting

Reply via email to