Loading...
Searching...
No Matches
eonc::Matter Class Reference

#include <Matter.h>

Classes

struct  Impl

Public Member Functions

 ~Matter ()
 Matter (std::shared_ptr< Potential > pot, const Parameters &params)
 Matter (std::unique_ptr< Potential > pot, const Parameters &params)
 Exclusive handoff.
bool holdsExclusivePotential () const
 True while no copy has shared the Potential from an exclusive handoff.
 Matter (const Matter &matter)
const Matter & operator= (const Matter &matter)
 Matter (Matter &&other) noexcept
 Move: transfers retained movie ConFrames (move-only).
Matter & operator= (Matter &&other) noexcept
bool compare (const Matter &matter, bool indistinguishable=false)
double distanceTo (const Matter &matter)
double perAtomNorm (const Matter &matter)
void setPotential (std::shared_ptr< Potential > pot)
std::shared_ptr< Potential > getPotential ()
void resize (long int nAtoms)
long int numberOfAtoms () const
Matrix3d getCell () const
void setCell (const Matrix3d &newCell)
double getPosition (long int atom, int axis) const
void setPosition (long int atom, int axis, double position)
void setVelocity (long int atom, int axis, double velocity)
bool relax (bool quiet=false, bool writeMovie=false, bool checkpoint=false, std::string prefixMovie=std::string(), std::string prefixCheckpoint=std::string(), bool retainMovieFrames=false)
const std::vector< readcon::ConFrame > & movieFrames () const
 In-memory minimization movie (same stamps as writeMovie CON).
void clearMovieFrames ()
std::vector< readcon::ConFrame > takeMovieFrames ()
 Take ownership of retained frames (leaves storage empty).
AtomMatrix pbc (const AtomMatrix &diff) const
VectorXd pbcV (const VectorXd &diff) const
size_t getPotentialCalls () const
const AtomMatrix & getPositions () const
AtomMatrix getPositionsCopy () const
VectorXd getPositionsV () const
AtomMatrix getPositionsFree () const
VectorXd getPositionsFreeV () const
void setPositions (const AtomMatrix &pos)
void setPositionsV (const VectorXd &pos)
void setPositionsFree (const AtomMatrix &pos)
void setPositionsFreeV (const VectorXd &pos)
AtomMatrix getVelocities () const
void setVelocities (const AtomMatrix &v)
void setBiasForces (const AtomMatrix &bf)
void setBiasPotential (BondBoost *bondBoost)
BondBoost * getBiasPotential () const
 The bias potential added to this Matter's forces, or nullptr.
void assignKeepingBias (const Matter &other)
 Copy another structure in and keep this Matter's own bias potential.
void setForces (const AtomMatrix &f)
AtomMatrix getAccelerations ()
const AtomMatrix & getForces () const
const AtomMatrix & getForcesRaw () const
AtomMatrix getBiasForces ()
VectorXd getForcesV () const
AtomMatrix getForcesFree () const
VectorXd getForcesFreeV () const
PbcConvention getPbcConvention () const
void setPbcConvention (PbcConvention convention)
double getMass (long int atom) const
void setMass (long int atom, double mass)
void setMasses (const VectorXd &massesIn)
long getAtomicNr (long int atom) const
void setAtomicNr (long int atom, long atomicNr)
VectorXi getAtomicNrs () const
VectorXi getAtomicNrsFree () const
void setAtomicNrs (const VectorXi &atmnrs)
int getFixed (long int atom) const
 1 if every Cartesian axis of the atom is fixed, else 0.
int getFixed (long int atom, int axis) const
 1 if this atom's axis is fixed, else 0. axis is 0=x, 1=y, 2=z.
std::array< bool, 3 > getFixedMask (long int atom) const
 Per-axis CON column-4 mask (bit0=x, bit1=y, bit2=z).
void setFixed (long int atom, int isFixed)
 Broadcast a whole-atom flag onto all three axes.
void setFixed (long int atom, int axis, int isFixed)
 Set one Cartesian axis. axis is 0=x, 1=y, 2=z.
void setFixedMask (long int atom, std::array< bool, 3 > mask)
double getEnergyVariance () const
double getPotentialEnergy () const
Matrix3d cauchyStress ()
 Cauchy stress in eV/Angstrom^3.
bool needsForceUpdate () const
 Whether forces need recomputation (positions or surface epoch changed).
void setSurfaceEpoch (unsigned long long epoch)
 Host surface generation.
unsigned long long getSurfaceEpoch () const noexcept
double * forcesData ()
 Mutable access to force storage for batched potential evaluation.
void setEvaluation (const AtomMatrix &forces, double energy)
 Puts a known evaluation back after a position reset: the forces and energy of a geometry this object held before, so no potential call follows.
void setComputedPotential (double energy, double variance)
 Set energy/variance from external batched evaluation and mark forces as up-to-date (recomputePotential = false).
double getKineticEnergy () const
double getMechanicalEnergy () const
double distance (long index1, long index2) const
double pdistance (long index1, long index2, int axis) const
double distance (const Matter &matter, long index) const
long int numberOfFreeAtoms () const
long int numberOfFixedAtoms () const
long getForceCalls () const
void resetForceCalls ()
double maxForce (void) const
double maxFreeAtomForce (const AtomMatrix &rows) const
 Max per-atom Euclidean norm of rows.
bool getWriteConForces () const noexcept
 Parameters.main_options().writeConForces for this Matter.
io::IoStatus writeTibble (std::string filename)
io::IoStatus inp2matter (const std::string &filename)
 Any structure file: .con/.convel via readcon, the rest via chemfiles.
io::IoStatus con2matter (std::string filename)
io::IoStatus con2matter (const readcon::ConFrame &frame, io::ConFrameMetadata *out_metadata=nullptr)
io::IoStatus convel2matter (std::string filename)
io::IoStatus matter2con (std::string filename, bool append=false, const io::ConFrameMetadata *metadata=nullptr)
io::IoStatus matter2convel (std::string filename)
io::IoStatus matter2xyz (std::string filename, bool append=false)
AtomMatrix getFree () const
VectorXd getFreeV () const
Eigen::Matrix< double, Eigen::Dynamic, 1 > getMasses () const
std::int64_t getAtomIndex (long int atom) const
 .con column-5 index (pre-grouping); public for I/O / bindings.
void setAtomIndex (long int atom, std::int64_t index)
long mapFileRow (long file_row) const
 Map a CON file-order row onto the Matter row after matter_order.
void setFileToMatter (std::vector< long > map)
const std::array< std::string, 5 > & getHeaderCon () const
 CON header lines (indices 0..4); public for I/O / bindings.
void setHeaderCon (const std::array< std::string, 5 > &headers)
void setHeaderConLine (size_t i, std::string line)
bool getPeriodic () const noexcept
void setPeriodic (bool periodic)
void setCancelToken (CancelToken token)
const CancelToken & cancelToken () const
void pollCancel (const char *site) const
void applyPeriodicBoundaryIfEnabled ()
 Apply MIC wrap when periodic boundaries are enabled (I/O path).

Private Member Functions

