Skip to content

Commit e168962

Browse files
committed
Fix terminology issues related to pressure
1 parent 459f971 commit e168962

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Fix bug in `PairwiseForceField` class: use `rmax` only, never `rcut`.
1313
- Fix version import.
14+
- Fix pressure-related terminology.
1415

1516

1617
## [0.2.0] - 2024-10-07

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ cell_length = 20.0
7373
# Compute stuff:
7474
# - The potential energy.
7575
# - An array with Cartesian forces, same shape as `atpos`.
76-
# - The (virial contribution to) the pressure, only the mechanical part.
77-
potential_energy, forces, mech_pressure = pwff(atpos, cell_length)
76+
# - The force contribution the pressure
77+
# (often the written as the second term in the virial pressure).
78+
potential_energy, forces, frc_pressure = pwff(atpos, cell_length)
7879
```
7980

8081
This basic recipe can be extended by passing additional options

src/tinyff/forcefield.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ def __call__(self, atpos: NDArray, cell_length: float):
126126
The potential energy.
127127
forces
128128
The forces acting on the atoms, same shape as atpos.
129-
mech_pressure
130-
The force-contribution to the pressure.
129+
frc_pressure
130+
The force-contribution to the pressure,
131+
i.e. usually the second term of the virial stress in most text books.
131132
"""
132133
# Sanity check
133134
if cell_length < 2 * self.rmax:
@@ -152,7 +153,7 @@ def __call__(self, atpos: NDArray, cell_length: float):
152153
forces = np.zeros(atpos.shape, dtype=float)
153154
np.add.at(forces, nlist["iatom0"], nlist["gdelta"])
154155
np.add.at(forces, nlist["iatom1"], -nlist["gdelta"])
155-
mech_pressure = -np.dot(nlist["gdist"], nlist["dist"]) / (3 * cell_length**3)
156+
frc_pressure = -np.dot(nlist["gdist"], nlist["dist"]) / (3 * cell_length**3)
156157
# Keep the neigborlist for the following function call
157158
self.nlist = nlist
158-
return energy, forces, mech_pressure
159+
return energy, forces, frc_pressure

tests/test_forcefield.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ def test_pairwise_force_field_two(build_nlist):
6868
pwff = PairwiseForceField(lj, rcut, build_nlist=build_nlist)
6969

7070
# Compute and check against manual result
71-
energy, forces, mech_press = pwff(atpos, cell_length)
71+
energy, forces, frc_press = pwff(atpos, cell_length)
7272
d = np.linalg.norm(atpos[0] - atpos[1])
7373
e, g = lj(d)
7474
assert energy == pytest.approx(e)
7575
assert forces == pytest.approx(np.array([[g, 0.0, 0.0], [-g, 0.0, 0.0]]))
76-
assert mech_press == pytest.approx(-g * d / (3 * cell_length**3))
76+
assert frc_press == pytest.approx(-g * d / (3 * cell_length**3))
7777

7878

7979
@pytest.mark.parametrize("build_nlist", [build_nlist_linked_cell, build_nlist_simple])
@@ -87,8 +87,8 @@ def test_pairwise_force_field_three(build_nlist):
8787
lj = CutOffWrapper(LennardJones(2.5, 1.3), rcut)
8888
pwff = PairwiseForceField(lj, rcut, build_nlist=build_nlist)
8989

90-
# Compute the energy, the forces and the mechanical pressure.
91-
energy1, forces1, mech_press1 = pwff(atpos, cell_length)
90+
# Compute the energy, the forces and the force contribution pressure.
91+
energy1, forces1, frc_press1 = pwff(atpos, cell_length)
9292

9393
# Compute the energy manually and compare.
9494
dists = [
@@ -110,8 +110,8 @@ def energy_volume(volume):
110110
scale = my_cell_length / cell_length
111111
return pwff(atpos * scale, my_cell_length)[0]
112112

113-
mech_press2 = -nd.Derivative(energy_volume)(cell_length**3)
114-
assert mech_press1 == pytest.approx(mech_press2)
113+
frc_press2 = -nd.Derivative(energy_volume)(cell_length**3)
114+
assert frc_press1 == pytest.approx(frc_press2)
115115

116116

117117
@pytest.mark.parametrize("build_nlist", [build_nlist_linked_cell, build_nlist_simple])
@@ -143,8 +143,8 @@ def test_pairwise_force_field_fifteen(build_nlist):
143143
lj = CutOffWrapper(LennardJones(2.5, 1.3), rcut)
144144
pwff = PairwiseForceField(lj, rcut, build_nlist=build_nlist)
145145

146-
# Compute the energy, the forces and the mechanical pressure.
147-
energy, forces1, mech_press1 = pwff(atpos, cell_length)
146+
# Compute the energy, the forces and the force contribution to the pressure.
147+
energy, forces1, frc_press1 = pwff(atpos, cell_length)
148148
assert energy < 0
149149

150150
# Test forces with numdifftool
@@ -158,8 +158,8 @@ def energy_volume(volume):
158158
scale = my_cell_length / cell_length
159159
return pwff(atpos * scale, my_cell_length)[0]
160160

161-
mech_press2 = -nd.Derivative(energy_volume)(cell_length**3)
162-
assert mech_press1 == pytest.approx(mech_press2)
161+
frc_press2 = -nd.Derivative(energy_volume)(cell_length**3)
162+
assert frc_press1 == pytest.approx(frc_press2)
163163

164164

165165
@pytest.mark.parametrize("build_nlist", [build_nlist_linked_cell, build_nlist_simple])

0 commit comments

Comments
 (0)