Loading...
Searching...
No Matches
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.
 Matter (const Matter &matter)
 Matter (Matter &&other) noexcept
 Move: transfers retained movie ConFrames (move-only).
bool holdsExclusivePotential () const
 True while no copy has shared the Potential from an exclusive handoff.
const Matter & operator= (const Matter &matter)
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 distance (const Matter &matter, long index) const
double pdistance (long index1, long index2, int axis) 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, if bound.
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
const Parameters * parameters
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())},
79 pbcConvention{PbcConvention::Legacy},
81 forceCalls{0},
84 parameters{&params},
85 nAtoms{0},
86 impl_{std::make_unique<Impl>()},
87 biasPotential{nullptr},
88 energyVariance{0.0},
89 potentialEnergy{0.0},
92 cachedPotEpoch_{0} {}
double potentialEnergy
Definition Matter.h:409
PbcConvention pbcConvention
Definition Matter.h:372
const Parameters * parameters
Definition Matter.h:393
bool removeNetForce
Definition Matter.h:390
long nAtoms
Definition Matter.h:394
std::shared_ptr< Potential > potential
Definition Matter.h:367
BondBoost * biasPotential
Definition Matter.h:399
long forceCalls
Definition Matter.h:376
unsigned long long cachedHostEpoch_
Definition Matter.h:411
std::unique_ptr< Impl > impl_
Definition Matter.h:398
unsigned long long cachedPotEpoch_
Definition Matter.h:412
bool recomputePotential
Definition Matter.h:373
unsigned long long surfaceEpoch_
Definition Matter.h:410
StructureComparisonOptions structComp
Definition Matter.h:391
bool usePeriodicBoundaries
Definition Matter.h:368
double energyVariance
Definition Matter.h:407
const main_options_t & main_options() const
const structure_comparison_options_t & structure_comparison_options() 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 94 of file Matter.cpp.

95 : Matter(std::shared_ptr<Potential>{}, params) {
96 ownedPotential = std::move(pot);
97 if (ownedPotential && ownedPotential->requiresIsolatedMoleculeLayout()) {
99 }
100}
std::unique_ptr< Potential > ownedPotential
Definition Matter.h:365
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 133 of file Matter.cpp.

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

◆ 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 196 of file Matter.cpp.

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

Member Function Documentation

◆ applyPeriodicBoundary() [1/3]

Definition at line 758 of file Matter.cpp.

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

◆ applyPeriodicBoundary() [2/3]

◆ applyPeriodicBoundary() [3/3]

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

◆ applyPeriodicBoundaryIfEnabled()

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

Definition at line 349 of file Matter.h.

349 {
352 }
353 }
void applyPeriodicBoundary()
Definition Matter.cpp:758

◆ assertIsolatedMoleculeLayoutSafe()

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

Definition at line 661 of file Matter.cpp.

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

◆ 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 467 of file Matter.cpp.

467 {
468 BondBoost *keep = biasPotential;
469 *this = other;
470 biasPotential = keep;
471}

◆ cancelToken()

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

Definition at line 346 of file Matter.h.

346{ return cancel_token_; }
CancelToken cancel_token_
Definition Matter.h:413

◆ captureStress()

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

Definition at line 896 of file Matter.cpp.

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

◆ 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 917 of file Matter.cpp.

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

◆ clearMovieFrames()

Definition at line 141 of file Matter.h.

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

◆ compare()

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

Definition at line 251 of file Matter.cpp.

251 {
252 if (nAtoms != matter.numberOfAtoms())
253 return false;
254 if (structComp.check_rotation && indistinguishable) {
255 return eonc::geometry::sortedR(*this, matter,
256 structComp.distance_difference);
257 } else if (indistinguishable) {
258 if (this->numberOfFixedAtoms() == 0 and structComp.remove_translation)
260 return eonc::geometry::identical(*this, matter,
261 structComp.distance_difference);
262 } else if (structComp.check_rotation) {
263 return eonc::geometry::rotationMatch(*this, matter,
264 structComp.distance_difference);
265 } else {
266 if (this->numberOfFixedAtoms() == 0 and structComp.remove_translation)
268 return (structComp.distance_difference) > perAtomNorm(matter);
269 }
270}
long int numberOfAtoms() const
Definition Matter.cpp:340
double perAtomNorm(const Matter &matter)
Definition Matter.cpp:281
long int numberOfFixedAtoms() const
Definition Matter.cpp:640
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 692 of file Matter.cpp.

