Skip to content
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

RGD may yield poor depictions #5569

Closed
jones-gareth opened this issue Sep 15, 2022 · 0 comments · Fixed by #5570
Closed

RGD may yield poor depictions #5569

jones-gareth opened this issue Sep 15, 2022 · 0 comments · Fixed by #5570
Labels
Milestone

Comments

@jones-gareth
Copy link
Contributor

Describe the bug

When decomposing structures and cores with coordinates the RGD algorithm will copy those coordinates to the output groups.

In some cases the attachment dummy atom is poorly positioned

To Reproduce

# %%

from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit.Chem.rdRGroupDecomposition import RGroupDecomposition, RGroupDecompositionParameters, \
    RGroupMatching, RGroupScore, RGroupLabels, RGroupCoreAlignment, RGroupLabelling
from rdkit.Chem.Draw import IPythonConsole

IPythonConsole.ipython_useSVG = True

from rdkit.Chem import PandasTools
from rdkit.Chem import Draw
from IPython.display import HTML

import pandas as pd

# %%

core_block = """
  ChemDraw09152209202D

  6  6  0  0  0  0  0  0  0  0999 V2000
    0.0001    0.8250    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.7144    0.4125    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.7144   -0.4125    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.0001   -0.8250    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0
    0.7144   -0.4125    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.7144    0.4125    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
  1  2  1  0      
  2  3  1  0      
  3  4  1  0      
  4  5  1  0      
  5  6  1  0      
  6  1  1  0      
M  END
"""
core = Chem.MolFromMolBlock(core_block)
core
# %%

test_block = """MolHeader
     RDKit          2D

 20 21  0  0  0  0  0  0  0  0999 V2000
   -2.6437    1.7625    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -3.3582    1.3500    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -3.3582    0.5250    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -2.6438    0.1125    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0
   -1.9293    0.5250    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -1.9293    1.3500    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -1.2148    1.7625    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.5003    1.3500    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.2141    1.7625    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.9286    1.3500    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.3692    2.3459    0.0000 F   0  0  0  0  0  0  0  0  0  0  0  0
    0.7975    2.3459    0.0000 F   0  0  0  0  0  0  0  0  0  0  0  0
   -2.6438   -0.7125    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -3.3582   -1.1250    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -3.3582   -1.9500    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -2.6438   -2.3625    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -1.9293   -1.9500    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -1.9293   -1.1250    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -3.2271   -2.9459    0.0000 F   0  0  0  0  0  0  0  0  0  0  0  0
   -2.0604   -2.9459    0.0000 F   0  0  0  0  0  0  0  0  0  0  0  0
  1  2  1  0
  2  3  1  0
  3  4  1  0
  4  5  1  0
  5  6  1  0
  6  1  1  0
  6  7  1  0
  7  8  1  0
  8  9  1  0
  9 10  1  0
  9 11  1  0
  9 12  1  0
  4 13  1  0
 13 14  1  0
 14 15  1  0
 15 16  1  0
 16 17  1  0
 17 18  1  0
 18 13  1  0
 16 19  1  0
 16 20  1  0
M  END
"""
test = Chem.MolFromMolBlock(test_block)
test
# %%

options = RGroupDecompositionParameters()
options.matchingStrategy = RGroupMatching.GreedyChunks
options.matchingStrategy = RGroupMatching.Exhaustive
options.onlyMatchAtRGroups = False
options.scoreMethod = RGroupScore.FingerprintVariance

decomp = RGroupDecomposition([core], options)
result1 = decomp.Add(test)
result1
# %%

decomp.Process()
groups = decomp.GetRGroupsAsColumns()
groups

# %%
df = PandasTools.RGroupDecompositionToFrame(groups, [test], include_core=True)
PandasTools.ChangeMoleculeRendering(df)
HTML(df.to_html())

Expected behavior
I expect to see the dummy attachment point for R2 in a reasonable position.

Screenshots
but this is what happens:

image

Configuration (please complete the following information):

  • RDKit version: built from master branch as of 9/14/22.
  • OS: [e.g. Ubuntu 20.04] Ubuntu 20.04
  • Python version (if relevant): 3.8.6
  • Are you using conda? Conda build environment
  • If you are using conda, which channel did you install the rdkit from?
  • If you are not using conda: how did you install the RDKit?

Additional context
I will see if I can fix and submit a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants