mdanalysis
mdanalysis copied to clipboard
Wrap RDKit drawing code for AtomGroups
Part of #2468 Depends on #2775
Changes made in this Pull Request:
- In notebooks, by importing
from MDAnalysis.visualization.RDKit import RDKitDrawer, the default representation of the AtomGroup is changed for small molecules: it displays an image of the AtomGroup using RDKit's drawing code (and the default representation for large AtomGroups)
- The default drawer displays PNG images for atomgroups below 200 atoms, removes non-polar hydrogens, kekulizes and flattens the structure, although all of these are configurable

- You can reuse the code that is used to generate the PNG/SVG by calling
drawer.atomgroup_to_image(ag, ...). There is also some code to automatically display or save gifs from an atomgroup:
- And all of this can be cancelled at any point

PR Checklist
- [ ] Tests?
- [x] Docs?
- [ ] CHANGELOG updated?
- [x] Issue raised/referenced?
Tagging @MDAnalysis/coredevs
I'm not sure if I've put the code in the right place but "visualization" made sense to me
Hello @cbouy! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
- In the file
package/MDAnalysis/visualization/RDKit.py:
Line 146:80: E501 line too long (98 > 79 characters)
- In the file
package/MDAnalysis/visualization/base.py:
Line 64:73: W291 trailing whitespace Line 87:73: W291 trailing whitespace
- In the file
testsuite/MDAnalysisTests/visualization/test_base.py:
Line 41:9: E731 do not assign a lambda expression, use a def Line 44:1: W293 blank line contains whitespace Line 46:9: E731 do not assign a lambda expression, use a def Line 52:9: E731 do not assign a lambda expression, use a def Line 56:46: W292 no newline at end of file
Line 72:62: W291 trailing whitespace
Comment last updated at 2020-08-31 16:50:33 UTC
I added a metaclass and a base class for "formatters" (i.e. classes that can modify the representation of other objects in interactive shells/notebooks), in case we want to add another visualization package like nglview to display atomgroups directly.
Also, I'm not sure how to test the AtomGroup representation and the generation of images...
Does anyone have some pointers ?
Codecov Report
Merging #2900 into develop will increase coverage by
5.37%. The diff coverage is1.02%.
@@ Coverage Diff @@
## develop #2900 +/- ##
===========================================
+ Coverage 87.20% 92.57% +5.37%
===========================================
Files 167 189 +22
Lines 21744 24690 +2946
Branches 3186 3196 +10
===========================================
+ Hits 18961 22857 +3896
+ Misses 2258 1787 -471
+ Partials 525 46 -479
| Impacted Files | Coverage Δ | |
|---|---|---|
| package/MDAnalysis/visualization/RDKit.py | 0.00% <0.00%> (ø) |
|
| package/MDAnalysis/visualization/base.py | 0.00% <0.00%> (ø) |
|
| package/MDAnalysis/__init__.py | 92.68% <100.00%> (+0.18%) |
:arrow_up: |
| package/MDAnalysis/topology/tpr/obj.py | 96.96% <0.00%> (-3.04%) |
:arrow_down: |
| package/MDAnalysis/lib/formats/libdcd.pyx | 88.48% <0.00%> (-0.85%) |
:arrow_down: |
| package/MDAnalysis/lib/formats/libmdaxdr.pyx | 89.81% <0.00%> (-0.16%) |
:arrow_down: |
| package/MDAnalysis/core/topology.py | 100.00% <0.00%> (ø) |
|
| package/MDAnalysis/analysis/polymer.py | 100.00% <0.00%> (ø) |
|
| package/MDAnalysis/coordinates/MMTF.py | 100.00% <0.00%> (ø) |
|
| package/MDAnalysis/coordinates/NAMDBIN.py | 100.00% <0.00%> (ø) |
|
| ... and 124 more |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 563995c...1f9d3d0. Read the comment docs.
I'm moving this to the 2.1.0 milestone
Maybe this helps with the SVG testing? https://github.com/ldomic/mdanalysis/blob/2af2d99447cc06d96fd3695b400b9f3bcbb0f4d5/testsuite/MDAnalysisTests/visualization/test_lintools.py