692 {
693 cancel_token_.poll("force");
695 if (!livePotential()) {
696 throw std::runtime_error(
697 "Matter::computePotential called without a potential");
698 }
700 if (livePotential()->isSurrogate()) {
701 // Surrogate potential case: uses free-atom subset interface
702 auto surrogatePotential =
703 static_cast<SurrogatePotential *>(livePotential());
704 auto [freePE, freeForces, vari] = surrogatePotential->get_ef_var(
705 this->getPositionsFree(), this->getAtomicNrsFree(), impl_->cell);
706 this->potentialEnergy = freePE;
707 this->energyVariance = vari;
708 impl_->haveStress = false;
709 for (long idx{0}, jdx{0}; idx < nAtoms; idx++) {
710 if (!getFixed(idx)) {
711 impl_->forces.row(idx) = freeForces.row(jdx);
712 jdx++;
713 }
714 }
715 } else {
716 // Hot path: call force() directly into member storage.
717 // No intermediate allocation, no tuple, no copy.
718 double var{0};
719 livePotential()->setFixedMask(nAtoms, impl_->isFixed.data());
720 const auto n = static_cast<size_t>(nAtoms);
721 // Isolated molecules still store a box for I/O. Pots that infer PBC
722 // from a non-zero cell (GFN2) must see a zero box here.
723 const Matrix3d force_cell =
724 (usePeriodicBoundaries || livePotential()->forwardsStoredCell())
725 ? impl_->cell
726 : Matrix3d::Zero();
727 livePotential()->force(
728 std::span<const double>(impl_->positions.data(), n * 3),
729 std::span<const int>(impl_->atomicNrs.data(), n),
730 std::span<double>(impl_->forces.data(), n * 3), &potentialEnergy,
731 &var, std::span<const double>(force_cell.data(), 9));
732 this->energyVariance = var;
733 livePotential()->recordForceCall();
735 }
736 if (!std::isfinite(potentialEnergy) || !impl_->forces.allFinite()) {
737 throw std::runtime_error(
738 "Potential returned non-finite energy or forces");
739 }
741 recomputePotential = false;
743
744 // One free atom: subtracting the mean force is identically zero,
745 // and NEB would then report immediate GOOD.
746 if (impl_->isFixed.maxCoeff() < 0.5 && removeNetForce && nAtoms > 1) {
747 const Vector3d tempForce = exactMeanForce(impl_->forces);
748 for (long int i = 0; i < nAtoms; i++) {
749 impl_->forces.row(i) -= tempForce.transpose();
750 }
751 }
752 }
753}
AtomMatrix getPositionsFree() const
Definition Matter.cpp:383
VectorXi getAtomicNrsFree() const
Definition Matter.cpp:392
void stampSurfaceEpoch() const
Definition Matter.cpp:679
bool epochDirty() const
Definition Matter.cpp:673
int getFixed(long int atom) const
1 if every Cartesian axis of the atom is fixed, else 0.
Definition Matter.cpp:572
void captureStress() const
Definition Matter.cpp:896

◆ con2matter() [1/2]

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

Definition at line 283 of file Matter.h.

284 {
285 return io::con2matter(*this, frame, out_metadata);
286 }
friend io::IoStatus io::con2matter(Matter &, const readcon::ConFrame &, io::ConFrameMetadata *)

◆ con2matter() [2/2]

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

Definition at line 279 of file Matter.h.

279 {
280 return io::con2matter(*this, filename);
281 }

◆ convel2matter()

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

Definition at line 287 of file Matter.h.

287 {
288 return io::convel2matter(*this, filename);
289 }

◆ distance() [1/2]

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

Definition at line 538 of file Matter.cpp.

538 {
539 checkAtom(nAtoms, index, "Matter::distance");
540 checkAtom(matter.nAtoms, index, "Matter::distance");
541 return pbc(impl_->positions.row(index) - matter.getPositions().row(index))
542 .norm();
543}
const AtomMatrix & getPositions() const
Definition Matter.cpp:375
AtomMatrix pbc(const AtomMatrix &diff) const
Definition Matter.cpp:940

