Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lmp: support other units for both pair deepmd and fix dplr #2800

Merged
merged 46 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
ee88a5d
add dist and force unit_cvt_factor
Yi-FanLi Sep 9, 2023
d259c3c
apply ener, force, and dist _unit_cvt_factors
Yi-FanLi Sep 10, 2023
cf91b8d
fix duplicate xener_unit_cvt_factor
Yi-FanLi Sep 10, 2023
a761e93
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 10, 2023
04b3289
remove ener_unit_cvt_factor from scale
Yi-FanLi Sep 10, 2023
f468f6f
add unit converters for fix dplr
Yi-FanLi Sep 10, 2023
b1a90ba
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 10, 2023
beeab43
support multiple units for compute deeptensor/atom
Yi-FanLi Sep 10, 2023
43701d0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 10, 2023
8f77ef1
add test_pair_deepmd_si
Yi-FanLi Sep 10, 2023
4fbfc4a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 10, 2023
2043905
fix error in test_pair_deepmd_si
Yi-FanLi Sep 10, 2023
cf55ead
write more decimals when writing lmp data file
Yi-FanLi Sep 10, 2023
5ee7b30
write more digits for atomic masses
Yi-FanLi Sep 10, 2023
99b5b59
use default skin value for the neighbor list
Yi-FanLi Sep 10, 2023
8c07676
convert unit for model cutoff
Yi-FanLi Sep 10, 2023
a28eb7a
convert unit for model cutoff loaded from DeepPotModelDevi
Yi-FanLi Sep 10, 2023
11b5afb
use small skin for si units
Yi-FanLi Sep 10, 2023
e1c9173
fix the error in dist_unit_cvt_factor
Yi-FanLi Sep 11, 2023
c441b4d
Merge branch 'devel' into lmp_units
Yi-FanLi Sep 11, 2023
431dc9a
delete redundant semicolon
Yi-FanLi Sep 14, 2023
642d91d
Merge branch 'lmp_units' of github.com:Yi-FanLi/deepmd-kit into lmp_u…
Yi-FanLi Sep 14, 2023
a7fc19e
allow more units in fix dplr and compute deeptensor/atom
Yi-FanLi Sep 15, 2023
d727d5d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 15, 2023
54eb918
Merge branch 'devel' into lmp_units
Yi-FanLi Sep 15, 2023
88e1207
reuse constants in test
Yi-FanLi Sep 15, 2023
8f13576
Merge branch 'lmp_units' of github.com:Yi-FanLi/deepmd-kit into lmp_u…
Yi-FanLi Sep 15, 2023
93f2d95
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 15, 2023
8650582
delete constants redefinition
Yi-FanLi Sep 15, 2023
0ac2406
Merge branch 'lmp_units' of github.com:Yi-FanLi/deepmd-kit into lmp_u…
Yi-FanLi Sep 15, 2023
068fc0b
put mass conversion to constants.py
Yi-FanLi Sep 15, 2023
b1c3f94
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 15, 2023
f463d8b
add charge converter in constants.py
Yi-FanLi Sep 16, 2023
c470f0f
fix merge conflicts
Yi-FanLi Sep 16, 2023
c139455
add dplr unittest for si units
Yi-FanLi Sep 16, 2023
bf21717
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 16, 2023
d4da810
more systematic unit conversion format
Yi-FanLi Sep 16, 2023
ad7e696
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 16, 2023
388faee
Update source/lmp/tests/test_dplr.py
Yi-FanLi Sep 17, 2023
29bf465
update test_dplr
Yi-FanLi Sep 17, 2023
8b53f03
Merge branch 'lmp_units' of github.com:Yi-FanLi/deepmd-kit into lmp_u…
Yi-FanLi Sep 17, 2023
771e747
write more decimals for charge when writing data file
Yi-FanLi Sep 17, 2023
876105d
add deeptensor unittest for si units
Yi-FanLi Sep 17, 2023
d8b58ed
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 17, 2023
0a5fa89
add LAMMPS units discussion in document
Yi-FanLi Sep 17, 2023
c671f24
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 17 additions & 14 deletions source/lmp/compute_deeptensor_atom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ using namespace LAMMPS_NS;

