OpenMD 3.0
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
NPTxyz.cpp
1/*
2 * Copyright (c) 2004-present, The University of Notre Dame. All rights
3 * reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
32 * research, please cite the appropriate papers when you publish your
33 * work. Good starting points are:
34 *
35 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
36 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
37 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
38 * [4] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
39 * [5] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
40 * [6] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
41 * [7] Lamichhane, Newman & Gezelter, J. Chem. Phys. 141, 134110 (2014).
42 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
43 */
44
46
47#include "brains/SimInfo.hpp"
48#include "brains/Thermo.hpp"
49#include "integrators/IntegratorCreator.hpp"
51#include "utils/Constants.hpp"
52#include "utils/simError.h"
53
54// Basic non-isotropic thermostating and barostating via the Melchionna
55// modification of the Hoover algorithm:
56//
57// Melchionna, S., Ciccotti, G., and Holian, B. L., 1993,
58// Molec. Phys., 78, 533.
59//
60// and
61//
62// Hoover, W. G., 1986, Phys. Rev. A, 34, 2499.
63
64namespace OpenMD {
65
66 RealType NPTxyz::calcConservedQuantity() {
67 thermostat = snap->getThermostat();
68 loadEta();
69
70 // We need NkBT a lot, so just set it here: This is the RAW number
71 // of integrableObjects, so no subtraction or addition of constraints or
72 // orientational degrees of freedom:
73 NkBT = info_->getNGlobalIntegrableObjects() * Constants::kB * targetTemp;
74
75 // fkBT is used because the thermostat operates on more degrees of freedom
76 // than the barostat (when there are particles with orientational degrees
77 // of freedom).
78 fkBT = info_->getNdf() * Constants::kB * targetTemp;
79
80 RealType conservedQuantity;
81 RealType totalEnergy;
82 RealType thermostat_kinetic;
83 RealType thermostat_potential;
84 RealType barostat_kinetic;
85 RealType barostat_potential;
86 RealType trEta;
87
88 totalEnergy = thermo.getTotalEnergy();
89
90 thermostat_kinetic = fkBT * tt2 * thermostat.first * thermostat.first /
91 (2.0 * Constants::energyConvert);
92
93 thermostat_potential = fkBT * thermostat.second / Constants::energyConvert;
94
95 SquareMatrix<RealType, 3> tmp = eta.transpose() * eta;
96 trEta = tmp.trace();
97
98 barostat_kinetic = NkBT * tb2 * trEta / (2.0 * Constants::energyConvert);
99
100 barostat_potential =
101 (targetPressure * thermo.getVolume() / Constants::pressureConvert) /
102 Constants::energyConvert;
103
104 conservedQuantity = totalEnergy + thermostat_kinetic +
105 thermostat_potential + barostat_kinetic +
106 barostat_potential;
107
108 return conservedQuantity;
109 }
110
111 void NPTxyz::scaleSimBox() {
112 int i, j;
113 Mat3x3d scaleMat;
114 RealType scaleFactor;
115 RealType bigScale, smallScale;
116 Mat3x3d hm;
117 Mat3x3d hmnew;
118
119 // Scale the box after all the positions have been moved:
120
121 // Use a taylor expansion for eta products: Hmat = Hmat . exp(dt * etaMat)
122 // Hmat = Hmat . ( Ident + dt * etaMat + dt^2 * etaMat*etaMat / 2)
123
124 bigScale = 1.0;
125 smallScale = 1.0;
126
127 for (i = 0; i < 3; i++) {
128 for (j = 0; j < 3; j++) {
129 scaleMat(i, j) = 0.0;
130 if (i == j) { scaleMat(i, j) = 1.0; }
131 }
132 }
133
134 for (i = 0; i < 3; i++) {
135 // calculate the scaleFactors
136
137 scaleFactor = exp(dt * eta(i, i));
138
139 scaleMat(i, i) = scaleFactor;
140
141 if (scaleMat(i, i) > bigScale) { bigScale = scaleMat(i, i); }
142
143 if (scaleMat(i, i) < smallScale) { smallScale = scaleMat(i, i); }
144 }
145
146 if ((bigScale > 1.1) || (smallScale < 0.9)) {
147 snprintf(
148 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
149 "NPTxyz error: Attempting a Box scaling of more than 10 percent.\n"
150 " Check your tauBarostat, as it is probably too small!\n\n"
151 " scaleMat = [%lf\t%lf\t%lf]\n"
152 " [%lf\t%lf\t%lf]\n"
153 " [%lf\t%lf\t%lf]\n",
154 scaleMat(0, 0), scaleMat(0, 1), scaleMat(0, 2), scaleMat(1, 0),
155 scaleMat(1, 1), scaleMat(1, 2), scaleMat(2, 0), scaleMat(2, 1),
156 scaleMat(2, 2));
157 painCave.isFatal = 1;
158 simError();
159 } else {
160 Mat3x3d hmat = snap->getHmat();
161 hmat = hmat * scaleMat;
162 snap->setHmat(hmat);
163 }
164 }
165
166 void NPTxyz::loadEta() { eta = snap->getBarostat(); }
167
168} // namespace OpenMD
int getNdf()
Returns the number of degrees of freedom.
Definition SimInfo.hpp:220
int getNGlobalIntegrableObjects()
Returns the total number of integrable objects (total number of rigid bodies plus the total number of...
Definition SimInfo.hpp:139
Mat3x3d getHmat()
Returns the H-Matrix.
Definition Snapshot.cpp:214
void setHmat(const Mat3x3d &m)
Sets the H-Matrix.
Definition Snapshot.cpp:217
Real trace() const
Returns the trace of this matrix.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.