rdkit / rdkit-js

A powerful cheminformatics and molecule rendering toolbelt for JavaScript, powered by RDKit .
https://rdkitjs.com
BSD 3-Clause "New" or "Revised" License
150 stars 36 forks source link

remove_hs function removes deuterium/tritium atoms #438

Open markarchibald opened 9 months ago

markarchibald commented 9 months ago

Using the remove_hs function to remove unnecessary explicit H atoms, I found that while it does not remove H atoms that are required to define stereochemistry, it does remove H atoms that are labelled as the isotopes deuterium or tritium – altering the chemical structure. The analogous Chem.RemoveHs function in core RDKit does not remove deuterium/tritium.

Can be reproduced on the RDKitJS demo page (https://www.rdkitjs.com/#introduction) by running this code using a mol block for D2O:

  var mol = RDKitModule.get_mol(`
  ACD/Labs04281711232D

  3  2  0  0  0  0  0  0  0  0  1 V2000
    1.1221   -0.6603    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 D   0  0  0  0  0  0  0  0  0  0  0  0
    2.3088    0.0000    0.0000 D   0  0  0  0  0  0  0  0  0  0  0  0
  1  2  1  0  0  0  0
  1  3  1  0  0  0  0
M  END`);
  var molRemovedH = RDKitModule.get_mol(mol.remove_hs());
  var dest = document.getElementById("example-1-output");
  var svg = molRemovedH.get_svg();
  dest.innerHTML = "<div id='drawing'>" + svg + "</div>";

which produces this depiction:

image

Expected behavior Expected behaviour is that D atoms are not removed (as they define chemical information that is otherwise lost), resulting in this depiction:

image

ptosco commented 9 months ago

@markarchibald You are right about deuterium and tritium - JSMol::remove_hs() calls MolOps::removeAllHs() which will remove ALL hydrogens, including isotopic ones. I will add an optional flag to enable retaining isotopic Hs, similarly to C++ and Python.

Regarding H atoms that are required to define stereochemistry, those are not actually present in the molecule graph, they are only added on-the-fly for visualization. You may avoid that those Hs are added by calling get_svg_with_highlights() or draw_to_canvas_with_highlights() and passing '{"addChiralHs":"false"}' as JSON details.

markarchibald commented 9 months ago

@ptosco thanks for the quick reply. Do you have a guess for when the change will find its way into a release?

(Regarding Hs defining stereo, I do want these to be displayed but it's useful to understand it better.)

ptosco commented 9 months ago

The rdkit-js release cycle follows the main rdkit repo release cycle, which is reported here: https://github.com/rdkit/rdkit/milestones Alternatively, as soon as I have made the change in master and it has been reviewed and merged (which will probably happen before the end of this week), you can build your own RDKit_minimal library using the Dockerfile: https://github.com/rdkit/rdkit/blob/master/Code/MinimalLib/docker/Dockerfile Documentation how to build the library is provided as comments in the Dockerfile itself.

markarchibald commented 9 months ago

That's great, thank you

markarchibald commented 2 months ago

@ptosco after some delays RDKitJS was released, but I can't see how to implement the option to retain isotopic H.

I might be looking in the wrong place, but I can't see anything either here: https://docs.rdkitjs.com/interfaces/JSMol.html#remove_hs or here: https://www.rdkit.org/docs/source/rdkit.Chem.rdmolops.html#rdkit.Chem.rdmolops.RemoveAllHs

Could you let me know the name of the flag?

ptosco commented 2 months ago

@markarchibald Sorry, this one slipped through the cracks. JSMol::remove_hs() calls MolOps::removeAllHs() which will remove ALL hydrogens, including isotopic ones. I had very limited time to dedicate to community requests during the last year. I'll try and get this done for the 2024.09 release.

markarchibald commented 2 months ago

@ptosco no problem - we appreciate the time that you and others commit to this

markarchibald commented 1 month ago

@ptosco I understand time is in short supply and don't want to hassle you – as the 2024.09 release date is not far away I just wanted to ask if there's any update on this one?