Closed oleksii-dukhno-bayer closed 1 week ago
Hi @oleksii-dukhno-bayer,
Many thanks for the detailed report and admirable persistence in trying to solve the problem. There are two separate issues here. The overlay of the two lines of the bond is very likely a different manifestation of a bug fixed by PR6571. I will check that tomorrow. The other one is harder. The dashed lines are all inside the ring for a full ring because the drawing code sees that it's a ring and makes it so. It does the same with double bonds in the kekule representation as well. When it doesn't have a ring to hang its hat on, it falls back on the rules for drawing non-ring double bonds. Those attempt to have it draw the dashed bonds inside the angles of the bonds coming off it. On the whole that works ok, but you can see in your examples that when there isn't a single inside option, it is pretty arbitrary which way it is drawn. I don't think there's any easy fix for that that doesn't involve looking outside the immediate environment of the bond itself which will be very complicated for an unusual case. I will have a look and see if there's anything obvious that can be done, but I think the answer might be that you have to live with it.
If anyone can come up with a convenient algorithm for making it look nicer, I'll be happy to have a crack at implementing it, because it is a bit unsightly.
Dave
Thanks for the response 😊 The issue indeed looks similar to what 6571 fixes, if that's the case I'll wait for the next release and live with it for now.
For the bond depictions flipping side to side (thankfully not a big deal for my use case): the only thing that comes to my mind would be something along these lines (as a postprocessing pass after atom coordinates have been decided):
k
=4 consecutive atoms in this chain (at the very chain edges, each 3 or each 2), essentially a rolling coordinate average; these serve as preliminary points of reference;k
might need to be adjusted too.
A potentially cleaner but more expensive solution would involve comparing the total amount of changes in "sidedness" of consecutive conjugated bonds, flipping the bonds appropriately, and then doing a pass of mild 2D geometry relaxation in case there's some atom overlap. Not sure if this would conflict with the existing drawing code, however.Hope this helps!
Just to confirm, this is how the master branch renders these molecules:
@oleksii-dukhno-bayer Thanks for the algorithm suggestion. I will have a think about it, but I suspect the answer might be that it's a lot of work for a low-incidence situation.
This issue was marked as stale because it has been open for 90 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.
Describe the bug When drawing query molecules constructed from SMARTS that have partial, unclosed aromatic rings, some aromatic bonds are drawn as a dashed line overlaying a solid line instead of a dashed line side-by-side with a solid line. The behavior does not happen with full rings. It seems that this behavior also depends on presence of labels on atoms, as turning them off fully fixes the issue.
To Reproduce In a Jupyter notebook:
Expected behavior All aromatic bonds are drawn as a dashed line side-by-side with a solid line.
Screenshots Executing above code results in these depictions:
Things tried that don't affect bond depictions:
kekulize=False
argument to MolToImage,Things tried that affect the bond depictions:
Setting
noAtomLabels
to True in drawing options fully fixes all bond depictions:Setting the
rdDepictor
to prefer fancier coordinate generation results in different behavior, with some offenders being fixed (but not all):One of the offenders at higher resolution (line overlay clearly visible):
Configuration (please complete the following information):
Thanks for keeping RDKit alive!