Hi Anonymous,

There is a one-line change source change that governs this behaviour, and
it's one that I've changed in the past, and maybe it should be an option.
If you have compiled Open Babel yourself, all you need to do is change
"return true" to "return false" in the right place.

The thing is, if this is set to "return false", then if you are converting
a million SMILES strings and the conversion fails on the 1000th SMILES
string, then at the command-line you will end up with only 1000 strings in
the output. What you actually want is a million lines, where one of the
lines is blank (or blank+title). The current behaviour is designed to make
this use case work.

If you want to know if there is an error when converting the SMILES string,
you just need to check the log before and after (I think that you can ask
for the number of errors).

I don't know the source of these SMILES strings, but if you want to check
whether the valence is chemically reasonable the code at
https://baoilleach.blogspot.com/2018/04/finding-texas-carbons-and-other-unusual.html
may be a useful starting point (you will need to port to OB3).

Regards,
Noel




On Fri, 27 Aug 2021 at 07:35, <theoki...@fz-juelich.de> wrote:

>
> Hi,
>
> I want to use openbabel to validate a SMILES string. I tried this:
>
> ----
> #!/usr/bin/env python3
> from openbabel import openbabel
>
> mol = openbabel.OBMol()
> obConversion = openbabel.OBConversion()
> obConversion.SetInFormat('smi')
>
> # case_1: success is True
> success = obConversion.ReadString(mol, 'CC((CC')
> print('<DBG> success:', success)
>
> # case_2: success is False
> success = obConversion.ReadString(mol, 'CC((CCX')
> print('<DBG> success:', success)
> ----
>
> The return value success is True for case_1, False for case_2.
> I was expecting success to be False in both cases,
> since both do not represent a valid SMILES string.
>
> I assume this is not the correct way to verify a SMILES string?
> Is there another way?
>
> Thanks in advance.
> _______________________________________________
> OpenBabel-discuss mailing list
> OpenBabel-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
>
_______________________________________________
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss

Reply via email to