Skip to content

Commit

Permalink
Fixed a bug where molstereo was shown as active, even if molecule edi…
Browse files Browse the repository at this point in the history
…tied to be nonisomeric. Updating of Stereo now runs everytime mol event is triggered.
  • Loading branch information
Esben Jannik Bjerrum committed Jul 29, 2024
1 parent 476000f commit b1c5b37
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
14 changes: 1 addition & 13 deletions rdeditor/molEditWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)}")

Expand Down
13 changes: 13 additions & 0 deletions rdeditor/molViewWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 0 additions & 2 deletions rdeditor/rdEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}")
Expand Down

0 comments on commit b1c5b37

Please sign in to comment.