diff --git a/src/LEPTON/pair_lepton.cpp b/src/LEPTON/pair_lepton.cpp index 46377a341a..f596a901f0 100644 --- a/src/LEPTON/pair_lepton.cpp +++ b/src/LEPTON/pair_lepton.cpp @@ -200,11 +200,15 @@ void PairLepton::coeff(int narg, char **arg) utils::bounds(FLERR, arg[0], 1, atom->ntypes, ilo, ihi, error); utils::bounds(FLERR, arg[1], 1, atom->ntypes, jlo, jhi, error); - std::string exp_one = arg[2]; double cut_one = cut_global; if (narg == 4) cut_one = utils::numeric(FLERR, arg[3], false, lmp); - // check if the expression can be parsed and evaluated as needed without error + // remove whitespace and quotes from expression string and then + // check if the expression can be parsed and evaluated without error + std::string exp_one; + for (const auto &c : std::string(arg[2])) + if (!isspace(c) && (c != '"') && (c != '\'')) exp_one.push_back(c); + try { auto epot = LMP_Lepton::Parser::parse(exp_one).createCompiledExpression(); auto force = LMP_Lepton::Parser::parse(exp_one).differentiate("r").createCompiledExpression(); @@ -258,7 +262,7 @@ double PairLepton::init_one(int i, int j) void PairLepton::write_data(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) - fprintf(fp, "%d '%s' %g\n", i, expressions[type2expression[i][i]].c_str(), cut[i][i]); + fprintf(fp, "%d %s %g\n", i, expressions[type2expression[i][i]].c_str(), cut[i][i]); } /* ---------------------------------------------------------------------- @@ -269,7 +273,7 @@ void PairLepton::write_data_all(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) for (int j = i; j <= atom->ntypes; j++) - fprintf(fp, "%d %d '%s' %g\n", i, j, expressions[type2expression[i][j]].c_str(), cut[i][j]); + fprintf(fp, "%d %d %s %g\n", i, j, expressions[type2expression[i][j]].c_str(), cut[i][j]); } /* ---------------------------------------------------------------------- */ diff --git a/unittest/force-styles/tests/mol-pair-lepton.yaml b/unittest/force-styles/tests/mol-pair-lepton.yaml index eaed580b02..56640e3834 100644 --- a/unittest/force-styles/tests/mol-pair-lepton.yaml +++ b/unittest/force-styles/tests/mol-pair-lepton.yaml @@ -14,17 +14,17 @@ input_file: in.fourmol pair_style: lepton 8.0 pair_coeff: ! | * * "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.015;sig=3.1" - 1 1 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.02;sig=2.5" + 1 1 '4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.02;sig=2.5' 1 2 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.01;sig=1.75" - 1 3 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.02;sig=2.85" - 1 4*5 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.0173205;sig=2.8" - 2 2 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.005;sig=1.0" - 2 3 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.01;sig=2.1" - 2 4 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.005;sig=0.5" - 2 5 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.00866025;sig=2.05" - 3 3 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.02;sig=3.2" - 3 4 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.0173205;sig=3.15" - 3 5 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.0173205;sig=3.15" + 1 3 '4.0*eps*((sig/r)^12-(sig/r)^6); eps=0.02;sig=2.85' + 1 4*5 "4.0*eps*((sig/r)^12-(sig/r)^6);eps=0.0173205; sig=2.8" + 2 2 "4.0*eps*((sig/r)^12-(sig/r)^6);eps=0.005;sig=1.0" + 2 3 "4.0*eps*((sig/r)^12-(sig/r)^6);eps=0.01;sig=2.1" + 2 4 "4.0*eps*((sig/r)^12-(sig/r)^6);eps=0.005;sig=0.5" + 2 5 "4.0*eps*((sig/r)^12-(sig/r)^6);eps=0.00866025;sig=2.05" + 3 3 "4.0*eps*((sig/r)^12-(sig/r)^6);eps=0.02;sig=3.2" + 3 4 "4.0*eps*((sig/r)^12-(sig/r)^6);eps=0.0173205;sig=3.15" + 3 5 "4.0*eps*((sig/r)^12-(sig/r)^6);eps=0.0173205;sig=3.15" extract: ! "" natoms: 29 init_vdwl: 749.2370315373564