◆ distance() [2/2]

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

Definition at line 515 of file Matter.cpp.

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

◆ distanceTo()

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

Definition at line 273 of file Matter.cpp.

273 {
274 if (matter.numberOfAtoms() != nAtoms) {
275 throw std::invalid_argument("Matter::distanceTo: size mismatch");
276 }
277 return pbc(impl_->positions - matter.impl_->positions).norm();
278}

◆ epochDirty()

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

Definition at line 673 of file Matter.cpp.

673 {
674 const unsigned long long pe =
675 livePotential() ? livePotential()->surfaceEpoch() : 0ULL;
677}

◆ forcesData()

Mutable access to force storage for batched potential evaluation.

Caller must also call setComputedPotential() after writing forces.

Definition at line 954 of file Matter.cpp.

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

◆ getAccelerations()

Definition at line 832 of file Matter.cpp.

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

◆ getAtomicNr()

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

Definition at line 562 of file Matter.cpp.

562 {
563 return (impl_->atomicNrs[indexAtom]);
564}

◆ getAtomicNrs()

VectorXi eonc::Matter::getAtomicNrs ( ) const

Definition at line 783 of file Matter.cpp.

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

◆ getAtomicNrsFree()

VectorXi eonc::Matter::getAtomicNrsFree ( ) const

Definition at line 392 of file Matter.cpp.

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

◆ 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 956 of file Matter.cpp.

956 {
957 return impl_->atomIndex(atom);
958}

◆ getBiasForces()

Definition at line 452 of file Matter.cpp.

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

◆ getBiasPotential()

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

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

Definition at line 465 of file Matter.cpp.

465{ return biasPotential; }

◆ getCell()

Definition at line 342 of file Matter.cpp.

342{ return impl_->cell; }

◆ getEnergyVariance()

Definition at line 889 of file Matter.cpp.

889 {
890 if (nAtoms > 0) {
892 }
893 return this->energyVariance;
894}

◆ 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 572 of file Matter.cpp.

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

◆ 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 581 of file Matter.cpp.

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

◆ 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 587 of file Matter.cpp.

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

◆ getForceCalls()

Definition at line 654 of file Matter.cpp.

654{ return (forceCalls); }

◆ getForces()

Definition at line 479 of file Matter.cpp.

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

◆ getForcesFree()

Definition at line 499 of file Matter.cpp.

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

◆ getForcesFreeV()

VectorXd eonc::Matter::getForcesFreeV ( ) const

Definition at line 509 of file Matter.cpp.

509 {
510 AtomMatrix freeForces = getForcesFree();
511 return VectorXd::Map(freeForces.data(), 3 * numberOfFreeAtoms());
512}
AtomMatrix getForcesFree() const
Definition Matter.cpp:499
long int numberOfFreeAtoms() const
Definition Matter.cpp:650

◆ getForcesRaw()

Definition at line 490 of file Matter.cpp.

490 {
492 return impl_->forces;
493}

◆ getForcesV()

VectorXd eonc::Matter::getForcesV ( ) const

Definition at line 495 of file Matter.cpp.

495 {
496 return VectorXd::Map(getForces().data(), 3 * numberOfAtoms());
497}

◆ getFree()

Definition at line 796 of file Matter.cpp.

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

◆ getFreeV()

VectorXd eonc::Matter::getFreeV ( ) const

Definition at line 812 of file Matter.cpp.

812 {
813 return VectorXd::Map(getFree().data(), 3 * numberOfAtoms());
814}

◆ 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 326 of file Matter.h.

326 {
327 return headerCon;
328 }
std::array< std::string, 5 > headerCon
Definition Matter.h:379

◆ getKineticEnergy()

Definition at line 629 of file Matter.cpp.

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

◆ getMass()

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

Definition at line 545 of file Matter.cpp.

545 {
546 checkAtom(nAtoms, indexAtom, "Matter::getMass");
547 return (impl_->masses[indexAtom]);
548}

◆ getMasses()

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

Definition at line 843 of file Matter.cpp.

843 {
844 return impl_->masses;
845}

