Skip to content

Commit a97331c

Browse files
committed
update
1 parent 886be90 commit a97331c

File tree

3 files changed

+167
-25
lines changed

3 files changed

+167
-25
lines changed

doc/model/train-energy-spin.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ $$L = p_e L_e + p_{fr} L_{fr} + p_{fm} L_{fm} + p_v L_v$$
8888

8989
where $L_e$, $L_{fr}$, $L_{fm}$ and $L_v$ denote the loss in energy, atomic force, magnatic force and virial, respectively. $p_e$, $p_{fr}$, $p_{fm}$ and $p_v$ give the prefactors of the energy, atomic force, magnatic force and virial losses.
9090

91-
:::{note}
92-
Please note that the virial and atomic virial are not currently supported in spin models.
93-
:::
94-
9591
The prefectors may not be a constant, rather it changes linearly with the learning rate. Taking the atomic force prefactor for example, at training step $t$, it is given by
9692

9793
$$p_{fr}(t) = p_{fr}^0 \frac{ \alpha(t) }{ \alpha(0) } + p_{fr}^\infty ( 1 - \frac{ \alpha(t) }{ \alpha(0) })$$
@@ -138,6 +134,7 @@ set.*/box.npy
138134
set.*/coord.npy
139135
set.*/energy.npy
140136
set.*/force.npy
137+
set.*/virial.npy
141138
```
142139

143140
This system contains `Nframes` frames with the same atom number `Natoms` and magnetic atom number `Nspins`, the total number of element and virtual types contained in all frames is `Ntypes`. The `box` and `energy` files are the same as those in [standard formats](../data/system.md). The `type` file contains the types of both real atoms and virtual atoms. In `coord` and `force` files, virtual atomic coordinates are integrated with real atomic coordinates, and magnetic forces are combined with atomic forces. Specifically, magnetic forces are obtained from [DeltaSpin](https://github.com/caizefeng/DeltaSpin) and virtual atomic coordinates are given by:
@@ -155,6 +152,7 @@ We list the details about spin system data format in TensorFlow backend:
155152
| box | Boxes | box.raw | Å | Nframes \* 3 \* 3 | in the order `XX XY XZ YX YY YZ ZX ZY ZZ` |
156153
| energy | Frame energies | energy.raw | eV | Nframes |
157154
| force | Atomic and magnetic forces | force.raw | eV/Å | Nframes \* (Natoms + Nspins) \* 3 | The first `3 \* Natoms` columns represent atomic forces, followed by `3 \* Nspins` columns representing magnetic forces. |
155+
| virial | Frame virial | virial.raw | eV | Nframes \* 9 | in the order `XX XY XZ YX YY YZ ZX ZY ZZ` |
158156

159157
### Spin data format in PyTorch/DP
160158

@@ -168,6 +166,7 @@ set.*/spin.npy
168166
set.*/energy.npy
169167
set.*/force.npy
170168
set.*/force_mag.npy
169+
set.*/virial.npy
171170
```
172171

173172
This system contains `Nframes` frames with the same atom number `Natoms`, the total number of element contained in all frames is `Ntypes`. Most files are the same as those in [standard formats](../data/system.md), here we only list the distinct ones:

log.lammps

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
LAMMPS (22 Jul 2025 - Update 2)
2+
using 1 OpenMP thread(s) per MPI task
3+
Loaded 0 plugins from
4+
units metal
5+
boundary p p p
6+
atom_style atomic
7+
neighbor 2.0 bin
8+
neigh_modify every 10 delay 0 check no
9+
read_data /home/outisli/Research/dpmd/source/lmp/tests/data.lmp
10+
Reading data file ...
11+
triclinic box = (0 0 0) to (13 13 13) with tilt (0 0 0)
12+
1 by 1 by 1 MPI processor grid
13+
reading atoms ...
14+
6 atoms
15+
read_data CPU = 0.000 seconds
16+
mass 1 16
17+
mass 2 2
18+
timestep 0.0005
19+
fix 1 all nve
20+
pair_style deepmd /home/outisli/Research/dpmd/source/tests/infer/deeppot_sea.pth
21+
ERROR: Unrecognized pair style 'deepmd' (src/src/force.cpp:275)
22+
Last input line: pair_style deepmd /home/outisli/Research/dpmd/source/tests/infer/deeppot_sea.pth
23+
Total wall time: 0:00:00

