improved docstrings in lib/distances.py#2070
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #2070 +/- ##
===========================================
+ Coverage 89.03% 89.27% +0.23%
===========================================
Files 144 159 +15
Lines 17363 18706 +1343
Branches 2673 2678 +5
===========================================
+ Hits 15460 16700 +1240
- Misses 1300 1402 +102
- Partials 603 604 +1
Continue to review full report at Codecov.
|
orbeckst
left a comment
There was a problem hiding this comment.
Thank you for taking the time to make the docs consistent and more readable.
I have a bunch of suggestions to improve the formatting and minor tweaks but I'll just approve the PR and if you want to do the changes then you can merge once you are ready.
| Functions | ||
| --------- | ||
|
|
||
| .. autofunction:: distance_array(reference, configuration [, box [, result [, backend]]]) |
There was a problem hiding this comment.
If it works here, i.e., just appending the definitions automatically then that's fine. If in doubt, I rather remove the :members: from the rst and list functions/classes explicitly with ..auto*: ....
There was a problem hiding this comment.
Removing the :members: from distances.rst and adding back the .. autofunction :: entries works, so I'll do that.
| box : array_like, optional | ||
| The unitcell dimensions of the system, which can be orthogonal or | ||
| triclinic and must be provided in the same format as returned by | ||
| :attr:`MDAnalysis.coordinates.base.Timestep.dimensions`:\n |
There was a problem hiding this comment.
I didn't know that \n worked in reST.
package/MDAnalysis/lib/distances.py
Outdated
| triclinic and must be provided in the same format as returned by | ||
| :attr:`MDAnalysis.coordinates.base.Timestep.dimensions`:\n | ||
| ``[lx, ly, lz, alpha, beta, gamma]``. | ||
| method : str, optional |
There was a problem hiding this comment.
You can provide the selection with
method : {"bruteforce", "nsgrid", "pkdtree", None}
Keyword to override the automatic guessing ofthe employed search method.
``None`` chooses an optimal method.(see https://numpydoc.readthedocs.io/en/latest/format.html#sections under 4. Parameters)
There was a problem hiding this comment.
The numpydoc docstring guide also says
If it is not necessary to specify a keyword argument, use
optional.
And furthermore (what you referred to)
When a parameter can only assume one of a fixed set of values, those values can be listed in braces, with the default appearing first.
Listing the default None (which should come first, btw) doesn't really make sense to me, that would be like describing an optional kwarg as, for example, x : int or None.
I think a proper way of combining the two guidelines should look like this:
method : {'bruteforce', 'nsgrid', 'pkdtree'}, optional
Keyword to override the automatic guessing of the employed search method.
The default is given in the function signature anyway.
What do you think?
package/MDAnalysis/lib/distances.py
Outdated
| .. SeeAlso:: :func:'MDAnalysis.lib.distances.distance_array' | ||
| .. SeeAlso:: :func:'MDAnalysis.lib.pkdtree.PeriodicKDTree.search' | ||
| .. SeeAlso:: :class:'MDAnalysis.lib.nsgrid.FastNS.search' | ||
| .. seealso:: :meth:`~MDAnalysis.lib.distances.distance_array` |
There was a problem hiding this comment.
This should use NUmpyDoc
See Also
--------
MDAnalysis.lib.distances.distance_array
MDAnalysis.lib.pkdtree.PeriodicKDTree.search
MDAnalysis.lib.nsgrid.FastNS.searchsee https://numpydoc.readthedocs.io/en/latest/format.html#sections, 11. See Also
package/MDAnalysis/lib/distances.py
Outdated
| coordinates ``reference[pairs[k, 0]]`` and | ||
| ``configuration[pairs[k, 1]]``. | ||
| """ | ||
| from .pkdtree import PeriodicKDTree |
There was a problem hiding this comment.
We rather have all imports at the top of the file instead of methods. If it has to be inside a method (eg to avoid circular imports) then it should be commented. See https://github.com/MDAnalysis/mdanalysis/wiki/Style-Guide#importing-modules
There was a problem hiding this comment.
(Yes, I know, this is not your code...)
There was a problem hiding this comment.
I'll move the imports to the top if they don't have any side effects (which they shouldn't).
package/MDAnalysis/lib/distances.py
Outdated
| .. SeeAlso:: :func:'MDAnalysis.lib.distances.self_distance_array' | ||
| .. SeeAlso:: :func:'MDAnalysis.lib.pkdtree.PeriodicKDTree.search' | ||
| .. SeeAlso:: :func:'MDAnalysis.lib.nsgrid.FastNS.self_search' | ||
| .. seealso:: :meth:`~MDAnalysis.lib.distances.self_distance_array` |
There was a problem hiding this comment.
Use See Also numpy doc. (See above)
package/MDAnalysis/lib/distances.py
Outdated
| triclinic and must be provided in the same format as returned by | ||
| :attr:`MDAnalysis.coordinates.base.Timestep.dimensions`:\n | ||
| ``[lx, ly, lz, alpha, beta, gamma]``. | ||
| method : str, optional |
| ------- | ||
| angle : float | ||
| The angle between the vectors `b`:math:`\\rightarrow`\ `a` and | ||
| `b`:math:`\\rightarrow`\ `c`. |
There was a problem hiding this comment.
Maybe add a
See Also
--------
calc_angles : calculate multiple angles efficientlyThere was a problem hiding this comment.
That is something I deliberately omitted. Since I introduced the new @check_coords() decorator, both calc_angle() and calc_angles() accept single coordinates as well as coordinate arrays, and return either an array or a single float, depending on the input.
The only difference is that calc_angle() returns the angle(s) in degrees while the result of calc_angles() is in radians. IMHO we should deprecate calc_angle().
See also my comments on calc_distance() and calc_dihedral().
| ------- | ||
| dihedral : float | ||
| The dihedral angle between the planes spanned by the coordinates | ||
| (`a`, `b`, `c`) and (`b`, `c`, `d`). |
There was a problem hiding this comment.
Maybe add a
See Also
--------
calc_dihedrals : calculate multiple dihedrals efficientlyThere was a problem hiding this comment.
Same as above. The only difference between calc_dihedral() and calc_dihedrals() is that the former returns degrees and the latter radians. We should probably deprecate calc_dihedral().
| Returns | ||
| ------- | ||
| distance : float | ||
| The distance between positions `a` and `b`. |
There was a problem hiding this comment.
Maybe add a
See Also
--------
calc_distances : calculate multiple distances efficientlyThere was a problem hiding this comment.
Both functions accept both single coordinates and coordinate arrays. There is virtually no difference left between calc_distance() and calc_bonds(). We might want to deprecate calc_distance().
…moved :embers: in doc/sphinx/source/documentation_pages/lib/distances.rst instead
|
@zemanj if you want to deprecate |
|
@richardjgowers I opened an issue (#2072) regarding the obsolete functions. Thanks for the info! |
Fixes (partially) #2046, this is the third of a series of related PRs, following PRs #2048 and #2062.
Changes made in this Pull Request:
MDAnalysis.lib.distances:.. autofunctionentries that caused duplicates in the documentation.boxparameter ofcapped_distance()andself_capped_distance()now also acceptarray_likeinput (now corresponding to the docs like all other functions accepting box input).PR Checklist