◆ getMechanicalEnergy()

Definition at line 636 of file Matter.cpp.

636 {
638}
double getKineticEnergy() const
Definition Matter.cpp:629
double getPotentialEnergy() const
Definition Matter.cpp:621

◆ 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 336 of file Matter.h.

336 {
338 }

◆ getPosition()

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

Definition at line 351 of file Matter.cpp.

351 {
352 checkAtom(nAtoms, indexAtom, "Matter::getPosition");
353 checkAxis(axis, "Matter::getPosition");
354 return impl_->positions(indexAtom, axis);
355}

◆ getPositions()

Definition at line 375 of file Matter.cpp.

375{ return impl_->positions; }

◆ getPositionsCopy()

Definition at line 377 of file Matter.cpp.

377{ return impl_->positions; }

◆ getPositionsFree()

Definition at line 383 of file Matter.cpp.

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

◆ getPositionsFreeV()

VectorXd eonc::Matter::getPositionsFreeV ( ) const

Definition at line 412 of file Matter.cpp.

412 {
413 return VectorXd::Map(getPositionsFree().data(), 3 * numberOfFreeAtoms());
414}

◆ getPositionsV()

VectorXd eonc::Matter::getPositionsV ( ) const

Definition at line 379 of file Matter.cpp.

379 {
380 return VectorXd::Map(impl_->positions.data(), 3 * numberOfAtoms());
381}

◆ getPotential()

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

Definition at line 935 of file Matter.cpp.

935 {
937 return potential;
938}
void shareOwnedPotential() const
Definition Matter.cpp:106

◆ getPotentialCalls()

Definition at line 885 of file Matter.cpp.

885 {
886 return this->livePotential()->forceCallCounter;
887}

◆ getPotentialEnergy()

Definition at line 621 of file Matter.cpp.

621 {
622 if (nAtoms > 0) {
624 return potentialEnergy;
625 } else
626 return 0.0;
627}

◆ getSurfaceEpoch()

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

Definition at line 228 of file Matter.h.

228 {
229 return surfaceEpoch_;
230 }

◆ getVelocities()

Definition at line 816 of file Matter.cpp.

816 {
817 return impl_->velocities.array() * getFree().array();
818}

◆ getWriteConForces()

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

Parameters.main_options().writeConForces for this Matter, if bound.

Definition at line 116 of file Matter.cpp.

116 {
117 return parameters != nullptr && parameters->main_options().writeConForces;
118}

◆ holdsExclusivePotential()

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

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

Definition at line 112 of file Matter.cpp.

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

◆ 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 276 of file Matter.h.

276 {
277 return io::inp2matter(*this, filename);
278 }

◆ livePotential()

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

Definition at line 102 of file Matter.cpp.

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

◆ 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 316 of file Matter.h.

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

◆ matter2con()

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

Definition at line 291 of file Matter.h.

292 {
293 return io::matter2con(*this, filename, append, metadata);
294 }

◆ matter2convel()

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

Definition at line 295 of file Matter.h.

295 {
296 return io::matter2convel(*this, filename);
297 }

◆ matter2xyz()

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

Definition at line 298 of file Matter.h.

299 {
300 return io::matter2xyz(*this, filename, append);
301 }

◆ maxForce()

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

Definition at line 777 of file Matter.cpp.

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

◆ 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 769 of file Matter.cpp.

769 {
770 if (rows.rows() != nAtoms) {
771 throw std::invalid_argument(
772 "Matter::maxFreeAtomForce: row count does not match atom count");
773 }
774 return maxFreeAtomForceNorm(rows.data(), impl_->isFixed.data(), nAtoms);
775}
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 340 of file Matter.cpp.

340{ return (nAtoms); }

◆ numberOfFixedAtoms()

Definition at line 640 of file Matter.cpp.

640 {
641 long n = 0;
642 for (long i = 0; i < nAtoms; ++i) {
643 if (getFixed(i)) {
644 ++n;
645 }
646 }
647 return n;
648}

◆ numberOfFreeAtoms()

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

Definition at line 650 of file Matter.cpp.

650 {
651 return nAtoms - numberOfFixedAtoms();
652}

◆ operator=() [1/2]

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

Definition at line 138 of file Matter.cpp.

