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