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

2ddrawenhancements2931 #2979

Merged
merged 54 commits into from
Mar 10, 2020
Merged

Conversation

DavidACosgrove
Copy link
Collaborator

Completes everything in #2931, AFAIK.

What does this implement/fix? Explain your changes.

As well as #2931, shows radicals in drawing.
Some general tidying in relevant code.

Any other comments?

David Cosgrove added 30 commits February 5, 2020 13:34
Made drawMolecule() take note of prepareMolsBeforeDrawing.
Updated more iterators to modern idiom.
Fixed some existing tests where, for example, scale on picture is now different.
…whackamole.

Updated some tests accordingly.
@DavidACosgrove
Copy link
Collaborator Author

DavidACosgrove commented Mar 3, 2020 via email

@d-b-w
Copy link
Contributor

d-b-w commented Mar 3, 2020

Since this is about depiction, it might be helpful to include some before/after images of depictions in the PR.

@DavidACosgrove
Copy link
Collaborator Author

These two pictures give some of the main differences. Top is the new, bottom is the old.
test4_mc_new
test4_mc_old

David Cosgrove added 2 commits March 4, 2020 07:56
Copy link
Member

@greglandrum greglandrum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not going to pretend that I read every line, but the images look a lot better than they did before and what I did read through seems solid.
Some suggestions anyway, of course. :-)

Code/GraphMol/MolDraw2D/MolDraw2D.h Show resolved Hide resolved
Point2D lc = getDrawCoords(cds.front());
cairo_move_to(dp_cr, lc.x, lc.y);
for (unsigned int i = 1; i < cds.size(); ++i) {
Point2D lc = getDrawCoords(cds[i]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's technically correct, but I find repeating variable names like this confusing. How about:

Suggested change
Point2D lc = getDrawCoords(cds[i]);
auto lci = getDrawCoords(cds[i]);

// Very few atomic symbols need to care about this, and common ones look a bit
// out of line. For example O sits to the left of a double bond. This is an
// empirical tweak to push it back a bit.
draw_coords.x += string_height * tmult * 0.1 * scale();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really supposed to be string_height? Seems odd to adjust the x coordinate by the height.

MolDraw2DUtils::updateDrawerParamsFromJSON(drawer, json);
drawer.drawMolecule(*m, "foo");
drawer.finishDrawing();
std::string text = drawer.getDrawingText();
std::ofstream outs("test13_1.svg");
std::ofstream outs("test983.svg");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change of name for this file?

@@ -628,7 +581,7 @@ void MolDraw2D::drawReaction(
setColour(options_.symbolColour);

// now add the symbols
BOOST_FOREACH (double plusLoc, plusLocs) {
for(double plusLoc: plusLocs) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for(double plusLoc: plusLocs) {
for(auto plusLoc: plusLocs) {

double this_y_min = at_cds_[activeMolIdx_][i].y - atsym_height / 2;
double this_y_max = at_cds_[activeMolIdx_][i].y + atsym_height / 2;
OrientType orient = atom_syms_[activeMolIdx_][i].second;
if (orient == W) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this set of if-elses could be a switch.


// need to move the centre
double cheight, cwidth;
if(orient == N) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could also be a switch

// which has it in C#
double xradius, yradius;
Point2D centre;
calcLabelEllipse(at_idx, highlight_radii, centre, xradius, yradius);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code below will misbehave if either xradius or yradius are 0. Maybe worth testing for that here?

// Some developers, when encountering a problem, say: “I know, I’ll
// use floating-point numbers !” Now, they have 1.9999999997 problems.
// — unknown
double costh = rot == 0.0 ? 0.0 : cos(rot);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do the transformation here using this class and avoid duplicating some code:
https://github.com/rdkit/rdkit/blob/master/Code/Geometry/Transform2D.h#L21

@greglandrum
Copy link
Member

greglandrum commented Mar 6, 2020

Looking through the output of the tests from the current version (c70a3f7), here are some observations.

This is all going to be pointing out problems (or things I perceive as problems), so I should point out at the very beginning that this looks a lot better than what the RDKit currently does. A big step forward!

Now on to the complaining. :-)

This is rxn_test1_1.svg in Chrome:
image
O:3 in the reactants is placed a bit oddly(not terrible), the H on N:6 in the products is cut off, and the H2O:4 is too close to the plus sign in the products.

rxn_test1_5.png:
image

The radicals here (and the other PNGs) are mighty small. Not sure if this is fixable, but the placement of the radicals on C:2 and C:7 is confusing/difficult to see

rxn_test2_1.png
image
The second reactant is mightly close to the "+" sign. May not be trivial to fix.

rxn_test2_2_3.png:
image
I don't like the H appearing centered over "N:4". Seems like it should be over the N

test4_1.png:
image
The boxes showing the atom collisions are not closed

test5_2.png:
image
the line width for the attachment point is too narrow. It's fine (maybe too thick, but having it be the same as the bonds is not a bad starting point) in the corresponding SVG

test6_1.svg:
image
This is another H centering thing. I think the "H" should be centered under the "N"

I didn't really see anything else new and "disturbing".

@DavidACosgrove
Copy link
Collaborator Author

DavidACosgrove commented Mar 8, 2020 via email

@greglandrum greglandrum merged commit 774892a into rdkit:master Mar 10, 2020
@DavidACosgrove DavidACosgrove deleted the 2ddrawenhancements2931 branch March 25, 2020 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants