52#include "brains/Snapshot.hpp"
56#include "utils/Utility.hpp"
57#include "utils/simError.h"
61 Snapshot::Snapshot(
int nAtoms,
int nRigidbodies,
int nCutoffGroups,
64 rigidbodyData(nRigidbodies),
65 cgData(nCutoffGroups, DataStorage::dslPosition), orthoTolerance_(1e-6) {
67 frameData.currentTime = 0;
68 frameData.hmat = Mat3x3d(0.0);
69 frameData.invHmat = Mat3x3d(0.0);
70 frameData.orthoRhombic =
false;
71 frameData.usePBC = usePBC;
72 frameData.bondPotential = 0.0;
73 frameData.bendPotential = 0.0;
74 frameData.torsionPotential = 0.0;
75 frameData.inversionPotential = 0.0;
76 frameData.lrPotentials = potVec(0.0);
77 frameData.surfacePotential = 0.0;
78 frameData.reciprocalPotential = 0.0;
79 frameData.selfPotentials = potVec(0.0);
80 frameData.excludedPotentials = potVec(0.0);
81 frameData.restraintPotential = 0.0;
82 frameData.rawPotential = 0.0;
83 frameData.xyArea = 0.0;
84 frameData.xzArea = 0.0;
85 frameData.yzArea = 0.0;
86 frameData.volume = 0.0;
87 frameData.thermostat = make_pair(0.0, 0.0);
88 frameData.electronicThermostat = make_pair(0.0, 0.0);
89 frameData.barostat = Mat3x3d(0.0);
90 frameData.virialTensor = Mat3x3d(0.0);
91 frameData.conductiveHeatFlux = Vector3d(0.0, 0.0, 0.0);
92 frameData.spfData = std::make_shared<SPFData>();
93 clearDerivedProperties();
96 Snapshot::Snapshot(
int nAtoms,
int nRigidbodies,
int nCutoffGroups,
97 int atomStorageLayout,
int rigidBodyStorageLayout,
98 int cutoffGroupStorageLayout,
bool usePBC) :
99 atomData(nAtoms, atomStorageLayout),
100 rigidbodyData(nRigidbodies, rigidBodyStorageLayout),
101 cgData(nCutoffGroups, cutoffGroupStorageLayout), orthoTolerance_(1e-6) {
103 frameData.currentTime = 0;
104 frameData.hmat = Mat3x3d(0.0);
105 frameData.invHmat = Mat3x3d(0.0);
106 frameData.bBox = Mat3x3d(0.0);
107 frameData.invBbox = Mat3x3d(0.0);
108 frameData.orthoRhombic =
false;
109 frameData.usePBC = usePBC;
110 frameData.bondPotential = 0.0;
111 frameData.bendPotential = 0.0;
112 frameData.torsionPotential = 0.0;
113 frameData.inversionPotential = 0.0;
114 frameData.lrPotentials = potVec(0.0);
115 frameData.surfacePotential = 0.0;
116 frameData.reciprocalPotential = 0.0;
117 frameData.selfPotentials = potVec(0.0);
118 frameData.excludedPotentials = potVec(0.0);
119 frameData.restraintPotential = 0.0;
120 frameData.rawPotential = 0.0;
121 frameData.xyArea = 0.0;
122 frameData.xzArea = 0.0;
123 frameData.yzArea = 0.0;
124 frameData.volume = 0.0;
125 frameData.thermostat = make_pair(0.0, 0.0);
126 frameData.electronicThermostat = make_pair(0.0, 0.0);
127 frameData.barostat = Mat3x3d(0.0);
128 frameData.virialTensor = Mat3x3d(0.0);
129 frameData.conductiveHeatFlux = Vector3d(0.0, 0.0, 0.0);
130 frameData.spfData = std::make_shared<SPFData>();
132 clearDerivedProperties();
135 void Snapshot::clearDerivedProperties() {
136 frameData.totalEnergy = 0.0;
137 frameData.translationalKinetic = 0.0;
138 frameData.rotationalKinetic = 0.0;
139 frameData.electronicKinetic = 0.0;
140 frameData.kineticEnergy = 0.0;
141 frameData.potentialEnergy = 0.0;
142 frameData.shortRangePotential = 0.0;
143 frameData.longRangePotential = 0.0;
144 frameData.excludedPotential = 0.0;
145 frameData.selfPotential = 0.0;
146 frameData.pressure = 0.0;
147 frameData.temperature = 0.0;
148 frameData.pressureTensor =
Mat3x3d(0.0);
149 frameData.systemDipole =
Vector3d(0.0);
150 frameData.systemQuadrupole =
Mat3x3d(0.0);
151 frameData.convectiveHeatFlux =
Vector3d(0.0, 0.0, 0.0);
152 frameData.electronicTemperature = 0.0;
153 frameData.netCharge = 0.0;
154 frameData.chargeMomentum = 0.0;
155 frameData.COM = V3Zero;
156 frameData.COMvel = V3Zero;
157 frameData.COMw = V3Zero;
159 hasTotalEnergy =
false;
160 hasTranslationalKineticEnergy =
false;
161 hasRotationalKineticEnergy =
false;
162 hasElectronicKineticEnergy =
false;
163 hasKineticEnergy =
false;
164 hasShortRangePotential =
false;
165 hasLongRangePotential =
false;
166 hasExcludedPotential =
false;
167 hasSelfPotential =
false;
168 hasPotentialEnergy =
false;
174 hasTemperature =
false;
175 hasElectronicTemperature =
false;
176 hasNetCharge =
false;
177 hasChargeMomentum =
false;
181 hasPressureTensor =
false;
182 hasSystemDipole =
false;
183 hasSystemQuadrupole =
false;
184 hasConvectiveHeatFlux =
false;
185 hasInertiaTensor =
false;
186 hasGyrationalVolume =
false;
187 hasHullVolume =
false;
188 hasBoundingBox =
false;
192 int Snapshot::getID() {
return frameData.id; }
195 void Snapshot::setID(
int id) { frameData.id = id; }
197 int Snapshot::getSize() {
198 return atomData.getSize() + rigidbodyData.getSize();
202 int Snapshot::getNumberOfAtoms() {
return atomData.getSize(); }
205 int Snapshot::getNumberOfRigidBodies() {
return rigidbodyData.getSize(); }
208 int Snapshot::getNumberOfCutoffGroups() {
return cgData.getSize(); }
211 int Snapshot::getFrameDataSize() {
return sizeof(
FrameData); }
214 Mat3x3d Snapshot::getHmat() {
return frameData.hmat; }
220 frameData.invHmat = frameData.hmat.
inverse();
223 bool oldOrthoRhombic = frameData.orthoRhombic;
225 RealType smallDiag = fabs(frameData.hmat(0, 0));
226 if (smallDiag > fabs(frameData.hmat(1, 1)))
227 smallDiag = fabs(frameData.hmat(1, 1));
228 if (smallDiag > fabs(frameData.hmat(2, 2)))
229 smallDiag = fabs(frameData.hmat(2, 2));
230 RealType tol = smallDiag * orthoTolerance_;
232 frameData.orthoRhombic =
true;
234 for (
int i = 0; i < 3; i++) {
235 for (
int j = 0; j < 3; j++) {
237 if (frameData.orthoRhombic) {
238 if (fabs(frameData.hmat(i, j)) >= tol)
239 frameData.orthoRhombic =
false;
245 if (oldOrthoRhombic != frameData.orthoRhombic) {
278 Mat3x3d Snapshot::getInvHmat() {
return frameData.invHmat; }
281 Mat3x3d Snapshot::getBoundingBox() {
return frameData.bBox; }
284 void Snapshot::setBoundingBox(
const Mat3x3d& m) {
286 frameData.invBbox = frameData.bBox.
inverse();
287 hasBoundingBox =
true;
291 Mat3x3d Snapshot::getInvBoundingBox() {
return frameData.invBbox; }
293 RealType Snapshot::getXYarea() {
295 Vector3d x = frameData.hmat.getColumn(0);
296 Vector3d y = frameData.hmat.getColumn(1);
297 frameData.xyArea =
cross(x, y).length();
300 return frameData.xyArea;
303 RealType Snapshot::getXZarea() {
305 Vector3d x = frameData.hmat.getColumn(0);
306 Vector3d z = frameData.hmat.getColumn(2);
307 frameData.xzArea =
cross(x, z).length();
310 return frameData.xzArea;
313 RealType Snapshot::getYZarea() {
315 Vector3d y = frameData.hmat.getColumn(1);
316 Vector3d z = frameData.hmat.getColumn(2);
317 frameData.yzArea =
cross(y, z).length();
320 return frameData.yzArea;
323 RealType Snapshot::getVolume() {
325 frameData.volume = frameData.hmat.determinant();
328 return frameData.volume;
331 void Snapshot::setVolume(RealType vol) {
333 frameData.volume = vol;
338 if (!frameData.usePBC)
return;
340 if (!frameData.orthoRhombic) {
341 Vector3d scaled = frameData.invHmat * pos;
342 for (
int i = 0; i < 3; i++) {
343 scaled[i] -= roundMe(scaled[i]);
346 pos = frameData.hmat * scaled;
349 for (
int i = 0; i < 3; i++) {
350 scaled = pos[i] * frameData.invHmat(i, i);
351 scaled -= roundMe(scaled);
352 pos[i] = scaled * frameData.hmat(i, i);
361 if (!frameData.orthoRhombic)
362 scaled = frameData.invHmat * pos;
365 for (
int i = 0; i < 3; i++)
366 scaled[i] = pos[i] * frameData.invHmat(i, i);
372 void Snapshot::setCOM(
const Vector3d& com) {
377 void Snapshot::setCOMvel(
const Vector3d& comVel) {
378 frameData.COMvel = comVel;
382 void Snapshot::setCOMw(
const Vector3d& comw) {
383 frameData.COMw = comw;
387 Vector3d Snapshot::getCOM() {
return frameData.COM; }
389 Vector3d Snapshot::getCOMvel() {
return frameData.COMvel; }
391 Vector3d Snapshot::getCOMw() {
return frameData.COMw; }
393 RealType Snapshot::getTime() {
return frameData.currentTime; }
395 void Snapshot::increaseTime(RealType dt) { setTime(getTime() + dt); }
397 void Snapshot::setTime(RealType time) { frameData.currentTime = time; }
399 void Snapshot::setBondPotential(RealType bp) {
400 frameData.bondPotential = bp;
401 hasShortRangePotential =
false;
402 hasPotentialEnergy =
false;
403 hasTotalEnergy =
false;
406 void Snapshot::setBendPotential(RealType bp) {
407 frameData.bendPotential = bp;
408 hasShortRangePotential =
false;
409 hasPotentialEnergy =
false;
410 hasTotalEnergy =
false;
413 void Snapshot::setTorsionPotential(RealType tp) {
414 frameData.torsionPotential = tp;
415 hasShortRangePotential =
false;
416 hasPotentialEnergy =
false;
417 hasTotalEnergy =
false;
420 void Snapshot::setInversionPotential(RealType ip) {
421 frameData.inversionPotential = ip;
422 hasShortRangePotential =
false;
423 hasPotentialEnergy =
false;
424 hasTotalEnergy =
false;
427 RealType Snapshot::getBondPotential() {
return frameData.bondPotential; }
429 RealType Snapshot::getBendPotential() {
return frameData.bendPotential; }
431 RealType Snapshot::getTorsionPotential() {
432 return frameData.torsionPotential;
435 RealType Snapshot::getInversionPotential() {
436 return frameData.inversionPotential;
439 RealType Snapshot::getShortRangePotential() {
440 if (!hasShortRangePotential) {
441 frameData.shortRangePotential = frameData.bondPotential;
442 frameData.shortRangePotential += frameData.bendPotential;
443 frameData.shortRangePotential += frameData.torsionPotential;
444 frameData.shortRangePotential += frameData.inversionPotential;
445 hasShortRangePotential =
true;
446 hasPotentialEnergy =
false;
447 hasTotalEnergy =
false;
449 return frameData.shortRangePotential;
452 void Snapshot::setSurfacePotential(RealType sp) {
453 frameData.surfacePotential = sp;
454 hasLongRangePotential =
false;
455 hasPotentialEnergy =
false;
456 hasTotalEnergy =
false;
459 RealType Snapshot::getSurfacePotential() {
460 return frameData.surfacePotential;
463 void Snapshot::setReciprocalPotential(RealType rp) {
464 frameData.reciprocalPotential = rp;
465 hasLongRangePotential =
false;
466 hasPotentialEnergy =
false;
469 RealType Snapshot::getReciprocalPotential() {
470 return frameData.reciprocalPotential;
473 void Snapshot::setSelfPotentials(potVec sp) {
474 frameData.selfPotentials = sp;
475 hasSelfPotential =
false;
476 hasPotentialEnergy =
false;
477 hasTotalEnergy =
false;
480 potVec Snapshot::getSelfPotentials() {
return frameData.selfPotentials; }
482 RealType Snapshot::getSelfPotential() {
483 if (!hasSelfPotential) {
484 for (
int i = 0; i < N_INTERACTION_FAMILIES; i++) {
485 frameData.selfPotential += frameData.selfPotentials[i];
487 hasSelfPotential =
true;
488 hasPotentialEnergy =
false;
489 hasTotalEnergy =
false;
491 return frameData.selfPotential;
494 void Snapshot::setLongRangePotentials(potVec lrPot) {
495 frameData.lrPotentials = lrPot;
496 hasLongRangePotential =
false;
497 hasPotentialEnergy =
false;
498 hasTotalEnergy =
false;
501 RealType Snapshot::getLongRangePotential() {
502 if (!hasLongRangePotential) {
503 for (
int i = 0; i < N_INTERACTION_FAMILIES; i++) {
504 frameData.longRangePotential += frameData.lrPotentials[i];
506 frameData.longRangePotential += frameData.reciprocalPotential;
507 frameData.longRangePotential += frameData.surfacePotential;
508 hasLongRangePotential =
true;
509 hasPotentialEnergy =
false;
510 hasTotalEnergy =
false;
512 return frameData.longRangePotential;
515 potVec Snapshot::getLongRangePotentials() {
return frameData.lrPotentials; }
517 RealType Snapshot::getPotentialEnergy() {
518 if (!hasPotentialEnergy) {
519 frameData.potentialEnergy = this->getLongRangePotential();
520 frameData.potentialEnergy += this->getShortRangePotential();
521 frameData.potentialEnergy += this->getSelfPotential();
522 frameData.potentialEnergy += this->getExcludedPotential();
523 hasPotentialEnergy =
true;
524 hasTotalEnergy =
false;
526 return frameData.potentialEnergy;
529 void Snapshot::setPotentialEnergy(
const RealType pe) {
530 frameData.potentialEnergy = pe;
531 hasPotentialEnergy =
true;
532 hasTotalEnergy =
false;
535 void Snapshot::setExcludedPotentials(potVec exPot) {
536 frameData.excludedPotentials = exPot;
537 hasExcludedPotential =
false;
538 hasPotentialEnergy =
false;
539 hasTotalEnergy =
false;
542 potVec Snapshot::getExcludedPotentials() {
543 return frameData.excludedPotentials;
546 RealType Snapshot::getExcludedPotential() {
547 if (!hasExcludedPotential) {
548 for (
int i = 0; i < N_INTERACTION_FAMILIES; i++) {
549 frameData.excludedPotential += frameData.excludedPotentials[i];
551 hasExcludedPotential =
true;
552 hasPotentialEnergy =
false;
553 hasTotalEnergy =
false;
555 return frameData.excludedPotential;
558 void Snapshot::setRestraintPotential(RealType rp) {
559 frameData.restraintPotential = rp;
562 RealType Snapshot::getRestraintPotential() {
563 return frameData.restraintPotential;
566 void Snapshot::setRawPotential(RealType rp) { frameData.rawPotential = rp; }
568 RealType Snapshot::getRawPotential() {
return frameData.rawPotential; }
570 void Snapshot::setSelectionPotentials(potVec selPot) {
571 frameData.selectionPotentials = selPot;
574 potVec Snapshot::getSelectionPotentials() {
575 return frameData.selectionPotentials;
578 RealType Snapshot::getTranslationalKineticEnergy() {
579 return frameData.translationalKinetic;
582 RealType Snapshot::getRotationalKineticEnergy() {
583 return frameData.rotationalKinetic;
586 RealType Snapshot::getElectronicKineticEnergy() {
587 return frameData.electronicKinetic;
590 RealType Snapshot::getKineticEnergy() {
return frameData.kineticEnergy; }
592 void Snapshot::setTranslationalKineticEnergy(RealType tke) {
593 frameData.translationalKinetic = tke;
594 hasTranslationalKineticEnergy =
true;
595 hasKineticEnergy =
false;
596 hasTotalEnergy =
false;
599 void Snapshot::setRotationalKineticEnergy(RealType rke) {
600 frameData.rotationalKinetic = rke;
601 hasRotationalKineticEnergy =
true;
602 hasKineticEnergy =
false;
603 hasTotalEnergy =
false;
606 void Snapshot::setElectronicKineticEnergy(RealType eke) {
607 frameData.electronicKinetic = eke;
608 hasElectronicKineticEnergy =
true;
609 hasKineticEnergy =
false;
610 hasTotalEnergy =
false;
613 void Snapshot::setKineticEnergy(RealType ke) {
614 frameData.kineticEnergy = ke;
615 hasKineticEnergy =
true;
616 hasTotalEnergy =
false;
619 RealType Snapshot::getTotalEnergy() {
return frameData.totalEnergy; }
621 void Snapshot::setTotalEnergy(RealType te) {
622 frameData.totalEnergy = te;
623 hasTotalEnergy =
true;
626 RealType Snapshot::getConservedQuantity() {
627 return frameData.conservedQuantity;
630 void Snapshot::setConservedQuantity(RealType cq) {
631 frameData.conservedQuantity = cq;
634 RealType Snapshot::getTemperature() {
return frameData.temperature; }
636 void Snapshot::setTemperature(RealType temp) {
637 hasTemperature =
true;
638 frameData.temperature = temp;
641 RealType Snapshot::getElectronicTemperature() {
642 return frameData.electronicTemperature;
645 void Snapshot::setElectronicTemperature(RealType eTemp) {
646 hasElectronicTemperature =
true;
647 frameData.electronicTemperature = eTemp;
650 RealType Snapshot::getNetCharge() {
return frameData.netCharge; }
652 void Snapshot::setNetCharge(RealType nChg) {
654 frameData.netCharge = nChg;
657 RealType Snapshot::getChargeMomentum() {
return frameData.chargeMomentum; }
659 void Snapshot::setChargeMomentum(RealType cMom) {
660 hasChargeMomentum =
true;
661 frameData.chargeMomentum = cMom;
664 RealType Snapshot::getPressure() {
return frameData.pressure; }
666 void Snapshot::setPressure(RealType pressure) {
668 frameData.pressure = pressure;
671 Mat3x3d Snapshot::getPressureTensor() {
return frameData.pressureTensor; }
673 void Snapshot::setPressureTensor(
const Mat3x3d& pressureTensor) {
674 hasPressureTensor =
true;
675 frameData.pressureTensor = pressureTensor;
678 void Snapshot::setVirialTensor(
const Mat3x3d& virialTensor) {
679 frameData.virialTensor = virialTensor;
682 Mat3x3d Snapshot::getVirialTensor() {
return frameData.virialTensor; }
684 void Snapshot::setConductiveHeatFlux(
const Vector3d& chf) {
685 frameData.conductiveHeatFlux = chf;
688 Vector3d Snapshot::getConductiveHeatFlux() {
689 return frameData.conductiveHeatFlux;
692 Vector3d Snapshot::getConvectiveHeatFlux() {
693 return frameData.convectiveHeatFlux;
696 void Snapshot::setConvectiveHeatFlux(
const Vector3d& chf) {
697 hasConvectiveHeatFlux =
true;
698 frameData.convectiveHeatFlux = chf;
701 Vector3d Snapshot::getHeatFlux() {
703 return getConductiveHeatFlux() + getConvectiveHeatFlux();
706 Vector3d Snapshot::getSystemDipole() {
return frameData.systemDipole; }
708 void Snapshot::setSystemDipole(
const Vector3d& bd) {
709 hasSystemDipole =
true;
710 frameData.systemDipole = bd;
713 Mat3x3d Snapshot::getSystemQuadrupole() {
return frameData.systemQuadrupole; }
715 void Snapshot::setSystemQuadrupole(
const Mat3x3d& bq) {
716 hasSystemQuadrupole =
true;
717 frameData.systemQuadrupole = bq;
720 void Snapshot::setThermostat(
const pair<RealType, RealType>& thermostat) {
721 frameData.thermostat = thermostat;
724 pair<RealType, RealType> Snapshot::getThermostat() {
725 return frameData.thermostat;
728 void Snapshot::setElectronicThermostat(
729 const pair<RealType, RealType>& eTherm) {
730 frameData.electronicThermostat = eTherm;
733 pair<RealType, RealType> Snapshot::getElectronicThermostat() {
734 return frameData.electronicThermostat;
737 void Snapshot::setBarostat(
const Mat3x3d& barostat) {
738 frameData.barostat = barostat;
741 Mat3x3d Snapshot::getBarostat() {
return frameData.barostat; }
743 void Snapshot::setSPFData(std::shared_ptr<SPFData> data) {
744 frameData.spfData = data;
747 std::shared_ptr<SPFData> Snapshot::getSPFData() {
return frameData.spfData; }
749 void Snapshot::setInertiaTensor(
const Mat3x3d& inertiaTensor) {
750 frameData.inertiaTensor = inertiaTensor;
751 hasInertiaTensor =
true;
754 Mat3x3d Snapshot::getInertiaTensor() {
return frameData.inertiaTensor; }
756 void Snapshot::setGyrationalVolume(
const RealType gyrationalVolume) {
757 frameData.gyrationalVolume = gyrationalVolume;
758 hasGyrationalVolume =
true;
761 RealType Snapshot::getGyrationalVolume() {
762 return frameData.gyrationalVolume;
765 void Snapshot::setHullVolume(
const RealType hullVolume) {
766 frameData.hullVolume = hullVolume;
767 hasHullVolume =
true;
770 RealType Snapshot::getHullVolume() {
return frameData.hullVolume; }
772 void Snapshot::setOrthoTolerance(RealType ot) { orthoTolerance_ = ot; }
SquareMatrix3< Real > inverse() const
Sets the value of this matrix to the inverse of itself.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
Vector3< Real > cross(const Vector3< Real > &v1, const Vector3< Real > &v2)
Returns the cross product of two Vectors.
FrameData is a structure for holding system-wide dynamic data about the simulation.