138 {
139 if (this == &matter) {
140 return *this;
141 }
142 nAtoms = matter.nAtoms;
143 resize(nAtoms);
144
145 impl_->positions = matter.impl_->positions;
146 impl_->forces = matter.impl_->forces;
147 impl_->masses = matter.impl_->masses;
148 impl_->atomicNrs = matter.impl_->atomicNrs;
149 impl_->isFixed = matter.impl_->isFixed;
150 impl_->atomIndex = matter.impl_->atomIndex;
151 fileToMatter = matter.fileToMatter;
152 impl_->cell = matter.impl_->cell;
153 impl_->cellInverse = matter.impl_->cellInverse;
154 impl_->stress = matter.impl_->stress;
155 impl_->haveStress = matter.impl_->haveStress;
156 impl_->velocities = matter.impl_->velocities;
157
159 structComp = matter.structComp;
160 parameters = matter.parameters;
161
164
165 matter.shareOwnedPotential();
166 ownedPotential.reset();
167 potential = matter.potential;
170 forceCalls = matter.forceCalls;
175 // Both caches describe the forces this object held before the assignment.
176 // resize() above already raises them; state it here alongside the members
177 // this function owns.
178 recomputeFreeMask = true;
180
181 // A BondBoost binds to one Matter (BondBoost.h:32 takes a Matter *), so a
182 // copy cannot share the source's: boosting through it would drive the
183 // original. The copy starts without one and re-establishes it through
184 // setBiasPotential. biasForces is zeroed by the resize above, which is the
185 // state that matches having no bias potential.
186 biasPotential = nullptr;
187
188 headerCon = matter.headerCon;
190 // ConFrame is move-only; copy does not retain movie trajectory.
191 movie_frames_.clear();
192
193 return *this;
194}
void resize(long int nAtoms)
Definition Matter.cpp:294

◆ operator=() [2/2]

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

Definition at line 201 of file Matter.cpp.

201 {
202 if (this == &other) {
203 return *this;
204 }
205 ownedPotential = std::move(other.ownedPotential);
206 potential = std::move(other.potential);
210 forceCalls = other.forceCalls;
211 headerCon = std::move(other.headerCon);
213 structComp = other.structComp;
214 parameters = other.parameters;
215 nAtoms = other.nAtoms;
216 impl_->positions = std::move(other.impl_->positions);
217 impl_->velocities = std::move(other.impl_->velocities);
218 impl_->forces = std::move(other.impl_->forces);
219 impl_->biasForces = std::move(other.impl_->biasForces);
221 other.biasPotential = nullptr;
222 impl_->masses = std::move(other.impl_->masses);
223 impl_->atomicNrs = std::move(other.impl_->atomicNrs);
224 impl_->isFixed = std::move(other.impl_->isFixed);
225 impl_->atomIndex = std::move(other.impl_->atomIndex);
226 fileToMatter = std::move(other.fileToMatter);
227 impl_->freeMask = std::move(other.impl_->freeMask);
228 impl_->maskedForces = std::move(other.impl_->maskedForces);
229 freeIndices = std::move(other.freeIndices);
232 impl_->cell = std::move(other.impl_->cell);
233 impl_->cellInverse = std::move(other.impl_->cellInverse);
234 impl_->stress = other.impl_->stress;
235 impl_->haveStress = other.impl_->haveStress;
237 movie_frames_ = std::move(other.movie_frames_);
239 cancel_token_ = std::move(other.cancel_token_);
243
244 other.nAtoms = 0;
245 other.recomputePotential = true;
246 other.recomputeFreeMask = true;
247 other.recomputeMaskedForces = true;
248 return *this;
249}

◆ pbc()

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

Definition at line 940 of file Matter.cpp.

940 {
942 return diff;
943 }
944 return eonc::pbc::apply(diff, impl_->cell, impl_->cellInverse);
945}
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 947 of file Matter.cpp.

947 {
949 return diff;
950 }
951 return eonc::pbc::applyV(diff, impl_->cell, impl_->cellInverse);
952}
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 524 of file Matter.cpp.

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

◆ perAtomNorm()

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

Definition at line 281 of file Matter.cpp.

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

◆ pollCancel()

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

