Skip to content

Commit f3bd2d4

Browse files
committed
Refactor SOGKSpace to inherit from KSpace and integrate FFT functionality
- Changed inheritance of SOGKSpace from PPPM to KSpace. - Updated includes to replace "pppm.h" with "kspace.h". - Added new private methods for FFT operations: compute_finufft, compute_mesh_fft, ensure_fft_plan, and destroy_fft_plan. - Introduced new member variables for FFT mesh configuration and data storage. - Removed unused variables related to n_dl_user_specified and n_dl_from_model.
1 parent 12e2fc7 commit f3bd2d4

6 files changed

Lines changed: 1049 additions & 560 deletions

File tree

deepmd/lib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/home/zyjin/anaconda3/envs/base_env/lib/python3.13/site-packages/deepmd/lib

log.lammps

Lines changed: 129 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,146 @@
11
LAMMPS (22 Jul 2025 - Update 4)
2-
units metal
3-
plugin load /data/zyjin/dp_pt/dp_devel/deepmd-kit-devel/build/sog_lmp_stable/lmp/plugin/libdeepmd_lmp.so
4-
Loading plugin: deepmd pair style v3.1.3-83-g3cba3c7a-dirty by Han Wang
5-
Loading plugin: deepspin pair style v3.1.3-83-g3cba3c7a-dirty by Duo Zhang
6-
Loading plugin: compute deeptensor/atom v3.1.3-83-g3cba3c7a-dirty by Han Wang
7-
Loading plugin: fix dplr v3.1.3-83-g3cba3c7a-dirty by Han Wang
8-
Loading plugin: kspace pppm/dplr v3.1.3-83-g3cba3c7a-dirty by Han Wang
9-
Loading plugin: kspace les v3.1.3-83-g3cba3c7a-dirty by DeepMD contributors
10-
Loading plugin: kspace sog v3.1.3-83-g3cba3c7a-dirty by DeepMD contributors
11-
atom_style charge
12-
region box block 0 10 0 10 0 10
13-
create_box 1 box
14-
Created orthogonal box = (0 0 0) to (10 10 10)
2+
units metal
3+
plugin load /data/zyjin/dp_pt/dp_devel/deepmd-kit-devel/build/sog_lmp_cxxdbg/lmp/plugin/libdeepmd_lmp.so
4+
Loading plugin: deepmd pair style v3.1.3-86-g12e2fc71-dirty by Han Wang
5+
Loading plugin: deepspin pair style v3.1.3-86-g12e2fc71-dirty by Duo Zhang
6+
Loading plugin: compute deeptensor/atom v3.1.3-86-g12e2fc71-dirty by Han Wang
7+
Loading plugin: fix dplr v3.1.3-86-g12e2fc71-dirty by Han Wang
8+
Loading plugin: kspace pppm/dplr v3.1.3-86-g12e2fc71-dirty by Han Wang
9+
Loading plugin: kspace les v3.1.3-86-g12e2fc71-dirty by DeepMD contributors
10+
Loading plugin: kspace sog v3.1.3-86-g12e2fc71-dirty by DeepMD contributors
11+
atom_style charge
12+
boundary p p p
13+
read_data /data/zyjin/dp_pt/dp_example/au-mgo/lmp/progress_report_20260601/results/lammps_md_20260602/stable.data
14+
Reading data file ...
15+
orthogonal box = (0 0 0) to (9.0474307 9.0474307 26.458861)
1516
1 by 1 by 1 MPI processor grid
16-
create_atoms 1 single 5.0 5.0 5.0
17-
Created 1 atoms
18-
using lattice units in orthogonal box = (0 0 0) to (10 10 10)
19-
create_atoms CPU = 0.000 seconds
20-
mass 1 1.0
21-
set atom 1 charge 0.1
22-
Setting atom values ...
23-
1 settings made for charge
17+
reading atoms ...
18+
110 atoms
19+
read_data CPU = 0.001 seconds
20+
mass 1 24.305
21+
mass 2 15.999
22+
mass 3 26.9815385
23+
mass 4 196.96657
24+
neighbor 1.0 bin
25+
neigh_modify every 1 delay 0 check yes
26+
thermo 20
27+
thermo_style custom step temp press pe ke etotal
28+
thermo_modify flush yes
29+
timestep 0.0005
30+
velocity all create 300.0 20260602 mom yes rot yes dist gaussian
31+
pair_style deepmd /tmp/sog_model_frozen_try.pth sog_sr yes
32+
Summary of lammps deepmd module ...
33+
>>> Info of deepmd-kit:
34+
installed to: /usr/local
35+
source: v3.1.3-86-g12e2fc71-dirty
36+
source branch: sog-lmp
37+
source commit: 12e2fc71
38+
source commit at: 2026-05-27 14:06:36 +0800
39+
support model ver.: 1.1
40+
build variant: cpu
41+
build with pt lib: torch;torch_library;/home/zyjin/anaconda3/envs/base_env/lib/python3.13/site-packages/torch/lib/libc10.so;/usr/local/cuda/lib64/libnvrtc.so;/home/zyjin/anaconda3/envs/base_env/lib/python3.13/site-packages/torch/lib/libc10_cuda.so
42+
set tf intra_op_parallelism_threads: 16
43+
set tf inter_op_parallelism_threads: 1
44+
>>> Info of lammps module:
45+
use deepmd-kit at: /usr/local
46+
source: v3.1.3-86-g12e2fc71-dirty
47+
source branch: sog-lmp
48+
source commit: 12e2fc71
49+
source commit at: 2026-05-27 14:06:36 +0800
50+
build with inc: /home/zyjin/anaconda3/envs/base_env/lib/python3.13/site-packages/torch/include;/home/zyjin/anaconda3/envs/base_env/lib/python3.13/site-packages/torch/include/torch/csrc/api/include
51+
build with lib: /home/zyjin/anaconda3/envs/base_env/lib/python3.13/site-packages/torch/lib
52+
WARNING: pair_style deepmd sog_sr=yes enables latent_charge_to_q automatically (/data/zyjin/dp_pt/dp_devel/deepmd-kit-devel/source/lmp/pair_deepmd.cpp:919)
53+
pair_coeff * *
54+
include /data/zyjin/dp_pt/dp_example/au-mgo/lmp/progress_report_20260601/results/lammps_md_20260602/kspace_sog.inc
55+
# Auto-generated from sog_model.ckpt; do not edit manually.
56+
kspace_style sog 9.9999999999999995e-07 n_dl_from_model yes amp_from_model yes bandwidth_from_model yes b 1.6297670882677646 sigma 3.6337174090094129 m 16 remove_self_interaction yes
57+
run 0
2458

