Skip to content

Commit

Permalink
Writing option added
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyvala committed Aug 4, 2021
1 parent 3c05bc8 commit 08c5ae8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
4 changes: 2 additions & 2 deletions examples/interface-LAMMPS/H2O_RPBE-D3_Committee/md.lmp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ clear
# Configuration files
variable cfgFile string "h2o_8640_liquid_NpT_RPBE-D3.data"
# Timesteps
variable numSteps equal 100
variable numSteps equal 100
variable dt equal 0.0005
# NN
variable nnpCutoff equal 6.36
Expand All @@ -35,7 +35,7 @@ dump 4a all custom 100 dump.myforce.* id type fx fy fz
###############################################################################
# NN
###############################################################################
pair_style nnp dir ${nnpDir} showew no showewsum 10 resetew no maxew 100 calcd 5 maxcd 0.1 cflength 1.8897261328 cfenergy 0.0367493254 emap "1:H,2:O"
pair_style nnp dir ${nnpDir} showew no showewsum 10 resetew no maxew 100 calcd 5 maxcd 0.1 wricd 10 cflength 1.8897261328 cfenergy 0.0367493254 emap "1:H,2:O"
pair_coeff * * ${nnpCutoff}

###############################################################################
Expand Down
9 changes: 9 additions & 0 deletions src/interface/LAMMPS/src/USER-NNP/pair_nnp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ void PairNNP::compute(int eflag, int vflag)
double* comSumForces = &committeeSumForces[0];
MPI_Bcast(comSumForces, globalNumAtoms, MPI_DOUBLE, 0, MPI_COMM_WORLD);
maxcdExceeded = interface.averageComDis(committeeSumForces, maxcd);
if (update->ntimestep % wricd == 0){
interface.writeCommitteeForces(update->ntimestep);}
}
else {
interface.getForces(atom->f);
Expand Down Expand Up @@ -132,6 +134,7 @@ void PairNNP::settings(int narg, char **arg)
comSize = 1;
calcd = 1;
maxcd = 0.0;
wricd = 1000;
maxcdExceeded = false;
resetew = false;
cflength = 1.0;
Expand Down Expand Up @@ -213,6 +216,12 @@ void PairNNP::settings(int narg, char **arg)
error->all(FLERR,"Illegal pair_style command");
calcd = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
iarg += 2;
// write to file committee disagreement for each wricd step
} else if (strcmp(arg[iarg],"wricd") == 0) {
if (iarg+2 > narg)
error->all(FLERR,"Illegal pair_style command");
wricd = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
iarg += 2;
// committee disagreement threshold
} else if (strcmp(arg[iarg],"maxcd") == 0) {
if (iarg+2 > narg)
Expand Down
1 change: 1 addition & 0 deletions src/interface/LAMMPS/src/USER-NNP/pair_nnp.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class PairNNP : public Pair {
int globalNumAtoms;
int comSize;
int calcd;
int wricd;
long numExtrapolationWarningsTotal;
long numExtrapolationWarningsSummary;
double cflength;
Expand Down
17 changes: 16 additions & 1 deletion src/libnnpif/LAMMPS/InterfaceLammps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ bool InterfaceLammps::averageComDis(std::vector<double> const& committeeSumForce
ai->aveComDis = sqrt(ai->aveComDis/(3*(ai->numNeighborsCom+1)));
if (ai->aveComDis > maxcd){
maxcdExceeded = true;
outfile.open("committee-force.txt", std::ios_base::app);
outfile.open("committee.stop", std::ios_base::app);
outfile << strpr("%i %16.6E %i\n", ai->tag, ai->aveComDis, ai->numNeighborsCom+1);
outfile.close();
}
Expand Down Expand Up @@ -799,4 +799,19 @@ void InterfaceLammps::writeEnergyCommittee() const
outfile.close();

return;
}

void InterfaceLammps::writeCommitteeForces(std::size_t const& timestep)
{
ofstream outfile;
outfile.open(strpr("committee.%d", timestep).c_str(), std::ios_base::app);
Atom* ai = NULL;
for (size_t i = 0; i < structure.atoms.size(); ++i)
{
ai = &(structure.atoms.at(i));
outfile << strpr("%i %16.6E %i\n", ai->tag, ai->aveComDis, ai->numNeighborsCom+1);
}
outfile.close();

return;
}
5 changes: 5 additions & 0 deletions src/libnnpif/LAMMPS/InterfaceLammps.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ class InterfaceLammps : public Mode
/** Write committee energies and committee disagreement to file.
*/
void writeEnergyCommittee() const;
/** Write committee force disagreement to file.
*
* @param[in] timestep Lammps molecular dynamics timestep.
*/
void writeCommitteeForces(std::size_t const& timestep);

protected:
/// Process rank.
Expand Down

0 comments on commit 08c5ae8

Please sign in to comment.