Potential * livePotential () const
void shareOwnedPotential () const
void assertIsolatedMoleculeLayoutSafe () const
 Throw if pot forbids PBC (isolated molecular QM backends, issue #188).
bool epochDirty () const
void stampSurfaceEpoch () const
void computePotential () const
void captureStress () const
void applyPeriodicBoundary ()
void applyPeriodicBoundary (double &component, int axis)
void applyPeriodicBoundary (AtomMatrix &diff)
void restoreFileForces (const AtomMatrix &fileForces, bool trustEnergy, double energy)
 Write .con forces without the fixed-atom mask setForces applies.

Private Attributes

eonc::log::Scoped m_log
std::unique_ptr< Potential > ownedPotential
std::shared_ptr< Potential > potential
bool usePeriodicBoundaries
PbcConvention pbcConvention
bool recomputePotential
long forceCalls
std::array< std::string, 5 > headerCon
bool removeNetForce {true}
StructureComparisonOptions structComp
std::shared_ptr< bool > writeConForces_
const Parameters * parameters {nullptr}
long nAtoms
std::unique_ptr< Impl > impl_
BondBoost * biasPotential {nullptr}
std::vector< long > fileToMatter
std::vector< int > freeIndices
bool recomputeFreeMask {true}
bool recomputeMaskedForces {true}
double energyVariance
std::vector< readcon::ConFrame > movie_frames_
double potentialEnergy
unsigned long long surfaceEpoch_ {0}
unsigned long long cachedHostEpoch_ {0}
unsigned long long cachedPotEpoch_ {0}
CancelToken cancel_token_

Friends

io::IoStatus io::con2matter (Matter &, const readcon::ConFrame &, io::ConFrameMetadata *)

Detailed Description

Definition at line 94 of file Matter.h.

Constructor & Destructor Documentation

◆ ~Matter()

eonc::Matter::~Matter ( )
default

◆ Matter() [1/4]

eonc::Matter::Matter ( std::shared_ptr< Potential > pot,
const Parameters & params )

Definition at line 76 of file Matter.cpp.

77 : potential{pot},
78 usePeriodicBoundaries{!(pot && pot->requiresIsolatedMoleculeLayout())},
81 forceCalls{0},
85 parameters{&params},
86 nAtoms{0},
87 impl_{std::make_unique<Impl>()},
88 biasPotential{nullptr},
89 energyVariance{0.0},
90 potentialEnergy{0.0},
93 cachedPotEpoch_{0} {}
const main_options_t & main_options() const
const structure_comparison_options_t & structure_comparison_options() const
double potentialEnergy
Definition Matter.h:414
PbcConvention pbcConvention
Definition Matter.h:374
const Parameters * parameters
Definition Matter.h:398
bool removeNetForce
Definition Matter.h:392
long nAtoms
Definition Matter.h:399
std::shared_ptr< Potential > potential
Definition Matter.h:369
BondBoost * biasPotential
Definition Matter.h:404
long forceCalls
Definition Matter.h:378
unsigned long long cachedHostEpoch_
Definition Matter.h:416
std::shared_ptr< bool > writeConForces_
Definition Matter.h:396
std::unique_ptr< Impl > impl_
Definition Matter.h:403
unsigned long long cachedPotEpoch_
Definition Matter.h:417
bool recomputePotential
Definition Matter.h:375
unsigned long long surfaceEpoch_
Definition Matter.h:415
StructureComparisonOptions structComp
Definition Matter.h:393
bool usePeriodicBoundaries
Definition Matter.h:370
double energyVariance
Definition Matter.h:412
shared_flag writeConForces
Opt-in "Forces of Component" sections in written .con frames (enables force+energy co-load on restart...
std::shared_ptr< bool > share() const

◆ Matter() [2/4]

eonc::Matter::Matter ( std::unique_ptr< Potential > pot,
const Parameters & params )

Exclusive handoff.

The Potential stays a unique_ptr until a copy shares that same instance. A copy does not clone it.

Definition at line 95 of file Matter.cpp.

96 : Matter(std::shared_ptr<Potential>{}, params) {
97 ownedPotential = std::move(pot);
98 if (ownedPotential && ownedPotential->requiresIsolatedMoleculeLayout()) {
100 }
101}
std::unique_ptr< Potential > ownedPotential
Definition Matter.h:367
Matter(std::shared_ptr< Potential > pot, const Parameters &params)
Definition Matter.cpp:76

◆ Matter() [3/4]

eonc::Matter::Matter ( const Matter & matter)

Definition at line 134 of file Matter.cpp.

135 : impl_{std::make_unique<Impl>()} {
136 operator=(matter);
137}
const Matter & operator=(const Matter &matter)
Definition Matter.cpp:139

◆ Matter() [4/4]

eonc::Matter::Matter ( Matter && other)
noexcept

Move: transfers retained movie ConFrames (move-only).

User copy suppresses implicit move — without this, relax(inplace=False, retain_frames=True) loses frames when returning the working Matter.

Definition at line 198 of file Matter.cpp.

199 : impl_{std::make_unique<Impl>()} {
200 operator=(std::move(other));
201}

Member Function Documentation

◆ applyPeriodicBoundary() [1/3]

void eonc::Matter::applyPeriodicBoundary ( )
private

Definition at line 761 of file Matter.cpp.

761 {
763 // Unset / singular cell (default after Matter construct is Zero) — do not
764 // wipe coordinates; callers set the cell before wrapping makes sense.
765 if (std::abs(impl_->cell.determinant()) < 1e-30) {
766 return;
767 }
768 impl_->positions = eonc::pbc::applyPositions(
769 impl_->positions, impl_->cell, impl_->cellInverse, pbcConvention);
770}
void assertIsolatedMoleculeLayoutSafe() const
Throw if pot forbids PBC (isolated molecular QM backends, issue #188).
Definition Matter.cpp:664
AtomMatrix applyPositions(const AtomMatrix &coords, const Matrix3d &cell, const Matrix3d &cellInverse, PbcConvention convention)
Definition Matter.h:66

◆ applyPeriodicBoundary() [2/3]

void eonc::Matter::applyPeriodicBoundary ( AtomMatrix & diff)
private

◆ applyPeriodicBoundary() [3/3]

void eonc::Matter::applyPeriodicBoundary ( double & component,
int axis )
private

◆ applyPeriodicBoundaryIfEnabled()

void eonc::Matter::applyPeriodicBoundaryIfEnabled ( )
inline

Apply MIC wrap when periodic boundaries are enabled (I/O path).

Definition at line 351 of file Matter.h.

351 {
354 }
355 }
void applyPeriodicBoundary()
Definition Matter.cpp:761

◆ assertIsolatedMoleculeLayoutSafe()

void eonc::Matter::assertIsolatedMoleculeLayoutSafe ( ) const
private

Throw if pot forbids PBC (isolated molecular QM backends, issue #188).

Definition at line 664 of file Matter.cpp.

664 {
665 if (!livePotential() || !livePotential()->requiresIsolatedMoleculeLayout()) {
666 return;
667 }
669 throw std::runtime_error(
670 "Potential requires an isolated (non-periodic) molecular layout "
671 "(NWChem/ORCA-class). Disable periodic boundaries before optimizing; "
672 "PBC wraps can tear non-centered molecules (issue #188).");
673 }
674}
Potential * livePotential() const
Definition Matter.cpp:103

◆ assignKeepingBias()

void eonc::Matter::assignKeepingBias ( const Matter & other)

Copy another structure in and keep this Matter's own bias potential.

operator= clears the bias pointer, because it names the source's boost.

Definition at line 470 of file Matter.cpp.

470 {
471 BondBoost *keep = biasPotential;
472 *this = other;
473 biasPotential = keep;
474}

◆ cancelToken()

const CancelToken & eonc::Matter::cancelToken ( ) const
inlinenodiscard

Definition at line 348 of file Matter.h.

348{ return cancel_token_; }
CancelToken cancel_token_
Definition Matter.h:418

◆ captureStress()

void eonc::Matter::captureStress ( ) const
private

Definition at line 899 of file Matter.cpp.

899 {
900 impl_->haveStress = false;
901 if (!livePotential()->computesStress()) {
902 return;
903 }
904 // A potential instance holds the stress of its own last call. With
905 // [Main] parallel on, a thread-safe shared instance can serve another
906 // image between that call and this read, so it is not read here.
907 const bool threads = parameters && parameters->main_options().parallel;
908 if (threads && livePotential()->isSharedInstanceThreadSafe() &&
909 !livePotential()->needsPerImageInstance()) {
910 return;
911 }
912 try {
913 impl_->stress = livePotential()->cauchyStress();
914 impl_->haveStress = impl_->stress.allFinite();
915 } catch (const std::logic_error &) {
916 impl_->haveStress = false;
917 }
918}
virtual Matrix3d cauchyStress() const
Cauchy stress in eV/Angstrom^3.
Definition Potential.h:212

◆ cauchyStress()

Matrix3d eonc::Matter::cauchyStress ( )

Cauchy stress in eV/Angstrom^3.

Recomputes the potential so the tensor belongs to this image. The potential must report stress.

Definition at line 920 of file Matter.cpp.

920 {
921 if (!livePotential() || !livePotential()->computesStress()) {
922 throw std::logic_error(
923 "Matter::cauchyStress requires a potential that reports stress");
924 }
925 // The stress that came with the cached evaluation describes this image.
926 if (!recomputePotential && impl_->haveStress) {
927 return impl_->stress;
928 }
929 recomputePotential = true;
932 if (!sigma.allFinite()) {
933 throw std::runtime_error("Potential returned a non-finite stress tensor");
934 }
935 return sigma;
936}
Eigen::Matrix< double, 3, 3, eOnStorageOrder > Matrix3d
Definition Eigen.h:35
void computePotential() const
Definition Matter.cpp:695

◆ clearMovieFrames()

void eonc::Matter::clearMovieFrames ( )
inline

Definition at line 141 of file Matter.h.

141{ movie_frames_.clear(); }
std::vector< readcon::ConFrame > movie_frames_
Definition Matter.h:413

◆ compare()

bool eonc::Matter::compare ( const Matter & matter,
bool indistinguishable = false )

Definition at line 254 of file Matter.cpp.

254 {
255 if (nAtoms != matter.numberOfAtoms())
256 return false;
257 if (structComp.check_rotation && indistinguishable) {
258 return eonc::geometry::sortedR(*this, matter,
259 structComp.distance_difference);
260 } else if (indistinguishable) {
261 if (this->numberOfFixedAtoms() == 0 and structComp.remove_translation)
263 return eonc::geometry::identical(*this, matter,
264 structComp.distance_difference);
265 } else if (structComp.check_rotation) {
266 return eonc::geometry::rotationMatch(*this, matter,
267 structComp.distance_difference);
268 } else {
269 if (this->numberOfFixedAtoms() == 0 and structComp.remove_translation)
271 return (structComp.distance_difference) > perAtomNorm(matter);
272 }
273}
long int numberOfAtoms() const
Definition Matter.cpp:343
double perAtomNorm(const Matter &matter)
Definition Matter.cpp:284
long int numberOfFixedAtoms() const
Definition Matter.cpp:643
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)

◆ computePotential()

void eonc::Matter::computePotential ( ) const
private

Definition at line 695 of file Matter.cpp.

695 {
696 cancel_token_.poll("force");
698 if (!livePotential()) {
699 throw std::runtime_error(
700 "Matter::computePotential called without a potential");
701 }
703 if (livePotential()->isSurrogate()) {
704 // Surrogate potential case: uses free-atom subset interface
705 auto surrogatePotential =
706 static_cast<SurrogatePotential *>(livePotential());
707 auto [freePE, freeForces, vari] = surrogatePotential->get_ef_var(
708 this->getPositionsFree(), this->getAtomicNrsFree(), impl_->cell);
709 this->potentialEnergy = freePE;
710 this->energyVariance = vari;
711 impl_->haveStress = false;
712 for (long idx{0}, jdx{0}; idx < nAtoms; idx++) {
713 if (!getFixed(idx)) {
714 impl_->forces.row(idx) = freeForces.row(jdx);
715 jdx++;
716 }
717 }
718 } else {
719 // Hot path: call force() directly into member storage.
720 // No intermediate allocation, no tuple, no copy.
721 double var{0};
722 livePotential()->setFixedMask(nAtoms, impl_->isFixed.data());
723 const auto n = static_cast<size_t>(nAtoms);
724 // Isolated molecules still store a box for I/O. Pots that infer PBC
725 // from a non-zero cell (GFN2) must see a zero box here.
726 const Matrix3d force_cell =
728 ? impl_->cell
729 : Matrix3d::Zero();
731 std::span<const double>(impl_->positions.data(), n * 3),
732 std::span<const int>(impl_->atomicNrs.data(), n),
733 std::span<double>(impl_->forces.data(), n * 3), &potentialEnergy,
734 &var, std::span<const double>(force_cell.data(), 9));
735 this->energyVariance = var;
738 }
739 if (!std::isfinite(potentialEnergy) || !impl_->forces.allFinite()) {
740 throw std::runtime_error(
741 "Potential returned non-finite energy or forces");
742 }
744 recomputePotential = false;
746
747 // One free atom: subtracting the mean force is identically zero,
748 // and NEB would then report immediate GOOD.
749 if (impl_->isFixed.maxCoeff() < 0.5 && removeNetForce && nAtoms > 1) {
750 const Vector3d tempForce = exactMeanForce(impl_->forces);
751 for (long int i = 0; i < nAtoms; i++) {
752 impl_->forces.row(i) -= tempForce.transpose();
753 }
754 }
755 }
756}
AtomMatrix getPositionsFree() const
Definition Matter.cpp:386
VectorXi getAtomicNrsFree() const
Definition Matter.cpp:395
void stampSurfaceEpoch() const
Definition Matter.cpp:682
bool epochDirty() const
Definition Matter.cpp:676
int getFixed(long int atom) const
1 if every Cartesian axis of the atom is fixed, else 0.
Definition Matter.cpp:575
void captureStress() const
Definition Matter.cpp:899
virtual void force(long nAtoms, const double *positions, const int *atomicNrs, double *forces, double *energy, double *variance, const double *box)=0
virtual bool forwardsStoredCell() const noexcept
A host that owns the cell reads the stored matrix.
Definition Potential.h:202
void recordForceCall() noexcept
Charge one evaluated geometry to this potential and its owning registry.
virtual void setFixedMask(long nAtoms, const double *isFixed)
Optional frozen-atom mask (nAtoms*3, 1.0 = fixed).
Definition Potential.h:110

