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