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

Molecules whose Y size is very small won't display as SVG #2762

Closed
ptosco opened this issue Nov 6, 2019 · 0 comments
Closed

Molecules whose Y size is very small won't display as SVG #2762

ptosco opened this issue Nov 6, 2019 · 0 comments
Assignees
Labels
Milestone

Comments

@ptosco
Copy link
Contributor

ptosco commented Nov 6, 2019

from rdkit import Chem
from rdkit.Chem import Draw
import math
from IPython.display import SVG

smi_list = ["*Cl", "CC"]
mols = [Chem.MolFromSmiles(smi) for smi in smi_list]
sub_size = [250,250]
mols_num = len(mols)
columns_num = 5
rows_num = math.ceil(mols_num/5)
grid = [columns_num,rows_num]
aa = grid[0]*sub_size[0]
ab = grid[1]*sub_size[1]
ac = sub_size[0]
ad = sub_size[1]
d = Draw.rdMolDraw2D.MolDraw2DSVG(aa, ab, ac, ad)
opt = d.drawOptions()
opt.legendFontSize=20
d.SetFontSize(1.3*d.FontSize())
d.SetLineWidth(1)
d.DrawMolecules(mols,
                highlightAtoms=None,
                highlightBonds=None,
                highlightAtomColors=None,
                highlightBondColors=None,
                legends=None)
d.FinishDrawing()
print(d.GetDrawingText())

<?xml version='1.0' encoding='iso-8859-1'?>
<svg version='1.1' baseProfile='full'
              xmlns='http://www.w3.org/2000/svg'
                      xmlns:rdkit='http://www.rdkit.org/xml'
                      xmlns:xlink='http://www.w3.org/1999/xlink'
                  xml:space='preserve'
width='1250px' height='250px' viewBox='0 0 1250 250'>
<!-- END OF HEADER -->
<rect style='opacity:1.0;fill:#FFFFFF;stroke:none' width='1250' height='250' x='0' y='0'> </rect>
<path class='bond-0' d='M 0,250 L 0,250' style='fill:none;fill-rule:evenodd;stroke:#7F7F7F;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1' />
<path class='bond-0' d='M 0,250 L 0,250' style='fill:none;fill-rule:evenodd;stroke:#00CC00;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1' />
<text x='0' y='250' style='font-size:0px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#7F7F7F' ><tspan>*</tspan></text>
<text x='0' y='250' style='font-size:0px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#00CC00' ><tspan>Cl</tspan></text>
<path d='M 0,250 L 0,250 L 0,250 L 0,250 Z' style='fill:none;stroke:#FF0000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;' />
<path class='bond-0' d='M 250,250 L 250,250' style='fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1' />
<path d='M 250,250 L 250,250 L 250,250 L 250,250 Z' style='fill:none;stroke:#FF0000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;' />
</svg>

This is caused by MolDraw2D::setScale setting the scale to 0 if the Y range is < 1e-4, as happens with molecules which are constituted by an horizontal bond and nothing more.

@ptosco ptosco self-assigned this Nov 6, 2019
ptosco added a commit to ptosco/rdkit that referenced this issue Nov 6, 2019
@ptosco ptosco mentioned this issue Nov 13, 2019
@greglandrum greglandrum added this to the 2019_09_2 milestone Nov 29, 2019
greglandrum pushed a commit that referenced this issue Dec 3, 2019
* - fixes #2762

* - reverted fabs()
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

2 participants