◆ con2matter() [1/2]

io::IoStatus eonc::Matter::con2matter ( const readcon::ConFrame & frame,
io::ConFrameMetadata * out_metadata = nullptr )
inlinenodiscard

Definition at line 285 of file Matter.h.

286 {
287 return io::con2matter(*this, frame, out_metadata);
288 }
IoStatus con2matter(Matter &m, std::string filename)

◆ con2matter() [2/2]

io::IoStatus eonc::Matter::con2matter ( std::string filename)
inlinenodiscard

Definition at line 281 of file Matter.h.

281 {
282 return io::con2matter(*this, filename);
283 }

◆ convel2matter()

io::IoStatus eonc::Matter::convel2matter ( std::string filename)
inlinenodiscard

Definition at line 289 of file Matter.h.

289 {
290 return io::convel2matter(*this, filename);
291 }
IoStatus convel2matter(Matter &m, std::string filename)

◆ distance() [1/2]

double eonc::Matter::distance ( const Matter & matter,
long index ) const

Definition at line 541 of file Matter.cpp.

541 {
542 checkAtom(nAtoms, index, "Matter::distance");
543 checkAtom(matter.nAtoms, index, "Matter::distance");
544 return pbc(impl_->positions.row(index) - matter.getPositions().row(index))
545 .norm();
546}
const AtomMatrix & getPositions() const
Definition Matter.cpp:378
long nAtoms
Definition Matter.h:399
AtomMatrix pbc(const AtomMatrix &diff) const
Definition Matter.cpp:943

◆ distance() [2/2]

double eonc::Matter::distance ( long index1,
long index2 ) const

Definition at line 518 of file Matter.cpp.

518 {
519 checkAtom(nAtoms, index1, "Matter::distance");
520 checkAtom(nAtoms, index2, "Matter::distance");
521 return pbc(impl_->positions.row(index1) - impl_->positions.row(index2))
522 .norm();
523}

◆ distanceTo()

double eonc::Matter::distanceTo ( const Matter & matter)

Definition at line 276 of file Matter.cpp.

276 {
277 if (matter.numberOfAtoms() != nAtoms) {
278 throw std::invalid_argument("Matter::distanceTo: size mismatch");
279 }
280 return pbc(impl_->positions - matter.impl_->positions).norm();
281}
std::unique_ptr< Impl > impl_
Definition Matter.h:403

◆ epochDirty()

bool eonc::Matter::epochDirty ( ) const
nodiscardprivate

Definition at line 676 of file Matter.cpp.

676 {
677 const unsigned long long pe =
680}
virtual unsigned long long surfaceEpoch() const noexcept
Host-visible surface generation.
Definition Potential.h:124

◆ forcesData()

double * eonc::Matter::forcesData ( )

Mutable access to force storage for batched potential evaluation.

Caller must also call setComputedPotential() after writing forces.

Definition at line 957 of file Matter.cpp.

957{ return impl_->forces.data(); }

◆ getAccelerations()

AtomMatrix eonc::Matter::getAccelerations ( )

Definition at line 835 of file Matter.cpp.

835 {
837 AtomMatrix ret = totF.array() * getFree().array();
838 // Single reciprocal mass computation, replicated across 3 columns
839 auto invMass = impl_->masses.array().inverse();
840 ret.col(0).array() *= invMass;
841 ret.col(1).array() *= invMass;
842 ret.col(2).array() *= invMass;
843 return ret;
844}
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
Definition Eigen.h:37
AtomMatrix getFree() const
Definition Matter.cpp:799
AtomMatrix getBiasForces()
Definition Matter.cpp:455
const AtomMatrix & getForces() const
Definition Matter.cpp:482

◆ getAtomicNr()

long eonc::Matter::getAtomicNr ( long int atom) const

Definition at line 565 of file Matter.cpp.

565 {
566 return (impl_->atomicNrs[indexAtom]);
567}

◆ getAtomicNrs()

VectorXi eonc::Matter::getAtomicNrs ( ) const

Definition at line 786 of file Matter.cpp.

786{ return this->impl_->atomicNrs; }

◆ getAtomicNrsFree()

VectorXi eonc::Matter::getAtomicNrsFree ( ) const

Definition at line 395 of file Matter.cpp.

