OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
DirectionalAtom.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 "types/DirectionalAdapter.hpp"
48#include "types/MultipoleAdapter.hpp"
49#include "utils/simError.h"
50
51namespace OpenMD {
52
53 DirectionalAtom::DirectionalAtom(AtomType* dAtomType) : Atom(dAtomType) {
54 objType_ = otDAtom;
55
56 DirectionalAdapter da = DirectionalAdapter(dAtomType);
57 I_ = da.getI();
58
59 MultipoleAdapter ma = MultipoleAdapter(dAtomType);
60 if (ma.isDipole()) { dipole_ = ma.getDipole(); }
61 if (ma.isQuadrupole()) { quadrupole_ = ma.getQuadrupole(); }
62
63 // Check if one of the diagonal inertia tensor of this directional
64 // atom is zero:
65 int nLinearAxis = 0;
66 Mat3x3d inertiaTensor = getI();
67 for (int i = 0; i < 3; i++) {
68 if (fabs(inertiaTensor(i, i)) < OpenMD::epsilon) {
69 linear_ = true;
70 linearAxis_ = i;
71 ++nLinearAxis;
72 }
73 }
74
75 if (nLinearAxis > 1) {
76 snprintf(
77 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
78 "Directional Atom warning.\n"
79 "\tOpenMD found more than one axis in this directional atom with a "
80 "vanishing \n"
81 "\tmoment of inertia.");
82 painCave.isFatal = 0;
83 simError();
84 }
85 }
86
87 Mat3x3d DirectionalAtom::getI() { return I_; }
88
89 void DirectionalAtom::setPrevA(const RotMat3x3d& a) {
90 ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_] = a;
91
92 if (atomType_->isMultipole()) {
93 RotMat3x3d atrans = a.transpose();
94
95 if (atomType_->isDipole()) {
96 ((snapshotMan_->getPrevSnapshot())->*storage_).dipole[localIndex_] =
97 atrans * dipole_;
98 }
99
100 if (atomType_->isQuadrupole()) {
101 ((snapshotMan_->getPrevSnapshot())->*storage_).quadrupole[localIndex_] =
102 atrans * quadrupole_ * a;
103 }
104 }
105 }
106
107 void DirectionalAtom::setA(const RotMat3x3d& a) {
108 ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_] = a;
109
110 if (atomType_->isMultipole()) {
111 RotMat3x3d atrans = a.transpose();
112
113 if (atomType_->isDipole()) {
114 ((snapshotMan_->getCurrentSnapshot())->*storage_).dipole[localIndex_] =
115 atrans * dipole_;
116 }
117
118 if (atomType_->isQuadrupole()) {
119 ((snapshotMan_->getCurrentSnapshot())->*storage_)
120 .quadrupole[localIndex_] = atrans * quadrupole_ * a;
121 }
122 }
123 }
124
125 void DirectionalAtom::setA(const RotMat3x3d& a, int snapshotNo) {
126 ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_] = a;
127
128 if (atomType_->isMultipole()) {
129 RotMat3x3d atrans = a.transpose();
130
131 if (atomType_->isDipole()) {
132 ((snapshotMan_->getSnapshot(snapshotNo))->*storage_)
133 .dipole[localIndex_] = atrans * dipole_;
134 }
135
136 if (atomType_->isQuadrupole()) {
137 ((snapshotMan_->getSnapshot(snapshotNo))->*storage_)
138 .quadrupole[localIndex_] = atrans * quadrupole_ * a;
139 }
140 }
141 }
142
143 void DirectionalAtom::rotateBy(const RotMat3x3d& m) { setA(m * getA()); }
144
145 std::vector<RealType> DirectionalAtom::getGrad() {
146 std::vector<RealType> grad(6, 0.0);
147 Vector3d force;
148 Vector3d torque;
149 Vector3d myEuler;
150 RealType phi, theta;
151 RealType cphi, sphi, ctheta, stheta;
152 Vector3d ephi;
153 Vector3d etheta;
154 Vector3d epsi;
155
156 force = getFrc();
157 torque = getTrq();
158
159 myEuler = getA().toEulerAngles();
160
161 phi = myEuler[0];
162 theta = myEuler[1];
163
164 cphi = cos(phi);
165 sphi = sin(phi);
166 ctheta = cos(theta);
167 stheta = sin(theta);
168
169 if (fabs(stheta) < 1.0E-9) { stheta = 1.0E-9; }
170
171 ephi[0] = -sphi * ctheta / stheta;
172 ephi[1] = cphi * ctheta / stheta;
173 ephi[2] = 1.0;
174
175 etheta[0] = cphi;
176 etheta[1] = sphi;
177 etheta[2] = 0.0;
178
179 epsi[0] = sphi / stheta;
180 epsi[1] = -cphi / stheta;
181 epsi[2] = 0.0;
182
183 // gradient is equal to -force
184 for (int j = 0; j < 3; j++)
185 grad[j] = -force[j];
186
187 for (int j = 0; j < 3; j++) {
188 grad[3] -= torque[j] * ephi[j];
189 grad[4] -= torque[j] * etheta[j];
190 grad[5] -= torque[j] * epsi[j];
191 }
192
193 return grad;
194 }
195
196 void DirectionalAtom::accept(BaseVisitor* v) { v->visit(this); }
197} // namespace OpenMD
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.