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
128 stars 35 forks source link

Achieve 3D coordinate generation using RDKit.js? #338

Open ben-ikt opened 1 year ago

ben-ikt commented 1 year ago

Is your feature request related to a problem? Please describe. I want to display a molecule in 3D via ThreeJS and the PDBLoader.

Describe the solution you'd like Be able to get 3D coordinates.

MichelML commented 9 months ago

Thanks for the request @ben-ikt, I would tend to say this isn't possible at the moment, but to be honest there are a few things I'm not sure of:

  1. Where does rdkit-js fit in your current use case? If you use ThreeJS and PDBLoader, it doesn't seem you need rdkit-js.
  2. Assuming you really want to retrieve 3D coordinates, that logic would currently be based on molfile (and not pdb, unless I'm wrong, rdkit-js doesn't support loading molecules from pdb) in rdkit-js. And the only way I can think of having 3D info at the moment, is you would have had initially loaded a molecule with get_mol using a molfile containing 3D coordinates, and then you would be able to retrieve it back calling get_molblock on the molecule object, but that would essentially give you back the original molfile, which contained the 3D coordinates in the first place.

We can continue the convo here if you have further questions after reading this, otherwise let me know and we'll close this.

themoenen commented 3 months ago

I'm running in the same limitation. In Python I'm able to generate 3D coordinates from an InChI or SMILES string:

mol_rdkit = Chem.MolFromSmiles(smiles)
mol_rdkit = Chem.AddHs(mol_rdkit) # Add explicit hydrogen atoms
Chem.rdDistGeom.EmbedMolecule(mol_rdkit) # Embed 3D coordinates
sdf = Chem.MolToMolBlock(mol_rdkit) # Generate SDF

Then in the frontend I render the 3D molecule based on the SDF coordinates.

I'm trying to move this logic into the frontend so I can render the molecule without having to wait for the slow API, but this doesn't seem possible due to lacking 3D coordinates.

IN JS this looks like:

const rdkMol = window.RDKit.get_mol(smiles)
rdkMol.add_hs() // Add explicit hydrogen atoms
// No way to embed 3D coordinates
const sdf = rdkMol.get_molblock() // Generate SDF

So, to be concrete, is a JS equivalent for Chem.rdDistGeom.EmbedMolecule not a priority or not possible?