395 {
396 getFree();
397 VectorXi ret(static_cast<Eigen::Index>(freeIndices.size()));
398 for (size_t j = 0; j < freeIndices.size(); j++) {
399 ret[static_cast<Eigen::Index>(j)] = impl_->atomicNrs[freeIndices[j]];
400 }
401 return ret;
402}
std::vector< int > freeIndices
Definition Matter.h:409

◆ getAtomIndex()

std::int64_t eonc::Matter::getAtomIndex ( long int atom) const
nodiscard

.con column-5 index (pre-grouping); public for I/O / bindings.

Held 64-bit wide: readcon carries the column as a uint64_t, and a 32-bit slot drops the high half of any id past 2^31.

Definition at line 959 of file Matter.cpp.

959 {
960 return impl_->atomIndex(atom);
961}

◆ getBiasForces()

AtomMatrix eonc::Matter::getBiasForces ( )

Definition at line 455 of file Matter.cpp.

455 {
456 if (biasPotential != nullptr) {
457 // Evaluate the current bias only. The MD job advances the bond-boost
458 // schedule once per step via BondBoost::advance().
459 biasPotential->boost();
460 }
461 return impl_->biasForces.array() * getFree().array();
462}

◆ getBiasPotential()

BondBoost * eonc::Matter::getBiasPotential ( ) const

The bias potential added to this Matter's forces, or nullptr.

Definition at line 468 of file Matter.cpp.

468{ return biasPotential; }

◆ getCell()

Matrix3d eonc::Matter::getCell ( ) const

Definition at line 345 of file Matter.cpp.

345{ return impl_->cell; }

◆ getEnergyVariance()

double eonc::Matter::getEnergyVariance ( ) const

Definition at line 892 of file Matter.cpp.

892 {
893 if (nAtoms > 0) {
895 }
896 return this->energyVariance;
897}

◆ getFixed() [1/2]

int eonc::Matter::getFixed ( long int atom) const

1 if every Cartesian axis of the atom is fixed, else 0.

Definition at line 575 of file Matter.cpp.

575 {
576 checkAtom(nAtoms, indexAtom, "Matter::getFixed");
577 return (impl_->isFixed(indexAtom, 0) > 0.5 &&
578 impl_->isFixed(indexAtom, 1) > 0.5 &&
579 impl_->isFixed(indexAtom, 2) > 0.5)
580 ? 1
581 : 0;
582}

◆ getFixed() [2/2]

int eonc::Matter::getFixed ( long int atom,
int axis ) const

1 if this atom's axis is fixed, else 0. axis is 0=x, 1=y, 2=z.

Definition at line 584 of file Matter.cpp.

584 {
585 checkAtom(nAtoms, indexAtom, "Matter::getFixed");
586 checkAxis(axis, "Matter::getFixed");
587 return impl_->isFixed(indexAtom, axis) > 0.5 ? 1 : 0;
588}

◆ getFixedMask()

std::array< bool, 3 > eonc::Matter::getFixedMask ( long int atom) const
nodiscard

Per-axis CON column-4 mask (bit0=x, bit1=y, bit2=z).

Definition at line 590 of file Matter.cpp.

590 {
591 checkAtom(nAtoms, indexAtom, "Matter::getFixedMask");
592 return {impl_->isFixed(indexAtom, 0) > 0.5,
593 impl_->isFixed(indexAtom, 1) > 0.5,
594 impl_->isFixed(indexAtom, 2) > 0.5};
595}

◆ getForceCalls()

long eonc::Matter::getForceCalls ( ) const

Definition at line 657 of file Matter.cpp.

657{ return (forceCalls); }

◆ getForces()

const AtomMatrix & eonc::Matter::getForces ( ) const

Definition at line 482 of file Matter.cpp.

482 {
485 // Use the cached freeMask (Nx3, 1.0 for free / 0.0 for fixed) to zero
486 // fixed-atom forces in a single vectorized Eigen operation.
487 impl_->maskedForces = impl_->forces.array() * getFree().array();
488 recomputeMaskedForces = false;
489 }
490 return impl_->maskedForces;
491}
bool recomputeMaskedForces
Definition Matter.h:411

◆ getForcesFree()

AtomMatrix eonc::Matter::getForcesFree ( ) const

Definition at line 502 of file Matter.cpp.

502 {
503 AtomMatrix allForces = getForces();
504 getFree(); // ensure freeIndices is up to date (mutable cache)
505 AtomMatrix ret(static_cast<long>(freeIndices.size()), 3);
506 for (size_t j = 0; j < freeIndices.size(); j++) {
507 ret.row(static_cast<long>(j)) = allForces.row(freeIndices[j]);
508 }
509 return ret;
510}

◆ getForcesFreeV()

VectorXd eonc::Matter::getForcesFreeV ( ) const

Definition at line 512 of file Matter.cpp.

512 {
513 AtomMatrix freeForces = getForcesFree();
514 return VectorXd::Map(freeForces.data(), 3 * numberOfFreeAtoms());
515}
AtomMatrix getForcesFree() const
Definition Matter.cpp:502
long int numberOfFreeAtoms() const
Definition Matter.cpp:653

◆ getForcesRaw()

const AtomMatrix & eonc::Matter::getForcesRaw ( ) const

Definition at line 493 of file Matter.cpp.

493 {
495 return impl_->forces;
496}

◆ getForcesV()

VectorXd eonc::Matter::getForcesV ( ) const

Definition at line 498 of file Matter.cpp.

498 {
499 return VectorXd::Map(getForces().data(), 3 * numberOfAtoms());
500}
long int numberOfAtoms() const
Definition Matter.cpp:343

◆ getFree()

AtomMatrix eonc::Matter::getFree ( ) const

Definition at line 799 of file Matter.cpp.

799 {
800 if (recomputeFreeMask) {
801 impl_->freeMask.resize(nAtoms, 3);
802 impl_->freeMask = 1.0 - impl_->isFixed.array();
803 freeIndices.clear();
804 freeIndices.reserve(static_cast<size_t>(nAtoms));
805 for (long i = 0; i < nAtoms; i++) {
806 if (impl_->freeMask.row(i).sum() > 0.5) {
807 freeIndices.push_back(static_cast<int>(i));
808 }
809 }
810 recomputeFreeMask = false;
811 }
812 return impl_->freeMask;
813}
bool recomputeFreeMask
Definition Matter.h:410

◆ getFreeV()

VectorXd eonc::Matter::getFreeV ( ) const

Definition at line 815 of file Matter.cpp.

815 {
816 return VectorXd::Map(getFree().data(), 3 * numberOfAtoms());
817}

◆ getHeaderCon()

const std::array< std::string, 5 > & eonc::Matter::getHeaderCon ( ) const
inlinenodiscard

CON header lines (indices 0..4); public for I/O / bindings.

Definition at line 328 of file Matter.h.

328 {
329 return headerCon;
330 }
std::array< std::string, 5 > headerCon
Definition Matter.h:381

◆ getKineticEnergy()

double eonc::Matter::getKineticEnergy ( ) const

Definition at line 632 of file Matter.cpp.

632 {
633 // 0.5 * sum(mass_i * |v_i,free|^2); a constrained axis does not contribute.
634 AtomMatrix vfree = impl_->velocities.array() * getFree().array();
635 Eigen::VectorXd speed2 = vfree.rowwise().squaredNorm();
636 return 0.5 * (impl_->masses.array() * speed2.array()).sum();
637}

◆ getMass()

double eonc::Matter::getMass ( long int atom) const

Definition at line 548 of file Matter.cpp.

548 {
549 checkAtom(nAtoms, indexAtom, "Matter::getMass");
550 return (impl_->masses[indexAtom]);
551}

◆ getMasses()

Matrix< double, Eigen::Dynamic, 1 > eonc::Matter::getMasses ( ) const

Definition at line 846 of file Matter.cpp.

846 {
847 return impl_->masses;
848}

◆ getMechanicalEnergy()

double eonc::Matter::getMechanicalEnergy ( ) const

Definition at line 639 of file Matter.cpp.

639 {
641}
double getKineticEnergy() const
Definition Matter.cpp:632
double getPotentialEnergy() const
Definition Matter.cpp:624

◆ getPbcConvention()

PbcConvention eonc::Matter::getPbcConvention ( ) const
inline

Definition at line 186 of file Matter.h.

186{ return pbcConvention; }

◆ getPeriodic()

bool eonc::Matter::getPeriodic ( ) const
inlinenodiscardnoexcept

Definition at line 338 of file Matter.h.

338 {
340 }

◆ getPosition()

double eonc::Matter::getPosition ( long int atom,
int axis ) const

Definition at line 354 of file Matter.cpp.

354 {
355 checkAtom(nAtoms, indexAtom, "Matter::getPosition");
356 checkAxis(axis, "Matter::getPosition");
357 return impl_->positions(indexAtom, axis);
358}

