Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/libnnp/Atom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Atom::Atom() : hasNeighborList (false),
numSymmetryFunctions (0 ),
energy (0.0 ),
charge (0.0 ),
chargeRef (0.0 )
chargeRef (0.0 ),
forceWeight (1.0 )
{
}

Expand Down Expand Up @@ -363,6 +364,7 @@ vector<string> Atom::info() const
v.push_back(strpr("energy : %16.8E\n", energy));
v.push_back(strpr("charge : %16.8E\n", charge));
v.push_back(strpr("chargeRef : %16.8E\n", chargeRef));
v.push_back(strpr("forceWeight : %16.8E\n", forceWeight));
v.push_back(strpr("r : %16.8E %16.8E %16.8E\n", r[0], r[1], r[2]));
v.push_back(strpr("f : %16.8E %16.8E %16.8E\n", f[0], f[1], f[2]));
v.push_back(strpr("fRef : %16.8E %16.8E %16.8E\n", fRef[0], fRef[1], fRef[2]));
Expand Down
2 changes: 2 additions & 0 deletions src/libnnp/Atom.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ struct Atom
double charge;
/// Atomic reference charge.
double chargeRef;
/// Force weight for training.
double forceWeight;
/// Cartesian coordinates
Vec3D r;
/// Force vector calculated by neural network.
Expand Down
10 changes: 10 additions & 0 deletions src/libnnp/Structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Structure::Structure() :
charge (0.0 ),
chargeRef (0.0 ),
volume (0.0 ),
strucWeight (1.0 ),
sampleType (ST_UNKNOWN),
comment ("" )
{
Expand Down Expand Up @@ -206,6 +207,10 @@ void Structure::readFromLines(vector<string> const& lines)
atoms.back().r[2] = atof(splitLine.at(3).c_str());
atoms.back().element = elementMap[splitLine.at(4)];
atoms.back().chargeRef = atof(splitLine.at(5).c_str());
atoms.back().forceWeight = atof(splitLine.at(6).c_str());
if (atoms.back().forceWeight == 0) {
atoms.back().forceWeight = 1.0;
}
atoms.back().fRef[0] = atof(splitLine.at(7).c_str());
atoms.back().fRef[1] = atof(splitLine.at(8).c_str());
atoms.back().fRef[2] = atof(splitLine.at(9).c_str());
Expand All @@ -221,6 +226,10 @@ void Structure::readFromLines(vector<string> const& lines)
{
chargeRef = atof(splitLine[1].c_str());
}
else if (splitLine.at(0) == "weight")
{
strucWeight = atof(splitLine[1].c_str());
}
else if (splitLine.at(0) == "end")
{
if (!(iBoxVector == 0 || iBoxVector == 3))
Expand Down Expand Up @@ -555,6 +564,7 @@ void Structure::reset()
charge = 0.0 ;
chargeRef = 0.0 ;
volume = 0.0 ;
strucWeight = 1.0 ;
sampleType = ST_UNKNOWN;
comment = "" ;

Expand Down
2 changes: 2 additions & 0 deletions src/libnnp/Structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ struct Structure
double chargeRef;
/// Simulation box volume.
double volume;
/// Structure weight
double strucWeight;
/// Sample type (training or test set).
SampleType sampleType;
/// Structure comment.
Expand Down
8 changes: 6 additions & 2 deletions src/libnnptrain/Dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ int Dataset::calculateBufferSize(Structure const& structure) const
MPI_Pack_size(1, MPI_CHAR , comm, &cs );

// Structure
bs += 5 * cs + 4 * ss + 4 * is + 5 * ds;
bs += 5 * cs + 4 * ss + 4 * is + 6 * ds;
// Structure.comment
bs += ss;
bs += (s.comment.length() + 1) * cs;
Expand All @@ -192,7 +192,7 @@ int Dataset::calculateBufferSize(Structure const& structure) const
bs += s.numAtomsPerElement.size() * ss;
// Structure.atoms
bs += ss;
bs += s.atoms.size() * (4 * cs + 6 * ss + i64s + 3 * ds + 3 * 3 * ds);
bs += s.atoms.size() * (4 * cs + 6 * ss + i64s + 4 * ds + 3 * 3 * ds);
for (vector<Atom>::const_iterator it = s.atoms.begin();
it != s.atoms.end(); ++it)
{
Expand Down Expand Up @@ -275,6 +275,7 @@ int Dataset::sendStructure(Structure const& structure, int dest) const
MPI_Pack(&(s.charge ), 1, MPI_DOUBLE, buf, bs, &p, comm);
MPI_Pack(&(s.chargeRef ), 1, MPI_DOUBLE, buf, bs, &p, comm);
MPI_Pack(&(s.volume ), 1, MPI_DOUBLE, buf, bs, &p, comm);
MPI_Pack(&(s.strucWeight ), 1, MPI_DOUBLE, buf, bs, &p, comm);
MPI_Pack(&(s.sampleType ), 1, MPI_INT , buf, bs, &p, comm);

// Strucuture.comment
Expand Down Expand Up @@ -325,6 +326,7 @@ int Dataset::sendStructure(Structure const& structure, int dest) const
MPI_Pack(&(it->energy ), 1, MPI_DOUBLE , buf, bs, &p, comm);
MPI_Pack(&(it->charge ), 1, MPI_DOUBLE , buf, bs, &p, comm);
MPI_Pack(&(it->chargeRef ), 1, MPI_DOUBLE , buf, bs, &p, comm);
MPI_Pack(&(it->forceWeight ), 1, MPI_DOUBLE , buf, bs, &p, comm);
MPI_Pack(&(it->r.r ), 3, MPI_DOUBLE , buf, bs, &p, comm);
MPI_Pack(&(it->f.r ), 3, MPI_DOUBLE , buf, bs, &p, comm);
MPI_Pack(&(it->fRef.r ), 3, MPI_DOUBLE , buf, bs, &p, comm);
Expand Down Expand Up @@ -492,6 +494,7 @@ int Dataset::recvStructure(Structure* const structure, int src)
MPI_Unpack(buf, bs, &p, &(s->charge ), 1, MPI_DOUBLE, comm);
MPI_Unpack(buf, bs, &p, &(s->chargeRef ), 1, MPI_DOUBLE, comm);
MPI_Unpack(buf, bs, &p, &(s->volume ), 1, MPI_DOUBLE, comm);
MPI_Unpack(buf, bs, &p, &(s->strucWeight ), 1, MPI_DOUBLE, comm);
MPI_Unpack(buf, bs, &p, &(s->sampleType ), 1, MPI_INT , comm);

// Strucuture.comment
Expand Down Expand Up @@ -549,6 +552,7 @@ int Dataset::recvStructure(Structure* const structure, int src)
MPI_Unpack(buf, bs, &p, &(it->energy ), 1, MPI_DOUBLE , comm);
MPI_Unpack(buf, bs, &p, &(it->charge ), 1, MPI_DOUBLE , comm);
MPI_Unpack(buf, bs, &p, &(it->chargeRef ), 1, MPI_DOUBLE , comm);
MPI_Unpack(buf, bs, &p, &(it->forceWeight ), 1, MPI_DOUBLE , comm);
MPI_Unpack(buf, bs, &p, &(it->r.r ), 3, MPI_DOUBLE , comm);
MPI_Unpack(buf, bs, &p, &(it->f.r ), 3, MPI_DOUBLE , comm);
MPI_Unpack(buf, bs, &p, &(it->fRef.r ), 3, MPI_DOUBLE , comm);
Expand Down
4 changes: 2 additions & 2 deletions src/libnnptrain/Training.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2451,12 +2451,12 @@ void Training::update(string const& property)
{
if (k == "energy")
{
pu.error.at(0).at(offset2) += s.energyRef - s.energy;
pu.error.at(0).at(offset2) += (s.energyRef - s.energy) * s.strucWeight;
}
else if (k == "force")
{
Atom const& a = s.atoms.at(c->a);
pu.error.at(0).at(offset2) += a.fRef[c->c] - a.f[c->c];
pu.error.at(0).at(offset2) += (a.fRef[c->c] - a.f[c->c]) * s.strucWeight * a.forceWeight;
}
else if (k == "charge")
{
Expand Down