Skip to content

Commit 7fd61c3

Browse files
committed
docs: regenerate API docs and fix Google-style docstrings for Sphinx
1 parent 41fc6bd commit 7fd61c3

56 files changed

Lines changed: 534 additions & 238 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/pr.yaml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,27 +79,36 @@ jobs:
7979
8080
docs:
8181
name: Docs
82+
needs: unit
8283
runs-on: ubuntu-24.04
8384
timeout-minutes: 25
85+
8486
steps:
8587
- name: Checkout
86-
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
88+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
8789

8890
- name: Set up Python 3.14
89-
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
91+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405
9092
with:
9193
python-version: "3.14"
9294
cache: pip
9395

94-
- name: Install (docs)
96+
- name: Install
9597
run: |
9698
python -m pip install --upgrade pip
9799
python -m pip install -e .[docs]
98100
99101
- name: Build docs
100102
run: |
101-
cd docs
102-
make
103+
make -C docs clean
104+
make -C docs html SPHINXOPTS="-W --keep-going"
105+
106+
- name: Upload docs artifact
107+
if: always()
108+
uses: actions/upload-artifact@v4
109+
with:
110+
name: docs-html
111+
path: docs/_build/html
103112

104113
pre-commit:
105114
name: Pre-commit

.pre-commit-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,20 @@ repos:
1717
- id: check-ast
1818
- id: end-of-file-fixer
1919
- id: trailing-whitespace
20+
21+
- repo: https://github.com/rstcheck/rstcheck
22+
rev: v6.2.0
23+
hooks:
24+
- id: rstcheck
25+
name: rstcheck (docstrings only)
26+
files: \.py$
27+
args: ["--report-level", "warning"]
28+
29+
- repo: local
30+
hooks:
31+
- id: sphinx-docs
32+
name: sphinx-build (pre-push, warnings as errors)
33+
entry: bash -lc 'make -C docs clean && make -C docs html SPHINXOPTS="-W --keep-going"'
34+
language: system
35+
pass_filenames: false
36+
stages: [pre-push]

CodeEntropy/config/argparse.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
55
1) A declarative argument specification (`ARG_SPECS`) used to build an
66
``argparse.ArgumentParser``.
7+
78
2) A `ConfigResolver` that:
9+
810
- loads YAML configuration (if present),
911
- merges YAML values with CLI values (CLI wins),
1012
- adjusts logging verbosity,
1113
- validates a subset of runtime inputs against the trajectory.
1214
1315
Notes:
16+
1417
- Boolean arguments are parsed via `str2bool` to support YAML/CLI interop and
1518
common string forms like "true"/"false".
1619
"""

CodeEntropy/entropy/configurational.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""Conformational entropy utilities.
22
33
This module provides:
4-
* Assigning discrete conformational states for a single dihedral time series.
5-
* Computing conformational entropy from a sequence of state labels.
64
7-
The public surface area is intentionally small to keep responsibilities clear.
5+
- Assignment of discrete conformational states for a single dihedral time series.
6+
- Computation of conformational entropy from a sequence of state labels.
7+
88
"""
99

