From 7b16911ddf9498d2384a0b68dc6f7505e1a7d353 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 23 May 2024 16:12:17 -0400 Subject: [PATCH] lmp: improve error message when compute/fix is not found (#3801) ## Summary by CodeRabbit - **Bug Fixes** - Enhanced error handling to ensure required computes or fixes are present before proceeding with operations, improving robustness and reliability. --------- Signed-off-by: Jinzhe Zeng Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Han Wang <92130845+wanghan-iapcm@users.noreply.github.com> --- source/lmp/pair_deepmd.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/source/lmp/pair_deepmd.cpp b/source/lmp/pair_deepmd.cpp index 027b42825b..d4fbdd3363 100644 --- a/source/lmp/pair_deepmd.cpp +++ b/source/lmp/pair_deepmd.cpp @@ -219,7 +219,9 @@ void PairDeepMD::make_fparam_from_compute(vector &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) { @@ -246,7 +248,9 @@ void PairDeepMD::make_aparam_from_compute(vector &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(dim_aparam) * nlocal); @@ -277,7 +281,9 @@ void PairDeepMD::make_ttm_fparam(vector &fparam) { ttm_fix = dynamic_cast(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); @@ -316,7 +322,9 @@ void PairDeepMD::make_ttm_aparam(vector &daparam) { ttm_fix = dynamic_cast(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;