OpenMD 3.2
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 following paper when you publish your work:
33 *
34 * [1] Drisko et al., J. Open Source Softw. 9, 7004 (2024).
35 *
36 * Good starting points for code and simulation methodology are:
37 *
38 * [2] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
39 * [3] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
40 * [4] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
41 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
42 * [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
43 * [7] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
44 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
45 * [9] Drisko & Gezelter, J. Chem. Theory Comput. 20, 4986-4997 (2024).
46 */
47
49
50#include "brains/SimInfo.hpp"
51#include "brains/Thermo.hpp"
52#include "integrators/IntegratorCreator.hpp"
54#include "utils/Constants.hpp"
55#include "utils/simError.h"
56
57// Basic non-isotropic thermostating and barostating via the Melchionna
58// modification of the Hoover algorithm:
59//
60// Melchionna, S., Ciccotti, G., and Holian, B. L., 1993,
61// Molec. Phys., 78, 533.
62//
63// and
64//
65// Hoover, W. G., 1986, Phys. Rev. A, 34, 2499.
66
67namespace OpenMD {
68
69 RealType NPTxyz::calcConservedQuantity() {
70 thermostat = snap->getThermostat();
71 loadEta();
72
73 // We need NkBT a lot, so just set it here: This is the RAW number
74 // of integrableObjects, so no subtraction or addition of constraints or
75 // orientational degrees of freedom:
76 NkBT = info_->getNGlobalIntegrableObjects() * Constants::kB * targetTemp;
77
78 // fkBT is used because the thermostat operates on more degrees of freedom
79 // than the barostat (when there are particles with orientational degrees
80 // of freedom).
81 fkBT = info_->getNdf() * Constants::kB * targetTemp;
82
83 RealType conservedQuantity;
84 RealType totalEnergy;
85 RealType thermostat_kinetic;
86 RealType thermostat_potential;
87 RealType barostat_kinetic;
88 RealType barostat_potential;
89 RealType trEta;
90
91 totalEnergy = thermo.getTotalEnergy();
92
93 thermostat_kinetic = fkBT * tt2 * thermostat.first * thermostat.first /
94 (2.0 * Constants::energyConvert);
95
96 thermostat_potential = fkBT * thermostat.second / Constants::energyConvert;
97
98 SquareMatrix<RealType, 3> tmp = eta.transpose() * eta;
99 trEta = tmp.trace();
100
101 barostat_kinetic = NkBT * tb2 * trEta / (2.0 * Constants::energyConvert);
102
103 barostat_potential =
104 (targetPressure * thermo.getVolume() / Constants::pressureConvert) /
105 Constants::energyConvert;
106
107 conservedQuantity = totalEnergy + thermostat_kinetic +
108 thermostat_potential + barostat_kinetic +
109 barostat_potential;
110
111 return conservedQuantity;
112 }
113
114 void NPTxyz::scaleSimBox() {
115 int i, j;
116 Mat3x3d scaleMat;
117 RealType scaleFactor;
118 RealType bigScale, smallScale;
119 Mat3x3d hm;
120 Mat3x3d hmnew;
121
122 // Scale the box after all the positions have been moved:
123
124 // Use a taylor expansion for eta products: Hmat = Hmat . exp(dt * etaMat)
125 // Hmat = Hmat . ( Ident + dt * etaMat + dt^2 * etaMat*etaMat / 2)
126
127 bigScale = 1.0;
128 smallScale = 1.0;
129
130 for (i = 0; i < 3; i++) {
131 for (j = 0; j < 3; j++) {
132 scaleMat(i, j) = 0.0;
133 if (i == j) { scaleMat(i, j) = 1.0; }
134 }
135 }
136
137 for (i = 0; i < 3; i++) {
138 // calculate the scaleFactors
139
140 scaleFactor = exp(dt * eta(i, i));
141
142 scaleMat(i, i) = scaleFactor;
143
144 if (scaleMat(i, i) > bigScale) { bigScale = scaleMat(i, i); }
145
146 if (scaleMat(i, i) < smallScale) { smallScale = scaleMat(i, i); }
147 }
148
149 if ((bigScale > 1.1) || (smallScale < 0.9)) {
150 snprintf(
151 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
152 "NPTxyz error: Attempting a Box scaling of more than 10 percent.\n"
153 " Check your tauBarostat, as it is probably too small!\n\n"
154 " scaleMat = [%lf\t%lf\t%lf]\n"
155 " [%lf\t%lf\t%lf]\n"
156 " [%lf\t%lf\t%lf]\n",
157 scaleMat(0, 0), scaleMat(0, 1), scaleMat(0, 2), scaleMat(1, 0),
158 scaleMat(1, 1), scaleMat(1, 2), scaleMat(2, 0), scaleMat(2, 1),
159 scaleMat(2, 2));
160 painCave.isFatal = 1;
161 simError();
162 } else {
163 Mat3x3d hmat = snap->getHmat();
164 hmat = hmat * scaleMat;
165 snap->setHmat(hmat);
166 }
167 }
168
169 void NPTxyz::loadEta() { eta = snap->getBarostat(); }
170
171} // namespace OpenMD
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.