ComputeDeeptensorAtom::ComputeDeeptensorAtom(LAMMPS *lmp, int narg, char **arg)
: Compute(lmp, narg, arg), dp(lmp), tensor(nullptr) {
if (!(strcmp(update->unit_style, "metal") == 0 ||
strcmp(update->unit_style, "real") == 0)) {
error->all(
FLERR,
"Compute deeptensor/atom requires metal or real unit; please set it by "
"\"units metal\" or \"units real\"");
if (strcmp(update->unit_style, "lj") == 0) {
error->all(FLERR,
"Compute deeptensor/atom does not support unit style lj. Please "
"use other "
"unit styles like metal or real unit instead. You may set it by "
"\"units metal\" or \"units real\"");
}

if (narg < 4) {
Expand All @@ -57,6 +57,8 @@ ComputeDeeptensorAtom::ComputeDeeptensorAtom(LAMMPS *lmp, int narg, char **arg)
timeflag = 1;

nmax = 0;

dist_unit_cvt_factor = force->angstrom;
}

/* ---------------------------------------------------------------------- */
Expand Down Expand Up @@ -116,16 +118,17 @@ void ComputeDeeptensorAtom::compute_peratom() {
dtype[ii] = type[ii] - 1;
}
// get box
dbox[0] = domain->h[0]; // xx
dbox[4] = domain->h[1]; // yy
dbox[8] = domain->h[2]; // zz
dbox[7] = domain->h[3]; // zy
dbox[6] = domain->h[4]; // zx
dbox[3] = domain->h[5]; // yx
dbox[0] = domain->h[0] / dist_unit_cvt_factor; // xx
dbox[4] = domain->h[1] / dist_unit_cvt_factor; // yy
dbox[8] = domain->h[2] / dist_unit_cvt_factor; // zz
dbox[7] = domain->h[3] / dist_unit_cvt_factor; // zy
dbox[6] = domain->h[4] / dist_unit_cvt_factor; // zx
dbox[3] = domain->h[5] / dist_unit_cvt_factor; // yx
// get coord
for (int ii = 0; ii < nall; ++ii) {
for (int dd = 0; dd < 3; ++dd) {
dcoord[ii * 3 + dd] = x[ii][dd] - domain->boxlo[dd];
dcoord[ii * 3 + dd] =
(x[ii][dd] - domain->boxlo[dd]) / dist_unit_cvt_factor;
}
}

Expand Down Expand Up @@ -155,7 +158,7 @@ void ComputeDeeptensorAtom::compute_peratom() {
// record when selected and in group
if (selected && ingroup) {
for (int jj = 0; jj < size_peratom_cols; ++jj) {
tensor[ii][jj] = atensor[iter_tensor + jj];
tensor[ii][jj] = atensor[iter_tensor + jj] * dist_unit_cvt_factor;
Yi-FanLi marked this conversation as resolved.
Show resolved Hide resolved
}
}
// if not selected or not in group set to 0.
Expand Down
1 change: 1 addition & 0 deletions source/lmp/compute_deeptensor_atom.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ComputeDeeptensorAtom : public Compute {
void compute_peratom() override;
double memory_usage() override;
void init_list(int, class NeighList *) override;
double dist_unit_cvt_factor;

private:
int nmax;
Expand Down
59 changes: 38 additions & 21 deletions source/lmp/fix_dplr.cpp
njzjz marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ FixDPLR::FixDPLR(LAMMPS *lmp, int narg, char **arg)
qe2f = force->qe2f;
xstyle = ystyle = zstyle = NONE;

if (strcmp(update->unit_style, "metal") != 0) {
error->all(
FLERR,
"Fix dplr requires metal unit, please set it by \"units metal\"");
if (strcmp(update->unit_style, "lj") == 0) {
error->all(FLERR,
"Fix dplr does not support unit style lj. Please use other "
"unit styles like metal or real unit instead. You may set it by "
"\"units metal\" or \"units real\"");
}

int iarg = 3;
Expand Down Expand Up @@ -142,6 +143,9 @@ FixDPLR::FixDPLR(LAMMPS *lmp, int narg, char **arg)
if (!pair_deepmd) {
error->all(FLERR, "pair_style deepmd should be set before this fix\n");
}
ener_unit_cvt_factor = pair_deepmd->ener_unit_cvt_factor;
dist_unit_cvt_factor = pair_deepmd->dist_unit_cvt_factor;
force_unit_cvt_factor = pair_deepmd->force_unit_cvt_factor;

int n = atom->ntypes;
std::vector<std::string> type_names = pair_deepmd->type_names;
Expand Down Expand Up @@ -445,16 +449,17 @@ void FixDPLR::pre_force(int vflag) {
dtype[ii] = type_idx_map[type[ii] - 1];
}
// get box
dbox[0] = domain->h[0]; // xx
dbox[4] = domain->h[1]; // yy
dbox[8] = domain->h[2]; // zz
dbox[7] = domain->h[3]; // zy
dbox[6] = domain->h[4]; // zx
dbox[3] = domain->h[5]; // yx
dbox[0] = domain->h[0] / dist_unit_cvt_factor; // xx
dbox[4] = domain->h[1] / dist_unit_cvt_factor; // yy
dbox[8] = domain->h[2] / dist_unit_cvt_factor; // zz
dbox[7] = domain->h[3] / dist_unit_cvt_factor; // zy
dbox[6] = domain->h[4] / dist_unit_cvt_factor; // zx
dbox[3] = domain->h[5] / dist_unit_cvt_factor; // yx
// get coord
for (int ii = 0; ii < nall; ++ii) {
for (int dd = 0; dd < 3; ++dd) {
dcoord[ii * 3 + dd] = x[ii][dd] - domain->boxlo[dd];
dcoord[ii * 3 + dd] =
(x[ii][dd] - domain->boxlo[dd]) / dist_unit_cvt_factor;
}
}
// get lammps nlist
Expand Down Expand Up @@ -523,9 +528,11 @@ void FixDPLR::pre_force(int vflag) {
int res_idx = sel_fwd[idx0];
// int ret_idx = dpl_bwd[res_idx];
for (int dd = 0; dd < 3; ++dd) {
x[idx1][dd] = x[idx0][dd] + tensor[res_idx * 3 + dd];
x[idx1][dd] =
x[idx0][dd] + tensor[res_idx * 3 + dd] * dist_unit_cvt_factor;
// res_buff[idx1 * odim + dd] = tensor[res_idx * odim + dd];
dipole_recd[idx0 * 3 + dd] = tensor[res_idx * 3 + dd];
dipole_recd[idx0 * 3 + dd] =
tensor[res_idx * 3 + dd] * dist_unit_cvt_factor;
}
}
// cout << "-------------------- fix/dplr: pre force " << endl;
Expand Down Expand Up @@ -568,17 +575,18 @@ void FixDPLR::post_force(int vflag) {
for (int ii = 0; ii < nall; ++ii) {
dtype[ii] = type_idx_map[type[ii] - 1];
}
dbox[0] = domain->h[0]; // xx
dbox[4] = domain->h[1]; // yy
dbox[8] = domain->h[2]; // zz
dbox[7] = domain->h[3]; // zy
dbox[6] = domain->h[4]; // zx
dbox[3] = domain->h[5]; // yx
dbox[0] = domain->h[0] / dist_unit_cvt_factor; // xx
dbox[4] = domain->h[1] / dist_unit_cvt_factor; // yy
dbox[8] = domain->h[2] / dist_unit_cvt_factor; // zz
dbox[7] = domain->h[3] / dist_unit_cvt_factor; // zy
dbox[6] = domain->h[4] / dist_unit_cvt_factor; // zx
dbox[3] = domain->h[5] / dist_unit_cvt_factor; // yx
// get coord
double **x = atom->x;
for (int ii = 0; ii < nall; ++ii) {
for (int dd = 0; dd < 3; ++dd) {
dcoord[ii * 3 + dd] = x[ii][dd] - domain->boxlo[dd];
dcoord[ii * 3 + dd] =
(x[ii][dd] - domain->boxlo[dd]) / dist_unit_cvt_factor;
}
}
// revise force according to efield
Expand All @@ -599,7 +607,7 @@ void FixDPLR::post_force(int vflag) {
for (int ii = 0; ii < nlocal; ++ii) {
double tmpf[3];
for (int dd = 0; dd < 3; ++dd) {
tmpf[dd] = q[ii] * efield[dd];
tmpf[dd] = q[ii] * efield[dd] * force->qe2f;
}
for (int dd = 0; dd < 3; ++dd) {
dfele[ii * 3 + dd] += tmpf[dd];
Expand Down Expand Up @@ -632,8 +640,17 @@ void FixDPLR::post_force(int vflag) {
vector<FLOAT_PREC> dfcorr, dvcorr;
// compute
try {
for (int ii = 0; ii < nlocal * 3; ++ii) {
dfele[ii] /= force_unit_cvt_factor;
}
dtm.compute(dfcorr, dvcorr, dcoord, dtype, dbox, valid_pairs, dfele, nghost,
lmp_list);
for (int ii = 0; ii < nlocal * 3; ++ii) {
dfcorr[ii] *= force_unit_cvt_factor;
}
for (int ii = 0; ii < 9; ++ii) {
dvcorr[ii] *= ener_unit_cvt_factor;
}
} catch (deepmd_compat::deepmd_exception &e) {
error->one(FLERR, e.what());
}
Expand Down
1 change: 1 addition & 0 deletions source/lmp/fix_dplr.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class FixDPLR : public Fix {
void unpack_reverse_comm(int, int *, double *) override;
double compute_scalar(void) override;
double compute_vector(int) override;
double ener_unit_cvt_factor, dist_unit_cvt_factor, force_unit_cvt_factor;

private:
PairDeepMD *pair_deepmd;
Expand Down