◆ getPositions()

const AtomMatrix & eonc::Matter::getPositions ( ) const

Definition at line 378 of file Matter.cpp.

378{ return impl_->positions; }

◆ getPositionsCopy()

AtomMatrix eonc::Matter::getPositionsCopy ( ) const

Definition at line 380 of file Matter.cpp.

380{ return impl_->positions; }

◆ getPositionsFree()

AtomMatrix eonc::Matter::getPositionsFree ( ) const

Definition at line 386 of file Matter.cpp.

386 {
387 getFree(); // ensure freeIndices is up to date
388 AtomMatrix ret(static_cast<long>(freeIndices.size()), 3);
389 for (size_t j = 0; j < freeIndices.size(); j++) {
390 ret.row(static_cast<long>(j)) = impl_->positions.row(freeIndices[j]);
391 }
392 return ret;
393}

◆ getPositionsFreeV()

VectorXd eonc::Matter::getPositionsFreeV ( ) const

Definition at line 415 of file Matter.cpp.

415 {
416 return VectorXd::Map(getPositionsFree().data(), 3 * numberOfFreeAtoms());
417}

◆ getPositionsV()

VectorXd eonc::Matter::getPositionsV ( ) const

Definition at line 382 of file Matter.cpp.

382 {
383 return VectorXd::Map(impl_->positions.data(), 3 * numberOfAtoms());
384}

◆ getPotential()

std::shared_ptr< Potential > eonc::Matter::getPotential ( )

Definition at line 938 of file Matter.cpp.

938 {
940 return potential;
941}
void shareOwnedPotential() const
Definition Matter.cpp:107

◆ getPotentialCalls()

size_t eonc::Matter::getPotentialCalls ( ) const

Definition at line 888 of file Matter.cpp.

888 {
889 return this->livePotential()->forceCallCounter;
890}
std::atomic< size_t > forceCallCounter
Definition Potential.h:57

◆ getPotentialEnergy()

double eonc::Matter::getPotentialEnergy ( ) const

Definition at line 624 of file Matter.cpp.

624 {
625 if (nAtoms > 0) {
627 return potentialEnergy;
628 } else
629 return 0.0;
630}

◆ getSurfaceEpoch()

unsigned long long eonc::Matter::getSurfaceEpoch ( ) const
inlinenodiscardnoexcept

Definition at line 228 of file Matter.h.

228 {
229 return surfaceEpoch_;
230 }

◆ getVelocities()

AtomMatrix eonc::Matter::getVelocities ( ) const

Definition at line 819 of file Matter.cpp.

819 {
820 return impl_->velocities.array() * getFree().array();
821}

◆ getWriteConForces()

bool eonc::Matter::getWriteConForces ( ) const
nodiscardnoexcept

Parameters.main_options().writeConForces for this Matter.

Follows later writes to that same Parameters. After it is destroyed, the last value remains. The read does not use the Parameters address.

Definition at line 117 of file Matter.cpp.

117 {
119}

◆ holdsExclusivePotential()

bool eonc::Matter::holdsExclusivePotential ( ) const
nodiscard

True while no copy has shared the Potential from an exclusive handoff.

Definition at line 113 of file Matter.cpp.

113 {
114 return static_cast<bool>(ownedPotential);
115}

◆ inp2matter()

io::IoStatus eonc::Matter::inp2matter ( const std::string & filename)
inlinenodiscard

Any structure file: .con/.convel via readcon, the rest via chemfiles.

Definition at line 278 of file Matter.h.

278 {
279 return io::inp2matter(*this, filename);
280 }
IoStatus inp2matter(Matter &m, const std::string &filename)
Input entry point: .con/.convel (and .gz/.zst) go to readcon, everything else goes to chemfiles.

◆ livePotential()

Potential * eonc::Matter::livePotential ( ) const
private

Definition at line 103 of file Matter.cpp.

103 {
104 return ownedPotential ? ownedPotential.get() : potential.get();
105}

◆ mapFileRow()

long eonc::Matter::mapFileRow ( long file_row) const
inlinenodiscard

Map a CON file-order row onto the Matter row after matter_order.

Identity when the Matter was not loaded from a .con, or the ids were already ascending.

Definition at line 318 of file Matter.h.

318 {
319 if (file_row < 0 || file_row >= nAtoms ||
320 fileToMatter.size() != static_cast<size_t>(nAtoms)) {
321 return file_row;
322 }
323 return fileToMatter[static_cast<size_t>(file_row)];
324 }
std::vector< long > fileToMatter
Definition Matter.h:405

◆ matter2con()

io::IoStatus eonc::Matter::matter2con ( std::string filename,
bool append = false,
const io::ConFrameMetadata * metadata = nullptr )
inlinenodiscard

Definition at line 293 of file Matter.h.

294 {
295 return io::matter2con(*this, filename, append, metadata);
296 }
IoStatus matter2con(Matter &m, std::string filename, bool append, const ConFrameMetadata *metadata)
Append a frame to a .con, or truncate and write one frame.

◆ matter2convel()

io::IoStatus eonc::Matter::matter2convel ( std::string filename)
inlinenodiscard

Definition at line 297 of file Matter.h.

297 {
298 return io::matter2convel(*this, filename);
299 }
IoStatus matter2convel(Matter &m, std::string filename)

◆ matter2xyz()

io::IoStatus eonc::Matter::matter2xyz ( std::string filename,
bool append = false )
inlinenodiscard

Definition at line 300 of file Matter.h.

301 {
302 return io::matter2xyz(*this, filename, append);
303 }
IoStatus matter2xyz(Matter &m, std::string filename, bool append)
Write one extended-XYZ frame: Lattice= cell and 17-digit coordinates.

◆ maxForce()

double eonc::Matter::maxForce ( void ) const

Definition at line 780 of file Matter.cpp.

780 {
781 // Ensures that the forces are up to date
783 return maxFreeAtomForce(getForces());
784}
double maxFreeAtomForce(const AtomMatrix &rows) const
Max per-atom Euclidean norm of rows.
Definition Matter.cpp:772

◆ maxFreeAtomForce()

double eonc::Matter::maxFreeAtomForce ( const AtomMatrix & rows) const
nodiscard

Max per-atom Euclidean norm of rows.

Atoms fixed on every axis are ignored. rows must have one row per atom.

Definition at line 772 of file Matter.cpp.

772 {
773 if (rows.rows() != nAtoms) {
774 throw std::invalid_argument(
775 "Matter::maxFreeAtomForce: row count does not match atom count");
776 }
777 return maxFreeAtomForceNorm(rows.data(), impl_->isFixed.data(), nAtoms);
778}
double maxFreeAtomForceNorm(const double *forces, const double *fixed, long nAtoms)
Max Euclidean norm over N x 3 row-major force rows.

◆ movieFrames()

const std::vector< readcon::ConFrame > & eonc::Matter::movieFrames ( ) const
inlinenodiscard

In-memory minimization movie (same stamps as writeMovie CON).

Cleared when retainMovieFrames=false on the next relax, or via clearMovieFrames().

Definition at line 138 of file Matter.h.

138 {
139 return movie_frames_;
140 }

◆ needsForceUpdate()

bool eonc::Matter::needsForceUpdate ( ) const
inlinenodiscard

Whether forces need recomputation (positions or surface epoch changed).

Definition at line 220 of file Matter.h.

220 {
221 return recomputePotential || epochDirty();
222 }

◆ numberOfAtoms()

long int eonc::Matter::numberOfAtoms ( ) const

Definition at line 343 of file Matter.cpp.

343{ return (nAtoms); }

◆ numberOfFixedAtoms()

long int eonc::Matter::numberOfFixedAtoms ( ) const

Definition at line 643 of file Matter.cpp.

643 {
644 long n = 0;
645 for (long i = 0; i < nAtoms; ++i) {
646 if (getFixed(i)) {
647 ++n;
648 }
649 }
650 return n;
651}

◆ numberOfFreeAtoms()

long int eonc::Matter::numberOfFreeAtoms ( ) const

Definition at line 653 of file Matter.cpp.

653 {
654 return nAtoms - numberOfFixedAtoms();
655}

◆ operator=() [1/2]

const Matter & eonc::Matter::operator= ( const Matter & matter)

Definition at line 139 of file Matter.cpp.

