From e3917fcdce6c47da9c7275bde7e0483489ceb578 Mon Sep 17 00:00:00 2001 From: mingzhong15 Date: Wed, 4 May 2022 12:40:14 +0800 Subject: [PATCH 1/9] add compute_fparam --- source/lmp/pair_deepmd.cpp | 242 +++++++++++++++++++----------------- source/lmp/pair_deepmd.h.in | 24 +++- 2 files changed, 151 insertions(+), 115 deletions(-) diff --git a/source/lmp/pair_deepmd.cpp b/source/lmp/pair_deepmd.cpp index b9793ff7f9..8424c0bc01 100644 --- a/source/lmp/pair_deepmd.cpp +++ b/source/lmp/pair_deepmd.cpp @@ -6,6 +6,7 @@ #include "domain.h" #include "comm.h" #include "force.h" +#include "compute.h" #include "memory.h" #include "update.h" #include "output.h" @@ -20,6 +21,8 @@ #include "fix_ttm_mod.h" #endif +#include "compute.h" + #include "pair_deepmd.h" using namespace LAMMPS_NS; @@ -176,6 +179,83 @@ make_uniform_aparam( } } + +oid PairDeepMD::make_compute_fparam( +#ifdef HIGH_PREC + vector & fparam +#else + vector & fparam +#endif +) +{ + assert(do_compute); + + int icompute = modify->find_compute(compute_id); + Compute *compute = modify->compute[icompute]; + + assert(compute); + fparam.resize(dim_fparam); + + if (dim_fparam == 1){ + compute->compute_scalar(); + fparam[0] = compute->scalar; + } + else if (dim_fparam >1){ + compute->compute_vector(); + double *cvector = compute->vector; + for (int jj = 0; jj < dim_aparam; ++jj){ + fparam[jj] =cvector[jj]; + } + } + +} + +#ifdef USE_TTM +void PairDeepMD::make_ttm_fparam( +#ifdef HIGH_PREC + vector & fparam +#else + vector & fparam +#endif + ) +{ + assert(do_ttm); + // get ttm_fix + const FixTTMMod * ttm_fix = NULL; + for (int ii = 0; ii < modify->nfix; ii++) { + if (string(modify->fix[ii]->id) == ttm_fix_id){ + ttm_fix = dynamic_cast(modify->fix[ii]); + } + } + assert(ttm_fix); + + fparam.resize(dim_fparam); + + vector nnodes = ttm_fix->get_nodes(); + int nxnodes = nnodes[0]; + int nynodes = nnodes[1]; + int nznodes = nnodes[2]; + double *** const T_electron = ttm_fix->get_T_electron(); + + int numb_effective_nodes = 0; + double total_Te = 0; + + // loop over grids to get average electron temperature + for (int ixnode = 0; ixnode < nxnodes; ixnode++) + for (int iynode = 0; iynode < nynodes; iynode++) + for (int iznode = 0; iznode < nznodes; iznode++) + { + if (T_electron[ixnode][iynode][iznode] != 0) + { + numb_effective_nodes += 1; + total_Te += T_electron[ixnode][iynode][iznode]; + } + } + + fparam[0] = total_Te/numb_effective_nodes; +} +#endif + #ifdef USE_TTM void PairDeepMD::make_ttm_aparam( #ifdef HIGH_PREC @@ -238,11 +318,6 @@ PairDeepMD::PairDeepMD(LAMMPS *lmp) error->all(FLERR,"Pair deepmd requires metal unit, please set it by \"units metal\""); } restartinfo = 1; -#if LAMMPS_VERSION_NUMBER>=20201130 - centroidstressflag = CENTROID_AVAIL ; // set centroidstressflag = CENTROID_AVAIL to allow the use of the centroid/stress/atom. Added by Davide Tisi -#else - centroidstressflag = 2 ; // set centroidstressflag = 2 to allow the use of the centroid/stress/atom. Added by Davide Tisi -#endif pppmflag = 1; respa_enable = 0; writedata = 0; @@ -271,12 +346,6 @@ void PairDeepMD::print_summary(const string pre) const { if (comm->me == 0){ - // capture cout to a string, then call LAMMPS's utils::logmesg - // https://stackoverflow.com/a/4043813/9567349 - std::stringstream buffer; - std::streambuf *sbuf = std::cout.rdbuf(); - std::cout.rdbuf(buffer.rdbuf()); - cout << "Summary of lammps deepmd module ..." << endl; cout << pre << ">>> Info of deepmd-kit:" << endl; deep_pot.print_summary(pre); @@ -289,9 +358,6 @@ PairDeepMD::print_summary(const string pre) const cout << pre << "build float prec: " << STR_FLOAT_PREC << endl; cout << pre << "build with tf inc: " << STR_TensorFlow_INCLUDE_DIRS << endl; cout << pre << "build with tf lib: " << STR_TensorFlow_LIBRARY << endl; - - std::cout.rdbuf(sbuf); - utils::logmesg(lmp, buffer.str()); } } @@ -359,10 +425,13 @@ void PairDeepMD::compute(int eflag, int vflag) } else if (do_ttm) { #ifdef USE_TTM - make_ttm_aparam(daparam); + //make_ttm_aparam(daparam); + make_ttm_fparam(fparam); #endif } - + if (do_compute){ + make_compute_fparam(fparam); + } // int ago = numb_models > 1 ? 0 : neighbor->ago; int ago = neighbor->ago; if (numb_models > 1) { @@ -380,14 +449,9 @@ void PairDeepMD::compute(int eflag, int vflag) if (do_ghost) { deepmd::InputNlist lmp_list (list->inum, list->ilist, list->numneigh, list->firstneigh); if (single_model || multi_models_no_mod_devi) { - //cvflag_atom is the right flag for the cvatom matrix - if ( ! (eflag_atom || cvflag_atom) ) { + if ( ! (eflag_atom || vflag_atom) ) { #ifdef HIGH_PREC - try { deep_pot.compute (dener, dforce, dvirial, dcoord, dtype, dbox, nghost, lmp_list, ago, fparam, daparam); - } catch(deepmd::deepmd_exception& e) { - error->all(FLERR, e.what()); - } #else vector dcoord_(dcoord.size()); vector dbox_(dbox.size()); @@ -396,11 +460,7 @@ void PairDeepMD::compute(int eflag, int vflag) vector dforce_(dforce.size(), 0); vector dvirial_(dvirial.size(), 0); double dener_ = 0; - try { deep_pot.compute (dener_, dforce_, dvirial_, dcoord_, dtype, dbox_, nghost, lmp_list, ago, fparam, daparam); - } catch(deepmd::deepmd_exception& e) { - error->all(FLERR, e.what()); - } for (unsigned dd = 0; dd < dforce.size(); ++dd) dforce[dd] = dforce_[dd]; for (unsigned dd = 0; dd < dvirial.size(); ++dd) dvirial[dd] = dvirial_[dd]; dener = dener_; @@ -422,11 +482,7 @@ void PairDeepMD::compute(int eflag, int vflag) vector deatom_(dforce.size(), 0); vector dvatom_(dforce.size(), 0); double dener_ = 0; - try { deep_pot.compute (dener_, dforce_, dvirial_, deatom_, dvatom_, dcoord_, dtype, dbox_, nghost, lmp_list, ago, fparam, daparam); - } catch(deepmd::deepmd_exception& e) { - error->all(FLERR, e.what()); - } for (unsigned dd = 0; dd < dforce.size(); ++dd) dforce[dd] = dforce_[dd]; for (unsigned dd = 0; dd < dvirial.size(); ++dd) dvirial[dd] = dvirial_[dd]; for (unsigned dd = 0; dd < deatom.size(); ++dd) deatom[dd] = deatom_[dd]; @@ -436,26 +492,14 @@ void PairDeepMD::compute(int eflag, int vflag) if (eflag_atom) { for (int ii = 0; ii < nlocal; ++ii) eatom[ii] += deatom[ii]; } - // Added by Davide Tisi 2020 - // interface the atomic virial computed by DeepMD - // with the one used in centroid atoms - if (cvflag_atom) { + if (vflag_atom) { for (int ii = 0; ii < nall; ++ii){ - //vatom[ii][0] += 1.0 * dvatom[9*ii+0]; - //vatom[ii][1] += 1.0 * dvatom[9*ii+4]; - //vatom[ii][2] += 1.0 * dvatom[9*ii+8]; - //vatom[ii][3] += 1.0 * dvatom[9*ii+3]; - //vatom[ii][4] += 1.0 * dvatom[9*ii+6]; - //vatom[ii][5] += 1.0 * dvatom[9*ii+7]; - cvatom[ii][0] += -1.0 * dvatom[9*ii+0]; // xx - cvatom[ii][1] += -1.0 * dvatom[9*ii+4]; // yy - cvatom[ii][2] += -1.0 * dvatom[9*ii+8]; // zz - cvatom[ii][3] += -1.0 * dvatom[9*ii+3]; // xy - cvatom[ii][4] += -1.0 * dvatom[9*ii+6]; // xz - cvatom[ii][5] += -1.0 * dvatom[9*ii+7]; // yz - cvatom[ii][6] += -1.0 * dvatom[9*ii+1]; // yx - cvatom[ii][7] += -1.0 * dvatom[9*ii+2]; // zx - cvatom[ii][8] += -1.0 * dvatom[9*ii+5]; // zy + vatom[ii][0] += 1.0 * dvatom[9*ii+0]; + vatom[ii][1] += 1.0 * dvatom[9*ii+4]; + vatom[ii][2] += 1.0 * dvatom[9*ii+8]; + vatom[ii][3] += 1.0 * dvatom[9*ii+3]; + vatom[ii][4] += 1.0 * dvatom[9*ii+6]; + vatom[ii][5] += 1.0 * dvatom[9*ii+7]; } } } @@ -468,11 +512,7 @@ void PairDeepMD::compute(int eflag, int vflag) vector all_energy; vector> all_atom_energy; vector> all_atom_virial; - try { deep_pot_model_devi.compute(all_energy, all_force, all_virial, all_atom_energy, all_atom_virial, dcoord, dtype, dbox, nghost, lmp_list, ago, fparam, daparam); - } catch(deepmd::deepmd_exception& e) { - error->all(FLERR, e.what()); - } // deep_pot_model_devi.compute_avg (dener, all_energy); // deep_pot_model_devi.compute_avg (dforce, all_force); // deep_pot_model_devi.compute_avg (dvirial, all_virial); @@ -498,11 +538,7 @@ void PairDeepMD::compute(int eflag, int vflag) vector> all_virial_; vector> all_atom_energy_; vector> all_atom_virial_; - try { deep_pot_model_devi.compute(all_energy_, all_force_, all_virial_, all_atom_energy_, all_atom_virial_, dcoord_, dtype, dbox_, nghost, lmp_list, ago, fparam, daparam); - } catch(deepmd::deepmd_exception& e) { - error->all(FLERR, e.what()); - } // deep_pot_model_devi.compute_avg (dener_, all_energy_); // deep_pot_model_devi.compute_avg (dforce_, all_force_); // deep_pot_model_devi.compute_avg (dvirial_, all_virial_); @@ -525,48 +561,25 @@ void PairDeepMD::compute(int eflag, int vflag) all_force[ii][jj] = all_force_[ii][jj]; } } - all_virial.resize(all_virial_.size()); - for (unsigned ii = 0; ii < all_virial_.size(); ++ii){ - all_virial[ii].resize(all_virial_[ii].size()); - for (unsigned jj = 0; jj < all_virial_[ii].size(); ++jj){ - all_virial[ii][jj] = all_virial_[ii][jj]; - } - } #endif if (eflag_atom) { for (int ii = 0; ii < nlocal; ++ii) eatom[ii] += deatom[ii]; } - // Added by Davide Tisi 2020 - // interface the atomic virial computed by DeepMD - // with the one used in centroid atoms - if (cvflag_atom) { + if (vflag_atom) { for (int ii = 0; ii < nall; ++ii){ - //vatom[ii][0] += 1.0 * dvatom[9*ii+0]; - //vatom[ii][1] += 1.0 * dvatom[9*ii+4]; - //vatom[ii][2] += 1.0 * dvatom[9*ii+8]; - //vatom[ii][3] += 1.0 * dvatom[9*ii+3]; - //vatom[ii][4] += 1.0 * dvatom[9*ii+6]; - //vatom[ii][5] += 1.0 * dvatom[9*ii+7]; - cvatom[ii][0] += -1.0 * dvatom[9*ii+0]; // xx - cvatom[ii][1] += -1.0 * dvatom[9*ii+4]; // yy - cvatom[ii][2] += -1.0 * dvatom[9*ii+8]; // zz - cvatom[ii][3] += -1.0 * dvatom[9*ii+3]; // xy - cvatom[ii][4] += -1.0 * dvatom[9*ii+6]; // xz - cvatom[ii][5] += -1.0 * dvatom[9*ii+7]; // yz - cvatom[ii][6] += -1.0 * dvatom[9*ii+1]; // yx - cvatom[ii][7] += -1.0 * dvatom[9*ii+2]; // zx - cvatom[ii][8] += -1.0 * dvatom[9*ii+5]; // zy + vatom[ii][0] += 1.0 * dvatom[9*ii+0]; + vatom[ii][1] += 1.0 * dvatom[9*ii+4]; + vatom[ii][2] += 1.0 * dvatom[9*ii+8]; + vatom[ii][3] += 1.0 * dvatom[9*ii+3]; + vatom[ii][4] += 1.0 * dvatom[9*ii+6]; + vatom[ii][5] += 1.0 * dvatom[9*ii+7]; } } if (out_freq > 0 && update->ntimestep % out_freq == 0) { int rank = comm->me; // std force if (newton_pair) { -#if LAMMPS_VERSION_NUMBER>=20220324 - comm->reverse_comm(this); -#else - comm->reverse_comm_pair(this); -#endif + comm->reverse_comm_pair(this); } vector std_f; #ifdef HIGH_PREC @@ -716,11 +729,7 @@ void PairDeepMD::compute(int eflag, int vflag) else { if (numb_models == 1) { #ifdef HIGH_PREC - try { deep_pot.compute (dener, dforce, dvirial, dcoord, dtype, dbox); - } catch(deepmd::deepmd_exception& e) { - error->all(FLERR, e.what()); - } #else vector dcoord_(dcoord.size()); vector dbox_(dbox.size()); @@ -729,11 +738,7 @@ void PairDeepMD::compute(int eflag, int vflag) vector dforce_(dforce.size(), 0); vector dvirial_(dvirial.size(), 0); double dener_ = 0; - try { deep_pot.compute (dener_, dforce_, dvirial_, dcoord_, dtype, dbox_); - } catch(deepmd::deepmd_exception& e) { - error->all(FLERR, e.what()); - } for (unsigned dd = 0; dd < dforce.size(); ++dd) dforce[dd] = dforce_[dd]; for (unsigned dd = 0; dd < dvirial.size(); ++dd) dvirial[dd] = dvirial_[dd]; dener = dener_; @@ -798,6 +803,7 @@ is_key (const string& input) keys.push_back("out_file"); keys.push_back("fparam"); keys.push_back("aparam"); + keys.push_back("compute"); keys.push_back("ttm"); keys.push_back("atomic"); keys.push_back("relative"); @@ -829,23 +835,15 @@ void PairDeepMD::settings(int narg, char **arg) } numb_models = models.size(); if (numb_models == 1) { - try { deep_pot.init (arg[0], get_node_rank(), get_file_content(arg[0])); - } catch(deepmd::deepmd_exception& e) { - error->all(FLERR, e.what()); - } cutoff = deep_pot.cutoff (); numb_types = deep_pot.numb_types(); dim_fparam = deep_pot.dim_fparam(); dim_aparam = deep_pot.dim_aparam(); } else { - try { deep_pot.init (arg[0], get_node_rank(), get_file_content(arg[0])); deep_pot_model_devi.init(models, get_node_rank(), get_file_content(models)); - } catch(deepmd::deepmd_exception& e) { - error->all(FLERR, e.what()); - } cutoff = deep_pot_model_devi.cutoff(); numb_types = deep_pot_model_devi.numb_types(); dim_fparam = deep_pot_model_devi.dim_fparam(); @@ -888,6 +886,7 @@ void PairDeepMD::settings(int narg, char **arg) } iarg += 1 + dim_fparam ; } + else if (string(arg[iarg]) == string("aparam")) { for (int ii = 0; ii < dim_aparam; ++ii){ if (iarg+1+ii >= narg || is_key(arg[iarg+1+ii])) { @@ -913,6 +912,20 @@ void PairDeepMD::settings(int narg, char **arg) error->all(FLERR, "The deepmd-kit was compiled without support for TTM, please rebuild it with -DUSE_TTM"); #endif } + /////////////////////////////////////////////// + // pair_style deepmd cp.pb compute TEMP + // compute TEMP all temp + ////////////////////////////////////////////// + else if (string(arg[iarg]) == string("compute")) { + for (int ii = 0; ii < 1; ++ii){ + if (iarg+1+ii >= narg || is_key(arg[iarg+1+ii])) { + error->all(FLERR, "invalid compute key: should be compute compute_id(str)"); + } + } + do_compute = true; + compute_id = arg[iarg+1]; + iarg += 1 + 1; + } else if (string(arg[iarg]) == string("atomic")) { out_each = 1; iarg += 1; @@ -940,7 +953,10 @@ void PairDeepMD::settings(int narg, char **arg) if (do_ttm && aparam.size() > 0) { error->all(FLERR,"aparam and ttm should NOT be set simultaneously"); } - + if (do_compute && fparam.size() > 0) { + error->all(FLERR,"fparam and compute should NOT be set simultaneously"); + } + if (comm->me == 0){ if (numb_models > 1 && out_freq > 0){ if (!is_restart) { @@ -974,13 +990,17 @@ void PairDeepMD::settings(int narg, char **arg) cout << endl << pre << "rcut in model: " << cutoff << endl << pre << "ntypes in model: " << numb_types << endl; - if (dim_fparam > 0) { + if (dim_fparam > 0 && do_compute ==0 && do_ttm ==0) { cout << pre << "using fparam(s): " ; for (int ii = 0; ii < dim_fparam; ++ii){ cout << fparam[ii] << " " ; } cout << endl; } + if (do_compute){ + cout << pre << "using compute compute: " ; + cout << compute_id << " " << endl; + } if (aparam.size() > 0) { cout << pre << "using aparam(s): " ; for (int ii = 0; ii < aparam.size(); ++ii){ @@ -988,6 +1008,10 @@ void PairDeepMD::settings(int narg, char **arg) } cout << endl; } + if (do_ttm){ + cout << pre << "using ttm fix: " ; + cout << ttm_fix_id << " " << endl; + } } comm_reverse = numb_models * 3; @@ -1043,14 +1067,10 @@ void PairDeepMD::coeff(int narg, char **arg) void PairDeepMD::init_style() { -#if LAMMPS_VERSION_NUMBER>=20220324 - neighbor->add_request(this, NeighConst::REQ_FULL); -#else int irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->half = 0; - neighbor->requests[irequest]->full = 1; + // neighbor->requests[irequest]->full = 1; // neighbor->requests[irequest]->newton = 2; -#endif if (out_each == 1){ int ntotal = atom->natoms; int nprocs = comm->nprocs; diff --git a/source/lmp/pair_deepmd.h.in b/source/lmp/pair_deepmd.h.in index 6c2373e114..f20153a02f 100644 --- a/source/lmp/pair_deepmd.h.in +++ b/source/lmp/pair_deepmd.h.in @@ -8,11 +8,7 @@ PairStyle(deepmd,PairDeepMD) #define LMP_PAIR_NNP_H #include "pair.h" -#ifdef LMPPLUGIN -#include "DeepPot.h" -#else #include "deepmd/DeepPot.h" -#endif #include #include @@ -93,6 +89,17 @@ private: float eps; float eps_v; #endif + + void make_compute_fparam( +#ifdef HIGH_PREC + std::vector & fparam +#else + std::vector & fparam +#endif + ); + bool do_compute; + std::string compute_id; + void make_ttm_aparam( #ifdef HIGH_PREC std::vector & dparam @@ -100,6 +107,15 @@ private: std::vector & dparam #endif ); + + void make_ttm_fparam( +#ifdef HIGH_PREC + std::vector & fparam +#else + std::vector & fparam +#endif + ); + bool do_ttm; std::string ttm_fix_id; int *counts,*displacements; From cf177ab163b23ab27237e9de4d09a3c8c118cf79 Mon Sep 17 00:00:00 2001 From: mingzhong15 Date: Wed, 4 May 2022 16:38:55 +0800 Subject: [PATCH 2/9] Revert "add compute_fparam" This reverts commit e3917fcdce6c47da9c7275bde7e0483489ceb578. --- source/lmp/pair_deepmd.cpp | 242 +++++++++++++++++------------------- source/lmp/pair_deepmd.h.in | 24 +--- 2 files changed, 115 insertions(+), 151 deletions(-) diff --git a/source/lmp/pair_deepmd.cpp b/source/lmp/pair_deepmd.cpp index 8424c0bc01..b9793ff7f9 100644 --- a/source/lmp/pair_deepmd.cpp +++ b/source/lmp/pair_deepmd.cpp @@ -6,7 +6,6 @@ #include "domain.h" #include "comm.h" #include "force.h" -#include "compute.h" #include "memory.h" #include "update.h" #include "output.h" @@ -21,8 +20,6 @@ #include "fix_ttm_mod.h" #endif -#include "compute.h" - #include "pair_deepmd.h" using namespace LAMMPS_NS; @@ -179,83 +176,6 @@ make_uniform_aparam( } } - -oid PairDeepMD::make_compute_fparam( -#ifdef HIGH_PREC - vector & fparam -#else - vector & fparam -#endif -) -{ - assert(do_compute); - - int icompute = modify->find_compute(compute_id); - Compute *compute = modify->compute[icompute]; - - assert(compute); - fparam.resize(dim_fparam); - - if (dim_fparam == 1){ - compute->compute_scalar(); - fparam[0] = compute->scalar; - } - else if (dim_fparam >1){ - compute->compute_vector(); - double *cvector = compute->vector; - for (int jj = 0; jj < dim_aparam; ++jj){ - fparam[jj] =cvector[jj]; - } - } - -} - -#ifdef USE_TTM -void PairDeepMD::make_ttm_fparam( -#ifdef HIGH_PREC - vector & fparam -#else - vector & fparam -#endif - ) -{ - assert(do_ttm); - // get ttm_fix - const FixTTMMod * ttm_fix = NULL; - for (int ii = 0; ii < modify->nfix; ii++) { - if (string(modify->fix[ii]->id) == ttm_fix_id){ - ttm_fix = dynamic_cast(modify->fix[ii]); - } - } - assert(ttm_fix); - - fparam.resize(dim_fparam); - - vector nnodes = ttm_fix->get_nodes(); - int nxnodes = nnodes[0]; - int nynodes = nnodes[1]; - int nznodes = nnodes[2]; - double *** const T_electron = ttm_fix->get_T_electron(); - - int numb_effective_nodes = 0; - double total_Te = 0; - - // loop over grids to get average electron temperature - for (int ixnode = 0; ixnode < nxnodes; ixnode++) - for (int iynode = 0; iynode < nynodes; iynode++) - for (int iznode = 0; iznode < nznodes; iznode++) - { - if (T_electron[ixnode][iynode][iznode] != 0) - { - numb_effective_nodes += 1; - total_Te += T_electron[ixnode][iynode][iznode]; - } - } - - fparam[0] = total_Te/numb_effective_nodes; -} -#endif - #ifdef USE_TTM void PairDeepMD::make_ttm_aparam( #ifdef HIGH_PREC @@ -318,6 +238,11 @@ PairDeepMD::PairDeepMD(LAMMPS *lmp) error->all(FLERR,"Pair deepmd requires metal unit, please set it by \"units metal\""); } restartinfo = 1; +#if LAMMPS_VERSION_NUMBER>=20201130 + centroidstressflag = CENTROID_AVAIL ; // set centroidstressflag = CENTROID_AVAIL to allow the use of the centroid/stress/atom. Added by Davide Tisi +#else + centroidstressflag = 2 ; // set centroidstressflag = 2 to allow the use of the centroid/stress/atom. Added by Davide Tisi +#endif pppmflag = 1; respa_enable = 0; writedata = 0; @@ -346,6 +271,12 @@ void PairDeepMD::print_summary(const string pre) const { if (comm->me == 0){ + // capture cout to a string, then call LAMMPS's utils::logmesg + // https://stackoverflow.com/a/4043813/9567349 + std::stringstream buffer; + std::streambuf *sbuf = std::cout.rdbuf(); + std::cout.rdbuf(buffer.rdbuf()); + cout << "Summary of lammps deepmd module ..." << endl; cout << pre << ">>> Info of deepmd-kit:" << endl; deep_pot.print_summary(pre); @@ -358,6 +289,9 @@ PairDeepMD::print_summary(const string pre) const cout << pre << "build float prec: " << STR_FLOAT_PREC << endl; cout << pre << "build with tf inc: " << STR_TensorFlow_INCLUDE_DIRS << endl; cout << pre << "build with tf lib: " << STR_TensorFlow_LIBRARY << endl; + + std::cout.rdbuf(sbuf); + utils::logmesg(lmp, buffer.str()); } } @@ -425,13 +359,10 @@ void PairDeepMD::compute(int eflag, int vflag) } else if (do_ttm) { #ifdef USE_TTM - //make_ttm_aparam(daparam); - make_ttm_fparam(fparam); + make_ttm_aparam(daparam); #endif } - if (do_compute){ - make_compute_fparam(fparam); - } + // int ago = numb_models > 1 ? 0 : neighbor->ago; int ago = neighbor->ago; if (numb_models > 1) { @@ -449,9 +380,14 @@ void PairDeepMD::compute(int eflag, int vflag) if (do_ghost) { deepmd::InputNlist lmp_list (list->inum, list->ilist, list->numneigh, list->firstneigh); if (single_model || multi_models_no_mod_devi) { - if ( ! (eflag_atom || vflag_atom) ) { + //cvflag_atom is the right flag for the cvatom matrix + if ( ! (eflag_atom || cvflag_atom) ) { #ifdef HIGH_PREC + try { deep_pot.compute (dener, dforce, dvirial, dcoord, dtype, dbox, nghost, lmp_list, ago, fparam, daparam); + } catch(deepmd::deepmd_exception& e) { + error->all(FLERR, e.what()); + } #else vector dcoord_(dcoord.size()); vector dbox_(dbox.size()); @@ -460,7 +396,11 @@ void PairDeepMD::compute(int eflag, int vflag) vector dforce_(dforce.size(), 0); vector dvirial_(dvirial.size(), 0); double dener_ = 0; + try { deep_pot.compute (dener_, dforce_, dvirial_, dcoord_, dtype, dbox_, nghost, lmp_list, ago, fparam, daparam); + } catch(deepmd::deepmd_exception& e) { + error->all(FLERR, e.what()); + } for (unsigned dd = 0; dd < dforce.size(); ++dd) dforce[dd] = dforce_[dd]; for (unsigned dd = 0; dd < dvirial.size(); ++dd) dvirial[dd] = dvirial_[dd]; dener = dener_; @@ -482,7 +422,11 @@ void PairDeepMD::compute(int eflag, int vflag) vector deatom_(dforce.size(), 0); vector dvatom_(dforce.size(), 0); double dener_ = 0; + try { deep_pot.compute (dener_, dforce_, dvirial_, deatom_, dvatom_, dcoord_, dtype, dbox_, nghost, lmp_list, ago, fparam, daparam); + } catch(deepmd::deepmd_exception& e) { + error->all(FLERR, e.what()); + } for (unsigned dd = 0; dd < dforce.size(); ++dd) dforce[dd] = dforce_[dd]; for (unsigned dd = 0; dd < dvirial.size(); ++dd) dvirial[dd] = dvirial_[dd]; for (unsigned dd = 0; dd < deatom.size(); ++dd) deatom[dd] = deatom_[dd]; @@ -492,14 +436,26 @@ void PairDeepMD::compute(int eflag, int vflag) if (eflag_atom) { for (int ii = 0; ii < nlocal; ++ii) eatom[ii] += deatom[ii]; } - if (vflag_atom) { + // Added by Davide Tisi 2020 + // interface the atomic virial computed by DeepMD + // with the one used in centroid atoms + if (cvflag_atom) { for (int ii = 0; ii < nall; ++ii){ - vatom[ii][0] += 1.0 * dvatom[9*ii+0]; - vatom[ii][1] += 1.0 * dvatom[9*ii+4]; - vatom[ii][2] += 1.0 * dvatom[9*ii+8]; - vatom[ii][3] += 1.0 * dvatom[9*ii+3]; - vatom[ii][4] += 1.0 * dvatom[9*ii+6]; - vatom[ii][5] += 1.0 * dvatom[9*ii+7]; + //vatom[ii][0] += 1.0 * dvatom[9*ii+0]; + //vatom[ii][1] += 1.0 * dvatom[9*ii+4]; + //vatom[ii][2] += 1.0 * dvatom[9*ii+8]; + //vatom[ii][3] += 1.0 * dvatom[9*ii+3]; + //vatom[ii][4] += 1.0 * dvatom[9*ii+6]; + //vatom[ii][5] += 1.0 * dvatom[9*ii+7]; + cvatom[ii][0] += -1.0 * dvatom[9*ii+0]; // xx + cvatom[ii][1] += -1.0 * dvatom[9*ii+4]; // yy + cvatom[ii][2] += -1.0 * dvatom[9*ii+8]; // zz + cvatom[ii][3] += -1.0 * dvatom[9*ii+3]; // xy + cvatom[ii][4] += -1.0 * dvatom[9*ii+6]; // xz + cvatom[ii][5] += -1.0 * dvatom[9*ii+7]; // yz + cvatom[ii][6] += -1.0 * dvatom[9*ii+1]; // yx + cvatom[ii][7] += -1.0 * dvatom[9*ii+2]; // zx + cvatom[ii][8] += -1.0 * dvatom[9*ii+5]; // zy } } } @@ -512,7 +468,11 @@ void PairDeepMD::compute(int eflag, int vflag) vector all_energy; vector> all_atom_energy; vector> all_atom_virial; + try { deep_pot_model_devi.compute(all_energy, all_force, all_virial, all_atom_energy, all_atom_virial, dcoord, dtype, dbox, nghost, lmp_list, ago, fparam, daparam); + } catch(deepmd::deepmd_exception& e) { + error->all(FLERR, e.what()); + } // deep_pot_model_devi.compute_avg (dener, all_energy); // deep_pot_model_devi.compute_avg (dforce, all_force); // deep_pot_model_devi.compute_avg (dvirial, all_virial); @@ -538,7 +498,11 @@ void PairDeepMD::compute(int eflag, int vflag) vector> all_virial_; vector> all_atom_energy_; vector> all_atom_virial_; + try { deep_pot_model_devi.compute(all_energy_, all_force_, all_virial_, all_atom_energy_, all_atom_virial_, dcoord_, dtype, dbox_, nghost, lmp_list, ago, fparam, daparam); + } catch(deepmd::deepmd_exception& e) { + error->all(FLERR, e.what()); + } // deep_pot_model_devi.compute_avg (dener_, all_energy_); // deep_pot_model_devi.compute_avg (dforce_, all_force_); // deep_pot_model_devi.compute_avg (dvirial_, all_virial_); @@ -561,25 +525,48 @@ void PairDeepMD::compute(int eflag, int vflag) all_force[ii][jj] = all_force_[ii][jj]; } } + all_virial.resize(all_virial_.size()); + for (unsigned ii = 0; ii < all_virial_.size(); ++ii){ + all_virial[ii].resize(all_virial_[ii].size()); + for (unsigned jj = 0; jj < all_virial_[ii].size(); ++jj){ + all_virial[ii][jj] = all_virial_[ii][jj]; + } + } #endif if (eflag_atom) { for (int ii = 0; ii < nlocal; ++ii) eatom[ii] += deatom[ii]; } - if (vflag_atom) { + // Added by Davide Tisi 2020 + // interface the atomic virial computed by DeepMD + // with the one used in centroid atoms + if (cvflag_atom) { for (int ii = 0; ii < nall; ++ii){ - vatom[ii][0] += 1.0 * dvatom[9*ii+0]; - vatom[ii][1] += 1.0 * dvatom[9*ii+4]; - vatom[ii][2] += 1.0 * dvatom[9*ii+8]; - vatom[ii][3] += 1.0 * dvatom[9*ii+3]; - vatom[ii][4] += 1.0 * dvatom[9*ii+6]; - vatom[ii][5] += 1.0 * dvatom[9*ii+7]; + //vatom[ii][0] += 1.0 * dvatom[9*ii+0]; + //vatom[ii][1] += 1.0 * dvatom[9*ii+4]; + //vatom[ii][2] += 1.0 * dvatom[9*ii+8]; + //vatom[ii][3] += 1.0 * dvatom[9*ii+3]; + //vatom[ii][4] += 1.0 * dvatom[9*ii+6]; + //vatom[ii][5] += 1.0 * dvatom[9*ii+7]; + cvatom[ii][0] += -1.0 * dvatom[9*ii+0]; // xx + cvatom[ii][1] += -1.0 * dvatom[9*ii+4]; // yy + cvatom[ii][2] += -1.0 * dvatom[9*ii+8]; // zz + cvatom[ii][3] += -1.0 * dvatom[9*ii+3]; // xy + cvatom[ii][4] += -1.0 * dvatom[9*ii+6]; // xz + cvatom[ii][5] += -1.0 * dvatom[9*ii+7]; // yz + cvatom[ii][6] += -1.0 * dvatom[9*ii+1]; // yx + cvatom[ii][7] += -1.0 * dvatom[9*ii+2]; // zx + cvatom[ii][8] += -1.0 * dvatom[9*ii+5]; // zy } } if (out_freq > 0 && update->ntimestep % out_freq == 0) { int rank = comm->me; // std force if (newton_pair) { - comm->reverse_comm_pair(this); +#if LAMMPS_VERSION_NUMBER>=20220324 + comm->reverse_comm(this); +#else + comm->reverse_comm_pair(this); +#endif } vector std_f; #ifdef HIGH_PREC @@ -729,7 +716,11 @@ void PairDeepMD::compute(int eflag, int vflag) else { if (numb_models == 1) { #ifdef HIGH_PREC + try { deep_pot.compute (dener, dforce, dvirial, dcoord, dtype, dbox); + } catch(deepmd::deepmd_exception& e) { + error->all(FLERR, e.what()); + } #else vector dcoord_(dcoord.size()); vector dbox_(dbox.size()); @@ -738,7 +729,11 @@ void PairDeepMD::compute(int eflag, int vflag) vector dforce_(dforce.size(), 0); vector dvirial_(dvirial.size(), 0); double dener_ = 0; + try { deep_pot.compute (dener_, dforce_, dvirial_, dcoord_, dtype, dbox_); + } catch(deepmd::deepmd_exception& e) { + error->all(FLERR, e.what()); + } for (unsigned dd = 0; dd < dforce.size(); ++dd) dforce[dd] = dforce_[dd]; for (unsigned dd = 0; dd < dvirial.size(); ++dd) dvirial[dd] = dvirial_[dd]; dener = dener_; @@ -803,7 +798,6 @@ is_key (const string& input) keys.push_back("out_file"); keys.push_back("fparam"); keys.push_back("aparam"); - keys.push_back("compute"); keys.push_back("ttm"); keys.push_back("atomic"); keys.push_back("relative"); @@ -835,15 +829,23 @@ void PairDeepMD::settings(int narg, char **arg) } numb_models = models.size(); if (numb_models == 1) { + try { deep_pot.init (arg[0], get_node_rank(), get_file_content(arg[0])); + } catch(deepmd::deepmd_exception& e) { + error->all(FLERR, e.what()); + } cutoff = deep_pot.cutoff (); numb_types = deep_pot.numb_types(); dim_fparam = deep_pot.dim_fparam(); dim_aparam = deep_pot.dim_aparam(); } else { + try { deep_pot.init (arg[0], get_node_rank(), get_file_content(arg[0])); deep_pot_model_devi.init(models, get_node_rank(), get_file_content(models)); + } catch(deepmd::deepmd_exception& e) { + error->all(FLERR, e.what()); + } cutoff = deep_pot_model_devi.cutoff(); numb_types = deep_pot_model_devi.numb_types(); dim_fparam = deep_pot_model_devi.dim_fparam(); @@ -886,7 +888,6 @@ void PairDeepMD::settings(int narg, char **arg) } iarg += 1 + dim_fparam ; } - else if (string(arg[iarg]) == string("aparam")) { for (int ii = 0; ii < dim_aparam; ++ii){ if (iarg+1+ii >= narg || is_key(arg[iarg+1+ii])) { @@ -912,20 +913,6 @@ void PairDeepMD::settings(int narg, char **arg) error->all(FLERR, "The deepmd-kit was compiled without support for TTM, please rebuild it with -DUSE_TTM"); #endif } - /////////////////////////////////////////////// - // pair_style deepmd cp.pb compute TEMP - // compute TEMP all temp - ////////////////////////////////////////////// - else if (string(arg[iarg]) == string("compute")) { - for (int ii = 0; ii < 1; ++ii){ - if (iarg+1+ii >= narg || is_key(arg[iarg+1+ii])) { - error->all(FLERR, "invalid compute key: should be compute compute_id(str)"); - } - } - do_compute = true; - compute_id = arg[iarg+1]; - iarg += 1 + 1; - } else if (string(arg[iarg]) == string("atomic")) { out_each = 1; iarg += 1; @@ -953,10 +940,7 @@ void PairDeepMD::settings(int narg, char **arg) if (do_ttm && aparam.size() > 0) { error->all(FLERR,"aparam and ttm should NOT be set simultaneously"); } - if (do_compute && fparam.size() > 0) { - error->all(FLERR,"fparam and compute should NOT be set simultaneously"); - } - + if (comm->me == 0){ if (numb_models > 1 && out_freq > 0){ if (!is_restart) { @@ -990,17 +974,13 @@ void PairDeepMD::settings(int narg, char **arg) cout << endl << pre << "rcut in model: " << cutoff << endl << pre << "ntypes in model: " << numb_types << endl; - if (dim_fparam > 0 && do_compute ==0 && do_ttm ==0) { + if (dim_fparam > 0) { cout << pre << "using fparam(s): " ; for (int ii = 0; ii < dim_fparam; ++ii){ cout << fparam[ii] << " " ; } cout << endl; } - if (do_compute){ - cout << pre << "using compute compute: " ; - cout << compute_id << " " << endl; - } if (aparam.size() > 0) { cout << pre << "using aparam(s): " ; for (int ii = 0; ii < aparam.size(); ++ii){ @@ -1008,10 +988,6 @@ void PairDeepMD::settings(int narg, char **arg) } cout << endl; } - if (do_ttm){ - cout << pre << "using ttm fix: " ; - cout << ttm_fix_id << " " << endl; - } } comm_reverse = numb_models * 3; @@ -1067,10 +1043,14 @@ void PairDeepMD::coeff(int narg, char **arg) void PairDeepMD::init_style() { +#if LAMMPS_VERSION_NUMBER>=20220324 + neighbor->add_request(this, NeighConst::REQ_FULL); +#else int irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->half = 0; - // neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->full = 1; // neighbor->requests[irequest]->newton = 2; +#endif if (out_each == 1){ int ntotal = atom->natoms; int nprocs = comm->nprocs; diff --git a/source/lmp/pair_deepmd.h.in b/source/lmp/pair_deepmd.h.in index f20153a02f..6c2373e114 100644 --- a/source/lmp/pair_deepmd.h.in +++ b/source/lmp/pair_deepmd.h.in @@ -8,7 +8,11 @@ PairStyle(deepmd,PairDeepMD) #define LMP_PAIR_NNP_H #include "pair.h" +#ifdef LMPPLUGIN +#include "DeepPot.h" +#else #include "deepmd/DeepPot.h" +#endif #include #include @@ -89,17 +93,6 @@ private: float eps; float eps_v; #endif - - void make_compute_fparam( -#ifdef HIGH_PREC - std::vector & fparam -#else - std::vector & fparam -#endif - ); - bool do_compute; - std::string compute_id; - void make_ttm_aparam( #ifdef HIGH_PREC std::vector & dparam @@ -107,15 +100,6 @@ private: std::vector & dparam #endif ); - - void make_ttm_fparam( -#ifdef HIGH_PREC - std::vector & fparam -#else - std::vector & fparam -#endif - ); - bool do_ttm; std::string ttm_fix_id; int *counts,*displacements; From 8d8a56cfae58739883c7031b7f991d6d34393e3f Mon Sep 17 00:00:00 2001 From: mingzhong15 <46273005+mingzhong15@users.noreply.github.com> Date: Wed, 4 May 2022 16:43:52 +0800 Subject: [PATCH 3/9] definition for make_fparam add definition for make_compute_fparam & make_ttm_fparam --- source/lmp/pair_deepmd.h.in | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/source/lmp/pair_deepmd.h.in b/source/lmp/pair_deepmd.h.in index 6c2373e114..e56229dcf7 100644 --- a/source/lmp/pair_deepmd.h.in +++ b/source/lmp/pair_deepmd.h.in @@ -93,6 +93,25 @@ private: float eps; float eps_v; #endif + + void make_compute_fparam( +#ifdef HIGH_PREC + std::vector & fparam +#else + std::vector & fparam +#endif + ); + bool do_compute; + std::string compute_id; + + void make_ttm_fparam( +#ifdef HIGH_PREC + std::vector & fparam +#else + std::vector & fparam +#endif + ); + void make_ttm_aparam( #ifdef HIGH_PREC std::vector & dparam From 2af920a8b659cd31487741e2b72234f217c49111 Mon Sep 17 00:00:00 2001 From: mingzhong15 <46273005+mingzhong15@users.noreply.github.com> Date: Wed, 4 May 2022 16:51:19 +0800 Subject: [PATCH 4/9] support fparam-update from compute now we can use `compute temp` or `fix ttm` to update the fparam each MD step --- source/lmp/pair_deepmd.cpp | 115 ++++++++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) diff --git a/source/lmp/pair_deepmd.cpp b/source/lmp/pair_deepmd.cpp index b9793ff7f9..291c3977cf 100644 --- a/source/lmp/pair_deepmd.cpp +++ b/source/lmp/pair_deepmd.cpp @@ -6,6 +6,7 @@ #include "domain.h" #include "comm.h" #include "force.h" +#include "compute.h" #include "memory.h" #include "update.h" #include "output.h" @@ -176,6 +177,81 @@ make_uniform_aparam( } } +void PairDeepMD::make_compute_fparam( +#ifdef HIGH_PREC + vector & fparam +#else + vector & fparam +#endif +) +{ + assert(do_compute); + + int icompute = modify->find_compute(compute_id); + Compute *compute = modify->compute[icompute]; + + assert(compute); + fparam.resize(dim_fparam); + + if (dim_fparam == 1){ + compute->compute_scalar(); + fparam[0] = compute->scalar; + } + else if (dim_fparam >1){ + compute->compute_vector(); + double *cvector = compute->vector; + for (int jj = 0; jj < dim_aparam; ++jj){ + fparam[jj] =cvector[jj]; + } + } +} + +#ifdef USE_TTM +void PairDeepMD::make_ttm_fparam( +#ifdef HIGH_PREC + vector & fparam +#else + vector & fparam +#endif + ) +{ + assert(do_ttm); + // get ttm_fix + const FixTTMMod * ttm_fix = NULL; + for (int ii = 0; ii < modify->nfix; ii++) { + if (string(modify->fix[ii]->id) == ttm_fix_id){ + ttm_fix = dynamic_cast(modify->fix[ii]); + } + } + assert(ttm_fix); + + fparam.resize(dim_fparam); + + vector nnodes = ttm_fix->get_nodes(); + int nxnodes = nnodes[0]; + int nynodes = nnodes[1]; + int nznodes = nnodes[2]; + double *** const T_electron = ttm_fix->get_T_electron(); + + int numb_effective_nodes = 0; + double total_Te = 0; + + // loop over grids to get average electron temperature + for (int ixnode = 0; ixnode < nxnodes; ixnode++) + for (int iynode = 0; iynode < nynodes; iynode++) + for (int iznode = 0; iznode < nznodes; iznode++) + { + if (T_electron[ixnode][iynode][iznode] != 0) + { + numb_effective_nodes += 1; + total_Te += T_electron[ixnode][iynode][iznode]; + } + } + + fparam[0] = total_Te/numb_effective_nodes; +} +#endif + #ifdef USE_TTM void PairDeepMD::make_ttm_aparam( #ifdef HIGH_PREC @@ -359,9 +435,18 @@ void PairDeepMD::compute(int eflag, int vflag) } else if (do_ttm) { #ifdef USE_TTM + if (aparam.size() > 0){ make_ttm_aparam(daparam); + } + if (dim_fparam > 0){ + make_ttm_fparam(fparam); + } #endif } + + if (do_compute){ + make_compute_fparam(fparam); + } // int ago = numb_models > 1 ? 0 : neighbor->ago; int ago = neighbor->ago; @@ -798,6 +883,7 @@ is_key (const string& input) keys.push_back("out_file"); keys.push_back("fparam"); keys.push_back("aparam"); + keys.push_back("compute"); keys.push_back("ttm"); keys.push_back("atomic"); keys.push_back("relative"); @@ -913,6 +999,22 @@ void PairDeepMD::settings(int narg, char **arg) error->all(FLERR, "The deepmd-kit was compiled without support for TTM, please rebuild it with -DUSE_TTM"); #endif } + + /////////////////////////////////////////////// + // pair_style deepmd cp.pb compute TEMP + // compute TEMP all temp + ////////////////////////////////////////////// + else if (string(arg[iarg]) == string("compute")) { + for (int ii = 0; ii < 1; ++ii){ + if (iarg+1+ii >= narg || is_key(arg[iarg+1+ii])) { + error->all(FLERR, "invalid compute key: should be compute compute_id(str)"); + } + } + do_compute = true; + compute_id = arg[iarg+1]; + iarg += 1 + 1; + } + else if (string(arg[iarg]) == string("atomic")) { out_each = 1; iarg += 1; @@ -940,6 +1042,9 @@ void PairDeepMD::settings(int narg, char **arg) if (do_ttm && aparam.size() > 0) { error->all(FLERR,"aparam and ttm should NOT be set simultaneously"); } + if (do_compute && fparam.size() > 0) { + error->all(FLERR,"fparam and compute should NOT be set simultaneously"); + } if (comm->me == 0){ if (numb_models > 1 && out_freq > 0){ @@ -974,13 +1079,17 @@ void PairDeepMD::settings(int narg, char **arg) cout << endl << pre << "rcut in model: " << cutoff << endl << pre << "ntypes in model: " << numb_types << endl; - if (dim_fparam > 0) { + if (dim_fparam > 0 && do_compute ==0 && do_ttm ==0) { cout << pre << "using fparam(s): " ; for (int ii = 0; ii < dim_fparam; ++ii){ cout << fparam[ii] << " " ; } cout << endl; } + if (do_compute){ + cout << pre << "using compute compute: " ; + cout << compute_id << " " << endl; + } if (aparam.size() > 0) { cout << pre << "using aparam(s): " ; for (int ii = 0; ii < aparam.size(); ++ii){ @@ -988,6 +1097,10 @@ void PairDeepMD::settings(int narg, char **arg) } cout << endl; } + if (do_ttm){ + cout << pre << "using ttm fix: " ; + cout << ttm_fix_id << " " << endl; + } } comm_reverse = numb_models * 3; From 2cd776dd095307316f5ed50552a3412c60a7aa07 Mon Sep 17 00:00:00 2001 From: mingzhong15 <46273005+mingzhong15@users.noreply.github.com> Date: Wed, 4 May 2022 16:53:54 +0800 Subject: [PATCH 5/9] support fparam-update from compute now we can use `compute temp` or `fix ttm` to update the fparam each MD step From 5517bbd6ea2d59795e97833c729830c8cfeb6472 Mon Sep 17 00:00:00 2001 From: mingzhong15 Date: Sun, 15 Jan 2023 20:42:13 +0800 Subject: [PATCH 6/9] improve the print information --- source/lmp/pair_deepmd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/lmp/pair_deepmd.cpp b/source/lmp/pair_deepmd.cpp index 291c3977cf..3c44924d6b 100644 --- a/source/lmp/pair_deepmd.cpp +++ b/source/lmp/pair_deepmd.cpp @@ -1087,7 +1087,7 @@ void PairDeepMD::settings(int narg, char **arg) cout << endl; } if (do_compute){ - cout << pre << "using compute compute: " ; + cout << pre << "using compute id: " ; cout << compute_id << " " << endl; } if (aparam.size() > 0) { From 9c19b96b0e65c29619f9240e5bb2bcf0d7db6013 Mon Sep 17 00:00:00 2001 From: mingzhong15 Date: Tue, 17 Jan 2023 18:43:28 +0800 Subject: [PATCH 7/9] 1. variable `FixTTMMod` in make_ttm_fparam is changed to `FixTTMDP` 2. function name `make_compute_fparam` is changed to `make_fparam_from_compute` --- source/lmp/pair_deepmd.cpp | 8 ++++---- source/lmp/pair_deepmd.h.in | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/lmp/pair_deepmd.cpp b/source/lmp/pair_deepmd.cpp index 894e07641b..3e4989767d 100644 --- a/source/lmp/pair_deepmd.cpp +++ b/source/lmp/pair_deepmd.cpp @@ -180,7 +180,7 @@ make_uniform_aparam( } } -void PairDeepMD::make_compute_fparam( +void PairDeepMD::make_fparam_from_compute( #ifdef HIGH_PREC vector & fparam #else @@ -220,10 +220,10 @@ void PairDeepMD::make_ttm_fparam( { assert(do_ttm); // get ttm_fix - const FixTTMMod * ttm_fix = NULL; + const FixTTMDP * ttm_fix = NULL; for (int ii = 0; ii < modify->nfix; ii++) { if (string(modify->fix[ii]->id) == ttm_fix_id){ - ttm_fix = dynamic_cast(modify->fix[ii]); + ttm_fix = dynamic_cast(modify->fix[ii]); } } assert(ttm_fix); @@ -449,7 +449,7 @@ void PairDeepMD::compute(int eflag, int vflag) } if (do_compute){ - make_compute_fparam(fparam); + make_fparam_from_compute(fparam); } // int ago = numb_models > 1 ? 0 : neighbor->ago; diff --git a/source/lmp/pair_deepmd.h.in b/source/lmp/pair_deepmd.h.in index 4cb3f1977c..f4bb0bb5b6 100644 --- a/source/lmp/pair_deepmd.h.in +++ b/source/lmp/pair_deepmd.h.in @@ -98,7 +98,7 @@ private: float eps_v; #endif - void make_compute_fparam( + void make_fparam_from_compute( #ifdef HIGH_PREC std::vector & fparam #else From 939a32c72a248c9f67314d85095b2e29dab08055 Mon Sep 17 00:00:00 2001 From: mingzhong15 Date: Sat, 28 Jan 2023 11:40:52 +0800 Subject: [PATCH 8/9] user interface is changed from to --- source/lmp/pair_deepmd.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/source/lmp/pair_deepmd.cpp b/source/lmp/pair_deepmd.cpp index 3e4989767d..dda8e67f83 100644 --- a/source/lmp/pair_deepmd.cpp +++ b/source/lmp/pair_deepmd.cpp @@ -439,10 +439,10 @@ void PairDeepMD::compute(int eflag, int vflag) } else if (do_ttm) { #ifdef USE_TTM - if (aparam.size() > 0){ + if (dim_aparam > 0){ make_ttm_aparam(daparam); } - if (dim_fparam > 0){ + else if (dim_fparam > 0){ make_ttm_fparam(fparam); } #endif @@ -891,7 +891,7 @@ is_key (const string& input) keys.push_back("out_file"); keys.push_back("fparam"); keys.push_back("aparam"); - keys.push_back("compute"); + keys.push_back("fparam_from_compute"); keys.push_back("ttm"); keys.push_back("atomic"); keys.push_back("relative"); @@ -1009,13 +1009,13 @@ void PairDeepMD::settings(int narg, char **arg) } /////////////////////////////////////////////// - // pair_style deepmd cp.pb compute TEMP + // pair_style deepmd cp.pb fparam_from_compute TEMP // compute TEMP all temp ////////////////////////////////////////////// - else if (string(arg[iarg]) == string("compute")) { + else if (string(arg[iarg]) == string("fparam_from_compute")) { for (int ii = 0; ii < 1; ++ii){ if (iarg+1+ii >= narg || is_key(arg[iarg+1+ii])) { - error->all(FLERR, "invalid compute key: should be compute compute_id(str)"); + error->all(FLERR, "invalid fparam_from_compute key: should be fparam_from_compute compute_id(str)"); } } do_compute = true; @@ -1051,7 +1051,7 @@ void PairDeepMD::settings(int narg, char **arg) error->all(FLERR,"aparam and ttm should NOT be set simultaneously"); } if (do_compute && fparam.size() > 0) { - error->all(FLERR,"fparam and compute should NOT be set simultaneously"); + error->all(FLERR,"fparam and fparam_from_compute should NOT be set simultaneously"); } if (comm->me == 0){ @@ -1087,7 +1087,7 @@ void PairDeepMD::settings(int narg, char **arg) cout << endl << pre << "rcut in model: " << cutoff << endl << pre << "ntypes in model: " << numb_types << endl; - if (dim_fparam > 0 && do_compute ==0 && do_ttm ==0) { + if (fparam.size() > 0) { cout << pre << "using fparam(s): " ; for (int ii = 0; ii < dim_fparam; ++ii){ cout << fparam[ii] << " " ; @@ -1107,7 +1107,13 @@ void PairDeepMD::settings(int narg, char **arg) } if (do_ttm){ cout << pre << "using ttm fix: " ; - cout << ttm_fix_id << " " << endl; + cout << ttm_fix_id << " " ; + if (dim_fparam > 0){ + cout << "(fparam)" << endl; + } + else if (dim_aparam > 0){ + cout << "(aparam)" << endl; + } } } From e555ee64307b28fceea97e63b932048febfcac1d Mon Sep 17 00:00:00 2001 From: mingzhong15 Date: Sat, 28 Jan 2023 12:41:16 +0800 Subject: [PATCH 9/9] update the document about \`fparam_from_compute\` --- doc/third-party/lammps-command.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/third-party/lammps-command.md b/doc/third-party/lammps-command.md index 23c23136f8..2e6dc08444 100644 --- a/doc/third-party/lammps-command.md +++ b/doc/third-party/lammps-command.md @@ -29,7 +29,7 @@ pair_style deepmd models ... keyword value ... - models = frozen model(s) to compute the interaction. If multiple models are provided, then only the first model serves to provide energy and force prediction for each timestep of molecular dynamics, and the model deviation will be computed among all models every `out_freq` timesteps. -- keyword = *out_file* or *out_freq* or *fparam* or *atomic* or *relative* or *relative_v* or *aparam* or *ttm* +- keyword = *out_file* or *out_freq* or *fparam* or *fparam_from_compute* or *atomic* or *relative* or *relative_v* or *aparam* or *ttm*
     out_file value = filename
         filename = The file name for the model deviation output. Default is model_devi.out