source/lmp/tests/test_lammps_spin_pt.py

Lines changed: 141 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Path,
1010
)
1111

12+
import constants
1213
import numpy as np
1314
import pytest
1415
from lammps import (
@@ -70,6 +71,124 @@
7071
]
7172
)
7273

74+
expected_v = -np.array(
75+
[
76+
0.0070639867264982,
77+
-0.0005923577001662,
78+
-0.0015491268442953,
79+
-0.0005741900039506,
80+
0.0004072991754844,
81+
0.0005919446476345,
82+
-0.0013659665914274,
83+
0.0005245686552392,
84+
0.0011288634277803,
85+
0.0074611996305919,
86+
-0.0015158254500315,
87+
-0.0030704181444311,
88+
-0.0015503527871207,
89+
0.0006417155838534,
90+
0.0010901024672963,
91+
-0.0032762727340245,
92+
0.0011481000769186,
93+
0.0022122852076016,
94+
-0.0049637269273085,
95+
-0.0033079530214069,
96+
0.0048850199723435,
97+
-0.0032277537906931,
98+
-0.0030526361938397,
99+
0.0044721003136312,
100+
0.0053457625015160,
101+
0.0044600355962439,
102+
-0.0065441506206723,
103+
-0.0044231868209291,
104+
-0.0033953486551904,
105+
0.0050014995082810,
106+
-0.0035584060948890,
107+
-0.0032308004485022,
108+
0.0047399657455500,
109+
0.0056902937417672,
110+
0.0047696802946761,
111+
-0.0070004831270587,
112+
0.0034978220789713,
113+
-0.0044217265408896,
114+
-0.0075771507215158,
115+
-0.0043265981217727,
116+
0.0016344211766637,
117+
0.0031438764476946,
118+
-0.0069613658908443,
119+
0.0032277030414985,
120+
0.0055466693735168,
121+
-0.0182670501038624,
122+
-0.0030197903610554,
123+
0.0012333318415169,
124+
-0.0030157009303137,
125+
0.0006787737562374,
126+
0.0017594542103399,
127+
0.0025814653441594,
128+
0.0020137939338955,
129+
0.0014966802677115,
130+
]
131+
).reshape(6, 9)
132+
133+
expected_v2 = -np.array(
134+
[
135+
-0.0068361570854045,
136+
0.0013367399255969,
137+
0.0027254156851031,
138+
0.0013170622611582,
139+
-0.0006584860372994,
140+
-0.0011202746253630,
141+
0.0034372788237214,
142+
-0.0014078563891643,
143+
-0.0026234422772135,
144+
-0.0065741762148638,
145+
0.0017805968136400,
146+
0.0034294170220393,
147+
0.0017765463870965,
148+
-0.0007431139812367,
149+
-0.0013178346591454,
150+
0.0028404497247166,
151+
-0.0010584927243460,
152+
-0.0019736773403821,
153+
-0.0005990686037429,
154+
-0.0006790752112473,
155+
0.0009843156545704,
156+
-0.0006499258389702,
157+
-0.0005944102287950,
158+
0.0008730050519947,
159+
0.0009534901617246,
160+
0.0008816224750390,
161+
-0.0012893921034252,
162+
-0.0004768372014215,
163+
-0.0006613274582292,
164+
0.0009616568976184,
165+
-0.0007221357003557,
166+
-0.0006885045030101,
167+
0.0010101324669343,
168+
0.0010319090966831,
169+
0.0009955172109546,
170+
-0.0014553634659113,
171+
0.0027303678059308,
172+
-0.0017755948961346,
173+
-0.0030761923779883,
174+
-0.0017183308924552,
175+
0.0006816964863724,
176+
0.0012957090028794,
177+
-0.0042486220709583,
178+
0.0018539755349361,
179+
0.0032531905210736,
180+
-0.0053263906035893,
181+
-0.0013059666848022,
182+
-0.0000753225555805,
183+
-0.0013078437276500,
184+
0.0003423965327707,
185+
0.0008080454760442,
186+
0.0003139988733780,
187+
0.0008955147923178,
188+
0.0008788489971600,
189+
]
190+
).reshape(6, 9)
191+
73192
box = np.array([0, 13, 0, 13, 0, 13, 0, 0, 0])
74193
coord = np.array(
75194
[
@@ -157,15 +276,15 @@ def test_pair_deepmd_virial(lammps) -> None:
157276
lammps.compute("pressure all pressure NULL pair")
158277
lammps.compute("virial all centroid/stress/atom NULL pair")
159278
lammps.variable("eatom atom c_peatom")
160-
# for ii in range(9):
161-
# jj = [0, 4, 8, 3, 6, 7, 1, 2, 5][ii]
162-
# lammps.variable(f"pressure{jj} equal c_pressure[{ii+1}]")
163-
# for ii in range(9):
164-
# jj = [0, 4, 8, 3, 6, 7, 1, 2, 5][ii]
165-
# lammps.variable(f"virial{jj} atom c_virial[{ii+1}]")
166-
# lammps.dump(
167-
# "1 all custom 1 dump id " + " ".join([f"v_virial{ii}" for ii in range(9)])
168-
# )
279+
for ii in range(9):
280+
jj = [0, 4, 8, 3, 6, 7, 1, 2, 5][ii]
281+
lammps.variable(f"pressure{jj} equal c_pressure[{ii + 1}]")
282+
for ii in range(9):
283+
jj = [0, 4, 8, 3, 6, 7, 1, 2, 5][ii]
284+
lammps.variable(f"virial{jj} atom c_virial[{ii + 1}]")
285+
lammps.dump(
286+
"1 all custom 1 dump id " + " ".join([f"v_virial{ii}" for ii in range(9)])
287+
)
169288
lammps.run(0)
170289
assert lammps.eval("pe") == pytest.approx(expected_e)
171290
for ii in range(4):
@@ -176,18 +295,19 @@ def test_pair_deepmd_virial(lammps) -> None:
176295
assert np.array(lammps.variables["eatom"].value) == pytest.approx(
177296
expected_ae[idx_map]
178297
)
179-
# vol = box[1] * box[3] * box[5]
180-
# for ii in range(6):
181-
# jj = [0, 4, 8, 3, 6, 7, 1, 2, 5][ii]
182-
# assert np.array(
183-
# lammps.variables[f"pressure{jj}"].value
184-
# ) / constants.nktv2p == pytest.approx(
185-
# -expected_v[idx_map, jj].sum(axis=0) / vol
186-
# )
187-
# for ii in range(9):
188-
# assert np.array(
189-
# lammps.variables[f"virial{ii}"].value
190-
# ) / constants.nktv2p == pytest.approx(expected_v[idx_map, ii])
298+
vol = box[1] * box[3] * box[5]
299+
for ii in range(6):
300+
jj = [0, 4, 8, 3, 6, 7, 1, 2, 5][ii]
301+
assert np.array(
302+
lammps.variables[f"pressure{jj}"].value
303+
) / constants.nktv2p == pytest.approx(
304+
-expected_v[idx_map, jj].sum(axis=0) / vol
305+
)
306+
for ii in range(9):
307+
jj = [0, 4, 8, 3, 6, 7, 1, 2, 5][ii]
308+
assert np.array(
309+
lammps.variables[f"virial{jj}"].value
310+
) / constants.nktv2p == pytest.approx(expected_v[idx_map, jj])
191311

192312

193313
@pytest.mark.skipif(

0 commit comments

Comments
 (0)