Skip to content

improved docstrings in lib/distances.py#2070

Merged
zemanj merged 13 commits intoMDAnalysis:developfrom
zemanj:issue-2046-lib-distances-rework
Sep 12, 2018
Merged

improved docstrings in lib/distances.py#2070
zemanj merged 13 commits intoMDAnalysis:developfrom
zemanj:issue-2046-lib-distances-rework

Conversation

@zemanj
Copy link
Copy Markdown
Member

@zemanj zemanj commented Sep 11, 2018

Fixes (partially) #2046, this is the third of a series of related PRs, following PRs #2048 and #2062.

Changes made in this Pull Request:

  • Improved documentation of all functions in MDAnalysis.lib.distances:
    • Ensured that parameters referenced in docstrings correspond to function signatures.
    • Properly formated references to other methods so that links are generated.
    • Now uses logical instead of visual markup.
    • Enforced 80 character lines.
    • Standardized phrasing of repeatedly occurring parameter descriptions.
    • Now uses correct type specifications for parameters and return values.
    • Marked optional parameters by adding , optional after the type.
  • Removed all .. autofunction entries that caused duplicates in the documentation.
  • Improved module description to better correspond to its contents.
  • box parameter of capped_distance() and self_capped_distance() now also accept array_like input (now corresponding to the docs like all other functions accepting box input).

PR Checklist

  • Tests?
  • Docs?
  • CHANGELOG updated?
  • Issue raised/referenced?

@zemanj zemanj changed the title Issue 2046 lib distances rework improved docstrings in lib/distances.py Sep 11, 2018
@codecov
Copy link
Copy Markdown

codecov bot commented Sep 11, 2018

Codecov Report

Merging #2070 into develop will increase coverage by 0.23%.
The diff coverage is 91.3%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ
package/MDAnalysis/lib/distances.py 95.36% <91.3%> (+0.01%) ⬆️
topology/base.py 97.67% <0%> (ø)
auxiliary/base.py 89% <0%> (ø)
util.py 100% <0%> (ø)
__init__.py 91.89% <0%> (ø)
formats/__init__.py 100% <0%> (ø)
auxiliary/__init__.py 100% <0%> (ø)
visualization/__init__.py 100% <0%> (ø)
coordinates/__init__.py 100% <0%> (ø)
dummy.py 100% <0%> (ø)
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e0a2b16...4caeea2. Read the comment docs.

Copy link
Copy Markdown
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

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

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]]])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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*: ....

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I didn't know that \n worked in reST.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Luckily, it does! 😄

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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?

.. 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`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should use NUmpyDoc

See Also
--------
MDAnalysis.lib.distances.distance_array
MDAnalysis.lib.pkdtree.PeriodicKDTree.search
MDAnalysis.lib.nsgrid.FastNS.search

see https://numpydoc.readthedocs.io/en/latest/format.html#sections, 11. See Also

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Right, will do.

coordinates ``reference[pairs[k, 0]]`` and
``configuration[pairs[k, 1]]``.
"""
from .pkdtree import PeriodicKDTree
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(Yes, I know, this is not your code...)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll move the imports to the top if they don't have any side effects (which they shouldn't).

.. 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`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use See Also numpy doc. (See above)

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

document options explicitly

-------
angle : float
The angle between the vectors `b`:math:`\\rightarrow`\ `a` and
`b`:math:`\\rightarrow`\ `c`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe add a

See Also
--------
calc_angles : calculate multiple angles efficiently

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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`).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe add a

See Also
--------
calc_dihedrals : calculate multiple dihedrals efficiently

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe add a

See Also
--------
calc_distances : calculate multiple distances efficiently

Copy link
Copy Markdown
Member Author

@zemanj zemanj Sep 12, 2018

Choose a reason for hiding this comment

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

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().

@zemanj zemanj merged commit 6741d1a into MDAnalysis:develop Sep 12, 2018
@richardjgowers
Copy link
Copy Markdown
Member

@zemanj if you want to deprecate calc_angle etc you can just remove them completely, they've never been released. It might be cleaner to have fewer functions

@zemanj
Copy link
Copy Markdown
Member Author

zemanj commented Sep 12, 2018

@richardjgowers I opened an issue (#2072) regarding the obsolete functions. Thanks for the info!
@orbeckst Thank you for the quick and very constructive review! 👍

@zemanj zemanj mentioned this pull request Sep 28, 2018
4 tasks
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.

3 participants