Skip to content

Commit 5b0ff59

Browse files
authored
Add plugin for GROMACS (#1160)
* Add gromacs examples * Add doc for gmx/dp plugin * Add gmx plugin in README.md * Add gmx/dp plugin code * Upgrade json.hpp to 3.9.1 * Update doc of installing gromacs * Change the min gcc version to 4.8 * Compile TENSORFLOW_ROOT and DEEPMD_ROOT in dp_gmx_patch * Remove extra files * Update doc to use gcc version 4.8 * Resolve inconsistency in gcc version
1 parent 077df3d commit 5b0ff59

37 files changed

+24456
-11189
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Please follow our [GitHub](https://github.com/deepmodeling/deepmd-kit) webpage t
6060

6161
DeePMD-kit offers multiple installation methods. It is recommend using easily methods like [offline packages](doc/install/easy-install.md#offline-packages), [conda](doc/install/easy-install.md#with-conda) and [docker](doc/install/easy-install.md#with-docker).
6262

63-
One may manually install DeePMD-kit by following the instuctions on [installing the Python interface](doc/install/install-from-source.md#install-the-python-interface) and [installing the C++ interface](doc/install/install-from-source.md#install-the-c-interface). The C++ interface is necessary when using DeePMD-kit with LAMMPS and i-PI.
63+
One may manually install DeePMD-kit by following the instuctions on [installing the Python interface](doc/install/install-from-source.md#install-the-python-interface) and [installing the C++ interface](doc/install/install-from-source.md#install-the-c-interface). The C++ interface is necessary when using DeePMD-kit with LAMMPS, i-PI or GROMACS.
6464

6565

6666
# Use DeePMD-kit
@@ -71,7 +71,7 @@ A quick-start on using DeePMD-kit can be found as follows:
7171
- [Training a model](doc/train/training.md)
7272
- [Freeze a model](doc/freeze/freeze.md)
7373
- [Test a model](doc/test/test.md)
74-
- [Running MD with LAMMPS](doc/third-party/lammps.md)
74+
- [Run MD with LAMMPS](doc/third-party/lammps.md)
7575

7676
A full [document](doc/train/train-input-auto.rst) on options in the training input script is available.
7777

@@ -113,10 +113,10 @@ A full [document](doc/train/train-input-auto.rst) on options in the training inp
113113
- [C++ interface](doc/inference/cxx.md)
114114
- [Integrate with third-party packages](doc/third-party/index.rst)
115115
- [Use deep potential with ASE](doc/third-party/ase.md)
116-
- [Running MD with LAMMPS](doc/third-party/lammps.md)
116+
- [Run MD with LAMMPS](doc/third-party/lammps.md)
117117
- [LAMMPS commands](doc/third-party/lammps-command.md)
118118
- [Run path-integral MD with i-PI](doc/third-party/ipi.md)
119-
119+
- [Run MD with GROMACS](doc/third-party/gromacs.md)
120120

121121
# Code structure
122122
The code is organized as follows:
@@ -135,6 +135,8 @@ The code is organized as follows:
135135

136136
* `source/lmp`: source code of Lammps module.
137137

138+
* `source/gmx`: source code of Gromacs plugin.
139+
138140
* `source/op`: tensorflow op implementation. working with library.
139141

140142

doc/install/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
- [Install from source code](install-from-source.md)
55
- [Install LAMMPS](install-lammps.md)
66
- [Install i-PI](install-ipi.md)
7+
- [Install GROMACS](install-gromacs.md)
78
- [Building conda packages](build-conda.md)

doc/install/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ Installation
88
install-from-source
99
install-lammps
1010
install-ipi
11+
install-gromacs
1112
build-conda

doc/install/install-from-source.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Check the compiler version on your machine
146146
gcc --version
147147
```
148148

149-
The C++ interface of DeePMD-kit was tested with compiler gcc >= 4.8. It is noticed that the I-Pi support is only compiled with gcc >= 4.9.
149+
The C++ interface of DeePMD-kit was tested with compiler gcc >= 4.8. It is noticed that the I-Pi support is only compiled with gcc >= 4.8.
150150

151151
First the C++ interface of Tensorflow should be installed. It is noted that the version of Tensorflow should be in consistent with the python interface. You may follow [the instruction](install-tf.2.3.md) to install the corresponding C++ interface.
152152

doc/install/install-gromacs.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Install GROMACS with DeepMD
2+
## Patch source code of GROMACS
3+
Download source code of a supported gromacs version (2020.2) from https://manual.gromacs.org/2020.2/download.html. Run the following command:
4+
```bash
5+
export PATH=$PATH:$deepmd_kit_root/bin
6+
dp_gmx_patch -d $gromacs_root -v $version -p
7+
```
8+
where `deepmd_kit_root` is the directory where the latest version of deepmd-kit is installed, and `gromacs_root` refers to source code directory of gromacs. And `version` represents the version of gromacs, **only support 2020.2 now**. You may patch another version of gromacs but still setting `version` to `2020.2`. However, we cannot ensure that it works.
9+
10+
<!-- ## Install C++ api of deepmd-kit and tensorflow
11+
The C++ interface of `deepmd-kit 2.x` and `tensorflow 2.x` are required. -->
12+
<!-- + Tips: C++ api of deepmd and tensorflow could be easily installed from the deepmd-kit offline packages. But before using tensorflow, you need to manually change the protobuf package to [version 3.9.2](https://github.com/protocolbuffers/protobuf/releases/tag/v3.9.2) in `$deepmd_env_dir/include/google/protobuf` (the offline package will install a version of 3.14, which will cause incompability). Here `deepmd_env_dir` refers to the directory of conda environment created by the deepmd-kit offline packages. -->
13+
14+
## Compile GROMACS with deepmd-kit
15+
The C++ interface of `deepmd-kit 2.x` and `tensorflow 2.x` are required. And be aware that only deepmd-kit with **high precision** is supported now, since we cannot ensure single precision is enough for a GROMACS simulation. Here is a sample compile scipt:
16+
```bash
17+
#!/bin/bash
18+
export CC=/usr/bin/gcc
19+
export CXX=/usr/bin/g++
20+
export CMAKE_PREFIX_PATH="/path/to/fftw-3.3.9" # fftw libraries
21+
mkdir build
22+
cd build
23+
24+
cmake3 .. -DCMAKE_CXX_STANDARD=14 \ # not required, but c++14 seems to be more compatible with higher version of tensorflow
25+
-DGMX_MPI=ON \
26+
-DGMX_GPU=CUDA \ # Gromacs on ROCm has not been fully developed yet
27+
-DCUDA_TOOLKIT_ROOT_DIR=/path/to/cuda \
28+
-DCMAKE_INSTALL_PREFIX=/path/to/gromacs-2020.2-deepmd
29+
make -j
30+
make install
31+
```

doc/third-party/gromacs.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Running MD with GROMACS
2+
## DP/MM Simulation
3+
This part gives a simple tutorial on how to run a DP/MM simulation for methane in water, which means using DP for methane and TIP3P for water. All relevant files can be found in `examples/methane`.
4+
### Topology Preparation
5+
Similar to QM/MM simulation, the internal interactions (including bond, angle, dihedrals, LJ, Columb) of the region descibed by a neural network potential (NNP) have to be **turned off**. In GROMACS, bonded interactions can be turned off by modifying `[ bonds ]`, `[ angles ]`, `[ dihedrals ]` and `[ pairs ]` sections. And LJ and Columb interactions must be turned off by `[ exclusions ]` section.
6+
7+
For example, if one wants to simulate ethane in water, using DeepPotential for methane and TIP3P for water, the topology of methane should be like the following (as presented in `examples/methane/methane.itp`):
8+
```
9+
[ atomtypes ]
10+
;name btype mass charge ptype sigma epsilon
11+
c3 c3 0.0 0.0 A 0.339771 0.451035
12+
hc hc 0.0 0.0 A 0.260018 0.087027
13+
14+
[ moleculetype ]
15+
;name nrexcl
16+
methane 3
17+
18+
[ atoms ]
19+
; nr type resnr residue atom cgnr charge mass
20+
1 c3 1 MOL C1 1 -0.1068 12.010
21+
2 hc 1 MOL H1 2 0.0267 1.008
22+
3 hc 1 MOL H2 3 0.0267 1.008
23+
4 hc 1 MOL H3 4 0.0267 1.008
24+
5 hc 1 MOL H4 5 0.0267 1.008
25+
26+
[ bonds ]
27+
; i j func b0 kb
28+
1 2 5
29+
1 3 5
30+
1 4 5
31+
1 5 5
32+
33+
[ exclusions ]
34+
; ai aj1 aj2 aj3 aj4
35+
1 2 3 4 5
36+
2 1 3 4 5
37+
3 1 2 4 5
38+
4 1 2 3 5
39+
5 1 2 3 4
40+
```
41+
For comparsion, the original topology file genearted by `acpype` will be:
42+
```
43+
; methane_GMX.itp created by acpype (v: 2021-02-05T22:15:50CET) on Wed Sep 8 01:21:53 2021
44+
45+
[ atomtypes ]
46+
;name bond_type mass charge ptype sigma epsilon Amb
47+
c3 c3 0.00000 0.00000 A 3.39771e-01 4.51035e-01 ; 1.91 0.1078
48+
hc hc 0.00000 0.00000 A 2.60018e-01 8.70272e-02 ; 1.46 0.0208
49+
50+
[ moleculetype ]
51+
;name nrexcl
52+
methane 3
53+
54+
[ atoms ]
55+
; nr type resi res atom cgnr charge mass ; qtot bond_type
56+
1 c3 1 MOL C1 1 -0.106800 12.01000 ; qtot -0.107
57+
2 hc 1 MOL H1 2 0.026700 1.00800 ; qtot -0.080
58+
3 hc 1 MOL H2 3 0.026700 1.00800 ; qtot -0.053
59+
4 hc 1 MOL H3 4 0.026700 1.00800 ; qtot -0.027
60+
5 hc 1 MOL H4 5 0.026700 1.00800 ; qtot 0.000
61+
62+
[ bonds ]
63+
; ai aj funct r k
64+
1 2 1 1.0970e-01 3.1455e+05 ; C1 - H1
65+
1 3 1 1.0970e-01 3.1455e+05 ; C1 - H2
66+
1 4 1 1.0970e-01 3.1455e+05 ; C1 - H3
67+
1 5 1 1.0970e-01 3.1455e+05 ; C1 - H4
68+
69+
[ angles ]
70+
; ai aj ak funct theta cth
71+
2 1 3 1 1.0758e+02 3.2635e+02 ; H1 - C1 - H2
72+
2 1 4 1 1.0758e+02 3.2635e+02 ; H1 - C1 - H3
73+
2 1 5 1 1.0758e+02 3.2635e+02 ; H1 - C1 - H4
74+
3 1 4 1 1.0758e+02 3.2635e+02 ; H2 - C1 - H3
75+
3 1 5 1 1.0758e+02 3.2635e+02 ; H2 - C1 - H4
76+
4 1 5 1 1.0758e+02 3.2635e+02 ; H3 - C1 - H4
77+
```
78+
### DeepMD Settings
79+
Before running simulation, we need to tell GROMACS to use DeepPotential by setting environment variable `GMX_DEEPMD_INPUT_JSON`:
80+
```bash
81+
export GMX_DEEPMD_INPUT_JSON=input.json
82+
```
83+
Then, in your working directories, we have to write `input.json` file:
84+
```json
85+
{
86+
"graph_file": "/path/to/graph.pb",
87+
"type_file": "type.raw",
88+
"index_file": "index.raw",
89+
"lambda": 1.0,
90+
"pbc": false
91+
}
92+
```
93+
Here is an explanation for these settings:
94+
+ `graph_file` : The graph file (with suffix .pb) generated by `dp freeze` command
95+
+ `type_file` : File to specify DP atom types (in space-sepreated format). Here, `type.raw` looks like
96+
```
97+
1 0 0 0 0
98+
```
99+
+ `index_file` : File containing indices of DP atoms (in space-seperated format), which should be in consistent with indices' order in .gro file but **starting from zero**. Here, `index.raw` looks like
100+
```
101+
0 1 2 3 4
102+
```
103+
+ `lambda`: Optional, default 1.0. Used in alchemical calculations.
104+
+ `pbc`: Optional, default true. If true, the GROMACS peroidic condition is passed to DeepMD.
105+
106+
### Run Simulation
107+
Finally, you can run GROMACS using `gmx mdrun` as usual.
108+
109+
## All-atom DP Simulation
110+
This part gives an example on how to run a simulation with all atoms described by a DeepPotential with Gromacs, taking water as an example. Instead of using `[ exclusions ]` to turn off the non-bonded energies, we can simply do this by setting LJ parameters (i.e. epsilon and sigma) and partial charges to 0, as shown in `examples/water/gmx/water.top`:
111+
```
112+
[ atomtypes ]
113+
; name at.num mass charge ptype sigma epsilon
114+
HW 1 1.008 0.0000 A 0.00000e+00 0.00000e+00
115+
OW 8 16.00 0.0000 A 0.00000e+00 0.00000e+00
116+
```
117+
As mentioned in the above section, `input.json` and relevant files (`index.raw`, `type.raw`) should also be created. Then, we can start the simulation under NVT ensemble and plot the radial distribution function (RDF) by `gmx rdf` command. We can see that the RDF given by Gromacs+DP matches perfectly with Lammps+DP, which further provides an evidence on the validity of our simulation.
118+
![rdf](../../examples/water/gmx/rdf.png)
119+
120+
However, we still recommend you run all-atom DP simulation using LAMMPS since it is more stable and efficient.

doc/third-party/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Note that the model for inference is required to be compatible with the DeePMD-kit package. See [Model compatibility](../troubleshooting/model-compatability.html) for details.
44

55
- [Use deep potential with ASE](ase.md)
6-
- [Running MD with LAMMPS](lammps.md)
6+
- [Run MD with LAMMPS](lammps.md)
77
- [LAMMPS commands](lammps-command.md)
8-
- [Run path-integral MD with i-PI](ipi.md)
8+
- [Run path-integral MD with i-PI](ipi.md)
9+
- [Run MD with GROMACS](gromacs.md)

doc/third-party/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ Note that the model for inference is required to be compatible with the DeePMD-k
1010
lammps
1111
lammps-command
1212
ipi
13+
gromacs

doc/third-party/lammps.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Running MD with LAMMPS
1+
# Run MD with LAMMPS
22

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

doc/troubleshooting/installation.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# Installation
22
## Inadequate versions of gcc/g++
3-
Sometimes you may use a gcc/g++ of version <4.9. If you have a gcc/g++ of version > 4.9, say, 7.2.0, you may choose to use it by doing
3+
Sometimes you may use a gcc/g++ of version < 4.8. In this way, you can still compile all the parts of TensorFlow and most of the parts of DeePMD-kit, but i-Pi and GROMACS plugin will be disabled automatically. Or if you have a gcc/g++ of version > 4.8, say, 7.2.0, you may choose to use it by doing
44
```bash
55
export CC=/path/to/gcc-7.2.0/bin/gcc
66
export CXX=/path/to/gcc-7.2.0/bin/g++
77
```
88

9-
If, for any reason, for example, you only have a gcc/g++ of version 4.8.5, you can still compile all the parts of TensorFlow and most of the parts of DeePMD-kit. i-Pi will be disabled automatically.
10-
119
## Build files left in DeePMD-kit
1210
When you try to build a second time when installing DeePMD-kit, files produced before may contribute to failure. Thus, you may clear them by
1311
```bash

0 commit comments

Comments
 (0)