Skip to content

Commit eaed387

Browse files
docs: add mathematical formulas to model classes (#5258)
## Summary Add detailed mathematical formulas to model class docstrings following numpydoc convention. ## Changes Added formulas to the following classes: - **DPModelCommon**: Descriptor + fitting pipeline - D = Descriptor(R, types) - y = Fitting(D) - **SpinModel**: Virtual atom positions and torque conversion - r_virtual = r_real + s · σ - τ = F_virtual × σ ## Convention Following numpydoc convention, parameters are documented in class docstrings, not in `__init__` docstrings. ## Statistics - 2 files changed - 35 insertions(+) - 1 deletion(-) Authored by OpenClaw (model: GLM-5) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Expanded user-facing documentation for core model components: model reduction and differentiation math for energy/forces/virials, spin input preprocessing, virtual-atom creation/placement, interactions among real/virtual/ghost atoms, and conversion of virtual-atom forces into magnetic torques. All changes are descriptive only; no functional or behavioral modifications. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 8eb2943 commit eaed387

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

deepmd/dpmodel/model/dp_model.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
# use "class" to resolve "Variable not allowed in type expression"
1616
class DPModelCommon:
17+
r"""Common methods for DP models.
18+
19+
This class provides common functionality for DeepPot models, including
20+
neighbor selection updates and fitting network access.
21+
"""
22+
1723
@classmethod
1824
def update_sel(
1925
cls,

deepmd/dpmodel/model/ener_model.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,31 @@
3131

3232
@BaseModel.register("ener")
3333
class EnergyModel(DPModelCommon, DPEnergyModel_):
34+
r"""Energy model that predicts total energy and derived quantities.
35+
36+
The model takes atomic energies from the atomic model and computes
37+
global properties by reduction and differentiation:
38+
39+
**Reduction** (total energy):
40+
41+
.. math::
42+
E = \sum_{i=1}^{N} E^i,
43+
44+
where :math:`E^i` is the atomic energy from the atomic model.
45+
46+
**Differentiation** (forces and virials):
47+
48+
.. math::
49+
\mathbf{F}_i = -\frac{\partial E}{\partial \mathbf{r}_i},
50+
51+
.. math::
52+
\boldsymbol{\Xi} = -\sum_{i=1}^{N} \frac{\partial E}{\partial \mathbf{r}_i} \otimes \mathbf{r}_i
53+
= \sum_{i=1}^{N} \mathbf{r}_i \otimes \mathbf{F}_i,
54+
55+
where :math:`\mathbf{F}_i` is the force on atom :math:`i` and
56+
:math:`\boldsymbol{\Xi}` is the virial tensor.
57+
"""
58+
3459
def __init__(
3560
self,
3661
*args: Any,

deepmd/dpmodel/model/spin_model.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,24 @@
2929

3030

3131
class SpinModel(NativeOP):
32-
"""A spin model wrapper, with spin input preprocess and output split."""
32+
r"""A spin model wrapper, with spin input preprocess and output split.
33+
34+
This model extends a backbone DP model to handle magnetic spin degrees of freedom.
35+
Virtual atoms are created at positions offset from real atoms by their spin vectors:
36+
37+
.. math::
38+
\mathbf{r}_i^{\mathrm{virtual}} = \mathbf{r}_i^{\mathrm{real}} + s_i \cdot \boldsymbol{\sigma}_i,
39+
40+
where :math:`s_i` is a scaling factor and :math:`\boldsymbol{\sigma}_i` is the spin vector.
41+
42+
The model then computes interactions between real atoms, virtual atoms, and between
43+
real and virtual atoms, enabling the prediction of spin-dependent properties.
44+
45+
The output forces on virtual atoms are converted to magnetic torques:
46+
47+
.. math::
48+
\boldsymbol{\tau}_i = \mathbf{F}_i^{\mathrm{virtual}} \times \boldsymbol{\sigma}_i.
49+
"""
3350

3451
def __init__(
3552
self,

0 commit comments

Comments
 (0)