Skip to content

Commit

Permalink
lmp: improve error message when compute/fix is not found (deepmodelin…
Browse files Browse the repository at this point in the history
…g#3801)

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

## Summary by CodeRabbit

- **Bug Fixes**
- Enhanced error handling to ensure required computes or fixes are
present before proceeding with operations, improving robustness and
reliability.

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

---------

Signed-off-by: Jinzhe Zeng <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Han Wang <[email protected]>
(cherry picked from commit 7b16911)
  • Loading branch information
njzjz committed Jul 2, 2024
1 parent 96139dc commit afb059c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions source/lmp/pair_deepmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ void PairDeepMD::make_fparam_from_compute(vector<double> &fparam) {
int icompute = modify->find_compute(compute_fparam_id);
Compute *compute = modify->compute[icompute];

assert(compute);
if (!compute) {
error->all(FLERR, "compute id is not found: " + compute_fparam_id);
}
fparam.resize(dim_fparam);

if (dim_fparam == 1) {
Expand All @@ -245,7 +247,9 @@ void PairDeepMD::make_aparam_from_compute(vector<double> &aparam) {
int icompute = modify->find_compute(compute_aparam_id);
Compute *compute = modify->compute[icompute];

assert(compute);
if (!compute) {
error->all(FLERR, "compute id is not found: " + compute_aparam_id);
}
int nlocal = atom->nlocal;
aparam.resize(static_cast<size_t>(dim_aparam) * nlocal);

Expand Down Expand Up @@ -276,7 +280,9 @@ void PairDeepMD::make_ttm_fparam(vector<double> &fparam) {
ttm_fix = dynamic_cast<FixTTMDP *>(modify->fix[ii]);
}
}
assert(ttm_fix);
if (!ttm_fix) {
error->all(FLERR, "fix ttm id is not found: " + ttm_fix_id);
}

fparam.resize(dim_fparam);

Expand Down Expand Up @@ -315,7 +321,9 @@ void PairDeepMD::make_ttm_aparam(vector<double> &daparam) {
ttm_fix = dynamic_cast<FixTTMDP *>(modify->fix[ii]);
}
}
assert(ttm_fix);
if (!ttm_fix) {
error->all(FLERR, "fix ttm id is not found: " + ttm_fix_id);
}
// modify
double **x = atom->x;
int *mask = atom->mask;
Expand Down

0 comments on commit afb059c

Please sign in to comment.