Definition at line 347 of file Matter.h.

347{ 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 401 of file Matter.cpp.

403 {
404 if (retainMovieFrames) {
405 movie_frames_.clear();
406 }
408 *this, *parameters, quiet, writeMovie, checkpoint, prefixMovie,
409 prefixCheckpoint, retainMovieFrames ? &movie_frames_ : nullptr);
410}
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()

Definition at line 656 of file Matter.cpp.

656 {
657 forceCalls = 0;
658 return;
659}

◆ resize()

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

Definition at line 294 of file Matter.cpp.

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

◆ 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 964 of file Matter.cpp.

965 {
966 impl_->forces = fileForces;
967 impl_->haveStress = false;
969 if (trustEnergy) {
970 potentialEnergy = energy;
971 energyVariance = 0.0;
972 recomputePotential = false;
973 } else {
974 recomputePotential = true;
975 }
976}

◆ setAtomicNr()

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

Definition at line 566 of file Matter.cpp.

566 {
567 impl_->atomicNrs[indexAtom] = atomicNr;
568 recomputePotential = true;
570}

◆ setAtomicNrs()

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

Definition at line 785 of file Matter.cpp.

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

◆ setAtomIndex()

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

Definition at line 960 of file Matter.cpp.

960 {
961 impl_->atomIndex(atom) = index;
962}

◆ setBiasForces()

Definition at line 473 of file Matter.cpp.

473 {
474 impl_->biasForces = bf.array() * getFree().array();
475}

◆ setBiasPotential()

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

Definition at line 461 of file Matter.cpp.

461 {
462 biasPotential = bondBoost;
463}

◆ setCancelToken()

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

Definition at line 345 of file Matter.h.

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

◆ setCell()

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

Definition at line 344 of file Matter.cpp.

344 {
345 impl_->cell = newCell;
346 impl_->cellInverse = impl_->cell.inverse();
347 recomputePotential = true;
349}

◆ 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 866 of file Matter.cpp.

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

◆ 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:964

◆ setFileToMatter()

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

Definition at line 323 of file Matter.h.

323{ 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 604 of file Matter.cpp.

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

◆ setFixed() [2/2]

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

Broadcast a whole-atom flag onto all three axes.

Definition at line 594 of file Matter.cpp.

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

◆ setFixedMask()

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

Definition at line 612 of file Matter.cpp.

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

◆ setForces()

Definition at line 824 of file Matter.cpp.

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

◆ setHeaderCon()

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

Definition at line 329 of file Matter.h.

329 {
330 headerCon = headers;
331 }

◆ setHeaderConLine()

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

Definition at line 332 of file Matter.h.

332 {
333 headerCon.at(i) = std::move(line);
334 }

◆ setMass()

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

Definition at line 550 of file Matter.cpp.

550 {
551 checkAtom(nAtoms, indexAtom, "Matter::setMass");
552 impl_->masses[indexAtom] = mass;
553}

◆ setMasses()

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

Definition at line 555 of file Matter.cpp.

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

◆ 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 339 of file Matter.h.

339 {
340 usePeriodicBoundaries = periodic;
341 recomputePotential = true;
343 }

◆ setPosition()

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

Definition at line 357 of file Matter.cpp.

357 {
358 checkAtom(nAtoms, indexAtom, "Matter::setPosition");
359 checkAxis(axis, "Matter::setPosition");
360 impl_->positions(indexAtom, axis) = position;
363 }
364 recomputePotential = true;
366}

◆ setPositions()

Definition at line 417 of file Matter.cpp.

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

◆ setPositionsFree()

Definition at line 434 of file Matter.cpp.

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

◆ setPositionsFreeV()

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

Definition at line 448 of file Matter.cpp.

448 {
449 setPositionsFree(AtomMatrix::Map(pos.data(), numberOfFreeAtoms(), 3));
450}
void setPositionsFree(const AtomMatrix &pos)
Definition Matter.cpp:434

◆ setPositionsV()

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

Definition at line 430 of file Matter.cpp.

430 {
431 setPositions(AtomMatrix::Map(pos.data(), numberOfAtoms(), 3));
432}
void setPositions(const AtomMatrix &pos)
Definition Matter.cpp:417

