Skip to content

Commit 704db2f

Browse files
authored
fix(lmp): add pair_deepmd_index arg to fix dplr for multiple deepmd pairs (#4274)
Fix #4273. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new optional keyword `pair_deepmd_index` in the `fix dplr` command for enhanced control in simulations. - Updated documentation with clearer instructions and examples for the DPLR model, including training process and simulation setup. - **Bug Fixes** - Improved error handling related to the new `pair_deepmd_index` parameter to ensure proper usage. - **Documentation** - Enhanced descriptions and usability of the DPLR model documentation. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Jinzhe Zeng <[email protected]>
1 parent ff04d8b commit 704db2f

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

doc/model/dplr.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ fix ID group-ID style_name keyword value ...
198198
- three or more keyword/value pairs may be appended
199199

200200
```
201-
keyword = *model* or *type_associate* or *bond_type* or *efield*
201+
keyword = *model* or *type_associate* or *bond_type* or *efield* or *pair_deepmd_index*
202202
*model* value = name
203203
name = name of DPLR model file (e.g. frozen_model.pb) (not DW model)
204204
*type_associate* values = NR1 NW1 NR2 NW2 ...
@@ -208,6 +208,8 @@ keyword = *model* or *type_associate* or *bond_type* or *efield*
208208
NBi = bond type of i-th (real atom, Wannier centroid) pair
209209
*efield* (optional) values = Ex Ey Ez
210210
Ex/Ey/Ez = electric field along x/y/z direction
211+
*pair_deepmd_index* (optional) values = idx
212+
idx = The index of pair_style deepmd, starting from 1, if more than one is used
211213
```
212214

213215
**Examples**
@@ -223,6 +225,8 @@ fix_modify 0 virial yes
223225
```
224226

225227
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.
228+
The fix command must be used after [pair_style `deepmd`](../third-party/lammps-command.md#pair_style-deepmd).
229+
If there are more than 1 pair_style `deepmd`, `pair_deepmd_index` (starting from 1) must be set to assign the index of the pair_style `deepmd`.
226230
The atom names specified in [pair_style `deepmd`](../third-party/lammps-command.md#pair_style-deepmd) will be used to determine elements.
227231
If it is not set, the training parameter {ref}`type_map <model/type_map>` will be mapped to LAMMPS atom types.
228232

source/lmp/fix_dplr.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ FixDPLR::FixDPLR(LAMMPS *lmp, int narg, char **arg)
6262
size_vector = 3;
6363
qe2f = force->qe2f;
6464
xstyle = ystyle = zstyle = NONE;
65+
pair_deepmd_index = 0;
6566

6667
if (strcmp(update->unit_style, "lj") == 0) {
6768
error->all(FLERR,
@@ -125,6 +126,12 @@ FixDPLR::FixDPLR(LAMMPS *lmp, int narg, char **arg)
125126
}
126127
sort(bond_type.begin(), bond_type.end());
127128
iarg = iend;
129+
} else if (string(arg[iarg]) == string("pair_deepmd_index")) {
130+
if (iarg + 1 >= narg) {
131+
error->all(FLERR, "Illegal pair_deepmd_index, not provided");
132+
}
133+
pair_deepmd_index = atoi(arg[iarg + 1]);
134+
iarg += 2;
128135
} else {
129136
break;
130137
}
@@ -141,7 +148,7 @@ FixDPLR::FixDPLR(LAMMPS *lmp, int narg, char **arg)
141148
error->one(FLERR, e.what());
142149
}
143150

144-
pair_deepmd = (PairDeepMD *)force->pair_match("deepmd", 1);
151+
pair_deepmd = (PairDeepMD *)force->pair_match("deepmd", 1, pair_deepmd_index);
145152
if (!pair_deepmd) {
146153
error->all(FLERR, "pair_style deepmd should be set before this fix\n");
147154
}

source/lmp/fix_dplr.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ class FixDPLR : public Fix {
8080
void update_efield_variables();
8181
enum { NONE, CONSTANT, EQUAL };
8282
std::vector<int> type_idx_map;
83+
/* The index of deepmd pair index, which starts from 1. By default 0, which
84+
* works only when there is one deepmd pair. */
85+
int pair_deepmd_index;
8386
};
8487
} // namespace LAMMPS_NS
8588

0 commit comments

Comments
 (0)