-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjust positions of hydrogen isotopes as if they were regular Hs #296
base: develop
Are you sure you want to change the base?
Conversation
I tried to implement the embed-align method which is a different approach to this PR. The main advantage of doing that is it has an almost seamless way to handle isotopes and isomers. But the re-generated mol conformation can still look different (even the RMSD is low, like 0.5) from the docked pose, which sometimes possesses a strange torsion. With that I don't think it's applicable at the moment. Embedding the isotope-containing fragment is another way, but again if the docked pose is distorted, there's inevitably a shift of the export ligand. Since we also need to recover the exact position of polar hydrogens, we don't want the ligand atom positions to change. Tomorrow I will go back to the Add-RemoveHs method and continue this (for the chirality rebuild, or check, i'm not sure..). I had many misconceptions about RDKit Smiles handling before this. A lot of what I previously commented on #297 and #295 was wrong. It cost me so much time to realize the way I wrote Smiles has many problems .. |
Documenting for future reference: I tried many different ways to call However, when multiple atoms (isotopes) are missing a valid coordinates (or just at (0,0,0)), the positions from I feel like this is because it's a function intended for single coordinate assignment, assuming the surrounding geometry is complete. This behavior has led to lots of confusion I had these days, but now I think the undesired positions have very little to do with docking poses being distorted. The unwanted geometry results from how the Thus, the real problem might be the usage of It should be noted that AddHs does not necessarily return the best geometry, either - there can be close contacts between hydrogens. from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit.Geometry import Point3D
"""
rdkit.__version__
'2024.09.3'
"""
# SMILES in Issue 295
smi = "[2H]C([2H])([2H])[C@H](O)C([2H])([2H])CCCn1c(=O)c2c(ncn2C)n(C)c1=O"
mol = Chem.MolFromSmiles(smi)
AllChem.EmbedMolecule(mol, AllChem.ETKDG())
mol_with_h = Chem.AddHs(mol, addCoords=True)
# Ideal, as reference
writer = Chem.SDWriter("mol_0.sdf")
writer.write(mol_with_h)
writer.close()
for atom in mol_with_h.GetAtoms():
idx = atom.GetIdx()
if atom.GetIsotope()>0:
neigh = atom.GetNeighbors()
AllChem.SetTerminalAtomCoords(mol_with_h, idx, neigh[0].GetIdx())
# OK, if isotopes are set one at a time?
writer = Chem.SDWriter("mol_1.sdf")
writer.write(mol_with_h)
writer.close()
conformer = mol_with_h.GetConformer()
for atom in mol_with_h.GetAtoms():
idx = atom.GetIdx()
if atom.GetIsotope()>0:
conformer.SetAtomPosition(idx, Point3D(0,0,0))
for atom in mol_with_h.GetAtoms():
idx = atom.GetIdx()
if atom.GetIsotope()>0:
neigh = atom.GetNeighbors()
AllChem.SetTerminalAtomCoords(mol_with_h, idx, neigh[0].GetIdx())
# Not OK - has distorted angels
writer = Chem.SDWriter("mol_2.sdf")
writer.write(mol_with_h)
writer.close() |
I agree: the problem is how I'm using |
[1a5373b] is a working version. I will do some cleanup, add comments and run more checks tomorrow. Added a function to replace Input: Output: Current state: The output looks exactly like the output when this PR was at c9435bb. The major improvement is handling of chirality, and I also refactored and encapsulated the additional process, to insert the minimal amount of codes into |
now initialize by Chem.rdCIPLabeler.AssignCIPLabels, and update from 3D by Chem.AssignStereochemistryFrom3D
[b1a2835] is a bugfix. I changed the CIP chirality tag assignment methods. Previously, I wasn't using the method that's 3D-aware to re-evaluate the chirality after the initial placement and the isotope swap. This PR should be ready at this point..! Some comments for future reference:
The added function,
There's another occurrence of |
This is for #295 and #298.
Added a function
set_h_isotope_atom_coords
to replaceSetTerminalAtomCoords
for the assignment of H isotope coordinates with AddHs, and with preserved chirality if from input molecular graph.More description in comments.