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

Bond Missing on Phytomedicine document : drawing option #7336

Open
urekam712 opened this issue Apr 5, 2024 · 7 comments
Open

Bond Missing on Phytomedicine document : drawing option #7336

urekam712 opened this issue Apr 5, 2024 · 7 comments
Labels

Comments

@urekam712
Copy link

Describe the bug
Bond is missing while using the drawing option : { "fixedBondLength": 20 , "bondLineWidth": 1, "additionalAtomLabelPadding": 1.25 , "multipleBondOffset": 0.08, "atomLabelFontFace": null, "atomLabelFontSize": 12 , "legendFontSize": 12 }
To Reproduce

##Phytomedicine

drawOptions = rdMolDraw2D.MolDrawOptions()
Draw.UpdateMolDrawOptionsFromJSON(drawOptions, '{ "fixedBondLength": 20 , "bondLineWidth": 1, "additionalAtomLabelPadding": 1.25 , "multipleBondOffset": 0.08, "atomLabelFontFace": null, "atomLabelFontSize": 12 , "legendFontSize": 12 }')
d2d = Draw.MolDraw2DSVG(250, 200, -1, -1, True)
d2d.SetDrawOptions(drawOptions)
d2d.DrawMolecule(m)
d2d.FinishDrawing()
txt = d2d.GetDrawingText()
SVG(txt)

issue is because of using "additionalAtomLabelPadding": 1.25

Expected behavior
In Chem draw, there is no bond missing on using the Phytomedicine document the same drawing option is used
image

https://chem.beloit.edu/classes/programs/ChemDraw_21_manual.pdf
refer page no. 62

Screenshots
output of the issue is

image

Configuration (please complete the following information):

  • RDKit version:
  • OS: [e.g. Ubuntu 20.04]
  • Python version (if relevant):
  • Are you using conda?
  • 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
Add any other context about the problem here.

@urekam712 urekam712 added the bug label Apr 5, 2024
@greglandrum
Copy link
Member

Please provide the input that was used to demonstrate the problem so that we can reproduce it

@urekam712
Copy link
Author

urekam712 commented Apr 8, 2024

from rdkit import Chem
from rdkit.Chem import AllChem, Draw, rdDepictor
from rdkit.Chem.Draw import rdMolDraw2D
from rdkit.Chem.Draw import rdMolDraw2D, rdDepictor
from rdkit.Chem.Draw import IPythonConsole
from IPython.display import SVG
from rdkit import rdBase
print(rdBase.rdkitVersion)

m = Chem.MolFromSmiles('c1ccccc1NC(=O)C1COC1')
d2d = Draw.MolDraw2DSVG(250, 200, -1, -1, True)
d2d.DrawMolecule(m)
d2d.FinishDrawing()
txt = d2d.GetDrawingText()
SVG(txt)

##Phytomedicine
drawOptions = rdMolDraw2D.MolDrawOptions()
Draw.UpdateMolDrawOptionsFromJSON(drawOptions, '{ "fixedBondLength": 20 , "bondLineWidth": 1,
                                 "additionalAtomLabelPadding": 1.25 , "multipleBondOffset": 0.08, 
                                  "atomLabelFontFace": null, "atomLabelFontSize": 12 , "legendFontSize": 12 }')
d2d = Draw.MolDraw2DSVG(250, 200, -1, -1, True)
d2d.SetDrawOptions(drawOptions)
d2d.DrawMolecule(m)
d2d.FinishDrawing()
txt = d2d.GetDrawingText()

SVG(txt)

@greglandrum Pl refer the above code

@greglandrum
Copy link
Member

@urekam712 this is happening because additionalAtomLabelPadding is too large. The value is a fraction of the font size, so 1.25 is huge. If you think you need to change that value, try something like 0.1

For what it's worth: "atomLabelFontFace" is not a valid option, so that will be ignored.

@greglandrum
Copy link
Member

@DavidACosgrove It's maybe worth figuring out why this happens.
Setting additionalAtomLabelPadding to 0.9 draws something:
image
but then going up to 1.25 causes a bond to disappear, but everything else, at least on first look, seems fine:
image

@DavidACosgrove
Copy link
Collaborator

@greglandrum yep, that does look odd. I’ll take a look in the next few days.

@urekam712
Copy link
Author

###ACS1996

drawOptions = rdMolDraw2D.MolDrawOptions()
Draw.UpdateMolDrawOptionsFromJSON(drawOptions, '{"fixedBondLength":14.4,"bondLineWidth":0.6,"multipleBondOffset":0.18,"atomLabelFontSize":10,"atomLabelFontFace":"Arial","legendFontSize":10,"additionalAtomLabelPadding":1.6}')
d2d = Draw.MolDraw2DSVG(250, 200, -1, -1, True)
d2d.SetDrawOptions(drawOptions)
d2d.DrawMolecule(m)
d2d.FinishDrawing()
txt = d2d.GetDrawingText()

SVG(txt)

In this drawing option, used additionalAtomLabelPadding":1.6 but seems good

@greglandrum
image

@DavidACosgrove
Copy link
Collaborator

Hi @greglandrum, @urekam712. I've had a look at this, and it seems to be behaving as intended. Whether that is sensible or not is a matter for debate that we can have. As Greg has observed, the problem is that the value for additonalAtomLabelPadding is very large, such that it produces padding round the character that is on a par with the bond length as drawn. The N-c bond is bond 5, the N-C bond is 6. I have produced an SVG just using additonalAtomLabelPadding = 1.25 and addBondIndices = true. Looking at it, there are the lines:

<path class='bond-5 atom-5 atom-6' d='M 121.5,131.5 L 121.6,131.5' style='fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2.0px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1' />
<path class='bond-5 atom-5 atom-6' d='M 121.6,131.5 L 121.6,131.5' style='fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2.0px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1' />
<path class='bond-6 atom-6 atom-7' d='M 204.0,155.8 L 204.9,156.8' style='fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2.0px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1' />
<path class='bond-6 atom-6 atom-7' d='M 204.9,156.8 L 205.8,157.8' style='fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2.0px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1' />

Showing that the bonds are being drawn, but are very short. Commenting out the commands in the SVG for the other bonds and scaling the image up gives
image
where you can see bond 6 is very short but visible. Bond 5 is also there, but looks like a bit of dust on your screen, probably. So the question is really, why are the bonds to the O atoms drawn, or in the case of Greg's picture above, why is bond 5 drawn but not bond 6? The answer to that is a decision we took a while back (to do with ACS mode drawings on a very small canvas, IIRC) that if the bond was completely obscured by the character and its padding, we wouldn't not draw a bond, we would draw the whole bond. So for those bonds, the O and its padding would remove the whole bond, so it is being drawn, but the bonds 5 and 6 have a tiny bit left, so that they appear missing but in fact the tiny bit beyond the circle round the N is being drawn.

So that's why you are seeing what you see. What to do about it is a different matter, and I am open to suggestions.

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

No branches or pull requests

3 participants