◆ setPotential()

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

Definition at line 847 of file Matter.cpp.

847 {
848 ownedPotential.reset();
849 this->potential = std::move(pot);
850 // Molecular QM backends (NWChem/ORCA) must not use PBC wraps (#188). Auto-off
851 // with a hard fail if code later forces PBC while this pot is attached.
852 if (livePotential() && livePotential()->requiresIsolatedMoleculeLayout() &&
854 usePeriodicBoundaries = false;
855 // Use EONC_LOG_* (not bare QUILL_LOG_* with eonc::log::get() as arg): the
856 // quill macros expand logger->… and choke on a call expression as the first
857 // macro argument on some GCC versions (CI: expected primary-expression).
859 "Disabled PBC for isolated-molecule potential (NWChem/ORCA-class); "
860 "re-enabling PBC will throw (issue #188)");
861 }
862 recomputePotential = true;
864}
#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 684 of file Matter.cpp.

684 {
685 if (epoch != surfaceEpoch_) {
686 surfaceEpoch_ = epoch;
687 recomputePotential = true;
689 }
690}

◆ setVelocities()

Definition at line 820 of file Matter.cpp.

820 {
821 impl_->velocities = v.array() * getFree().array();
822}

◆ setVelocity()

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

Definition at line 368 of file Matter.cpp.

368 {
369 checkAtom(nAtoms, indexAtom, "Matter::setVelocity");
370 checkAxis(axis, "Matter::setVelocity");
371 impl_->velocities(indexAtom, axis) = vel;
372}

◆ shareOwnedPotential()

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

Definition at line 106 of file Matter.cpp.

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

◆ stampSurfaceEpoch()

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

Definition at line 679 of file Matter.cpp.

679 {
681 cachedPotEpoch_ = livePotential() ? livePotential()->surfaceEpoch() : 0ULL;
682}

◆ 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 272 of file Matter.h.

272 {
273 return io::writeTibble(*this, filename);
274 }

◆ 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 399 of file Matter.h.

399{nullptr};

◆ cachedHostEpoch_

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

Definition at line 411 of file Matter.h.

411{0};

◆ cachedPotEpoch_

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

Definition at line 412 of file Matter.h.

412{0};

◆ cancel_token_

CancelToken eonc::Matter::cancel_token_
private

Definition at line 413 of file Matter.h.

◆ energyVariance

double eonc::Matter::energyVariance
mutableprivate

Definition at line 407 of file Matter.h.

◆ fileToMatter

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

Definition at line 400 of file Matter.h.

◆ forceCalls

long eonc::Matter::forceCalls
mutableprivate

Definition at line 376 of file Matter.h.

◆ freeIndices

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

Definition at line 404 of file Matter.h.

◆ headerCon

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

Definition at line 379 of file Matter.h.

◆ impl_

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

Definition at line 398 of file Matter.h.

◆ m_log

Definition at line 362 of file Matter.h.

◆ movie_frames_

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

Definition at line 408 of file Matter.h.

◆ nAtoms

long eonc::Matter::nAtoms
private

Definition at line 394 of file Matter.h.

◆ ownedPotential

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

Definition at line 365 of file Matter.h.

◆ parameters

Definition at line 393 of file Matter.h.

◆ pbcConvention

PbcConvention eonc::Matter::pbcConvention
private

Definition at line 372 of file Matter.h.

◆ potential

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

Definition at line 367 of file Matter.h.

◆ potentialEnergy

double eonc::Matter::potentialEnergy
mutableprivate

Definition at line 409 of file Matter.h.

◆ recomputeFreeMask

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

Definition at line 405 of file Matter.h.

405{true};

◆ recomputeMaskedForces

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

Definition at line 406 of file Matter.h.

406{true};

◆ recomputePotential

bool eonc::Matter::recomputePotential
mutableprivate

Definition at line 373 of file Matter.h.

◆ removeNetForce

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

Definition at line 390 of file Matter.h.

390{true};

◆ structComp

StructureComparisonOptions eonc::Matter::structComp
private

Definition at line 391 of file Matter.h.

◆ surfaceEpoch_

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

Definition at line 410 of file Matter.h.

410{0};

◆ usePeriodicBoundaries

Definition at line 368 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