139 {
140 if (this == &matter) {
141 return *this;
142 }
143 nAtoms = matter.nAtoms;
144 resize(nAtoms);
145
146 impl_->positions = matter.impl_->positions;
147 impl_->forces = matter.impl_->forces;
148 impl_->masses = matter.impl_->masses;
149 impl_->atomicNrs = matter.impl_->atomicNrs;
150 impl_->isFixed = matter.impl_->isFixed;
151 impl_->atomIndex = matter.impl_->atomIndex;
152 fileToMatter = matter.fileToMatter;
153 impl_->cell = matter.impl_->cell;
154 impl_->cellInverse = matter.impl_->cellInverse;
155 impl_->stress = matter.impl_->stress;
156 impl_->haveStress = matter.impl_->haveStress;
157 impl_->velocities = matter.impl_->velocities;
158
160 structComp = matter.structComp;
162 parameters = matter.parameters;
163
166
167 matter.shareOwnedPotential();
168 ownedPotential.reset();
169 potential = matter.potential;
172 forceCalls = matter.forceCalls;
177 // Both caches describe the forces this object held before the assignment.
178 // resize() above already raises them; state it here alongside the members
179 // this function owns.
180 recomputeFreeMask = true;
182
183 // A BondBoost binds to one Matter (BondBoost.h:32 takes a Matter *), so a
184 // copy cannot share the source's: boosting through it would drive the
185 // original. The copy starts without one and re-establishes it through
186 // setBiasPotential. biasForces is zeroed by the resize above, which is the
187 // state that matches having no bias potential.
188 biasPotential = nullptr;
189
190 headerCon = matter.headerCon;
192 // ConFrame is move-only; copy does not retain movie trajectory.
193 movie_frames_.clear();
194
195 return *this;
196}
double potentialEnergy
Definition Matter.h:414
PbcConvention pbcConvention
Definition Matter.h:374
const Parameters * parameters
Definition Matter.h:398
bool removeNetForce
Definition Matter.h:392
std::shared_ptr< Potential > potential
Definition Matter.h:369
long forceCalls
Definition Matter.h:378
unsigned long long cachedHostEpoch_
Definition Matter.h:416
std::shared_ptr< bool > writeConForces_
Definition Matter.h:396
unsigned long long cachedPotEpoch_
Definition Matter.h:417
bool recomputePotential
Definition Matter.h:375
unsigned long long surfaceEpoch_
Definition Matter.h:415
std::array< std::string, 5 > headerCon
Definition Matter.h:381
StructureComparisonOptions structComp
Definition Matter.h:393
bool usePeriodicBoundaries
Definition Matter.h:370
CancelToken cancel_token_
Definition Matter.h:418
void shareOwnedPotential() const
Definition Matter.cpp:107
std::vector< long > fileToMatter
Definition Matter.h:405
double energyVariance
Definition Matter.h:412
void resize(long int nAtoms)
Definition Matter.cpp:297

◆ operator=() [2/2]

Matter & eonc::Matter::operator= ( Matter && other)
noexcept

Definition at line 203 of file Matter.cpp.

203 {
204 if (this == &other) {
205 return *this;
206 }
207 ownedPotential = std::move(other.ownedPotential);
208 potential = std::move(other.potential);
212 forceCalls = other.forceCalls;
213 headerCon = std::move(other.headerCon);
215 structComp = other.structComp;
217 parameters = other.parameters;
218 nAtoms = other.nAtoms;
219 impl_->positions = std::move(other.impl_->positions);
220 impl_->velocities = std::move(other.impl_->velocities);
221 impl_->forces = std::move(other.impl_->forces);
222 impl_->biasForces = std::move(other.impl_->biasForces);
224 other.biasPotential = nullptr;
225 impl_->masses = std::move(other.impl_->masses);
226 impl_->atomicNrs = std::move(other.impl_->atomicNrs);
227 impl_->isFixed = std::move(other.impl_->isFixed);
228 impl_->atomIndex = std::move(other.impl_->atomIndex);
229 fileToMatter = std::move(other.fileToMatter);
230 impl_->freeMask = std::move(other.impl_->freeMask);
231 impl_->maskedForces = std::move(other.impl_->maskedForces);
232 freeIndices = std::move(other.freeIndices);
235 impl_->cell = std::move(other.impl_->cell);
236 impl_->cellInverse = std::move(other.impl_->cellInverse);
237 impl_->stress = other.impl_->stress;
238 impl_->haveStress = other.impl_->haveStress;
240 movie_frames_ = std::move(other.movie_frames_);
242 cancel_token_ = std::move(other.cancel_token_);
246
247 other.nAtoms = 0;
248 other.recomputePotential = true;
249 other.recomputeFreeMask = true;
250 other.recomputeMaskedForces = true;
251 return *this;
252}
bool recomputeFreeMask
Definition Matter.h:410
std::vector< readcon::ConFrame > movie_frames_
Definition Matter.h:413
std::vector< int > freeIndices
Definition Matter.h:409
bool recomputeMaskedForces
Definition Matter.h:411
std::unique_ptr< Potential > ownedPotential
Definition Matter.h:367
BondBoost * biasPotential
Definition Matter.h:404

◆ pbc()

AtomMatrix eonc::Matter::pbc ( const AtomMatrix & diff) const

Definition at line 943 of file Matter.cpp.

943 {
945 return diff;
946 }
947 return eonc::pbc::apply(diff, impl_->cell, impl_->cellInverse);
948}
AtomMatrix apply(const AtomMatrix &diff, const Matrix3d &cell, const Matrix3d &cellInverse)
Definition Matter.h:46

◆ pbcV()

VectorXd eonc::Matter::pbcV ( const VectorXd & diff) const

Definition at line 950 of file Matter.cpp.

950 {
952 return diff;
953 }
954 return eonc::pbc::applyV(diff, impl_->cell, impl_->cellInverse);
955}
VectorXd applyV(const VectorXd &diffVector, const Matrix3d &cell, const Matrix3d &cellInverse)
Definition Matter.h:77

◆ pdistance()

double eonc::Matter::pdistance ( long index1,
long index2,
int axis ) const

Definition at line 527 of file Matter.cpp.

527 {
528 checkAtom(nAtoms, index1, "Matter::pdistance");
529 checkAtom(nAtoms, index2, "Matter::pdistance");
530 checkAxis(axis, "Matter::pdistance");
531 Matrix<double, 1, 3> ret;
532 ret.setZero();
533 ret(0, axis) =
534 impl_->positions(index1, axis) - impl_->positions(index2, axis);
535 ret = pbc(ret);
536 return ret(0, axis);
537}

◆ perAtomNorm()

double eonc::Matter::perAtomNorm ( const Matter & matter)

Definition at line 284 of file Matter.cpp.

284 {
285 long i = 0;
286 double max_distance = 0.0;
287
288 if (matter.numberOfAtoms() == nAtoms) {
289 AtomMatrix diff = pbc(impl_->positions - matter.impl_->positions);
290 for (i = 0; i < nAtoms; i++) {
291 max_distance = std::max(diff.row(i).norm(), max_distance);
292 }
293 }
294 return max_distance;
295}

◆ pollCancel()

void eonc::Matter::pollCancel ( const char * site) const
inline

Definition at line 349 of file Matter.h.

349{ cancel_token_.poll(site); }

◆ relax()

bool eonc::Matter::relax ( bool quiet = false,
bool writeMovie = false,
bool checkpoint = false,
std::string prefixMovie = std::string(),
std::string prefixCheckpoint = std::string(),
bool retainMovieFrames = false )

Definition at line 404 of file Matter.cpp.

406 {
407 if (retainMovieFrames) {
408 movie_frames_.clear();
409 }
411 *this, *parameters, quiet, writeMovie, checkpoint, prefixMovie,
412 prefixCheckpoint, retainMovieFrames ? &movie_frames_ : nullptr);
413}
bool relaxMatter(Matter &matter, const Parameters &params, 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)

◆ resetForceCalls()

void eonc::Matter::resetForceCalls ( )

Definition at line 659 of file Matter.cpp.

659 {
660 forceCalls = 0;
661 return;
662}

◆ resize()

void eonc::Matter::resize ( long int nAtoms)

Definition at line 297 of file Matter.cpp.

297 {
298 if (length < 0) {
299 throw std::invalid_argument("Matter::resize: negative atom count");
300 }
301 // Same-N resize still zeros coordinates. Keep .con column-5 ids and
302 // the file-order map so a later matter2con does not stamp 1..N.
303 const bool keepAtomIds =
304 (length == nAtoms && impl_->atomIndex.size() == length &&
305 fileToMatter.size() == static_cast<size_t>(length));
306 // Zero is a real size: leaving nAtoms at the old value there sends
307 // setMasses and every other nAtoms loop off the end of an empty array.
308 nAtoms = length;
309 impl_->positions.resize(length, 3);
310 impl_->positions.setZero();
311
312 impl_->velocities.resize(length, 3);
313 impl_->velocities.setZero();
314
315 impl_->biasForces.resize(length, 3);
316 impl_->biasForces.setZero();
317
318 impl_->forces.resize(length, 3);
319 impl_->forces.setZero();
320
321 impl_->masses.resize(length);
322 impl_->masses.setZero();
323
324 impl_->atomicNrs.resize(length);
325 impl_->atomicNrs.setZero();
326
327 impl_->isFixed.resize(length, 3);
328 impl_->isFixed.setZero();
329
330 if (!keepAtomIds) {
331 impl_->atomIndex.resize(length);
332 fileToMatter.resize(static_cast<size_t>(length));
333 for (long i = 0; i < length; i++) {
334 impl_->atomIndex(i) = static_cast<std::int64_t>(i); // default: sequential
335 fileToMatter[static_cast<size_t>(i)] = i;
336 }
337 }
338 recomputePotential = true;
340 recomputeFreeMask = true;
341}