1010
from __future__ import annotations
@@ -127,15 +127,17 @@ def conformational_entropy_calculation(
127127
"""Compute conformational entropy for a sequence of state labels.
128128
129129
Entropy is computed as:
130+
130131
S = -R * sum_i p_i * ln(p_i)
131-
where p_i is the observed probability of state i in `states`.
132+
133+
where p_i is the observed probability of state i in ``states``.
132134
133135
Args:
134136
states: Sequence/array of discrete state labels. Empty/None yields 0.0.
135137
number_frames: Frame count metadata.
136138
137139
Returns:
138-
Conformational entropy in J/mol/K.
140+
float: Conformational entropy in J/mol/K.
139141
"""
140142
_ = number_frames
141143

CodeEntropy/entropy/workflow.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
33
This module defines `EntropyWorkflow`, which coordinates the end-to-end entropy
44
workflow:
5-
* Determine trajectory bounds and frame count.
6-
* Build a reduced universe based on atom selection.
7-
* Identify molecule groups and hierarchy levels.
8-
* Optionally compute water entropy and adjust selection.
9-
* Execute the level DAG (matrix/state preparation).
10-
* Execute the entropy graph (entropy calculations and aggregation).
11-
* Finalize and persist results.
5+
- Determine trajectory bounds and frame count.
6+
- Build a reduced universe based on atom selection.
7+
- Identify molecule groups and hierarchy levels.
8+
- Optionally compute water entropy and adjust selection.
9+
- Execute the level DAG (matrix/state preparation).
10+
- Execute the entropy graph (entropy calculations and aggregation).
11+
- Finalize and persist results.
1212
1313
The manager intentionally delegates calculations to dedicated components.
1414
"""

CodeEntropy/levels/axes.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,20 @@ class AxesCalculator:
2424
rotation, and handling bead-based representations of molecular systems.
2525
2626
Provides utility methods to:
27-
- extract averaged positions,
28-
- convert coordinates to spherical systems (future/legacy scope),
29-
- compute axes used to rotate forces around,
30-
- compute custom moments of inertia,
31-
- manipulate vectors under periodic boundary conditions (PBC),
32-
- construct custom moment-of-inertia tensors and principal axes.
27+
28+
- Extract averaged positions.
29+
- Convert coordinates to spherical systems (future/legacy scope).
30+
- Compute axes used to rotate forces around.
31+
- Compute custom moments of inertia.
32+
- Manipulate vectors under periodic boundary conditions (PBC).
33+
- Construct custom moment-of-inertia tensors and principal axes.
3334
3435
Notes:
35-
This class deliberately does **not**:
36-
- compute weighted forces/torques (that belongs in ForceTorqueCalculator),
37-
- build covariances,
38-
- compute entropies.
36+
This class deliberately does not:
37+
38+
- Compute weighted forces/torques (that belongs in ForceTorqueCalculator).
39+
- Build covariances.
40+
- Compute entropies.
3941
"""
4042

4143
def __init__(self) -> None:
@@ -363,7 +365,7 @@ def get_vanilla_axes(self, molecule):
363365
Returns:
364366
Tuple[np.ndarray, np.ndarray]:
365367
- principal_axes: (3, 3) axes.
366-
- moment_of_inertia: (3,) moments sorted descending by |value|.
368+
- moment_of_inertia: (3,) moments sorted descending by absolute value.
367369
"""
368370
moment_of_inertia_tensor = molecule.moment_of_inertia(unwrap=True)
369371
make_whole(molecule.atoms)
@@ -388,13 +390,13 @@ def get_custom_axes(
388390
389391
- axis1: use the normalised vector ab as axis1. If there is more than one
390392
bonded heavy atom (HA), average over all the normalised vectors
391-
calculated from b_list and use this as axis1). b_list contains all the
393+
calculated from b_list and use this as axis1. b_list contains all the
392394
bonded heavy atom coordinates.
393395
394396
- axis2: use the cross product of normalised vector ac and axis1 as axis2.
395397
If there are more than two bonded heavy atoms, then use normalised vector
396-
b[0]c to cross product with axis1, this gives the axis perpendicular
397-
(represented by |_ symbol below) to axis1.
398+
b[0]c to cross product with axis1. This gives the axis perpendicular
399+
to axis1.
398400
399401
- axis3: the cross product of axis1 and axis2, which is perpendicular to
400402
axis1 and axis2.
@@ -405,12 +407,12 @@ def get_custom_axes(
405407
c: Coordinates of a second heavy atom or a hydrogen atom.
406408
dimensions: Simulation box dimensions (3,).
407409
408-
::
410+
.. code-block:: text
409411
410412
a 1 = norm_ab
411-
/ \ 2 = |_ norm_ab and norm_ac (use bc if more than 2 HAs)
412-
/ \ 3 = |_ 1 and 2
413-
b c
413+
/ \ 2 = perpendicular to norm_ab and norm_ac (or bc if >2 HAs)
414+
/ \ 3 = perpendicular to 1 and 2
415+
b c
414416
415417
Returns:
416418
np.ndarray: (3, 3) array of the axes used to rotate forces.
@@ -458,8 +460,10 @@ def get_custom_moment_of_inertia(
458460
heavy atom position in a UA).
459461
460462
Original behaviour preserved:
463+
461464
- Uses PBC-aware translated coordinates.
462-
- Sums contributions from each atom: |axis x r|^2 * mass.
465+
- Sums contributions from each atom using the squared norm of (axis × r)
466+
multiplied by mass.
463467
- Removes the lowest MOI degree of freedom if the UA only has a single
464468
bonded H (i.e. UA has 2 atoms total).
465469
@@ -581,6 +585,7 @@ def get_custom_principal_axes(
581585
built-in MDAnalysis principal_axes() function.
582586
583587
Original behaviour preserved:
588+
584589
- Eigenvalues are sorted by descending absolute magnitude.
585590
- Eigenvectors are transposed so axes are returned as rows.
586591
- Z axis is flipped to enforce the same handedness convention as the

CodeEntropy/levels/dihedrals.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def build_conformational_states(
4747
residue-level state generation depending on which hierarchy levels are
4848
enabled per molecule.
4949
50-
Progress reporting is optional and UI-agnostic: if a progress sink is
50+
Progress reporting is optional and UI-agnostic. If a progress sink is
5151
provided, the method will create a single task and advance it once per
5252
molecule group.
5353
@@ -66,17 +66,17 @@ def build_conformational_states(
6666
Must expose add_task(), update(), and advance().
6767
6868
Returns:
69-
Tuple of:
70-
states_ua: Dict mapping (group_id, local_residue_id) -> list of state
71-
labels (strings) across the analyzed trajectory.
72-
states_res: List-like structure indexed by group_id (or equivalent)
73-
containing residue-level state labels (strings) across the
74-
analyzed trajectory.
69+
tuple: (states_ua, states_res)
70+
71+
- states_ua: Dict mapping (group_id, local_residue_id) -> list of state
72+
labels (strings) across the analyzed trajectory.
73+
- states_res: Structure indexed by group_id (or equivalent) containing
74+
residue-level state labels (strings) across the analyzed trajectory.
7575
7676
Notes:
7777
- This function advances progress once per group_id.
7878
- Frame slicing arguments (start/end/step) are forwarded to downstream
79-
helpers as implemented in this module.
79+
helpers as implemented in this module.
8080
"""
8181
number_groups = len(groups)
8282
states_ua: Dict[UAKey, List[str]] = {}

CodeEntropy/levels/hierarchy.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
"""Hierarchy level selection and bead construction.
22
3-
This module defines `HierarchyBuilder`, which is responsible for:
4-
1) Determining which hierarchy levels apply to each molecule.
5-
2) Constructing "beads" (AtomGroups) for a given molecule at a given level.
3+
This module defines ``HierarchyBuilder``, which is responsible for:
4+
5+
- Determining which hierarchy levels apply to each molecule.
6+
- Constructing "beads" (AtomGroups) for a given molecule at a given level.
67
78
Notes:
8-
- The "residue" bead construction must use residues attached to the provided
9-
AtomGroup/container. Using `resindex` selection strings is unsafe because
10-
`resindex` is global to the Universe and can produce empty/incorrect beads
11-
when operating on per-molecule containers beyond the first molecule.
9+
The "residue" bead construction must use residues attached to the provided
10+
AtomGroup/container. Using ``resindex`` selection strings is unsafe because
11+
``resindex`` is global to the Universe and can produce empty or incorrect
12+
beads when operating on per-molecule containers beyond the first molecule.
13+
1214
"""
1315

1416
from __future__ import annotations

CodeEntropy/levels/mda.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,18 @@ def merge_forces(
136136
"""Create a universe by merging coordinates and forces from different files.
137137
138138
This method loads:
139-
- coordinates + dimensions from the coordinate trajectory (tprfile + trrfile)
140-
- forces from the force trajectory (tprfile + forcefile)
141139
142-
If the force trajectory does not expose forces in MDAnalysis (e.g. the file
140+
- Coordinates and dimensions from the coordinate trajectory
141+
(``tprfile`` + ``trrfile``).
142+
- Forces from the force trajectory (``tprfile`` + ``forcefile``).
143+
144+
If the force trajectory does not expose forces in MDAnalysis (e.g., the file
143145
does not contain forces, or the reader does not provide them), then:
144-
- if `fallback_to_positions_if_no_forces` is True, positions from the force
145-
trajectory are used as the "forces" array (backwards-compatible behaviour
146-
with earlier implementations).
147-
- otherwise, the underlying `NoDataError` is raised.
146+
147+
- If ``fallback_to_positions_if_no_forces`` is True, positions from the
148+
force trajectory are used as the "forces" array (backwards-compatible
149+
behaviour with earlier implementations).
150+
- Otherwise, the underlying ``NoDataError`` is raised.
148151
149152
Args:
150153
tprfile: Topology input file.
@@ -155,14 +158,15 @@ def merge_forces(
155158
recognised by MDAnalysis.
156159
kcal: If True, scale the force array by 4.184 to convert from kcal to kJ.
157160
force_format: Optional file format for the force trajectory. If not
158-
provided, uses `fileformat`.
161+
provided, uses ``fileformat``.
159162
fallback_to_positions_if_no_forces: If True, and the force trajectory has
160163
no accessible forces, use positions from the force trajectory as a
161164
fallback (legacy behaviour).
162165
163166
Returns:
164-
A new Universe containing coordinates, forces and dimensions loaded into
165-
memory.
167+
MDAnalysis.Universe: A new Universe containing coordinates, forces and
168+
dimensions loaded into memory.
169+
166170
"""
167171
logger.debug("Loading coordinate Universe with %s", trrfile)
168172
u = mda.Universe(tprfile, trrfile, format=fileformat)

CodeEntropy/levels/nodes/covariance.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ class FrameCovarianceNode:
3737
3838
This node computes per-frame second-moment matrices (outer products) for
3939
force and torque generalized vectors at hierarchy levels:
40-
- united_atom
41-
- residue
42-
- polymer
40+
41+
- united_atom
42+
- residue
43+
- polymer
4344
4445
Within a single frame, outputs are incrementally averaged across molecules
4546
that belong to the same group. Frame-to-frame accumulation is handled
4647
elsewhere (by a higher-level reducer).
48+
4749
"""
4850

4951
def __init__(self) -> None:

0 commit comments

Comments
 (0)