Skip to content

Commit

Permalink
Lock scaling to stop molecule jumping when atoms are added
Browse files Browse the repository at this point in the history
  • Loading branch information
jacktday committed Dec 11, 2024
1 parent 147a30d commit 173c91b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 6 additions & 1 deletion rdeditor/molViewWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 0 additions & 4 deletions rdeditor/templatehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 173c91b

Please sign in to comment.