@@ -37,6 +37,8 @@ and the model deviation will be computed among all models every `out_freq` times
         freq = Frequency for the model deviation output. Default is 100.
     fparam value = parameters
         parameters = one or more frame parameters required for model evaluation.
+    fparam_from_compute value = id
+        id = compute id used to update the frame parameter.
     atomic = no value is required. 
         If this keyword is set, the model deviation of each atom will be output.
     relative value = level
@@ -55,6 +57,9 @@ 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
 pair_coeff * * O H
+
+pair_style deepmd cp.pb fparam_from_compute TEMP
+compute    TEMP all temp
 ```
 
 ### Description
@@ -74,6 +79,7 @@ If the keyword `relative_v` is set, then the relative model deviation of the vir
 $$E_{v_i}=\frac{\left|D_{v_i}\right|}{\left|v_i\right|+l}$$
 
 If the keyword `fparam` is set, the given frame parameter(s) will be fed to the model.
+If the keyword `fparam_from_compute` is set, the global parameter(s) from compute command (e.g., temperature from [compute temp command](https://docs.lammps.org/compute_temp.html)) will be fed to the model as the frame parameter(s).
 If the keyword `aparam` is set, the given atomic parameter(s) will be fed to the model, where each atom is assumed to have the same atomic parameter(s). 
 If the keyword `ttm` is set, electronic temperatures from [fix ttm command](https://docs.lammps.org/fix_ttm.html) will be fed to the model as the atomic parameters.