◆ restoreFileForces()

void eonc::Matter::restoreFileForces ( const AtomMatrix & fileForces,
bool trustEnergy,
double energy )
private

Write .con forces without the fixed-atom mask setForces applies.

Definition at line 967 of file Matter.cpp.

968 {
969 impl_->forces = fileForces;
970 impl_->haveStress = false;
972 if (trustEnergy) {
973 potentialEnergy = energy;
974 energyVariance = 0.0;
975 recomputePotential = false;
976 } else {
977 recomputePotential = true;
978 }
979}

◆ setAtomicNr()

void eonc::Matter::setAtomicNr ( long int atom,
long atomicNr )

Definition at line 569 of file Matter.cpp.

569 {
570 impl_->atomicNrs[indexAtom] = atomicNr;
571 recomputePotential = true;
573}

◆ setAtomicNrs()

void eonc::Matter::setAtomicNrs ( const VectorXi & atmnrs)

Definition at line 788 of file Matter.cpp.

788 {
789 if (atmnrs.size() != this->nAtoms) {
790 throw std::invalid_argument(
791 "Vector of atomic numbers not equal to the number of atoms");
792 } else {
793 this->impl_->atomicNrs = atmnrs;
794 recomputePotential = true;
796 }
797}

◆ setAtomIndex()

void eonc::Matter::setAtomIndex ( long int atom,
std::int64_t index )

Definition at line 963 of file Matter.cpp.

963 {
964 impl_->atomIndex(atom) = index;
965}

◆ setBiasForces()

void eonc::Matter::setBiasForces ( const AtomMatrix & bf)

Definition at line 476 of file Matter.cpp.

476 {
477 impl_->biasForces = bf.array() * getFree().array();
478}

◆ setBiasPotential()

void eonc::Matter::setBiasPotential ( BondBoost * bondBoost)

Definition at line 464 of file Matter.cpp.

464 {
465 biasPotential = bondBoost;
466}

◆ setCancelToken()

void eonc::Matter::setCancelToken ( CancelToken token)
inline

Definition at line 347 of file Matter.h.

347{ cancel_token_ = std::move(token); }

◆ setCell()

void eonc::Matter::setCell ( const Matrix3d & newCell)

Definition at line 347 of file Matter.cpp.

347 {
348 impl_->cell = newCell;
349 impl_->cellInverse = impl_->cell.inverse();
350 recomputePotential = true;
352}

◆ setComputedPotential()

void eonc::Matter::setComputedPotential ( double energy,
double variance )

Set energy/variance from external batched evaluation and mark forces as up-to-date (recomputePotential = false).

Definition at line 869 of file Matter.cpp.

869 {
870 potentialEnergy = energy;
871 energyVariance = variance;
872 // A batch leaves at most the last system's stress on the potential.
873 impl_->haveStress = false;
874 recomputePotential = false;
877 forceCalls++;
878
879 // Apply the same net force removal as computePotential()
880 if (impl_->isFixed.maxCoeff() < 0.5 && removeNetForce && nAtoms > 1) {
881 const Vector3d tempForce = exactMeanForce(impl_->forces);
882 for (long int i = 0; i < nAtoms; i++) {
883 impl_->forces.row(i) -= tempForce.transpose();
884 }
885 }
886}

◆ setEvaluation()

void eonc::Matter::setEvaluation ( const AtomMatrix & forces,
double energy )
inline

Puts a known evaluation back after a position reset: the forces and energy of a geometry this object held before, so no potential call follows.

Fixed-atom masking applies on read as for any evaluation.

Definition at line 238 of file Matter.h.

238 {
239 restoreFileForces(forces, true, energy);
240 }
void restoreFileForces(const AtomMatrix &fileForces, bool trustEnergy, double energy)
Write .con forces without the fixed-atom mask setForces applies.
Definition Matter.cpp:967

◆ setFileToMatter()

void eonc::Matter::setFileToMatter ( std::vector< long > map)
inline

Definition at line 325 of file Matter.h.

325{ fileToMatter = std::move(map); }

◆ setFixed() [1/2]

void eonc::Matter::setFixed ( long int atom,
int axis,
int isFixed )

Set one Cartesian axis. axis is 0=x, 1=y, 2=z.

Definition at line 607 of file Matter.cpp.

607 {
608 checkAtom(nAtoms, indexAtom, "Matter::setFixed");
609 checkAxis(axis, "Matter::setFixed");
610 impl_->isFixed(indexAtom, axis) = isFixed_passed ? 1.0 : 0.0;
611 recomputeFreeMask = true;
613}

◆ setFixed() [2/2]

void eonc::Matter::setFixed ( long int atom,
int isFixed )

Broadcast a whole-atom flag onto all three axes.

Definition at line 597 of file Matter.cpp.

597 {
598 checkAtom(nAtoms, indexAtom, "Matter::setFixed");
599 const double v = isFixed_passed ? 1.0 : 0.0;
600 impl_->isFixed(indexAtom, 0) = v;
601 impl_->isFixed(indexAtom, 1) = v;
602 impl_->isFixed(indexAtom, 2) = v;
603 recomputeFreeMask = true;
605}

◆ setFixedMask()

void eonc::Matter::setFixedMask ( long int atom,
std::array< bool, 3 > mask )

Definition at line 615 of file Matter.cpp.

615 {
616 checkAtom(nAtoms, indexAtom, "Matter::setFixedMask");
617 impl_->isFixed(indexAtom, 0) = mask[0] ? 1.0 : 0.0;
618 impl_->isFixed(indexAtom, 1) = mask[1] ? 1.0 : 0.0;
619 impl_->isFixed(indexAtom, 2) = mask[2] ? 1.0 : 0.0;
620 recomputeFreeMask = true;
622}

◆ setForces()

void eonc::Matter::setForces ( const AtomMatrix & f)

Definition at line 827 of file Matter.cpp.

827 {
828 impl_->forces = f.array() * getFree().array();
829 impl_->maskedForces = impl_->forces;
830 impl_->haveStress = false;
831 recomputeMaskedForces = false;
832 recomputePotential = false;
833}

◆ setHeaderCon()

void eonc::Matter::setHeaderCon ( const std::array< std::string, 5 > & headers)
inline

Definition at line 331 of file Matter.h.

331 {
332 headerCon = headers;
333 }

◆ setHeaderConLine()

void eonc::Matter::setHeaderConLine ( size_t i,
std::string line )
inline

Definition at line 334 of file Matter.h.

334 {
335 headerCon.at(i) = std::move(line);
336 }

◆ setMass()

void eonc::Matter::setMass ( long int atom,
double mass )

Definition at line 553 of file Matter.cpp.

553 {
554 checkAtom(nAtoms, indexAtom, "Matter::setMass");
555 impl_->masses[indexAtom] = mass;
556}

◆ setMasses()

void eonc::Matter::setMasses ( const VectorXd & massesIn)

Definition at line 558 of file Matter.cpp.

558 {
559 if (massesIn.size() != nAtoms) {
560 throw std::invalid_argument("Matter::setMasses: size mismatch");
561 }
562 impl_->masses = massesIn;
563}

◆ setPbcConvention()

void eonc::Matter::setPbcConvention ( PbcConvention convention)
inline

Definition at line 187 of file Matter.h.

187 {
188 pbcConvention = convention;
189 }

◆ setPeriodic()

void eonc::Matter::setPeriodic ( bool periodic)
inline

Definition at line 341 of file Matter.h.

341 {
342 usePeriodicBoundaries = periodic;
343 recomputePotential = true;
345 }

◆ setPosition()

void eonc::Matter::setPosition ( long int atom,
int axis,
double position )

Definition at line 360 of file Matter.cpp.

360 {
361 checkAtom(nAtoms, indexAtom, "Matter::setPosition");
362 checkAxis(axis, "Matter::setPosition");
363 impl_->positions(indexAtom, axis) = position;
366 }
367 recomputePotential = true;
369}

◆ setPositions()

void eonc::Matter::setPositions ( const AtomMatrix & pos)

