Indeed - Andrew's approach is all you can do at the moment. I've often
thought it would be a useful option to add, and just a one or two line
change to the C++ (just skip the part where the "organic subset" is treated
as special).

Regarding SMARTS, given that "CC" is also a valid SMARTS that would match
the SMILES "CC", it sounds like you want a bespoke conversion solution. But
either way, it's not available as an option.

Regards,
Noel

On Wed, 22 Feb 2023 at 11:06, Thomas <odioidenti...@gmail.com> wrote:

> Thank you Andrew, your script does the job.
>
> Apparently, this was the original behaviour of OB back in 2011, then it
> has been preferred to write H as atoms instead (
> https://sourceforge.net/p/openbabel/mailman/message/26960761/).
>
> I would include your script under GPL license if you don't mind.
> Thank you
>
> Il giorno mer 22 feb 2023 alle ore 11:12 Andrew Dalke <
> da...@dalkescientific.com> ha scritto:
>
>> On Feb 21, 2023, at 19:23, Thomas <odioidenti...@gmail.com> wrote:
>> > Is it possible to get SMILES with explicit hydrogens as a "property" of
>> another atom?
>> > For example from the SMILES "CC" I'd like to get '[CH3][CH3]' instead
>> of '[H]C(C([H])([H])[H])([H])[H]'
>>
>> I don't see a direct way to do it.
>>
>> I wrote to_H_smiles() at
>> https://paste.sr.ht/~dalke/8f51a0df8b37585010ca38b54a337f4efbec8667
>> which I think does what you want.
>>
>> In short, I add an atom class to each atom, generate the SMILES with the
>> 'a' option to include the atom class. As a side-effect, this also include
>> the H3 terms you're looking for. I then post-process the output SMILES to
>> adjust the atom classes, either to remove them (if the original atom didn't
>> have an atom class) or to use the original input value.
>>
>> > Furthermore, is it possible to generate SMARTS? For example from "CC"
>> I'd like to get '[#6]-[#6]'
>>
>> I don't know of one, though that doesn't mean there isn't one.
>>
>>
>>                                 Andrew
>>                                 da...@dalkescientific.com
>>
>>
>> _______________________________________________
> 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