-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Refactor ring methods in Molecule class #855
Conversation
The toolkit wrappers are disagreeing on the number of rings in naphthalene:
but the other methods are behaving well in some simple tests. |
Looks like a test is failing due to a toolkit disagreement in how many rings a molecule has. I'll look into that tomorrow, probably just removing it since it's a deprecated API point - otherwise this is ready for review @j-wags |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to be nitpicky here, but I can't meaningfully review this if we're planning to fully remove Molecule.rings
and n_rings
before merging (like I think we've decided to do, though maybe we understood different things from the discussion). Most of the lines in the test diffs will be substantially changed and so the review would be huge and it'd be hard to keep track of everything under discussion.
I think we should immediately remove those API points with no deprecation warning. It's bad, but we don't have a release planned where anyone would see a deprecation warning anyway, and 0.11.0 will hopefully be our only major API break this year, so this is probably the most realistic way forward.
My read of the discussion was that we'd deprecate those points in this release with the intention of removing them later - probably since that's what we would typically do. I will update this to remove them now, though. |
Co-authored-by: Jeff Wagner <jwagnerjpl@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is starting to come together really well. I think we can simplify the toolkitwrapper method signatures and avoid a lot of weird edge cases in the process -- See suggested code changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the iteration on this. I'm approving this PR, pending changes in the comment before this post.
Co-authored-by: Jeff Wagner <jwagnerjpl@gmail.com>
This pull request introduces 1 alert when merging c413f35 into a7a9f18 - view on LGTM.com new alerts:
|
This pull request introduces 1 alert when merging 475abc7 into a7a9f18 - view on LGTM.com new alerts:
|
9362b71 Refactor ring methods in Molecule class (#855) * Refactor Molecule._get_rings() to ToolkitWrapper.call() * Refactor .n_rings, .is_in_ring to methods that call toolkit wrappers * Add Molecule.n_rings and OpenEye implementations, tests * Add bond_is_in_ring methods in cheminformatics toolkit wrappers * Add back Molecule.rings with deprecation warning * Add test for biphenyl's central bond not being "in a ring" * Have Bond.is_in_ring route to wrapper methods * Update release history * Update pre-commit config, re-run black * Fix mypy and tests * Move is_in_ring tests to test_toolkits.py * Fix tests, add back Molecule.n_rings as deprecated * Update docs/releasehistory.md Co-authored-by: Jeff Wagner <jwagnerjpl@gmail.com> * Remove Molecule.rings and Molecule.n_rings * Fix TestMolecule::test_is_in_ring * Update biphenyl ring tests with mapped smiles * Remove unused import * Apply suggestions from code review Co-authored-by: Jeff Wagner <jwagnerjpl@gmail.com> * Rework ring checks to only take Atom or Bond * Add test for error when Atom/Bond not attached to molecule * Update docstring and changelog * Fix test for unattached bond case * Cleanup Co-authored-by: Jeff Wagner <jwagnerjpl@gmail.com>
9362b71 Refactor ring methods in Molecule class (#855) * Refactor Molecule._get_rings() to ToolkitWrapper.call() * Refactor .n_rings, .is_in_ring to methods that call toolkit wrappers * Add Molecule.n_rings and OpenEye implementations, tests * Add bond_is_in_ring methods in cheminformatics toolkit wrappers * Add back Molecule.rings with deprecation warning * Add test for biphenyl's central bond not being "in a ring" * Have Bond.is_in_ring route to wrapper methods * Update release history * Update pre-commit config, re-run black * Fix mypy and tests * Move is_in_ring tests to test_toolkits.py * Fix tests, add back Molecule.n_rings as deprecated * Update docs/releasehistory.md Co-authored-by: Jeff Wagner <jwagnerjpl@gmail.com> * Remove Molecule.rings and Molecule.n_rings * Fix TestMolecule::test_is_in_ring * Update biphenyl ring tests with mapped smiles * Remove unused import * Apply suggestions from code review Co-authored-by: Jeff Wagner <jwagnerjpl@gmail.com> * Rework ring checks to only take Atom or Bond * Add test for error when Atom/Bond not attached to molecule * Update docstring and changelog * Fix test for unattached bond case * Cleanup Co-authored-by: Jeff Wagner <jwagnerjpl@gmail.com>
9362b71 Refactor ring methods in Molecule class (#855) * Refactor Molecule._get_rings() to ToolkitWrapper.call() * Refactor .n_rings, .is_in_ring to methods that call toolkit wrappers * Add Molecule.n_rings and OpenEye implementations, tests * Add bond_is_in_ring methods in cheminformatics toolkit wrappers * Add back Molecule.rings with deprecation warning * Add test for biphenyl's central bond not being "in a ring" * Have Bond.is_in_ring route to wrapper methods * Update release history * Update pre-commit config, re-run black * Fix mypy and tests * Move is_in_ring tests to test_toolkits.py * Fix tests, add back Molecule.n_rings as deprecated * Update docs/releasehistory.md Co-authored-by: Jeff Wagner <jwagnerjpl@gmail.com> * Remove Molecule.rings and Molecule.n_rings * Fix TestMolecule::test_is_in_ring * Update biphenyl ring tests with mapped smiles * Remove unused import * Apply suggestions from code review Co-authored-by: Jeff Wagner <jwagnerjpl@gmail.com> * Rework ring checks to only take Atom or Bond * Add test for error when Atom/Bond not attached to molecule * Update docstring and changelog * Fix test for unattached bond case * Cleanup Co-authored-by: Jeff Wagner <jwagnerjpl@gmail.com> Co-authored-by: Jeff Wagner <jwagnerjpl@gmail.com>
Fixes #823
This PR tries to implement solutions to #823. The major change is that several properties
Molecule.rings
,.n_rings
,Atom.is_in_ring
,Bond.is_in_ring
, have been converted to methods, which breaks the existing API. The ways that membership in rings was being checked wasn't necessarily the best, since RDKit exposes a more direct way to do this (I assume OEChem does as well).The main problem with the earlier implementation is that storing rings in
Molecule._rings
loses the provenance of which toolkit determined the number of rings (RDKit, OpenEye, and other toolkits are not guaranteed to agree). So these methods now generate rings on the fly as needed instead of storing them as private attributes and exposing getters. This should work around edge cases resulting from toolkit differences (unclear how we can test these without OpenEye functionality added). There an obvious downside of this change is wasteful re-computing the rings. I don't know if this is an important performance hit or not.Bond.is_in_ring
to use direct cheminformatics toolkit callsMolecule.rings
andMolecule.n_rings