25-
pair_style coul/long 6.0
26-
pair_coeff * *
59+
CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE
60+
61+
Your simulation uses code contributions which should be cited:
62+
63+
- USER-DEEPMD package:
64+
65+
@article{Wang_ComputPhysCommun_2018_v228_p178,
66+
author = {Wang, Han and Zhang, Linfeng and Han, Jiequn and E, Weinan},
67+
doi = {10.1016/j.cpc.2018.03.016},
68+
url = {https://doi.org/10.1016/j.cpc.2018.03.016},
69+
year = 2018,
70+
month = {jul},
71+
publisher = {Elsevier {BV}},
72+
volume = 228,
73+
journal = {Comput. Phys. Commun.},
74+
title = {{DeePMD-kit: A deep learning package for many-body potential energy representation and molecular dynamics}},
75+
pages = {178--184}
76+
}
77+
@article{Zeng_JChemPhys_2023_v159_p054801,
78+
title = {{DeePMD-kit v2: A software package for deep potential models}},
79+
author = {Jinzhe Zeng and Duo Zhang and Denghui Lu and Pinghui Mo and Zeyu Li
80+
and Yixiao Chen and Mari{\'a}n Rynik and Li'ang Huang and Ziyao Li and
81+
Shaochen Shi and Yingze Wang and Haotian Ye and Ping Tuo and Jiabin
82+
Yang and Ye Ding and Yifan Li and Davide Tisi and Qiyu Zeng and Han
83+
Bao and Yu Xia and Jiameng Huang and Koki Muraoka and Yibo Wang and
84+
Junhan Chang and Fengbo Yuan and Sigbj{\o}rn L{\o}land Bore and Chun
85+
Cai and Yinnian Lin and Bo Wang and Jiayan Xu and Jia-Xin Zhu and
86+
Chenxing Luo and Yuzhi Zhang and Rhys E A Goodall and Wenshuo Liang
87+
and Anurag Kumar Singh and Sikai Yao and Jingchao Zhang and Renata
88+
Wentzcovitch and Jiequn Han and Jie Liu and Weile Jia and Darrin M
89+
York and Weinan E and Roberto Car and Linfeng Zhang and Han Wang},
90+
journal = {J. Chem. Phys.},
91+
volume = 159,
92+
issue = 5,
93+
year = 2023,
94+
pages = 054801,
95+
doi = {10.1063/5.0155600},
96+
}
97+
@Article{Zeng_JChemTheoryComput_2025_v21_p4375,
98+
author = {Jinzhe Zeng and Duo Zhang and Anyang Peng and Xiangyu Zhang and Sensen
99+
He and Yan Wang and Xinzijian Liu and Hangrui Bi and Yifan Li and Chun
100+
Cai and Chengqian Zhang and Yiming Du and Jia-Xin Zhu and Pinghui Mo
101+
and Zhengtao Huang and Qiyu Zeng and Shaochen Shi and Xuejian Qin and
102+
Zhaoxi Yu and Chenxing Luo and Ye Ding and Yun-Pei Liu and Ruosong Shi
103+
and Zhenyu Wang and Sigbj{\o}rn L{\o}land Bore and Junhan Chang and
104+
Zhe Deng and Zhaohan Ding and Siyuan Han and Wanrun Jiang and Guolin
105+
Ke and Zhaoqing Liu and Denghui Lu and Koki Muraoka and Hananeh Oliaei
106+
and Anurag Kumar Singh and Haohui Que and Weihong Xu and Zhangmancang
107+
Xu and Yong-Bin Zhuang and Jiayu Dai and Timothy J. Giese and Weile
108+
Jia and Ben Xu and Darrin M. York and Linfeng Zhang and Han Wang},
109+
title = {{DeePMD-kit v3: A Multiple-Backend Framework for Machine Learning
110+
Potentials}},
111+
journal = {J. Chem. Theory Comput.},
112+
year = 2025,
113+
volume = 21,
114+
number = 9,
115+
pages = {4375--4385},
116+
doi = {10.1021/acs.jctc.5c00340},
117+
}
118+
119+
CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE
27120

28-
kspace_style sog 1.0e-6 amp 0.1 bandwidth 0.5
29-
thermo_style custom step pe
30-
thermo 1
31-
run 0
32121
WARNING: No fixes with time integration, atoms won't move
33122
For more information see https://docs.lammps.org/err0028 (src/verlet.cpp:60)
34123
PPPM initialization ...
35-
WARNING: System is not charge neutral, net charge = 0.1
36-
For more information see https://docs.lammps.org/err0029 (src/kspace.cpp:335)
37124
using 12-bit tables for long-range coulomb
38125
WARNING: For better accuracy use 'pair_modify table 0' (src/kspace.cpp:373)
39126
G vector (1/distance) = 1
40-
grid = 30 30 30
127+
grid = 20 20 54
41128
stencil order = 5
42-
estimated absolute RMS force accuracy = 3.4929588e-07
43-
estimated relative force accuracy = 2.4257256e-08
129+
estimated absolute RMS force accuracy = 1.5438285e-06
130+
estimated relative force accuracy = 1.0721295e-07
44131
using double precision KISS FFT
45-
3d grid and FFT values/proc = 68921 27000
46-
Generated 0 of 0 mixed pair_coeff terms from geometric mixing rule
132+
3d grid and FFT values/proc = 44469 21600
133+
Generated 0 of 6 mixed pair_coeff terms from geometric mixing rule
47134
Neighbor list info ...
48135
update: every = 1 steps, delay = 0 steps, check = yes
49136
max neighbors/atom: 2000, page size: 100000
50-
master list distance cutoff = 8
51-
ghost atom cutoff = 8
52-
binsize = 4, bins = 3 3 3
137+
master list distance cutoff = 7
138+
ghost atom cutoff = 7
139+
binsize = 3.5, bins = 3 3 8
53140
1 neighbor lists, perpetual/occasional/extra = 1 0 0
54-
(1) pair coul/long, perpetual
55-
attributes: half, newton on
56-
pair build: half/bin/atomonly/newton
57-
stencil: half/bin/3d
141+
(1) pair deepmd, perpetual
142+
attributes: full, newton on
143+
pair build: full/bin/atomonly
144+
stencil: full/bin/3d
58145
bin: standard
59-
Per MPI rank memory allocation (min/avg/max) = 8.426 | 8.426 | 8.426 Mbytes
60-
Step PotEng
61-
0 0.001285803
62-
Loop time of 1.302e-06 on 1 procs for 0 steps with 1 atoms
63-
64-
153.6% CPU use with 1 MPI tasks x no OpenMP threads
65-
66-
MPI task timing breakdown:
67-
Section | min time | avg time | max time |%varavg| %total
68-
---------------------------------------------------------------
69-
Pair | 0 | 0 | 0 | 0.0 | 0.00
70-
Kspace | 0 | 0 | 0 | 0.0 | 0.00
71-
Neigh | 0 | 0 | 0 | 0.0 | 0.00
72-
Comm | 0 | 0 | 0 | 0.0 | 0.00
73-
Output | 0 | 0 | 0 | 0.0 | 0.00
74-
Modify | 0 | 0 | 0 | 0.0 | 0.00
75-
Other | | 1.302e-06 | | |100.00
76-
77-
Nlocal: 1 ave 1 max 1 min
78-
Histogram: 1 0 0 0 0 0 0 0 0 0
79-
Nghost: 26 ave 26 max 26 min
80-
Histogram: 1 0 0 0 0 0 0 0 0 0
81-
Neighs: 0 ave 0 max 0 min
82-
Histogram: 1 0 0 0 0 0 0 0 0 0
83-
84-
Total # of neighbors = 0
85-
Ave neighs/atom = 0
86-
Neighbor list builds = 0
87-
Dangerous builds = 0
88-
Total wall time: 0:00:00
146+
ERROR on proc 0: DeePMD-kit Error: DeePMD-kit PyTorch backend error: DeePMD-kit Error: charge tensor must have last dimension 1 to map to atom->q. (/data/zyjin/dp_pt/dp_devel/deepmd-kit-devel/source/lmp/pair_deepmd.cpp:382)

source/lmp/pair_deepmd.cpp

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22
#include <string.h>
33

44
#include <cassert>
5-
#include <cctype>
6-
#include <cmath>
7-
#include <cstdlib>
85
#include <iomanip>
96
#include <iostream>
107
#include <limits>
118
#include <map>
12-
#include <regex>
139
#include <sstream>
1410

1511
#include "atom.h"
@@ -39,21 +35,6 @@
3935
using namespace LAMMPS_NS;
4036
using namespace std;
4137

42-
namespace {
43-
44-
bool has_json_suffix(const std::string& path) {
45-
if (path.size() < 5) {
46-
return false;
47-
}
48-
std::string suffix = path.substr(path.size() - 5);
49-
for (char& c : suffix) {
50-
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
51-
}
52-
return suffix == ".json";
53-
}
54-
55-
} // namespace
56-
5738
static const char cite_user_deepmd_package[] =
5839
"USER-DEEPMD package:\n\n"
5940
"@article{Wang_ComputPhysCommun_2018_v228_p178,\n"
@@ -140,90 +121,12 @@ PairDeepMD::PairDeepMD(LAMMPS* lmp)
140121
: PairDeepBaseModel(
141122
lmp, cite_user_deepmd_package, deep_pot, deep_pot_model_devi) {
142123
latent_charge_to_q = false;
143-
model_n_dl = 0.0;
144-
has_model_n_dl = 0;
145124
}
146125

147126
PairDeepMD::~PairDeepMD() {
148127
// Ensure base class destructor is called
149128
}
150129

151-
bool PairDeepMD::parse_model_n_dl_from_json(const std::string& model_path,
152-
double& n_dl_out) const {
153-
if (!has_json_suffix(model_path)) {
154-
return false;
155-
}
156-
157-
std::string content;
158-
try {
159-
deepmd_compat::read_file_to_string(model_path, content);
160-
} catch (...) {
161-
return false;
162-
}
163-
164-
static const std::regex n_dl_pattern(
165-
R"("n_dl"\s*:\s*([-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?))");
166-
167-
std::smatch match;
168-
if (!std::regex_search(content, match, n_dl_pattern)) {
169-
return false;
170-
}
171-
172-
const double candidate = std::strtod(match[1].str().c_str(), nullptr);
173-
if (!(std::isfinite(candidate) && candidate > 0.0)) {
174-
return false;
175-
}
176-
177-
n_dl_out = candidate;
178-
return true;
179-
}
180-
181-
void PairDeepMD::detect_model_n_dl(const std::vector<std::string>& models) {
182-
has_model_n_dl = 0;
183-
model_n_dl = 0.0;
184-
185-
double first_n_dl = 0.0;
186-
bool found = false;
187-
188-
for (const auto& model_path : models) {
189-
double parsed = 0.0;
190-
if (!parse_model_n_dl_from_json(model_path, parsed)) {
191-
continue;
192-
}
193-
if (!found) {
194-
first_n_dl = parsed;
195-
found = true;
196-
continue;
197-
}
198-
if (std::fabs(parsed - first_n_dl) > 1e-12 && comm->me == 0) {
199-
error->warning(
200-
FLERR,
201-
"pair_style deepmd found inconsistent n_dl across model JSON files; "
202-
"using the first model value");
203-
}
204-
}
205-
206-
if (found) {
207-
has_model_n_dl = 1;
208-
model_n_dl = first_n_dl;
209-
}
210-
}
211-
212-
void* PairDeepMD::extract(const char* str, int& dim) {
213-
if (strcmp(str, "deepmd_model_n_dl") == 0) {
214-
dim = 0;
215-
if (has_model_n_dl) {
216-
return (void*)&model_n_dl;
217-
}
218-
return nullptr;
219-
}
220-
if (strcmp(str, "deepmd_model_n_dl_available") == 0) {
221-
dim = 0;
222-
return (void*)&has_model_n_dl;
223-
}
224-
return PairDeepBaseModel::extract(str, dim);
225-
}
226-
227130
void PairDeepMD::compute(int eflag, int vflag) {
228131
if (numb_models == 0) {
229132
return;
@@ -712,7 +615,6 @@ void PairDeepMD::settings(int narg, char** arg) {
712615
for (int ii = 0; ii < iarg; ++ii) {
713616
models.push_back(arg[ii]);
714617
}
715-
detect_model_n_dl(models);
716618
numb_models = models.size();
717619
if (numb_models == 1) {
718620
try {

source/lmp/pair_deepmd.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class PairDeepMD : public PairDeepBaseModel {
4444
public:
4545
PairDeepMD(class LAMMPS*);
4646
~PairDeepMD() override;
47-
void* extract(const char*, int&) override;
4847
void settings(int, char**) override;
4948
void coeff(int, char**) override;
5049
void compute(int, int) override;
@@ -56,14 +55,8 @@ class PairDeepMD : public PairDeepBaseModel {
5655
deepmd_compat::DeepPotModelDevi deep_pot_model_devi;
5756

5857
private:
59-
bool parse_model_n_dl_from_json(const std::string& model_path,
60-
double& n_dl_out) const;
61-
void detect_model_n_dl(const std::vector<std::string>& models);
62-
6358
CommBrickDeepMD* commdata_;
6459
bool latent_charge_to_q;
65-
double model_n_dl;
66-
int has_model_n_dl;
6760
};
6861

6962
} // namespace LAMMPS_NS

0 commit comments

Comments
 (0)