Skip to content

Commit a4b12e3

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 0e6c423 commit a4b12e3

29 files changed

Lines changed: 423 additions & 562 deletions

doc/development/create-a-model-pt.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,7 @@ def descrpt_some_args() -> list[Argument]:
168168
allows one to use your new descriptor as below:
169169

170170
```json
171-
"descriptor" :{
172-
"type": "some_descrpt",
173-
"arg1": true,
174-
"arg2": 6.0
175-
}
171+
"descriptor" : {"type" : "some_descrpt", "arg1" : true, "arg2" : 6.0}
176172
```
177173

178174
The arguments here should be consistent with the class arguments of your new component.

doc/development/create-a-model-tf.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ def descrpt_some_args() -> list[Argument]:
4747
allows one to use your new descriptor as below:
4848

4949
```json
50-
"descriptor" :{
51-
"type": "some_descrpt",
52-
"arg1": true,
53-
"arg2": 6.0
54-
}
50+
"descriptor" : {"type" : "some_descrpt", "arg1" : true, "arg2" : 6.0}
5551
```
5652

5753
The arguments here should be consistent with the class arguments of your new component.

doc/development/type-embedding.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ A detailed introduction can be found at [`se_e2_a_tebd`](../model/train-se-e2-a-
4949
An example of `type_embedding` is like
5050

5151
```json
52-
"type_embedding":{
53-
"neuron": [2, 4, 8],
54-
"resnet_dt": false,
55-
"seed": 1
56-
}
52+
"type_embedding" : {"neuron" : [ 2, 4, 8 ], "resnet_dt" : false, "seed" : 1}
5753
```
5854

5955
## Code Modification

doc/inference/cxx.md

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ The C++ interface of DeePMD-kit is also available for the model interface, which
1111
```cpp
1212
#include "deepmd/DeepPot.h"
1313

14-
int main(){
15-
deepmd::DeepPot dp ("graph.pb");
16-
std::vector<double > coord = {1., 0., 0., 0., 0., 1.5, 1. ,0. ,3.};
17-
std::vector<double > cell = {10., 0., 0., 0., 10., 0., 0., 0., 10.};
18-
std::vector<int > atype = {1, 0, 1};
19-
double e;
20-
std::vector<double > f, v;
21-
dp.compute (e, f, v, coord, atype, cell);
14+
int main()
15+
{
16+
deepmd::DeepPot dp("graph.pb");
17+
std::vector<double> coord = {1., 0., 0., 0., 0., 1.5, 1., 0., 3.};
18+
std::vector<double> cell = {10., 0., 0., 0., 10., 0., 0., 0., 10.};
19+
std::vector<int> atype = {1, 0, 1};
20+
double e;
21+
std::vector<double> f, v;
22+
dp.compute(e, f, v, coord, atype, cell);
2223
}
2324
```
2425

@@ -44,37 +45,38 @@ Although C is harder to write, the C library will not be affected by different v
4445
An example `infer_water.c` is given below:
4546

4647
```cpp
48+
#include "deepmd/c_api.h"
4749
#include <stdio.h>
4850
#include <stdlib.h>
49-
#include "deepmd/c_api.h"
5051

51-
int main(){
52-
const char* model = "graph.pb";
53-
double coord[] = {1., 0., 0., 0., 0., 1.5, 1. ,0. ,3.};
54-
double cell[] = {10., 0., 0., 0., 10., 0., 0., 0., 10.};
55-
int atype[] = {1, 0, 1};
56-
// init C pointers with given memory
57-
double* e = malloc(sizeof(*e));
58-
double* f = malloc(sizeof(*f) * 9); // natoms * 3
59-
double* v = malloc(sizeof(*v) * 9);
60-
double* ae = malloc(sizeof(*ae) * 9); // natoms
61-
double* av = malloc(sizeof(*av) * 27); // natoms * 9
62-
// DP model
63-
DP_DeepPot* dp = DP_NewDeepPot(model);
64-
DP_DeepPotCompute (dp, 3, coord, atype, cell, e, f, v, ae, av);
65-
// print results
66-
printf("energy: %f\n", *e);
67-
for (int ii = 0; ii < 9; ++ii)
68-
printf("force[%d]: %f\n", ii, f[ii]);
69-
for (int ii = 0; ii < 9; ++ii)
70-
printf("force[%d]: %f\n", ii, v[ii]);
71-
// free memory
72-
free(e);
73-
free(f);
74-
free(v);
75-
free(ae);
76-
free(av);
77-
DP_DeleteDeepPot(dp);
52+
int main()
53+
{
54+
const char *model = "graph.pb";
55+
double coord[] = {1., 0., 0., 0., 0., 1.5, 1., 0., 3.};
56+
double cell[] = {10., 0., 0., 0., 10., 0., 0., 0., 10.};
57+
int atype[] = {1, 0, 1};
58+
// init C pointers with given memory
59+
double *e = malloc(sizeof(*e));
60+
double *f = malloc(sizeof(*f) * 9); // natoms * 3
61+
double *v = malloc(sizeof(*v) * 9);
62+
double *ae = malloc(sizeof(*ae) * 9); // natoms
63+
double *av = malloc(sizeof(*av) * 27); // natoms * 9
64+
// DP model
65+
DP_DeepPot *dp = DP_NewDeepPot(model);
66+
DP_DeepPotCompute(dp, 3, coord, atype, cell, e, f, v, ae, av);
67+
// print results
68+
printf("energy: %f\n", *e);
69+
for (int ii = 0; ii < 9; ++ii)
70+
printf("force[%d]: %f\n", ii, f[ii]);
71+
for (int ii = 0; ii < 9; ++ii)
72+
printf("force[%d]: %f\n", ii, v[ii]);
73+
// free memory
74+
free(e);
75+
free(f);
76+
free(v);
77+
free(ae);
78+
free(av);
79+
DP_DeleteDeepPot(dp);
7880
}
7981
```
8082

@@ -103,14 +105,15 @@ To use it, include `deepmd/deepmd.hpp`.
103105
```cpp
104106
#include "deepmd/deepmd.hpp"
105107

106-
int main(){
107-
deepmd::hpp::DeepPot dp ("graph.pb");
108-
std::vector<double > coord = {1., 0., 0., 0., 0., 1.5, 1. ,0. ,3.};
109-
std::vector<double > cell = {10., 0., 0., 0., 10., 0., 0., 0., 10.};
110-
std::vector<int > atype = {1, 0, 1};
111-
double e;
112-
std::vector<double > f, v;
113-
dp.compute (e, f, v, coord, atype, cell);
108+
int main()
109+
{
110+
deepmd::hpp::DeepPot dp("graph.pb");
111+
std::vector<double> coord = {1., 0., 0., 0., 0., 1.5, 1., 0., 3.};
112+
std::vector<double> cell = {10., 0., 0., 0., 10., 0., 0., 0., 10.};
113+
std::vector<int> atype = {1, 0, 1};
114+
double e;
115+
std::vector<double> f, v;
116+
dp.compute(e, f, v, coord, atype, cell);
114117
}
115118
```
116119

@@ -132,17 +135,13 @@ and then run the program:
132135
In some cases, one may want to pass the custom neighbor list instead of the native neighbor list. The above code can be revised as follows:
133136

134137
```cpp
135-
// neighbor list
136-
std::vector<std::vector<int >> nlist_vec = {
137-
{1, 2},
138-
{0, 2},
139-
{0, 1}
140-
};
141-
std::vector<int> ilist(3), numneigh(3);
142-
std::vector<int*> firstneigh(3);
143-
InputNlist nlist(3, &ilist[0], &numneigh[0], &firstneigh[0]);
144-
convert_nlist(nlist, nlist_vec);
145-
dp.compute (e, f, v, coord, atype, cell, 0, nlist, 0);
138+
// neighbor list
139+
std::vector<std::vector<int>> nlist_vec = {{1, 2}, {0, 2}, {0, 1}};
140+
std::vector<int> ilist(3), numneigh(3);
141+
std::vector<int *> firstneigh(3);
142+
InputNlist nlist(3, &ilist[0], &numneigh[0], &firstneigh[0]);
143+
convert_nlist(nlist, nlist_vec);
144+
dp.compute(e, f, v, coord, atype, cell, 0, nlist, 0);
146145
```
147146
148147
Here, `nlist_vec` means the neighbors of atom 0 are atom 1 and atom 2, the neighbors of atom 1 are atom 0 and atom 2, and the neighbors of atom 2 are atom 0 and atom 1.

doc/model/dplr.md

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,14 @@ It is noted that **the tutorial dataset is not enough for training a productive
5050
Two settings make the training input script different from an energy training input:
5151

5252
```json
53-
"fitting_net": {
54-
"type": "dipole",
55-
"dipole_type": [0],
56-
"neuron": [128, 128, 128],
57-
"seed": 1
58-
},
53+
"fitting_net" : {"type" : "dipole", "dipole_type" : [0], "neuron" : [ 128, 128, 128 ], "seed" : 1},
5954
```
6055

6156
The type of fitting is set to {ref}`dipole <model[standard]/fitting_net[dipole]>`. The dipole is associated with type 0 atoms (oxygens), by the setting `"dipole_type": [0]`. What we trained is the displacement of the WC from the corresponding oxygen atom. It shares the same training input as the atomic dipole because both are 3-dimensional vectors defined on atoms.
6257
The loss section is provided as follows
6358

6459
```json
65-
"loss": {
66-
"type": "tensor",
67-
"pref": 0.0,
68-
"pref_atomic": 1.0
69-
},
60+
"loss" : {"type" : "tensor", "pref" : 0.0, "pref_atomic" : 1.0},
7061
```
7162

7263
so that the atomic dipole is trained as labels. Note that the NumPy compressed file `atomic_dipole.npy` should be provided in each dataset. In the context of DPLR models, the atomic dipole data represents the displacement vector from each atom to its associated Wannier centroid (WC), which can be calculated as `atomic_dipole = wannier_centroid_position - atom_position` from DFT calculations using tools such as VASP with Wannier90.
@@ -82,14 +73,14 @@ dp train dw.json && dp freeze -o dw.pb
8273
The training of the DPLR model is very similar to the standard short-range DP models. An example input script can be found in the example directory. The following section is introduced to compute the long-range energy contribution of the DPLR model, and modify the short-range DP model by this part.
8374

8475
```json
85-
"modifier": {
86-
"type": "dipole_charge",
87-
"model_name": "dw.pb",
88-
"model_charge_map": [-8],
89-
"sys_charge_map": [6, 1],
90-
"ewald_h": 1.00,
91-
"ewald_beta": 0.40
92-
},
76+
"modifier" : {
77+
"type" : "dipole_charge",
78+
"model_name" : "dw.pb",
79+
"model_charge_map" : [-8],
80+
"sys_charge_map" : [ 6, 1 ],
81+
"ewald_h" : 1.00,
82+
"ewald_beta" : 0.40
83+
},
9384
```
9485

9586
The {ref}`model_name <model/modifier[dipole_charge]/model_name>` specifies which DW model is used to predict the position of WCs. {ref}`model_charge_map <model/modifier[dipole_charge]/model_charge_map>` gives the amount of charge assigned to WCs. {ref}`sys_charge_map <model/modifier[dipole_charge]/sys_charge_map>` provides the nuclear charge of oxygen (type 0) and hydrogen (type 1) atoms. {ref}`ewald_beta <model/modifier[dipole_charge]/ewald_beta>` (unit $\text{Å}^{-1}$) gives the spread parameter controls the spread of Gaussian charges, and {ref}`ewald_h <model/modifier[dipole_charge]/ewald_h>` (unit Å) assigns the grid size of Fourier transformation.

doc/model/dprc.md

Lines changed: 59 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Two levels of data use the same MM method, so $E_\text{MM}$ is eliminated.
6363
In a DPRc model, QM atoms and MM atoms have different atom types. Assuming we have 4 QM atom types (C, H, O, P) and 2 MM atom types (HW, OW):
6464

6565
```json
66-
"type_map": ["C", "H", "HW", "O", "OW", "P"]
66+
"type_map" : [ "C", "H", "HW", "O", "OW", "P" ]
6767
```
6868

6969
As described in the paper, the DPRc model only corrects $E_\text{QM}$ and $E_\text{QM/MM}$ within the cutoff, so we use a hybrid descriptor to describe them separately:
@@ -73,29 +73,35 @@ As described in the paper, the DPRc model only corrects $E_\text{QM}$ and $E_\te
7373
:::{tab-item} TensorFlow {{ tensorflow_icon }}
7474

7575
```json
76-
"descriptor" :{
77-
"type": "hybrid",
78-
"list" : [
76+
"descriptor":
77+
{
78+
"type" : "hybrid", "list" : [
7979
{
80-
"type": "se_a_ebd_v2",
81-
"sel": [6, 11, 0, 6, 0, 1],
82-
"rcut_smth": 1.00,
83-
"rcut": 9.00,
84-
"neuron": [12, 25, 50],
85-
"exclude_types": [[2, 2], [2, 4], [4, 4], [0, 2], [0, 4], [1, 2], [1, 4], [3, 2], [3, 4], [5, 2], [5, 4]],
86-
"axis_neuron": 12,
87-
"_comment": " QM/QM interaction"
80+
"type" : "se_a_ebd_v2",
81+
"sel" : [ 6, 11, 0, 6, 0, 1 ],
82+
"rcut_smth" : 1.00,
83+
"rcut" : 9.00,
84+
"neuron" : [ 12, 25, 50 ],
85+
"exclude_types" : [
86+
[ 2, 2 ], [ 2, 4 ], [ 4, 4 ], [ 0, 2 ], [ 0, 4 ], [ 1, 2 ], [ 1, 4 ], [ 3, 2 ], [ 3, 4 ], [ 5, 2 ],
87+
[ 5, 4 ]
88+
],
89+
"axis_neuron" : 12,
90+
"_comment" : " QM/QM interaction"
8891
},
8992
{
90-
"type": "se_a_ebd_v2",
91-
"sel": [6, 11, 100, 6, 50, 1],
92-
"rcut_smth": 0.50,
93-
"rcut": 6.00,
94-
"neuron": [12, 25, 50],
95-
"exclude_types": [[0, 0], [0, 1], [0, 3], [0, 5], [1, 1], [1, 3], [1, 5], [3, 3], [3, 5], [5, 5], [2, 2], [2, 4], [4, 4]],
96-
"axis_neuron": 12,
97-
"set_davg_zero": true,
98-
"_comment": " QM/MM interaction"
93+
"type" : "se_a_ebd_v2",
94+
"sel" : [ 6, 11, 100, 6, 50, 1 ],
95+
"rcut_smth" : 0.50,
96+
"rcut" : 6.00,
97+
"neuron" : [ 12, 25, 50 ],
98+
"exclude_types" : [
99+
[ 0, 0 ], [ 0, 1 ], [ 0, 3 ], [ 0, 5 ], [ 1, 1 ], [ 1, 3 ], [ 1, 5 ], [ 3, 3 ], [ 3, 5 ], [ 5, 5 ],
100+
[ 2, 2 ], [ 2, 4 ], [ 4, 4 ]
101+
],
102+
"axis_neuron" : 12,
103+
"set_davg_zero" : true,
104+
"_comment" : " QM/MM interaction"
99105
}
100106
]
101107
}
@@ -106,31 +112,37 @@ As described in the paper, the DPRc model only corrects $E_\text{QM}$ and $E_\te
106112
:::{tab-item} PyTorch {{ pytorch_icon }}
107113

108114
```json
109-
"descriptor" :{
110-
"type": "hybrid",
111-
"list" : [
115+
"descriptor":
116+
{
117+
"type" : "hybrid", "list" : [
112118
{
113-
"type": "se_e2_a",
114-
"sel": [6, 11, 0, 6, 0, 1],
115-
"rcut_smth": 1.00,
116-
"rcut": 9.00,
117-
"neuron": [12, 25, 50],
118-
"exclude_types": [[2, 2], [2, 4], [4, 4], [0, 2], [0, 4], [1, 2], [1, 4], [3, 2], [3, 4], [5, 2], [5, 4]],
119-
"axis_neuron": 12,
120-
"type_one_side": true,
121-
"_comment": " QM/QM interaction"
119+
"type" : "se_e2_a",
120+
"sel" : [ 6, 11, 0, 6, 0, 1 ],
121+
"rcut_smth" : 1.00,
122+
"rcut" : 9.00,
123+
"neuron" : [ 12, 25, 50 ],
124+
"exclude_types" : [
125+
[ 2, 2 ], [ 2, 4 ], [ 4, 4 ], [ 0, 2 ], [ 0, 4 ], [ 1, 2 ], [ 1, 4 ], [ 3, 2 ], [ 3, 4 ], [ 5, 2 ],
126+
[ 5, 4 ]
127+
],
128+
"axis_neuron" : 12,
129+
"type_one_side" : true,
130+
"_comment" : " QM/QM interaction"
122131
},
123132
{
124-
"type": "se_e2_a",
125-
"sel": [6, 11, 100, 6, 50, 1],
126-
"rcut_smth": 0.50,
127-
"rcut": 6.00,
128-
"neuron": [12, 25, 50],
129-
"exclude_types": [[0, 0], [0, 1], [0, 3], [0, 5], [1, 1], [1, 3], [1, 5], [3, 3], [3, 5], [5, 5], [2, 2], [2, 4], [4, 4]],
130-
"axis_neuron": 12,
131-
"set_davg_zero": true,
132-
"type_one_side": true,
133-
"_comment": " QM/MM interaction"
133+
"type" : "se_e2_a",
134+
"sel" : [ 6, 11, 100, 6, 50, 1 ],
135+
"rcut_smth" : 0.50,
136+
"rcut" : 6.00,
137+
"neuron" : [ 12, 25, 50 ],
138+
"exclude_types" : [
139+
[ 0, 0 ], [ 0, 1 ], [ 0, 3 ], [ 0, 5 ], [ 1, 1 ], [ 1, 3 ], [ 1, 5 ], [ 3, 3 ], [ 3, 5 ], [ 5, 5 ],
140+
[ 2, 2 ], [ 2, 4 ], [ 4, 4 ]
141+
],
142+
"axis_neuron" : 12,
143+
"set_davg_zero" : true,
144+
"type_one_side" : true,
145+
"_comment" : " QM/MM interaction"
134146
}
135147
]
136148
}
@@ -166,10 +178,9 @@ print(
166178
Also, DPRc assumes MM atom energies ({ref}`atom_ener <model[standard]/fitting_net[ener]/atom_ener>`) are zero:
167179

168180
```json
169-
"fitting_net": {
170-
"neuron": [240, 240, 240],
171-
"resnet_dt": true,
172-
"atom_ener": [null, null, 0.0, null, 0.0, null]
181+
"fitting_net":
182+
{
183+
"neuron" : [ 240, 240, 240 ], "resnet_dt" : true, "atom_ener" : [ null, null, 0.0, null, 0.0, null ]
173184
}
174185
```
175186

@@ -201,10 +212,7 @@ It is noted that the [`se_atten` descriptor](./train-se-atten.md) should be used
201212
"model": {
202213
"type": "pairwise_dprc",
203214
"type_map": ["C", "P", "O", "H", "OW", "HW"],
204-
"type_embedding": {
205-
"neuron": [8],
206-
"precision": "float32"
207-
},
215+
"type_embedding": { "neuron": [8], "precision": "float32" },
208216
"qm_model": {
209217
"descriptor": {
210218
"type": "se_atten_v2",

0 commit comments

Comments
 (0)