You need to set the input format before calling ReadString. Also
ReadString returns False if it fails. See the API at
http://openbabel.org/api/2.3/classOpenBabel_1_1OBConversion.shtml#a93558e9c89cda2e1a4f9fb2cadc5c8d1

Regards,
   Noel

On 23 January 2011 22:57, kohai.raul <[email protected]> wrote:
>
> Hi all!!
>
> I'm testing OpenBabel 2.2.3 with Perl Bindings, and found a very very
> strange behaviour related to  OBConversion.
>
> By now, I created a simple perl script 'smiles2anything.pl'
>
> ==== smiles2anything.pl ========
>
> #!/usr/bin/perl
>
> use Chemistry::OpenBabel;
>
>  $smiles = shift;
>  $service = shift;
>
>  my $obMolIn = new Chemistry::OpenBabel::OBMol;
>  my $obConv = new Chemistry::OpenBabel::OBConversion;
>
>  $obConv->ReadString($obMolIn, $smiles);
>  $obConv->SetInAndOutFormats("SMI", $service);
>  my $obOut=$obConv->WriteString($obMolIn);
>
>  print ("$obOut");
>
> ==== Shell ====
>
> I've used it as follows:
>
> $ ./openbabel-bridge.pl '[H]C([H])=C([H])O[B-]([H])([H])OC([H])[H]' 'INCHI'
>
> But the result is:
>
> *** Open Babel Error  in InChI code
>  InChI generation failed
>
> ??????
>
> ==== After that ====
>
> after that, and many many many tests ... I found that if I apply the
> following "ununderstandable" variation, everything changes!! :-?
>
> #!/usr/bin/perl
>
> use Chemistry::OpenBabel;
>
>  $smiles = shift;
>  $service = shift;
>
>  my $obMolIn = new Chemistry::OpenBabel::OBMol;
>  my $obConv = new Chemistry::OpenBabel::OBConversion;
>
>  $obConv->ReadString($obMolIn, $smiles);
>  $obConv->SetInAndOutFormats("SMI", "MOL");
>  my $obOut=$obConv->WriteString($obMolIn);
>
>  $obMolIn->Clear();
>  $obConv->ReadString($obMolIn, $smiles);
>  $obConv->SetInAndOutFormats("SMI", $service);
>  my $obOut=$obConv->WriteString($obMolIn);
>
>  print ("$obOut");
>
> ==== SHELL 2nd attempt ======
>
> And now.... :-O
>
> $./openbabel-bridge.pl '[H]C([H])=C([H])O[B-]([H])([H])OC([H])[H]' 'INCHI'
>
> InChI=1S/C3H8BO2/c1-3-6-4-5-2/h3H,1,4H2,2H3/q-1
>
> =======================
>
> Is this behaviour normal??? does anyone with similar problems??
>
> Best Regards,
>
>
>
> --
> View this message in context: 
> http://forums.openbabel.org/Very-Strange-behaviour-OBConversion-Perl-Bindings-tp3233147p3233147.html
> Sent from the openbabel-scripting mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
> Finally, a world-class log management solution at an even better price-free!
> Download using promo code Free_Logger_4_Dev2Dev. Offer expires
> February 28th, so secure your free ArcSight Logger TODAY!
> http://p.sf.net/sfu/arcsight-sfd2d
> _______________________________________________
> OpenBabel-scripting mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/openbabel-scripting
>

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
OpenBabel-scripting mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbabel-scripting

Reply via email to