From b1c5b379267f2d9313ddccd8b035406c83056773 Mon Sep 17 00:00:00 2001 From: Esben Jannik Bjerrum Date: Mon, 29 Jul 2024 20:42:15 +0200 Subject: [PATCH] Fixed a bug where molstereo was shown as active, even if molecule editied to be nonisomeric. Updating of Stereo now runs everytime mol event is triggered. --- rdeditor/molEditWidget.py | 14 +------------- rdeditor/molViewWidget.py | 13 +++++++++++++ rdeditor/rdEditor.py | 2 -- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/rdeditor/molEditWidget.py b/rdeditor/molEditWidget.py index 2618896..67b1bdf 100644 --- a/rdeditor/molEditWidget.py +++ b/rdeditor/molEditWidget.py @@ -504,11 +504,8 @@ def toogleRS(self, atom): self.logger.debug("New stereotype set to %s" % atom.GetChiralTag()) # rdDepictor.Compute2DCoords(self._mol) # self._mol.ClearComputedProps() - self._mol.UpdatePropertyCache() + self._mol.UpdatePropertyCache(strict=False) rdDepictor.Compute2DCoords(self._mol) - if atom.HasProp("_CIPCode"): - atom.ClearProp("_CIPCode") - Chem.rdCIPLabeler.AssignCIPLabels(self._mol) self.molChanged.emit() def assert_stereo_atoms(self, bond): @@ -546,12 +543,6 @@ def assign_stereo_atoms(self, mol: Chem.Mol): stereoatoms[1], stereoatoms[0] ) # Not sure why this can get the wrong way. Seem to now work correctly for Absisic Acid - def updateMolStereo(self, mol): - self.logger.debug("Updating stereo info") - Chem.rdmolops.SetDoubleBondNeighborDirections(mol) - mol.UpdatePropertyCache() - Chem.rdCIPLabeler.AssignCIPLabels(mol) - def toogleEZ(self, bond: Chem.Bond): self.backupMol() @@ -579,9 +570,6 @@ def toogleEZ(self, bond: Chem.Bond): self.logger.debug(f"StereoAtoms are {list(bond.GetStereoAtoms())}") self.logger.debug(f"Bond properties are {bond.GetPropsAsDict(includePrivate=True, includeComputed=True)}") - bond.ClearProp("_CIPCode") - self.updateMolStereo(self._mol) - self.logger.debug(f"StereoAtoms are {list(bond.GetStereoAtoms())}") self.logger.debug(f"Bond properties are {bond.GetPropsAsDict(includePrivate=True, includeComputed=True)}") diff --git a/rdeditor/molViewWidget.py b/rdeditor/molViewWidget.py index 74fe058..63be035 100644 --- a/rdeditor/molViewWidget.py +++ b/rdeditor/molViewWidget.py @@ -235,10 +235,23 @@ def canon_coords_and_draw(self): self._drawmol = copy.deepcopy(self._mol) # Chem.Mol(self._mol.ToBinary()) self.draw() + def updateStereo(self): + self.logger.debug("Updating stereo info") + for atom in self.mol.GetAtoms(): + if atom.HasProp("_CIPCode"): + atom.ClearProp("_CIPCode") + for bond in self.mol.GetBonds(): + if bond.HasProp("_CIPCode"): + bond.ClearProp("_CIPCode") + Chem.rdmolops.SetDoubleBondNeighborDirections(self.mol) + self.mol.UpdatePropertyCache(strict=False) + Chem.rdCIPLabeler.AssignCIPLabels(self.mol) + sanitizeSignal = QtCore.Signal(str, name="sanitizeSignal") @QtCore.Slot() def sanitizeDrawMol(self, kekulize=False, drawkekulize=False): + self.updateStereo() self.computeNewCoords() # self._drawmol_test = Chem.Mol(self._mol.ToBinary()) # Is this necessary? # self._drawmol = Chem.Mol(self._mol.ToBinary()) # Is this necessary? diff --git a/rdeditor/rdEditor.py b/rdeditor/rdEditor.py index 5d1b7c0..088d328 100644 --- a/rdeditor/rdEditor.py +++ b/rdeditor/rdEditor.py @@ -366,8 +366,6 @@ def paste(self): self.editor.assign_stereo_atoms(mol) Chem.rdmolops.SetBondStereoFromDirections(mol) - self.editor.updateMolStereo(mol) - self.editor.mol = mol else: self.editor.logger.warning(f"Failed to parse the content of the clipboard as a SMILES: {repr(text)}")