Skip to content

Commit a5bdd14

Browse files
authored
interface for deepmd with the centroids atoms, full 3x3 "atomic-virial" (#1093)
* done interface for deepmd with the centroids atoms * Update lammps-command.md Added documentation to the computation of the heat flux
1 parent e2fc5e3 commit a5bdd14

File tree

3 files changed

+91
-16
lines changed

3 files changed

+91
-16
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![GitHub release](https://img.shields.io/github/release/deepmodeling/deepmd-kit.svg?maxAge=86400)](https://github.com/deepmodeling/deepmd-kit/releases)
44
[![doi:10.1016/j.cpc.2018.03.016](https://img.shields.io/badge/DOI-10.1016%2Fj.cpc.2018.03.016-blue)](https://doi.org/10.1016/j.cpc.2020.107206)
55
[![offline packages](https://img.shields.io/github/downloads/deepmodeling/deepmd-kit/total?label=offline%20packages)](https://github.com/deepmodeling/deepmd-kit/releases)
6+
[![conda install](https://img.shields.io/badge/downloads-9k%20total-green.svg?style=round-square&label=conda%20install)](https://anaconda.org/deepmodeling/deepmd-kit)
67
[![pip install](https://img.shields.io/pypi/dm/deepmd-kit?label=pip%20install)](https://pypi.org/project/deepmd-kit)
78
[![docker pull](https://img.shields.io/docker/pulls/deepmodeling/deepmd-kit)](https://hub.docker.com/r/deepmodeling/deepmd-kit)
89
[![Documentation Status](https://readthedocs.org/projects/deepmd/badge/)](https://deepmd.readthedocs.io/)

doc/third-party/lammps-command.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,53 @@ kspace_modify gewald 0.45
9494
```
9595
Please notice that the DeePMD does nothing to the direct space part of the electrostatic interaction, because this part is assumed to be fitted in the DeePMD model (the direct space cut-off is thus the cut-off of the DeePMD model). The splitting parameter `gewald` is modified by the `kspace_modify` command.
9696

97+
## Use of the centroid/stress/atom to get the full 3x3 "atomic-virial"
98+
99+
The [DeePMD-kit](https://github.com/deepmodeling/deepmd-kit) allows also the computation of per-atom stress tensor defined as:
100+
101+
<img src="https://render.githubusercontent.com/render/math?math=dvatom=\sum_{m}( \mathbf{r}_n- \mathbf{r}_m) \frac{de_m}{d\mathbf{r}_n} ">
102+
103+
Where <img src="https://render.githubusercontent.com/render/math?math=\mathbf{r}_n "> is the atomic position of nth atom, <img src="https://render.githubusercontent.com/render/math?math=\mathbf{v}_n "> velocity of atom and <img src="https://render.githubusercontent.com/render/math?math=\frac{de_m}{d\mathbf{r}_n} "> the derivative of the atomic energy.
104+
105+
In LAMMPS one can get the per-atom stress using the command `centroid/stress/atom`:
106+
```bash
107+
compute ID group-ID centroid/stress/atom NULL virial
108+
```
109+
see [LAMMPS doc page](https://docs.lammps.org/compute_stress_atom.html#thompson2) for more detailes on the meaning of the keywords.
110+
### Examples
111+
In order of computing the 9-component per-atom stress
112+
```bash
113+
compute stress all centroid/stress/atom NULL virial
114+
```
115+
Thus `c_stress` is an array with 9 component in the order `xx,yy,zz,xy,xz,yz,yx,zx,zy`.
116+
117+
If you use this feature please cite [D. Tisi, L. Zhang, R. Bertossa, H. Wang, R. Car, S. Baroni - arXiv preprint arXiv:2108.10850, 2021](https://arxiv.org/abs/2108.10850)
118+
119+
## Computation of heat flux
120+
Using per-atom stress tensor one can, for example, compute the heat flux defined as:
121+
122+
<img src="https://render.githubusercontent.com/render/math?math=\mathbf{J}=\sum_n e_n \mathbf{v}_n + \sum_{nm}( \mathbf{r}_m- \mathbf{r}_n) \frac{de_m}{d\mathbf{r}_n} \mathbf{v}_n">
123+
124+
to compute the heat flux with LAMMPS:
125+
```bash
126+
compute ke_ID all ke/atom
127+
compute pe_ID all pe/atom
128+
compute stress_ID group-ID centroid/stress/atom NULL virial
129+
compute flux_ID all heat/flux ke_ID pe_ID stress_ID
130+
```
131+
132+
### Examples
133+
134+
```bash
135+
compute ke all ke/atom
136+
compute pe all pe/atom
137+
compute stress all centroid/stress/atom NULL virial
138+
compute flux all heat/flux ke pe stress
139+
```
140+
`c_flux` is a global vector of length 6. The first three components are the `x`, `y` and `z` components of the full heat flux vector. The others are the components of the so-called convective portion, see [LAMMPS doc page](https://docs.lammps.org/compute_heat_flux.html) for more detailes.
141+
142+
If you use these features please cite [D. Tisi, L. Zhang, R. Bertossa, H. Wang, R. Car, S. Baroni - arXiv preprint arXiv:2108.10850, 2021](https://arxiv.org/abs/2108.10850)
143+
144+
97145
[DP]:https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.120.143001
98-
[DP-SE]:https://dl.acm.org/doi/10.5555/3327345.3327356
146+
[DP-SE]:https://dl.acm.org/doi/10.5555/3327345.3327356

source/lmp/pair_deepmd.cpp

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ PairDeepMD::PairDeepMD(LAMMPS *lmp)
238238
error->all(FLERR,"Pair deepmd requires metal unit, please set it by \"units metal\"");
239239
}
240240
restartinfo = 1;
241+
centroidstressflag = 2 ; // set centroidstressflag = 2 to allow the use of the centroid/stress/atom. Added by Davide Tisi
241242
pppmflag = 1;
242243
respa_enable = 0;
243244
writedata = 0;
@@ -366,7 +367,8 @@ void PairDeepMD::compute(int eflag, int vflag)
366367
if (do_ghost) {
367368
deepmd::InputNlist lmp_list (list->inum, list->ilist, list->numneigh, list->firstneigh);
368369
if (single_model || multi_models_no_mod_devi) {
369-
if ( ! (eflag_atom || vflag_atom) ) {
370+
//cvflag_atom is the right flag for the cvatom matrix
371+
if ( ! (eflag_atom || cvflag_atom) ) {
370372
#ifdef HIGH_PREC
371373
deep_pot.compute (dener, dforce, dvirial, dcoord, dtype, dbox, nghost, lmp_list, ago, fparam, daparam);
372374
#else
@@ -409,14 +411,26 @@ void PairDeepMD::compute(int eflag, int vflag)
409411
if (eflag_atom) {
410412
for (int ii = 0; ii < nlocal; ++ii) eatom[ii] += deatom[ii];
411413
}
412-
if (vflag_atom) {
414+
// Added by Davide Tisi 2020
415+
// interface the atomic virial computed by DeepMD
416+
// with the one used in centroid atoms
417+
if (cvflag_atom) {
413418
for (int ii = 0; ii < nall; ++ii){
414-
vatom[ii][0] += 1.0 * dvatom[9*ii+0];
415-
vatom[ii][1] += 1.0 * dvatom[9*ii+4];
416-
vatom[ii][2] += 1.0 * dvatom[9*ii+8];
417-
vatom[ii][3] += 1.0 * dvatom[9*ii+3];
418-
vatom[ii][4] += 1.0 * dvatom[9*ii+6];
419-
vatom[ii][5] += 1.0 * dvatom[9*ii+7];
419+
//vatom[ii][0] += 1.0 * dvatom[9*ii+0];
420+
//vatom[ii][1] += 1.0 * dvatom[9*ii+4];
421+
//vatom[ii][2] += 1.0 * dvatom[9*ii+8];
422+
//vatom[ii][3] += 1.0 * dvatom[9*ii+3];
423+
//vatom[ii][4] += 1.0 * dvatom[9*ii+6];
424+
//vatom[ii][5] += 1.0 * dvatom[9*ii+7];
425+
cvatom[ii][0] += -1.0 * dvatom[9*ii+0]; // xx
426+
cvatom[ii][1] += -1.0 * dvatom[9*ii+4]; // yy
427+
cvatom[ii][2] += -1.0 * dvatom[9*ii+8]; // zz
428+
cvatom[ii][3] += -1.0 * dvatom[9*ii+3]; // xy
429+
cvatom[ii][4] += -1.0 * dvatom[9*ii+6]; // xz
430+
cvatom[ii][5] += -1.0 * dvatom[9*ii+7]; // yz
431+
cvatom[ii][6] += -1.0 * dvatom[9*ii+1]; // yx
432+
cvatom[ii][7] += -1.0 * dvatom[9*ii+2]; // zx
433+
cvatom[ii][8] += -1.0 * dvatom[9*ii+5]; // zy
420434
}
421435
}
422436
}
@@ -489,14 +503,26 @@ void PairDeepMD::compute(int eflag, int vflag)
489503
if (eflag_atom) {
490504
for (int ii = 0; ii < nlocal; ++ii) eatom[ii] += deatom[ii];
491505
}
492-
if (vflag_atom) {
506+
// Added by Davide Tisi 2020
507+
// interface the atomic virial computed by DeepMD
508+
// with the one used in centroid atoms
509+
if (cvflag_atom) {
493510
for (int ii = 0; ii < nall; ++ii){
494-
vatom[ii][0] += 1.0 * dvatom[9*ii+0];
495-
vatom[ii][1] += 1.0 * dvatom[9*ii+4];
496-
vatom[ii][2] += 1.0 * dvatom[9*ii+8];
497-
vatom[ii][3] += 1.0 * dvatom[9*ii+3];
498-
vatom[ii][4] += 1.0 * dvatom[9*ii+6];
499-
vatom[ii][5] += 1.0 * dvatom[9*ii+7];
511+
//vatom[ii][0] += 1.0 * dvatom[9*ii+0];
512+
//vatom[ii][1] += 1.0 * dvatom[9*ii+4];
513+
//vatom[ii][2] += 1.0 * dvatom[9*ii+8];
514+
//vatom[ii][3] += 1.0 * dvatom[9*ii+3];
515+
//vatom[ii][4] += 1.0 * dvatom[9*ii+6];
516+
//vatom[ii][5] += 1.0 * dvatom[9*ii+7];
517+
cvatom[ii][0] += -1.0 * dvatom[9*ii+0]; // xx
518+
cvatom[ii][1] += -1.0 * dvatom[9*ii+4]; // yy
519+
cvatom[ii][2] += -1.0 * dvatom[9*ii+8]; // zz
520+
cvatom[ii][3] += -1.0 * dvatom[9*ii+3]; // xy
521+
cvatom[ii][4] += -1.0 * dvatom[9*ii+6]; // xz
522+
cvatom[ii][5] += -1.0 * dvatom[9*ii+7]; // yz
523+
cvatom[ii][6] += -1.0 * dvatom[9*ii+1]; // yx
524+
cvatom[ii][7] += -1.0 * dvatom[9*ii+2]; // zx
525+
cvatom[ii][8] += -1.0 * dvatom[9*ii+5]; // zy
500526
}
501527
}
502528
if (out_freq > 0 && update->ntimestep % out_freq == 0) {

0 commit comments

Comments
 (0)