Skip to content

Commit

Permalink
fix(lmp): call model deviation interface without atomic properties wh…
Browse files Browse the repository at this point in the history
…en they are not requested (#4012)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced computation flexibility by introducing conditional logic for
handling different sets of parameters based on specific flags.

- **Bug Fixes**
- Improved robustness by ensuring computations do not attempt to access
uninitialized elements, preventing potential errors.

- **Refactor**
- Modified control flow to accommodate various computational scenarios,
optimizing the function's performance.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: Jinzhe Zeng <[email protected]>
  • Loading branch information
njzjz authored Jul 24, 2024
1 parent 806859b commit a010ae9
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions source/lmp/pair_deepmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,12 +662,23 @@ void PairDeepMD::compute(int eflag, int vflag) {
vector<double> all_energy;
vector<vector<double>> all_atom_energy;
vector<vector<double>> 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_compat::deepmd_exception &e) {
error->one(FLERR, e.what());
if (!(eflag_atom || cvflag_atom)) {
try {
deep_pot_model_devi.compute(all_energy, all_force, all_virial, dcoord,
dtype, dbox, nghost, lmp_list, ago,
fparam, daparam);
} catch (deepmd_compat::deepmd_exception &e) {
error->one(FLERR, e.what());
}
} else {
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_compat::deepmd_exception &e) {
error->one(FLERR, e.what());
}
}
// deep_pot_model_devi.compute_avg (dener, all_energy);
// deep_pot_model_devi.compute_avg (dforce, all_force);
Expand All @@ -677,9 +688,8 @@ void PairDeepMD::compute(int eflag, int vflag) {
dener = all_energy[0];
dforce = all_force[0];
dvirial = all_virial[0];
deatom = all_atom_energy[0];
dvatom = all_atom_virial[0];
if (eflag_atom) {
deatom = all_atom_energy[0];
for (int ii = 0; ii < nlocal; ++ii) {
eatom[ii] += scale[1][1] * deatom[ii] * ener_unit_cvt_factor;
}
Expand All @@ -688,6 +698,7 @@ void PairDeepMD::compute(int eflag, int vflag) {
// interface the atomic virial computed by DeepMD
// with the one used in centroid atoms
if (cvflag_atom) {
dvatom = all_atom_virial[0];
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];
Expand Down

0 comments on commit a010ae9

Please sign in to comment.