From dfb29bb5cdc2e586b0001c84b17fd74c39befe4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yifan=20Li=E6=9D=8E=E4=B8=80=E5=B8=86?= Date: Wed, 31 May 2023 18:53:31 -0400 Subject: [PATCH 01/18] Use a sorted dpl_type vector in binary search --- source/lmp/fix_dplr.cpp | 6 ++++-- source/lmp/fix_dplr.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index e66cb643f9..583cd871d6 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -115,6 +115,8 @@ FixDPLR::FixDPLR(LAMMPS *lmp, int narg, char **arg) for (int ii = 0; ii < sel_type.size(); ++ii) { dpl_type.push_back(type_asso[sel_type[ii]]); } + dpl_type_sorted = dpl_type; + sort(dpl_type_sorted.begin(), dpl_type_sorted.end()); pair_deepmd = (PairDeepMD *)force->pair_match("deepmd", 1); if (!pair_deepmd) { @@ -192,13 +194,13 @@ void FixDPLR::get_valid_pairs(vector > &pairs) { } if (binary_search(sel_type.begin(), sel_type.end(), dtype[bondlist[ii][0]]) && - binary_search(dpl_type.begin(), dpl_type.end(), + binary_search(dpl_type_sorted.begin(), dpl_type_sorted.end(), dtype[bondlist[ii][1]])) { idx0 = bondlist[ii][0]; idx1 = bondlist[ii][1]; } else if (binary_search(sel_type.begin(), sel_type.end(), dtype[bondlist[ii][1]]) && - binary_search(dpl_type.begin(), dpl_type.end(), + binary_search(dpl_type_sorted.begin(), dpl_type_sorted.end(), dtype[bondlist[ii][0]])) { idx0 = bondlist[ii][1]; idx1 = bondlist[ii][0]; diff --git a/source/lmp/fix_dplr.h b/source/lmp/fix_dplr.h index 953e9ad183..9056ce8f18 100644 --- a/source/lmp/fix_dplr.h +++ b/source/lmp/fix_dplr.h @@ -58,6 +58,7 @@ class FixDPLR : public Fix { int ntypes; std::vector sel_type; std::vector dpl_type; + std::vector dpl_type_sorted; std::vector bond_type; std::map type_asso; std::map bk_type_asso; From d9adea5bd5808d813c348d95f3f757ba4dade7a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yifan=20Li=E6=9D=8E=E4=B8=80=E5=B8=86?= Date: Wed, 31 May 2023 19:02:46 -0400 Subject: [PATCH 02/18] Delete redundant dpl_type assigning --- source/lmp/fix_dplr.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index 583cd871d6..c141379ea6 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -308,11 +308,7 @@ void FixDPLR::pre_force(int vflag) { // } // } - // selected type - vector dpl_type; - for (int ii = 0; ii < sel_type.size(); ++ii) { - dpl_type.push_back(type_asso[sel_type[ii]]); - } + vector sel_fwd, sel_bwd; int sel_nghost; deepmd_compat::select_by_type(sel_fwd, sel_bwd, sel_nghost, dcoord, dtype, From f25835bf4ea168cf2a745a9a2923011e21a35bec Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 31 May 2023 23:03:45 +0000 Subject: [PATCH 03/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/lmp/fix_dplr.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index c141379ea6..feff697078 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -308,7 +308,6 @@ void FixDPLR::pre_force(int vflag) { // } // } - vector sel_fwd, sel_bwd; int sel_nghost; deepmd_compat::select_by_type(sel_fwd, sel_bwd, sel_nghost, dcoord, dtype, From 239a696ad2b1d1ed46cd8207192cb1323642c72f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yifan=20Li=E6=9D=8E=E4=B8=80=E5=B8=86?= Date: Wed, 31 May 2023 19:18:44 -0400 Subject: [PATCH 04/18] Make pppm_dplr optional in fix dplr --- source/lmp/fix_dplr.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index feff697078..2afd94d7d2 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -364,16 +364,21 @@ void FixDPLR::post_force(int vflag) { "atomic virial calculation is not supported by this fix\n"); } + int nlocal = atom->nlocal; + PPPMDPLR *pppm_dplr = (PPPMDPLR *)force->kspace_match("pppm/dplr", 1); - if (!pppm_dplr) { - error->all(FLERR, "kspace_style pppm/dplr should be set before this fix\n"); + if (pppm_dplr) { + const vector &dfele_(pppm_dplr->get_fele()); + assert(dfele_.size() == nlocal * 3); } - const vector &dfele_(pppm_dplr->get_fele()); - int nlocal = atom->nlocal; + int nghost = atom->nghost; int nall = nlocal + nghost; vector dcoord(nall * 3, 0.0), dbox(9, 0.0), dfele(nlocal * 3, 0.0); + for (int ii = 0; ii < nlocal * 3; ++ii) { + dfele.push_back(0.0); + } vector dtype(nall, 0); // set values for dcoord, dbox, dfele { @@ -394,10 +399,11 @@ void FixDPLR::post_force(int vflag) { dcoord[ii * 3 + dd] = x[ii][dd] - domain->boxlo[dd]; } } - assert(dfele_.size() == nlocal * 3); // revise force according to efield - for (int ii = 0; ii < nlocal * 3; ++ii) { - dfele[ii] = dfele_[ii]; + if (pppm_dplr) { + for (int ii = 0; ii < nlocal * 3; ++ii) { + dfele[ii] += dfele_[ii]; + } } // revise force and virial according to efield double *q = atom->q; From ce75497d60b762790401853ba2d84b3c6e203474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yifan=20Li=E6=9D=8E=E4=B8=80=E5=B8=86?= Date: Wed, 31 May 2023 19:23:26 -0400 Subject: [PATCH 05/18] Fix a bug --- source/lmp/fix_dplr.cpp | 112 +++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 58 deletions(-) diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index 2afd94d7d2..c533fb6634 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -364,14 +364,8 @@ void FixDPLR::post_force(int vflag) { "atomic virial calculation is not supported by this fix\n"); } - int nlocal = atom->nlocal; - PPPMDPLR *pppm_dplr = (PPPMDPLR *)force->kspace_match("pppm/dplr", 1); - if (pppm_dplr) { - const vector &dfele_(pppm_dplr->get_fele()); - assert(dfele_.size() == nlocal * 3); - } - + int nlocal = atom->nlocal; int nghost = atom->nghost; int nall = nlocal + nghost; vector dcoord(nall * 3, 0.0), dbox(9, 0.0), @@ -381,62 +375,64 @@ void FixDPLR::post_force(int vflag) { } vector dtype(nall, 0); // set values for dcoord, dbox, dfele - { - int *type = atom->type; - for (int ii = 0; ii < nall; ++ii) { - dtype[ii] = type[ii] - 1; + + int *type = atom->type; + for (int ii = 0; ii < nall; ++ii) { + dtype[ii] = 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 + // 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]; } - 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 - // 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]; - } + } + // revise force according to efield + if (pppm_dplr) { + const vector &dfele_(pppm_dplr->get_fele()); + assert(dfele_.size() == nlocal * 3); + for (int ii = 0; ii < nlocal * 3; ++ii) { + dfele[ii] += dfele_[ii]; + } +} + // revise force and virial according to efield + double *q = atom->q; + imageint *image = atom->image; + double unwrap[3]; + double v[6]; + efield_fsum[0] = efield_fsum[1] = efield_fsum[2] = efield_fsum[3] = 0.0; + efield_force_flag = 0; + for (int ii = 0; ii < nlocal; ++ii) { + double tmpf[3]; + for (int dd = 0; dd < 3; ++dd) { + tmpf[dd] = q[ii] * efield[dd]; } - // revise force according to efield - if (pppm_dplr) { - for (int ii = 0; ii < nlocal * 3; ++ii) { - dfele[ii] += dfele_[ii]; - } + for (int dd = 0; dd < 3; ++dd) { + dfele[ii * 3 + dd] += tmpf[dd]; } - // revise force and virial according to efield - double *q = atom->q; - imageint *image = atom->image; - double unwrap[3]; - double v[6]; - efield_fsum[0] = efield_fsum[1] = efield_fsum[2] = efield_fsum[3] = 0.0; - efield_force_flag = 0; - for (int ii = 0; ii < nlocal; ++ii) { - double tmpf[3]; - for (int dd = 0; dd < 3; ++dd) { - tmpf[dd] = q[ii] * efield[dd]; - } - for (int dd = 0; dd < 3; ++dd) { - dfele[ii * 3 + dd] += tmpf[dd]; - } - domain->unmap(x[ii], image[ii], unwrap); - efield_fsum[0] -= - tmpf[0] * unwrap[0] + tmpf[1] * unwrap[1] + tmpf[2] * unwrap[2]; - efield_fsum[1] += tmpf[0]; - efield_fsum[2] += tmpf[1]; - efield_fsum[3] += tmpf[2]; - if (evflag) { - v[0] = tmpf[0] * unwrap[0]; - v[1] = tmpf[1] * unwrap[1]; - v[2] = tmpf[2] * unwrap[2]; - v[3] = tmpf[0] * unwrap[1]; - v[4] = tmpf[0] * unwrap[2]; - v[5] = tmpf[1] * unwrap[2]; - v_tally(ii, v); - } + domain->unmap(x[ii], image[ii], unwrap); + efield_fsum[0] -= + tmpf[0] * unwrap[0] + tmpf[1] * unwrap[1] + tmpf[2] * unwrap[2]; + efield_fsum[1] += tmpf[0]; + efield_fsum[2] += tmpf[1]; + efield_fsum[3] += tmpf[2]; + if (evflag) { + v[0] = tmpf[0] * unwrap[0]; + v[1] = tmpf[1] * unwrap[1]; + v[2] = tmpf[2] * unwrap[2]; + v[3] = tmpf[0] * unwrap[1]; + v[4] = tmpf[0] * unwrap[2]; + v[5] = tmpf[1] * unwrap[2]; + v_tally(ii, v); } } + // lmp nlist NeighList *list = pair_deepmd->list; deepmd_compat::InputNlist lmp_list(list->inum, list->ilist, list->numneigh, From 6f6d316a30ce14e7477f1dfc402404bb102a1998 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 31 May 2023 23:29:00 +0000 Subject: [PATCH 06/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/lmp/fix_dplr.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index c533fb6634..b7a56f773b 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -395,12 +395,12 @@ void FixDPLR::post_force(int vflag) { } // revise force according to efield if (pppm_dplr) { - const vector &dfele_(pppm_dplr->get_fele()); - assert(dfele_.size() == nlocal * 3); - for (int ii = 0; ii < nlocal * 3; ++ii) { - dfele[ii] += dfele_[ii]; + const vector &dfele_(pppm_dplr->get_fele()); + assert(dfele_.size() == nlocal * 3); + for (int ii = 0; ii < nlocal * 3; ++ii) { + dfele[ii] += dfele_[ii]; + } } -} // revise force and virial according to efield double *q = atom->q; imageint *image = atom->image; @@ -432,7 +432,7 @@ void FixDPLR::post_force(int vflag) { v_tally(ii, v); } } - + // lmp nlist NeighList *list = pair_deepmd->list; deepmd_compat::InputNlist lmp_list(list->inum, list->ilist, list->numneigh, From 9e2dfdf1aaaba1a46a0a5da769cf5a9b98a83d0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yifan=20Li=E6=9D=8E=E4=B8=80=E5=B8=86?= Date: Wed, 31 May 2023 19:49:50 -0400 Subject: [PATCH 07/18] Do not push_back 0 for dfele --- source/lmp/fix_dplr.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index b7a56f773b..7d171f4b6b 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -370,9 +370,6 @@ void FixDPLR::post_force(int vflag) { int nall = nlocal + nghost; vector dcoord(nall * 3, 0.0), dbox(9, 0.0), dfele(nlocal * 3, 0.0); - for (int ii = 0; ii < nlocal * 3; ++ii) { - dfele.push_back(0.0); - } vector dtype(nall, 0); // set values for dcoord, dbox, dfele From 9cbc51338b9d9f4412b100d6faa85ffc5a84269c Mon Sep 17 00:00:00 2001 From: Yifan Li Date: Fri, 2 Jun 2023 11:25:41 -0400 Subject: [PATCH 08/18] directly sort dpl_type --- source/lmp/fix_dplr.cpp | 7 +++---- source/lmp/fix_dplr.h | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index feff697078..090f1478a4 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -115,8 +115,7 @@ FixDPLR::FixDPLR(LAMMPS *lmp, int narg, char **arg) for (int ii = 0; ii < sel_type.size(); ++ii) { dpl_type.push_back(type_asso[sel_type[ii]]); } - dpl_type_sorted = dpl_type; - sort(dpl_type_sorted.begin(), dpl_type_sorted.end()); + sort(dpl_type.begin(), dpl_type.end()); pair_deepmd = (PairDeepMD *)force->pair_match("deepmd", 1); if (!pair_deepmd) { @@ -194,13 +193,13 @@ void FixDPLR::get_valid_pairs(vector > &pairs) { } if (binary_search(sel_type.begin(), sel_type.end(), dtype[bondlist[ii][0]]) && - binary_search(dpl_type_sorted.begin(), dpl_type_sorted.end(), + binary_search(dpl_type.begin(), dpl_type.end(), dtype[bondlist[ii][1]])) { idx0 = bondlist[ii][0]; idx1 = bondlist[ii][1]; } else if (binary_search(sel_type.begin(), sel_type.end(), dtype[bondlist[ii][1]]) && - binary_search(dpl_type_sorted.begin(), dpl_type_sorted.end(), + binary_search(dpl_type.begin(), dpl_type.end(), dtype[bondlist[ii][0]])) { idx0 = bondlist[ii][1]; idx1 = bondlist[ii][0]; diff --git a/source/lmp/fix_dplr.h b/source/lmp/fix_dplr.h index 9056ce8f18..953e9ad183 100644 --- a/source/lmp/fix_dplr.h +++ b/source/lmp/fix_dplr.h @@ -58,7 +58,6 @@ class FixDPLR : public Fix { int ntypes; std::vector sel_type; std::vector dpl_type; - std::vector dpl_type_sorted; std::vector bond_type; std::map type_asso; std::map bk_type_asso; From f87b0c71d5aad49edf7e6e02c7c39be439265305 Mon Sep 17 00:00:00 2001 From: Yifan Li Date: Sun, 4 Jun 2023 23:14:12 -0400 Subject: [PATCH 09/18] do more rigorous type check for bonded pairs --- source/lmp/fix_dplr.cpp | 56 +++++++++++++++++++++++++---------------- source/lmp/fix_dplr.h | 1 + 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index 090f1478a4..2c9a2818fc 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -115,7 +115,6 @@ FixDPLR::FixDPLR(LAMMPS *lmp, int narg, char **arg) for (int ii = 0; ii < sel_type.size(); ++ii) { dpl_type.push_back(type_asso[sel_type[ii]]); } - sort(dpl_type.begin(), dpl_type.end()); pair_deepmd = (PairDeepMD *)force->pair_match("deepmd", 1); if (!pair_deepmd) { @@ -176,11 +175,9 @@ void FixDPLR::get_valid_pairs(vector > &pairs) { int nall = nlocal + nghost; vector dtype(nall); // get type - { - int *type = atom->type; - for (int ii = 0; ii < nall; ++ii) { - dtype[ii] = type[ii] - 1; - } + int *type = atom->type; + for (int ii = 0; ii < nall; ++ii) { + dtype[ii] = type[ii] - 1; } int **bondlist = neighbor->bondlist; @@ -191,21 +188,38 @@ void FixDPLR::get_valid_pairs(vector > &pairs) { if (!binary_search(bond_type.begin(), bond_type.end(), bd_type)) { continue; } - if (binary_search(sel_type.begin(), sel_type.end(), - dtype[bondlist[ii][0]]) && - binary_search(dpl_type.begin(), dpl_type.end(), - dtype[bondlist[ii][1]])) { - idx0 = bondlist[ii][0]; - idx1 = bondlist[ii][1]; - } else if (binary_search(sel_type.begin(), sel_type.end(), - dtype[bondlist[ii][1]]) && - binary_search(dpl_type.begin(), dpl_type.end(), - dtype[bondlist[ii][0]])) { - idx0 = bondlist[ii][1]; - idx1 = bondlist[ii][0]; - } else { - error->all(FLERR, - "find a bonded pair the types of which are not associated"); + it = find(sel_type.begin(), sel_type.end(), dtype[bondlist[ii][0]]); + if (it != sel_type.end()) { + int idx_type = distance(sel_type.begin(), it); + if (dtype[bondlist[ii][1]] == dpl_type[idx_type]) { + idx0 = bondlist[ii][0]; + idx1 = bondlist[ii][1]; + } + else { + char str[300]; + sprintf(str, "The type of virtual atom associated to atom %d is not consistent with the type you provided from \"type_associate\".\n A virtual atom of type %d is expected, but the type of atom %d is %d.\n Please check your data file carefully.\n", atom->tag[bondlist[ii][0]], dpl_type[idx_type]+1, atom->tag[bondlist[ii][1]], type[bondlist[ii][1]]); + error->all(FLERR, str); + } + } + else { + it = find(sel_type.begin(), sel_type.end(), dtype[bondlist[ii][1]]); + if (it != sel_type.end()) { + int idx_type = distance(sel_type.begin(), it); + if (dtype[bondlist[ii][0]] == dpl_type[idx_type]) { + idx0 = bondlist[ii][1]; + idx1 = bondlist[ii][0]; + } + else { + char str[300]; + sprintf(str, "The type of virtual atom associated to atom %d is not consistent with the type you provided from \"type_associate\".\n A virtual atom of type %d is expected, but the type of atom %d is %d.\n Please check your data file carefully.\n", atom->tag[bondlist[ii][1]], dpl_type[idx_type]+1, atom->tag[bondlist[ii][0]], type[bondlist[ii][0]]); + error->all(FLERR, str); + } + } + else { + char str[300]; + sprintf(str, "Atoms %d and %d are not expected to have Wannier centroids\n Please check your data file carefully.\n", atom->tag[bondlist[ii][0]], atom->tag[bondlist[ii][1]]); + error->all(FLERR, str); + } } if (!(idx0 < nlocal && idx1 < nlocal)) { error->all(FLERR, diff --git a/source/lmp/fix_dplr.h b/source/lmp/fix_dplr.h index 953e9ad183..3e1c2a7280 100644 --- a/source/lmp/fix_dplr.h +++ b/source/lmp/fix_dplr.h @@ -58,6 +58,7 @@ class FixDPLR : public Fix { int ntypes; std::vector sel_type; std::vector dpl_type; + std::vector::iterator it; std::vector bond_type; std::map type_asso; std::map bk_type_asso; From 7005f7c118935ff04a72db40c5e67198d1af2449 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 5 Jun 2023 03:14:37 +0000 Subject: [PATCH 10/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/lmp/fix_dplr.cpp | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index 2c9a2818fc..c628c87110 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -194,30 +194,43 @@ void FixDPLR::get_valid_pairs(vector > &pairs) { if (dtype[bondlist[ii][1]] == dpl_type[idx_type]) { idx0 = bondlist[ii][0]; idx1 = bondlist[ii][1]; - } - else { + } else { char str[300]; - sprintf(str, "The type of virtual atom associated to atom %d is not consistent with the type you provided from \"type_associate\".\n A virtual atom of type %d is expected, but the type of atom %d is %d.\n Please check your data file carefully.\n", atom->tag[bondlist[ii][0]], dpl_type[idx_type]+1, atom->tag[bondlist[ii][1]], type[bondlist[ii][1]]); + sprintf( + str, + "The type of virtual atom associated to atom %d is not consistent " + "with the type you provided from \"type_associate\".\n A " + "virtual atom of type %d is expected, but the type of atom %d is " + "%d.\n Please check your data file carefully.\n", + atom->tag[bondlist[ii][0]], dpl_type[idx_type] + 1, + atom->tag[bondlist[ii][1]], type[bondlist[ii][1]]); error->all(FLERR, str); } - } - else { + } else { it = find(sel_type.begin(), sel_type.end(), dtype[bondlist[ii][1]]); if (it != sel_type.end()) { int idx_type = distance(sel_type.begin(), it); if (dtype[bondlist[ii][0]] == dpl_type[idx_type]) { idx0 = bondlist[ii][1]; idx1 = bondlist[ii][0]; - } - else { + } else { char str[300]; - sprintf(str, "The type of virtual atom associated to atom %d is not consistent with the type you provided from \"type_associate\".\n A virtual atom of type %d is expected, but the type of atom %d is %d.\n Please check your data file carefully.\n", atom->tag[bondlist[ii][1]], dpl_type[idx_type]+1, atom->tag[bondlist[ii][0]], type[bondlist[ii][0]]); - error->all(FLERR, str); + sprintf(str, + "The type of virtual atom associated to atom %d is not " + "consistent with the type you provided from " + "\"type_associate\".\n A virtual atom of type %d is " + "expected, but the type of atom %d is %d.\n Please " + "check your data file carefully.\n", + atom->tag[bondlist[ii][1]], dpl_type[idx_type] + 1, + atom->tag[bondlist[ii][0]], type[bondlist[ii][0]]); + error->all(FLERR, str); } - } - else { + } else { char str[300]; - sprintf(str, "Atoms %d and %d are not expected to have Wannier centroids\n Please check your data file carefully.\n", atom->tag[bondlist[ii][0]], atom->tag[bondlist[ii][1]]); + sprintf(str, + "Atoms %d and %d are not expected to have Wannier centroids\n " + " Please check your data file carefully.\n", + atom->tag[bondlist[ii][0]], atom->tag[bondlist[ii][1]]); error->all(FLERR, str); } } From be06a848adb710eaf98a94ef1bba449574c273d9 Mon Sep 17 00:00:00 2001 From: Yifan Li Date: Sun, 4 Jun 2023 23:23:20 -0400 Subject: [PATCH 11/18] add a period in error message --- source/lmp/fix_dplr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index 2c9a2818fc..7eadbee81a 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -217,7 +217,7 @@ void FixDPLR::get_valid_pairs(vector > &pairs) { } else { char str[300]; - sprintf(str, "Atoms %d and %d are not expected to have Wannier centroids\n Please check your data file carefully.\n", atom->tag[bondlist[ii][0]], atom->tag[bondlist[ii][1]]); + sprintf(str, "Atoms %d and %d are not expected to have Wannier centroids.\n Please check your data file carefully.\n", atom->tag[bondlist[ii][0]], atom->tag[bondlist[ii][1]]); error->all(FLERR, str); } } From f7a6b843d96441b944e3feec0b5f02dd07fb609c Mon Sep 17 00:00:00 2001 From: Yifan Li Date: Sun, 4 Jun 2023 23:24:28 -0400 Subject: [PATCH 12/18] add a period in error message --- source/lmp/fix_dplr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index c628c87110..cf8f13818e 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -228,7 +228,7 @@ void FixDPLR::get_valid_pairs(vector > &pairs) { } else { char str[300]; sprintf(str, - "Atoms %d and %d are not expected to have Wannier centroids\n " + "Atoms %d and %d are not expected to have Wannier centroids.\n " " Please check your data file carefully.\n", atom->tag[bondlist[ii][0]], atom->tag[bondlist[ii][1]]); error->all(FLERR, str); From 0f00325dee26b0e5f9cb3e81e5ee56516e51f3d4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 5 Jun 2023 03:24:53 +0000 Subject: [PATCH 13/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/lmp/fix_dplr.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index cf8f13818e..46080e93f5 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -227,10 +227,11 @@ void FixDPLR::get_valid_pairs(vector > &pairs) { } } else { char str[300]; - sprintf(str, - "Atoms %d and %d are not expected to have Wannier centroids.\n " - " Please check your data file carefully.\n", - atom->tag[bondlist[ii][0]], atom->tag[bondlist[ii][1]]); + sprintf( + str, + "Atoms %d and %d are not expected to have Wannier centroids.\n " + " Please check your data file carefully.\n", + atom->tag[bondlist[ii][0]], atom->tag[bondlist[ii][1]]); error->all(FLERR, str); } } From de35136deda5dae026a5235833760d034a20f35e Mon Sep 17 00:00:00 2001 From: Yifan Li Date: Sun, 4 Jun 2023 23:37:04 -0400 Subject: [PATCH 14/18] clearer error message --- source/lmp/fix_dplr.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index cf8f13818e..19cf36851f 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -198,11 +198,9 @@ void FixDPLR::get_valid_pairs(vector > &pairs) { char str[300]; sprintf( str, - "The type of virtual atom associated to atom %d is not consistent " - "with the type you provided from \"type_associate\".\n A " - "virtual atom of type %d is expected, but the type of atom %d is " + "Invalid pair: %d %d \n A virtual atom of type %d is expected, but the type of atom %d is " "%d.\n Please check your data file carefully.\n", - atom->tag[bondlist[ii][0]], dpl_type[idx_type] + 1, + atom->tag[bondlist[ii][0]], atom->tag[bondlist[ii][1]], dpl_type[idx_type] + 1, atom->tag[bondlist[ii][1]], type[bondlist[ii][1]]); error->all(FLERR, str); } @@ -216,20 +214,17 @@ void FixDPLR::get_valid_pairs(vector > &pairs) { } else { char str[300]; sprintf(str, - "The type of virtual atom associated to atom %d is not " - "consistent with the type you provided from " - "\"type_associate\".\n A virtual atom of type %d is " + "Invalid pair: %d %d \n A virtual atom of type %d is " "expected, but the type of atom %d is %d.\n Please " "check your data file carefully.\n", - atom->tag[bondlist[ii][1]], dpl_type[idx_type] + 1, + atom->tag[bondlist[ii][0]], atom->tag[bondlist[ii][1]], dpl_type[idx_type] + 1, atom->tag[bondlist[ii][0]], type[bondlist[ii][0]]); error->all(FLERR, str); } } else { char str[300]; sprintf(str, - "Atoms %d and %d are not expected to have Wannier centroids.\n " - " Please check your data file carefully.\n", + "Invalid pair: %d %d \n They are not expected to have Wannier centroid.\n Please check your data file carefully.\n", atom->tag[bondlist[ii][0]], atom->tag[bondlist[ii][1]]); error->all(FLERR, str); } From eae05dfe4e462131e0ed420594029f501366fce2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 5 Jun 2023 03:38:20 +0000 Subject: [PATCH 15/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/lmp/fix_dplr.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index 19cf36851f..df4355613f 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -196,12 +196,13 @@ void FixDPLR::get_valid_pairs(vector > &pairs) { idx1 = bondlist[ii][1]; } else { char str[300]; - sprintf( - str, - "Invalid pair: %d %d \n A virtual atom of type %d is expected, but the type of atom %d is " - "%d.\n Please check your data file carefully.\n", - atom->tag[bondlist[ii][0]], atom->tag[bondlist[ii][1]], dpl_type[idx_type] + 1, - atom->tag[bondlist[ii][1]], type[bondlist[ii][1]]); + sprintf(str, + "Invalid pair: %d %d \n A virtual atom of type %d is " + "expected, but the type of atom %d is " + "%d.\n Please check your data file carefully.\n", + atom->tag[bondlist[ii][0]], atom->tag[bondlist[ii][1]], + dpl_type[idx_type] + 1, atom->tag[bondlist[ii][1]], + type[bondlist[ii][1]]); error->all(FLERR, str); } } else { @@ -217,14 +218,17 @@ void FixDPLR::get_valid_pairs(vector > &pairs) { "Invalid pair: %d %d \n A virtual atom of type %d is " "expected, but the type of atom %d is %d.\n Please " "check your data file carefully.\n", - atom->tag[bondlist[ii][0]], atom->tag[bondlist[ii][1]], dpl_type[idx_type] + 1, - atom->tag[bondlist[ii][0]], type[bondlist[ii][0]]); + atom->tag[bondlist[ii][0]], atom->tag[bondlist[ii][1]], + dpl_type[idx_type] + 1, atom->tag[bondlist[ii][0]], + type[bondlist[ii][0]]); error->all(FLERR, str); } } else { char str[300]; sprintf(str, - "Invalid pair: %d %d \n They are not expected to have Wannier centroid.\n Please check your data file carefully.\n", + "Invalid pair: %d %d \n They are not expected to have " + "Wannier centroid.\n Please check your data file " + "carefully.\n", atom->tag[bondlist[ii][0]], atom->tag[bondlist[ii][1]]); error->all(FLERR, str); } From a7639dd2f13f5dddf3e25f4faab65bd7005313f0 Mon Sep 17 00:00:00 2001 From: Yifan Li Date: Sun, 4 Jun 2023 23:49:03 -0400 Subject: [PATCH 16/18] declare iterator it in get_valid_pairs --- source/lmp/fix_dplr.cpp | 2 +- source/lmp/fix_dplr.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index df4355613f..790766ccf0 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -188,7 +188,7 @@ void FixDPLR::get_valid_pairs(vector > &pairs) { if (!binary_search(bond_type.begin(), bond_type.end(), bd_type)) { continue; } - it = find(sel_type.begin(), sel_type.end(), dtype[bondlist[ii][0]]); + std::vector::iterator it = find(sel_type.begin(), sel_type.end(), dtype[bondlist[ii][0]]); if (it != sel_type.end()) { int idx_type = distance(sel_type.begin(), it); if (dtype[bondlist[ii][1]] == dpl_type[idx_type]) { diff --git a/source/lmp/fix_dplr.h b/source/lmp/fix_dplr.h index 3e1c2a7280..953e9ad183 100644 --- a/source/lmp/fix_dplr.h +++ b/source/lmp/fix_dplr.h @@ -58,7 +58,6 @@ class FixDPLR : public Fix { int ntypes; std::vector sel_type; std::vector dpl_type; - std::vector::iterator it; std::vector bond_type; std::map type_asso; std::map bk_type_asso; From ff1de5593987315910614597df51695db84953be Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 5 Jun 2023 03:49:34 +0000 Subject: [PATCH 17/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/lmp/fix_dplr.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index 790766ccf0..f79b39ea70 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -188,7 +188,8 @@ void FixDPLR::get_valid_pairs(vector > &pairs) { if (!binary_search(bond_type.begin(), bond_type.end(), bd_type)) { continue; } - std::vector::iterator it = find(sel_type.begin(), sel_type.end(), dtype[bondlist[ii][0]]); + std::vector::iterator it = + find(sel_type.begin(), sel_type.end(), dtype[bondlist[ii][0]]); if (it != sel_type.end()) { int idx_type = distance(sel_type.begin(), it); if (dtype[bondlist[ii][1]] == dpl_type[idx_type]) { From 8c0342b0c248cd9cdf66a7a414b0cf9f4e53309e Mon Sep 17 00:00:00 2001 From: Yifan Li Date: Mon, 5 Jun 2023 00:24:24 -0400 Subject: [PATCH 18/18] revert indention --- source/lmp/fix_dplr.cpp | 106 ++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index 4fa08cfe92..8ee0344d5c 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -398,64 +398,64 @@ void FixDPLR::post_force(int vflag) { dfele(nlocal * 3, 0.0); vector dtype(nall, 0); // set values for dcoord, dbox, dfele - - int *type = atom->type; - for (int ii = 0; ii < nall; ++ii) { - dtype[ii] = 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 - // 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]; - } - } - // revise force according to efield - if (pppm_dplr) { - const vector &dfele_(pppm_dplr->get_fele()); - assert(dfele_.size() == nlocal * 3); - for (int ii = 0; ii < nlocal * 3; ++ii) { - dfele[ii] += dfele_[ii]; + { + int *type = atom->type; + for (int ii = 0; ii < nall; ++ii) { + dtype[ii] = type[ii] - 1; } - } - // revise force and virial according to efield - double *q = atom->q; - imageint *image = atom->image; - double unwrap[3]; - double v[6]; - efield_fsum[0] = efield_fsum[1] = efield_fsum[2] = efield_fsum[3] = 0.0; - efield_force_flag = 0; - for (int ii = 0; ii < nlocal; ++ii) { - double tmpf[3]; - for (int dd = 0; dd < 3; ++dd) { - tmpf[dd] = q[ii] * efield[dd]; + 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 + // 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]; + } } - for (int dd = 0; dd < 3; ++dd) { - dfele[ii * 3 + dd] += tmpf[dd]; + // revise force according to efield + if (pppm_dplr) { + const vector &dfele_(pppm_dplr->get_fele()); + assert(dfele_.size() == nlocal * 3); + for (int ii = 0; ii < nlocal * 3; ++ii) { + dfele[ii] += dfele_[ii]; + } } - domain->unmap(x[ii], image[ii], unwrap); - efield_fsum[0] -= - tmpf[0] * unwrap[0] + tmpf[1] * unwrap[1] + tmpf[2] * unwrap[2]; - efield_fsum[1] += tmpf[0]; - efield_fsum[2] += tmpf[1]; - efield_fsum[3] += tmpf[2]; - if (evflag) { - v[0] = tmpf[0] * unwrap[0]; - v[1] = tmpf[1] * unwrap[1]; - v[2] = tmpf[2] * unwrap[2]; - v[3] = tmpf[0] * unwrap[1]; - v[4] = tmpf[0] * unwrap[2]; - v[5] = tmpf[1] * unwrap[2]; - v_tally(ii, v); + // revise force and virial according to efield + double *q = atom->q; + imageint *image = atom->image; + double unwrap[3]; + double v[6]; + efield_fsum[0] = efield_fsum[1] = efield_fsum[2] = efield_fsum[3] = 0.0; + efield_force_flag = 0; + for (int ii = 0; ii < nlocal; ++ii) { + double tmpf[3]; + for (int dd = 0; dd < 3; ++dd) { + tmpf[dd] = q[ii] * efield[dd]; + } + for (int dd = 0; dd < 3; ++dd) { + dfele[ii * 3 + dd] += tmpf[dd]; + } + domain->unmap(x[ii], image[ii], unwrap); + efield_fsum[0] -= + tmpf[0] * unwrap[0] + tmpf[1] * unwrap[1] + tmpf[2] * unwrap[2]; + efield_fsum[1] += tmpf[0]; + efield_fsum[2] += tmpf[1]; + efield_fsum[3] += tmpf[2]; + if (evflag) { + v[0] = tmpf[0] * unwrap[0]; + v[1] = tmpf[1] * unwrap[1]; + v[2] = tmpf[2] * unwrap[2]; + v[3] = tmpf[0] * unwrap[1]; + v[4] = tmpf[0] * unwrap[2]; + v[5] = tmpf[1] * unwrap[2]; + v_tally(ii, v); + } } } - // lmp nlist NeighList *list = pair_deepmd->list; deepmd_compat::InputNlist lmp_list(list->inum, list->ilist, list->numneigh,