Skip to content

Commit

Permalink
highlight LAMMPS codes in doc (#1921)
Browse files Browse the repository at this point in the history
  • Loading branch information
njzjz authored and root committed Mar 8, 2023
1 parent 9e244fe commit 6f6e63d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
6 changes: 4 additions & 2 deletions deepmd/nvnmd/entrypoints/wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ class Wrap():
the model file can be use to run the NVNMD with lammps
the pair style need set as:
| :code:`pair_style nvnmd model.pb`
| :code:`pair_coeff * *`
.. code-block:: lammps
pair_style nvnmd model.pb
pair_coeff * *
Parameters
----------
Expand Down
14 changes: 7 additions & 7 deletions doc/model/dplr.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The training of the DPLR model is very similar to the standard short-range DP mo
```
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 transform.
The DPLR model can be trained and frozen by (from the example directory)
```
```bash
dp train ener.json && dp freeze -o ener.pb
```

Expand Down Expand Up @@ -108,7 +108,7 @@ An example input script is provided in
$deepmd_source_dir/examples/water/dplr/lmp/in.lammps
```
Here are some explanations
```
```lammps
# groups of real and virtual atoms
group real_atom type 1 2
group virtual_atom type 3
Expand All @@ -124,7 +124,7 @@ special_bonds lj/coul 1 1 1 angle no
```
Type 1 and 2 (O and H) are `real_atom`s, while type 3 (WCs) are `virtual_atom`s. The model file `ener.pb` stores both the DW and DPLR models, so the position of WCs and the energy can be inferred from it. A virtual bond type is specified by `bond_style zero`. The `special_bonds` command switches off the exclusion of intramolecular interactions.

```
```lammps
# kspace_style "pppm/dplr" should be used. in addition the
# gewald(1/distance) should be set the same as that used in
# training. Currently only ik differentiation is supported.
Expand All @@ -133,7 +133,7 @@ kspace_modify gewald ${BETA} diff ik mesh ${KMESH} ${KMESH} ${KMESH}
```
The long-range part is calculated by the `kspace` support of LAMMPS. The `kspace_style` `pppm/dplr` is required. The spread parameter set by variable `BETA` should be set the same as that used in training. The `KMESH` should be set dense enough so the long-range calculation is converged.

```
```lammps
# "fix dplr" set the position of the virtual atom, and spread the
# electrostatic interaction asserting on the virtual atom to the real
# atoms. "type_associate" associates the real atom type its
Expand All @@ -144,20 +144,20 @@ fix_modify 0 virial yes
```
The fix command `dplr` calculates the position of WCs by the DW model and back-propagates the long-range interaction on virtual atoms to real toms.

```
```lammps
# compute the temperature of real atoms, excluding virtual atom contribution
compute real_temp real_atom temp
compute real_press all pressure real_temp
fix 1 real_atom nvt temp ${TEMP} ${TEMP} ${TAU_T}
fix_modify 1 temp real_temp
```
The temperature of the system should be computed from the real atoms. The kinetic contribution in the pressure tensor is also computed from the real atoms. The thermostat is applied to only real atoms. The computed temperature and pressure of real atoms can be accessed by, e.g.
```
```lammps
fix thermo_print all print ${THERMO_FREQ} "$(step) $(pe) $(ke) $(etotal) $(enthalpy) $(c_real_temp) $(c_real_press) $(vol) $(c_real_press[1]) $(c_real_press[2]) $(c_real_press[3])" append thermo.out screen no title "# step pe ke etotal enthalpy temp press vol pxx pyy pzz"
```

The LAMMPS simulation can be started from the example directory by
```
```bash
lmp -i in.lammps
```
If LAMMPS complains that no model file `ener.pb` exists, it can be copied from the training example directory.
Expand Down
22 changes: 11 additions & 11 deletions doc/third-party/lammps-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

If you are using the plugin mode, enable DeePMD-kit package in LAMMPS with `plugin` command:

```
```lammps
plugin load libdeepmd_lmp.so
```

Expand All @@ -22,7 +22,7 @@ The built-in mode doesn't need this step.

The DeePMD-kit package provides the pair_style `deepmd`

```
```lammps
pair_style deepmd models ... keyword value ...
```
- deepmd = style of this pair_style
Expand All @@ -44,7 +44,7 @@ and the model deviation will be computed among all models every `out_freq` times
</pre>

### Examples
```
```lammps
pair_style deepmd graph.pb
pair_style deepmd graph.pb fparam 1.2
pair_style deepmd graph_0.pb graph_1.pb graph_2.pb out_file md.out out_freq 10 atomic relative 1.0
Expand All @@ -71,7 +71,7 @@ where $D_{f_i}$ is the absolute model deviation of the force on atom $i$, $f_i$

The DeePMD-kit package provide the compute `deeptensor/atom` for computing atomic tensorial properties.

```
```lammps
compute ID group-ID deeptensor/atom model_file
```
- ID: user-assigned name of the computation
Expand All @@ -80,11 +80,11 @@ compute ID group-ID deeptensor/atom model_file
- model_file: the name of the binary model file.

### Examples
```
```lammps
compute dipole all deeptensor/atom dipole.pb
```
The result of the compute can be dump to trajctory file by
```
```lammps
dump 1 all custom 100 water.dump id type c_dipole[1] c_dipole[2] c_dipole[3]
```

Expand All @@ -94,7 +94,7 @@ dump 1 all custom 100 water.dump id type c_dipole[1] c_dipole[2] c_di

## Long-range interaction
The reciprocal space part of the long-range interaction can be calculated by LAMMPS command `kspace_style`. To use it with DeePMD-kit, one writes
```bash
```lammps
pair_style deepmd graph.pb
pair_coeff * *
kspace_style pppm 1.0e-5
Expand All @@ -111,13 +111,13 @@ $$dvatom=\sum_{m}( \mathbf{r}_n- \mathbf{r}_m) \frac{de_m}{d\mathbf{r}_n}$$
Where $\mathbf{r}_n$ is the atomic position of nth atom, $\mathbf{v}_n$ velocity of atom and $\frac{de_m}{d\mathbf{r}_n}$ the derivative of the atomic energy.

In LAMMPS one can get the per-atom stress using the command `centroid/stress/atom`:
```bash
```lammps
compute ID group-ID centroid/stress/atom NULL virial
```
see [LAMMPS doc page](https://docs.lammps.org/compute_stress_atom.html#thompson2) for more detailes on the meaning of the keywords.
### Examples
In order of computing the 9-component per-atom stress
```bash
```lammps
compute stress all centroid/stress/atom NULL virial
```
Thus `c_stress` is an array with 9 component in the order `xx,yy,zz,xy,xz,yz,yx,zx,zy`.
Expand All @@ -130,7 +130,7 @@ Using per-atom stress tensor one can, for example, compute the heat flux defined
$$\mathbf J = \sum_n e_n \mathbf v_n + \sum_{n,m} ( \mathbf r_m- \mathbf r_n) \frac{de_m}{d\mathbf r_n} \mathbf v_n$$

to compute the heat flux with LAMMPS:
```bash
```lammps
compute ke_ID all ke/atom
compute pe_ID all pe/atom
compute stress_ID group-ID centroid/stress/atom NULL virial
Expand All @@ -139,7 +139,7 @@ compute flux_ID all heat/flux ke_ID pe_ID stress_ID

### Examples

```bash
```lammps
compute ke all ke/atom
compute pe all pe/atom
compute stress all centroid/stress/atom NULL virial
Expand Down
2 changes: 1 addition & 1 deletion doc/third-party/lammps.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Running an MD simulation with LAMMPS is simpler. In the LAMMPS input file, one needs to specify the pair style as follows

```
```lammps
pair_style deepmd graph.pb
pair_coeff * *
```
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
"deepmodeling-sphinx>=0.1.0",
"dargs>=0.3.1",
"sphinx-argparse",
"pygments-lammps",
],
**extras_require,
},
Expand Down

0 comments on commit 6f6e63d

Please sign in to comment.