From 147a30d16da90d1d4b744c435e3535b1e03051f8 Mon Sep 17 00:00:00 2001 From: Jack Day Date: Tue, 10 Dec 2024 21:52:17 +1000 Subject: [PATCH 1/2] Set a fixed bond length to reduce jumping when adding atoms --- rdeditor/molViewWidget.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rdeditor/molViewWidget.py b/rdeditor/molViewWidget.py index 8cd606f..0d353b3 100644 --- a/rdeditor/molViewWidget.py +++ b/rdeditor/molViewWidget.py @@ -310,6 +310,7 @@ def getMolSvg(self): # Chiral tags on R/S # chiraltags = Chem.FindMolChiralCenters(self._drawmol) opts = self.drawer.drawOptions() + opts.fixedBondLength = 15.0 if self._darkmode: rdMolDraw2D.SetDarkMode(opts) if (not self.molecule_sanitizable) and self.unsanitizable_background_colour: From 173c91b8fa50ec9316eb8cc415d4c021521c6b44 Mon Sep 17 00:00:00 2001 From: Jack Day Date: Wed, 11 Dec 2024 12:10:25 +1000 Subject: [PATCH 2/2] Lock scaling to stop molecule jumping when atoms are added --- rdeditor/molViewWidget.py | 7 ++++++- rdeditor/templatehandler.py | 4 ---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/rdeditor/molViewWidget.py b/rdeditor/molViewWidget.py index 0d353b3..3d1226f 100644 --- a/rdeditor/molViewWidget.py +++ b/rdeditor/molViewWidget.py @@ -304,13 +304,18 @@ def sanitizeDrawMol(self, kekulize=False, drawkekulize=False): finishedDrawing = QtCore.Signal(name="finishedDrawing") def getMolSvg(self): - self.drawer = rdMolDraw2D.MolDraw2DSVG(300, 300) + height = 300 + width = 300 + self.drawer = rdMolDraw2D.MolDraw2DSVG(width, height) # TODO, what if self._drawmol doesn't exist? if self._drawmol is not None: # Chiral tags on R/S # chiraltags = Chem.FindMolChiralCenters(self._drawmol) opts = self.drawer.drawOptions() opts.fixedBondLength = 15.0 + maxv = Point2D(0.5 * width / opts.scalingFactor, 0.5 * height / opts.scalingFactor) + minv = Point2D(-maxv.x, -maxv.y) + self.drawer.SetScale(width, height, minv, maxv) if self._darkmode: rdMolDraw2D.SetDarkMode(opts) if (not self.molecule_sanitizable) and self.unsanitizable_background_colour: diff --git a/rdeditor/templatehandler.py b/rdeditor/templatehandler.py index 56a489b..e264572 100644 --- a/rdeditor/templatehandler.py +++ b/rdeditor/templatehandler.py @@ -160,10 +160,6 @@ def apply_template_to_canvas(self, mol: Chem.Mol, point: Point2D, templatelabel: """Apply to canvas""" template = Chem.MolFromSmiles(self.templates[templatelabel]["canvas"], sanitize=False) - if mol.GetNumAtoms() == 0: - point.x = 0.0 - point.y = 0.0 - combined = Chem.rdchem.RWMol(Chem.CombineMols(mol, template)) # This should only trigger if we have an empty canvas if not combined.GetNumConformers():