OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
ApproximateModel.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
48#include "hydrodynamics/ApproximateModel.hpp"
49
50#include "hydrodynamics/CompositeShape.hpp"
51#include "hydrodynamics/Ellipsoid.hpp"
52#include "hydrodynamics/Sphere.hpp"
54#include "math/LU.hpp"
56#include "utils/Constants.hpp"
57#include "utils/simError.h"
58
59namespace OpenMD {
60
61 /**
62 * References:
63 *
64 * For the General Hydro Framework:
65 * Beatriz Carrasco and Jose Gracia de la Torre; "Hydrodynamic
66 * Properties of Rigid Particles: Comparison of Different Modeling
67 * and Computational Procedures", Biophysical Journal, 75(6), 3044,
68 * 1999
69 *
70 * Xiuquan Sun, Teng Lin, and J. Daniel Gezelter; "Langevin dynamics
71 * for rigid bodies of arbitrary shape", J. Chem. Phys. 128, 234107
72 * (2008)
73 *
74 * For overlapping beads and overlapping volume:
75 *
76 * Beatriz Carrasco and Jose Garcia de la Torre and Peter Zipper;
77 * "Calculation of hydrodynamic properties of macromolecular bead
78 * models with overlapping spheres", Eur Biophys J (1999) 28:
79 * 510-515
80 *
81 * For overlapping volume between two spherical beads:
82 * http://mathworld.wolfram.com/Sphere-SphereIntersection.html
83 *
84 * For non-overlapping and overlapping translation-translation
85 * mobility tensors:
86 *
87 * Zuk, P. J., E. Wajnryb, K. A. Mizerski, and P. Szymczak;
88 * “Rotne–Prager–Yamakawa Approximation for Different-Sized
89 * Particles in Application to Macromolecular Bead Models.”, Journal
90 * of Fluid Mechanics, 741 (2014)
91 *
92 * For distinctions between centers of resistance and diffusion:
93 * Steven Harvey and Jose Garcia de la Torre; "Coordinate Systems
94 * for Modeling the Hydrodynamic Resistance and Diffusion
95 * Coefficients of Irregularly Shaped Rigid Macromolecules",
96 * Macromolecules 1980 13 (4), 960-964
97 **/
98 ApproximateModel::ApproximateModel() : HydrodynamicsModel() {
99 elements_.clear();
100 }
101
102 void ApproximateModel::setShape(Shape* shape) {
103 elements_.clear();
104 shape_ = shape;
105 std::cerr << "Assigning Elements...";
106 assignElements();
107 std::cerr << " done.\n";
108 }
109
110 HydroProp* ApproximateModel::calcHydroProps(RealType viscosity) {
111 HydroProp* hp = new HydroProp();
112 hp->setName(shape_->getName());
113 std::size_t nelements = elements_.size();
114 if (nelements == 0) nelements = assignElements();
115
116 DynamicRectMatrix<RealType> B(3 * nelements, 3 * nelements);
117 DynamicRectMatrix<RealType> C(3 * nelements, 3 * nelements);
118 Mat3x3d I = Mat3x3d::identity();
119
120 std::cerr << "Checking " << nelements << " elements...";
121 for (std::size_t i = 0; i < nelements; ++i)
122 checkElement(i);
123 std::cerr << " done.\n";
124
125 std::cerr << "Calculating B matrix...";
126 for (std::size_t i = 0; i < nelements; ++i) {
127 for (std::size_t j = 0; j < nelements; ++j) {
128 Mat3x3d Tij = interactionTensor(i, j, viscosity);
129 B.setSubMatrix(i * 3, j * 3, Tij);
130 }
131 }
132 std::cerr << " done.\n";
133
134 // invert B Matrix
135 std::cerr << "Inverting B matrix...";
136 invertMatrix(B, C); // B is modified during the inversion
137 std::cerr << " done.\n";
138
139 // prepare U Matrix relative to arbitrary origin O(0.0, 0.0, 0.0);
140 // relative to the original geometry
141
142 std::vector<Mat3x3d> U;
143 for (unsigned int i = 0; i < nelements; ++i) {
144 Mat3x3d currU;
145 currU.setupSkewMat(elements_[i].pos);
146 U.push_back(currU);
147 }
148
149 // calculate Xi matrix at arbitrary origin O
150 Mat3x3d Xiott;
151 Mat3x3d Xiorr;
152 Mat3x3d Xiotr;
153
154 std::cerr << "Assembling resistance tensor...";
155 for (std::size_t i = 0; i < nelements; ++i) {
156 for (std::size_t j = 0; j < nelements; ++j) {
157 Mat3x3d Cij;
158 C.getSubMatrix(i * 3, j * 3, Cij);
159
160 Xiott += Cij;
161 Xiotr += U[i] * Cij;
162 // Uncorrected here. Volume correction is added after we
163 // assemble Xiorr
164 Xiorr += -U[i] * Cij * U[j];
165 }
166 }
167
168 // If the model requires it, calculate the total volume,
169 // discounting overlap:
170
171 RealType volume = volumeCorrection();
172
173 // Add the volume correction
174 Xiorr += (6.0 * viscosity * volume) * I;
175
176 Xiott *= Constants::viscoConvert;
177 Xiotr *= Constants::viscoConvert;
178 Xiorr *= Constants::viscoConvert;
179
180 // calculate center of resistance
181 Mat3x3d tmp;
182 Vector3d tmpVec;
183 tmp(0, 0) = Xiott(1, 1) + Xiott(2, 2);
184 tmp(0, 1) = -Xiott(0, 1);
185 tmp(0, 2) = -Xiott(0, 2);
186 tmp(1, 0) = -Xiott(0, 1);
187 tmp(1, 1) = Xiott(0, 0) + Xiott(2, 2);
188 tmp(1, 2) = -Xiott(1, 2);
189 tmp(2, 0) = -Xiott(0, 2);
190 tmp(2, 1) = -Xiott(1, 2);
191 tmp(2, 2) = Xiott(1, 1) + Xiott(0, 0);
192
193 tmpVec[0] = Xiotr(2, 1) - Xiotr(1, 2);
194 tmpVec[1] = Xiotr(0, 2) - Xiotr(2, 0);
195 tmpVec[2] = Xiotr(1, 0) - Xiotr(0, 1);
196
197 // center of resistance
198 Vector3d ror = tmp.inverse() * tmpVec;
199
200 // calculate Resistance Tensor at center of resistance
201 Mat3x3d Uor;
202 Uor.setupSkewMat(ror);
203
204 Mat3x3d Xirtt;
205 Mat3x3d Xirrr;
206 Mat3x3d Xirtr;
207
208 // Resistance tensors at the center of resistance
209 Xirtt = Xiott;
210 Xirtr = (Xiotr - Uor * Xiott);
211 Xirrr = Xiorr - Uor * Xiott * Uor + Xiotr * Uor - Uor * Xiotr.transpose();
212
213 // calculate Diffusion tensors at center of resistance
214 Mat6x6d Xi;
215 Mat6x6d Dr;
216
217 hp->setCenterOfResistance(ror);
218
219 Xi.setSubMatrix(0, 0, Xirtt);
220 Xi.setSubMatrix(0, 3, Xirtr.transpose());
221 Xi.setSubMatrix(3, 0, Xirtr);
222 Xi.setSubMatrix(3, 3, Xirrr);
223 std::cerr << " done.\n";
224
225 hp->setResistanceTensor(Xi);
226
227 return hp;
228 }
229} // namespace OpenMD
Rectangular matrix class with contiguous flat storage.
static SquareMatrix< Real, Dim > identity()
Returns an identity matrix.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
bool invertMatrix(MatrixType &A, MatrixType &AI)
Invert input square matrix A into matrix AI.
Definition LU.hpp:101