26 if (
this == &matter) {
92 forces = std::move(other.forces);
95 other.biasPotential =
nullptr;
96 masses = std::move(other.masses);
98 isFixed = std::move(other.isFixed);
100 freeMask = std::move(other.freeMask);
105 cell = std::move(other.cell);
112 other.recomputePotential =
true;
113 other.recomputeFreeMask =
true;
114 other.recomputeMaskedForces =
true;
132 if (
structComp.check_rotation && indistinguishable) {
135 }
else if (indistinguishable) {
162 double max_distance = 0.0;
166 for (i = 0; i <
nAtoms; i++) {
167 max_distance = std::max(diff.row(i).norm(), max_distance);
175 throw std::invalid_argument(
"Matter::resize: negative atom count");
202 for (
long i = 0; i < length; i++)
203 atomIndex(i) =
static_cast<std::int64_t
>(i);
258 std::string prefixMovie, std::string prefixCheckpoint,
259 bool retainMovieFrames) {
260 if (retainMovieFrames) {
264 *
this, *
parameters, quiet, writeMovie, checkpoint, prefixMovie,
265 prefixCheckpoint, retainMovieFrames ? &
movie_frames_ :
nullptr);
349 ret.row(
static_cast<long>(j)) = allForces.row(
freeIndices[j]);
367 Matrix<double, 1, 3> ret;
387 for (
int i = 0; i <
nAtoms; i++) {
403 return (
isFixed(indexAtom, 0) > 0.5 &&
isFixed(indexAtom, 1) > 0.5 &&
410 return isFixed(indexAtom, axis) > 0.5 ? 1 : 0;
419 const double v = isFixed_passed ? 1.0 : 0.0;
428 isFixed(indexAtom, axis) = isFixed_passed ? 1.0 : 0.0;
434 isFixed(indexAtom, 0) = mask[0] ? 1.0 : 0.0;
435 isFixed(indexAtom, 1) = mask[1] ? 1.0 : 0.0;
436 isFixed(indexAtom, 2) = mask[2] ? 1.0 : 0.0;
457 Eigen::VectorXd speed2 = vfree.rowwise().squaredNorm();
458 return 0.5 * (
masses.array() * speed2.array()).sum();
467 for (
long i = 0; i <
nAtoms; ++i) {
491 throw std::runtime_error(
492 "Potential requires an isolated (non-periodic) molecular layout "
493 "(NWChem/ORCA-class). Disable periodic boundaries before optimizing; "
494 "PBC wraps can tear non-centered molecules (issue #188).");
501 throw std::runtime_error(
502 "Matter::computePotential called without a potential");
507 auto surrogatePotential =
509 auto [freePE, freeForces, vari] = surrogatePotential->
get_ef_var(
513 for (
long idx{0}, jdx{0}; idx <
nAtoms; idx++) {
515 forces.row(idx) = freeForces.row(jdx);
533 for (
long int i = 0; i <
nAtoms; i++) {
534 forces.row(i) -= tempForce.transpose();
547 if (std::abs(
cell.determinant()) < 1e-30) {
560 for (
int i = 0; i <
nAtoms; i++) {
572 if (atmnrs.size() != this->nAtoms) {
573 throw std::invalid_argument(
574 "Vector of atomic numbers not equal to the number of atoms");
586 for (
long i = 0; i <
nAtoms; i++) {
616 auto invMass =
masses.array().inverse();
617 ret.col(0).array() *= invMass;
618 ret.col(1).array() *= invMass;
619 ret.col(2).array() *= invMass;
636 "Disabled PBC for isolated-molecule potential (NWChem/ORCA-class); "
637 "re-enabling PBC will throw (issue #188)");
653 for (
long int i = 0; i <
nAtoms; i++) {
654 forces.row(i) -= tempForce.transpose();
660 return this->
potential->forceCallCounter;
Eigen::Matrix< double, 3, 3, eOnStorageOrder > Matrix3d
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
#define EONC_LOG_WARNING(...)
Matter(std::shared_ptr< Potential > pot, const Parameters ¶ms)
Functionality relying on the conjugate gradients algorithm.
Parameters::structure_comparison_options_t structComp
double getPotentialEnergy() const
VectorXd getFreeV() const
long int numberOfFixedAtoms() const
void setComputedPotential(double energy, double variance)
Set energy/variance from external batched evaluation and mark forces as up-to-date (recomputePotentia...
void setForces(const AtomMatrix &f)
Eigen::Matrix< std::int64_t, Eigen::Dynamic, 1 > atomIndex
void setPositionsFreeV(const VectorXd &pos)
PbcConvention pbcConvention
void setAtomicNrs(const VectorXi &atmnrs)
VectorXd getPositionsV() const
std::vector< readcon::ConFrame > movie_frames_
long getForceCalls() const
void setMasses(const VectorXd &massesIn)
void setPosition(long int atom, int axis, double position)
void computePotential() const
std::vector< int > freeIndices
double distance(long index1, long index2) const
AtomMatrix getFree() const
void setBiasPotential(BondBoost *bondBoost)
const AtomMatrix & getForces() const
double maxForce(void) const
bool recomputeMaskedForces
void setVelocities(const AtomMatrix &v)
VectorXi getAtomicNrs() const
const Parameters * parameters
void setBiasForces(const AtomMatrix &bf)
AtomMatrix pbc(const AtomMatrix &diff) const
VectorXd getForcesV() const
std::shared_ptr< Potential > potential
double getEnergyVariance() const
AtomMatrix getPositionsCopy() const
BondBoost * biasPotential
long int numberOfAtoms() const
Eigen::Matrix< double, Eigen::Dynamic, 1 > getMasses() const
AtomMatrix getPositionsFree() const
std::shared_ptr< Potential > getPotential()
void setPositionsFree(const AtomMatrix &pos)
double getPosition(long int atom, int axis) const
void resize(long int nAtoms)
void applyPeriodicBoundary()
const AtomMatrix & getForcesRaw() const
void setMass(long int atom, double mass)
void setPositionsV(const VectorXd &pos)
void setCell(const Matrix3d &newCell)
bool relax(bool quiet=false, bool writeMovie=false, bool checkpoint=false, std::string prefixMovie=std::string(), std::string prefixCheckpoint=std::string(), bool retainMovieFrames=false)
std::array< std::string, 5 > headerCon
void assertIsolatedMoleculeLayoutSafe() const
Throw if pot forbids PBC (isolated molecular QM backends, issue #188).
bool usePeriodicBoundaries
std::array< bool, 3 > getFixedMask(long int atom) const
Per-axis CON column-4 mask (bit0=x, bit1=y, bit2=z).
VectorXd getForcesFreeV() const
Matter(std::shared_ptr< Potential > pot, const Parameters ¶ms)
VectorXd getPositionsFreeV() const
VectorXi getAtomicNrsFree() const
double getMechanicalEnergy() const
const Matter & operator=(const Matter &matter)
long int numberOfFreeAtoms() const
bool compare(const Matter &matter, bool indistinguishable=false)
void setFixed(long int atom, int isFixed)
Broadcast a whole-atom flag onto all three axes.
long getAtomicNr(long int atom) const
void setFixedMask(long int atom, std::array< bool, 3 > mask)
AtomMatrix getVelocities() const
double perAtomNorm(const Matter &matter)
AtomMatrix getForcesFree() const
void setPositions(const AtomMatrix &pos)
double getKineticEnergy() const
double getMass(long int atom) const
double distanceTo(const Matter &matter)
size_t getPotentialCalls() const
void setVelocity(long int atom, int axis, double velocity)
const AtomMatrix & getPositions() const
AtomMatrix getAccelerations()
AtomMatrix getBiasForces()
double pdistance(long index1, long index2, int axis) const
void setAtomicNr(long int atom, long atomicNr)
void setPotential(std::shared_ptr< Potential > pot)
int getFixed(long int atom) const
1 if every Cartesian axis of the atom is fixed, else 0.
static PotRegistry & get() noexcept
Process-lifetime singleton.
void on_force_call(PotType t) noexcept
std::tuple< double, AtomMatrix, double > get_ef_var(const AtomMatrix pos, const VectorXi atmnrs, const Matrix3d box)
bool relaxMatter(Matter &matter, const Parameters ¶ms, bool quiet=false, bool writeMovie=false, bool checkpoint=false, std::string prefixMovie=std::string(), std::string prefixCheckpoint=std::string(), std::vector< readcon::ConFrame > *outFrames=nullptr)
bool rotationMatch(const Matter &m1, const Matter &m2, const double max_diff)
bool identical(const Matter &m1, const Matter &m2, const double distanceDifference)
bool sortedR(const Matter &m1, const Matter &m2, const double distanceDifference)
void translationRemove(Matter &m1, const AtomMatrix r1)
AtomMatrix applyPositions(const AtomMatrix &coords, const Matrix3d &cell, const Matrix3d &cellInverse, PbcConvention convention)