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

Fixes a bug in AddHs() involving sp2 centers with degree 1 #3383

Merged
merged 3 commits into from
Aug 31, 2020

Conversation

ptosco
Copy link
Contributor

@ptosco ptosco commented Aug 30, 2020

Hs are not put in the same plane as the sp2 system the atom belongs to. This affects ethylene (2 heavies only) and conjugated systems of any size.

This gist demonstrates the bug:
https://gist.github.com/ptosco/620edc8a3fd411928499204003eefb59

This gist shows the results obtained after merging this PR:
https://gist.github.com/ptosco/93f85d18794ed46da4122fa35bdb7b6e

@ptosco
Copy link
Contributor Author

ptosco commented Aug 30, 2020

The Windows CI failure is not a real one - failed download. The Windows DLL build passed.

@@ -1976,6 +1976,100 @@ void testAddHsCoords() {
delete m;
delete m2;

// make sure Hs are on the xy plane if conformer is 2D
Copy link
Member

Choose a reason for hiding this comment

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

This is ok as-is, but I've started (mostly) adding new test cases so that more "modern" style (like using _smiles) can be used.

auto nh2NbrRange = boost::make_iterator_range(
m2->getAtomNeighbors(m2->getAtomWithIdx(nh2Idx)));
std::vector<ROMol::vertex_descriptor> nh2His(2);
auto it = std::copy_if(nh2NbrRange.begin(), nh2NbrRange.end(), nh2His.begin(),
Copy link
Member

Choose a reason for hiding this comment

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

In the line above you've restricted the size of nh2His to be 2, but then you use this general approach to find the H neighbors. That feels inconsistent.
Since you know the order in which the Hs are added (and we don't say anywhere that you shouldn't rely upon this), I think it makes things simpler and considerably more readable to just specifically use the atom IDs of the Hs in the testing code

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 think it's worth simplifying the test, but if you strongly prefer it this way I'm ok leaving it as is.

@ptosco
Copy link
Contributor Author

ptosco commented Aug 31, 2020

@greglandrum Done. Yeah, I went a bit over the top with the std::copy_if thing - I really love implicit loop constructs : ) But you are right that I should then have sized the vector as getNumAtoms() and then trimmed it down afterwards. It does look simpler now. I'll save the std::copy_if for the next occasion.

@greglandrum
Copy link
Member

@greglandrum Done. Yeah, I went a bit over the top with the std::copy_if thing - I really love implicit loop constructs : ) But you are right that I should then have sized the vector as getNumAtoms() and then trimmed it down afterwards. It does look simpler now. I'll save the std::copy_if for the next occasion.

You can actually use an std::back_inserter() to avoid needing to set the size in advance at all, but I still don't think it's the best answer here. :-)

@greglandrum greglandrum added this to the 2020_03_6 milestone Aug 31, 2020
@greglandrum greglandrum merged commit d372865 into rdkit:master Aug 31, 2020
@ptosco ptosco deleted the addhs branch September 3, 2020 09:07
greglandrum pushed a commit that referenced this pull request Sep 19, 2020
* Fixes a bug in AddHs() involving sp2 centers with degree 1

* Changes in response to review

* forgot to run clang-format
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 this pull request may close these issues.

None yet

2 participants