Definition at line 420 of file Matter.cpp.

420 {
421 if (pos.rows() != nAtoms) {
422 throw std::invalid_argument("Matter::setPositions: row count mismatch");
423 }
424 impl_->positions = pos;
427 }
428 recomputePotential = true;
430}

◆ setPositionsFree()

void eonc::Matter::setPositionsFree ( const AtomMatrix & pos)

Definition at line 437 of file Matter.cpp.

437 {
438 getFree(); // ensure freeIndices is up to date
439 for (size_t j = 0; j < freeIndices.size(); j++) {
440 impl_->positions.row(freeIndices[j]) = pos.row(static_cast<long>(j));
441 }
442 // Optimizers write free-atom coords only (TIP4P/SPCE and any PBC pot).
443 // Match setPositions: wrap the full configuration when PBC is on (#171).
446 }
447 recomputePotential = true;
449}

◆ setPositionsFreeV()

void eonc::Matter::setPositionsFreeV ( const VectorXd & pos)

Definition at line 451 of file Matter.cpp.

451 {
452 setPositionsFree(AtomMatrix::Map(pos.data(), numberOfFreeAtoms(), 3));
453}
void setPositionsFree(const AtomMatrix &pos)
Definition Matter.cpp:437

◆ setPositionsV()

void eonc::Matter::setPositionsV ( const VectorXd & pos)

Definition at line 433 of file Matter.cpp.

433 {
434 setPositions(AtomMatrix::Map(pos.data(), numberOfAtoms(), 3));
435}
void setPositions(const AtomMatrix &pos)
Definition Matter.cpp:420

◆ setPotential()

void eonc::Matter::setPotential ( std::shared_ptr< Potential > pot)

Definition at line 850 of file Matter.cpp.

850 {
851 ownedPotential.reset();
852 this->potential = std::move(pot);
853 // Molecular QM backends (NWChem/ORCA) must not use PBC wraps (#188). Auto-off
854 // with a hard fail if code later forces PBC while this pot is attached.
855 if (livePotential() && livePotential()->requiresIsolatedMoleculeLayout() &&
857 usePeriodicBoundaries = false;
858 // Use EONC_LOG_* (not bare QUILL_LOG_* with eonc::log::get() as arg): the
859 // quill macros expand logger->… and choke on a call expression as the first
860 // macro argument on some GCC versions (CI: expected primary-expression).
862 "Disabled PBC for isolated-molecule potential (NWChem/ORCA-class); "
863 "re-enabling PBC will throw (issue #188)");
864 }
865 recomputePotential = true;
867}
#define EONC_LOG_WARNING(...)
Definition EonLogger.h:322

◆ setSurfaceEpoch()

void eonc::Matter::setSurfaceEpoch ( unsigned long long epoch)

Host surface generation.

A GP refit increments this; identical positions then miss the energy and variance caches. Combined with Potential::surfaceEpoch() as the other half of the cache key.

Definition at line 687 of file Matter.cpp.

687 {
688 if (epoch != surfaceEpoch_) {
689 surfaceEpoch_ = epoch;
690 recomputePotential = true;
692 }
693}

◆ setVelocities()

void eonc::Matter::setVelocities ( const AtomMatrix & v)

Definition at line 823 of file Matter.cpp.

823 {
824 impl_->velocities = v.array() * getFree().array();
825}

◆ setVelocity()

void eonc::Matter::setVelocity ( long int atom,
int axis,
double velocity )

Definition at line 371 of file Matter.cpp.

371 {
372 checkAtom(nAtoms, indexAtom, "Matter::setVelocity");
373 checkAxis(axis, "Matter::setVelocity");
374 impl_->velocities(indexAtom, axis) = vel;
375}

◆ shareOwnedPotential()

void eonc::Matter::shareOwnedPotential ( ) const
private

Definition at line 107 of file Matter.cpp.

107 {
108 if (ownedPotential) {
109 potential = std::shared_ptr<Potential>(std::move(ownedPotential));
110 }
111}

◆ stampSurfaceEpoch()

void eonc::Matter::stampSurfaceEpoch ( ) const
private

Definition at line 682 of file Matter.cpp.

◆ takeMovieFrames()

std::vector< readcon::ConFrame > eonc::Matter::takeMovieFrames ( )
inlinenodiscard

Take ownership of retained frames (leaves storage empty).

Definition at line 143 of file Matter.h.

143 {
144 return std::move(movie_frames_);
145 }

◆ writeTibble()

io::IoStatus eonc::Matter::writeTibble ( std::string filename)
inlinenodiscard

Definition at line 274 of file Matter.h.

274 {
275 return io::writeTibble(*this, filename);
276 }
IoStatus writeTibble(Matter &m, std::string fname)
Debug table (positions, optional cached forces). Not a structure format.

◆ io::con2matter

io::IoStatus io::con2matter ( Matter & ,
const readcon::ConFrame & ,
io::ConFrameMetadata *  )
friend

Member Data Documentation

◆ biasPotential

BondBoost* eonc::Matter::biasPotential {nullptr}
private

Definition at line 404 of file Matter.h.

404{nullptr};

◆ cachedHostEpoch_

unsigned long long eonc::Matter::cachedHostEpoch_ {0}
mutableprivate

Definition at line 416 of file Matter.h.

416{0};

◆ cachedPotEpoch_

unsigned long long eonc::Matter::cachedPotEpoch_ {0}
mutableprivate

Definition at line 417 of file Matter.h.

417{0};

◆ cancel_token_

CancelToken eonc::Matter::cancel_token_
private

Definition at line 418 of file Matter.h.

◆ energyVariance

double eonc::Matter::energyVariance
mutableprivate

Definition at line 412 of file Matter.h.

◆ fileToMatter

std::vector<long> eonc::Matter::fileToMatter
private

Definition at line 405 of file Matter.h.

◆ forceCalls

long eonc::Matter::forceCalls
mutableprivate

Definition at line 378 of file Matter.h.

◆ freeIndices

std::vector<int> eonc::Matter::freeIndices
mutableprivate

Definition at line 409 of file Matter.h.

◆ headerCon

std::array<std::string, 5> eonc::Matter::headerCon
private

Definition at line 381 of file Matter.h.

◆ impl_

std::unique_ptr<Impl> eonc::Matter::impl_
private

Definition at line 403 of file Matter.h.

◆ m_log

eonc::log::Scoped eonc::Matter::m_log
private

Definition at line 364 of file Matter.h.

◆ movie_frames_

std::vector<readcon::ConFrame> eonc::Matter::movie_frames_
private

Definition at line 413 of file Matter.h.

◆ nAtoms

long eonc::Matter::nAtoms
private

Definition at line 399 of file Matter.h.

◆ ownedPotential

std::unique_ptr<Potential> eonc::Matter::ownedPotential
mutableprivate

Definition at line 367 of file Matter.h.

◆ parameters

const Parameters* eonc::Matter::parameters {nullptr}
private

Definition at line 398 of file Matter.h.

398{nullptr};

◆ pbcConvention

PbcConvention eonc::Matter::pbcConvention
private

Definition at line 374 of file Matter.h.

◆ potential

std::shared_ptr<Potential> eonc::Matter::potential
mutableprivate

Definition at line 369 of file Matter.h.

◆ potentialEnergy

double eonc::Matter::potentialEnergy
mutableprivate

Definition at line 414 of file Matter.h.

◆ recomputeFreeMask

bool eonc::Matter::recomputeFreeMask {true}
mutableprivate

Definition at line 410 of file Matter.h.

410{true};

◆ recomputeMaskedForces

bool eonc::Matter::recomputeMaskedForces {true}
mutableprivate

Definition at line 411 of file Matter.h.

411{true};

◆ recomputePotential

bool eonc::Matter::recomputePotential
mutableprivate

Definition at line 375 of file Matter.h.

◆ removeNetForce

bool eonc::Matter::removeNetForce {true}
private

Definition at line 392 of file Matter.h.

392{true};

◆ structComp

StructureComparisonOptions eonc::Matter::structComp
private

Definition at line 393 of file Matter.h.

◆ surfaceEpoch_

unsigned long long eonc::Matter::surfaceEpoch_ {0}
private

Definition at line 415 of file Matter.h.

415{0};

◆ usePeriodicBoundaries

bool eonc::Matter::usePeriodicBoundaries
private

Definition at line 370 of file Matter.h.

◆ writeConForces_

std::shared_ptr<bool> eonc::Matter::writeConForces_
private

Definition at line 396 of file Matter.h.


The documentation for this class was generated from the following files:
  • /home/runner/work/eOn/eOn/include/eon/Matter.h
  • /home/runner/work/eOn/eOn/client/Matter.cpp