OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
RigidBody.hpp
Go to the documentation of this file.
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/**
49 * @file RigidBody.hpp
50 * @author tlin
51 * @date 10/23/2004
52 * @version 1.0
53 */
54
55#ifndef PRIMITIVES_RIGIDBODY_HPP
56#define PRIMITIVES_RIGIDBODY_HPP
57
58#include <vector>
59
62#include "types/AtomStamp.hpp"
63
64namespace OpenMD {
65 class RigidBody : public StuntDouble {
66 public:
67 using AtomIterator = std::vector<Atom*>::iterator;
68
69 RigidBody();
70
71 virtual std::string getType() { return name_; }
72
73 /** Sets the name of this stuntRealType*/
74 virtual void setType(const std::string& name) { name_ = name; }
75
76 /**
77 * Sets the previous rotation matrix of this stuntdouble
78 * @param a new rotation matrix
79 */
80 virtual void setPrevA(const RotMat3x3d& a);
81
82 /**
83 * Sets the current rotation matrix of this stuntdouble
84 * @param a new rotation matrix
85 * @note setA will not change the position and rotation matrix of
86 * Directional atoms belong to this rigidbody. If you want to do that, use
87 * #updateAtoms
88 */
89 virtual void setA(const RotMat3x3d& a);
90 /**
91 * Sets the rotation matrix of this stuntdouble in specified snapshot
92 * @param a rotation matrix to be set
93 * @param snapshotNo
94 * @see #getA
95 */
96 virtual void setA(const RotMat3x3d& a, int snapshotNo);
97
98 /**
99 * Returns the inertia tensor of this stuntdouble
100 * @return the inertia tensor of this stuntdouble
101 */
102 virtual Mat3x3d getI();
103
104 /**
105 * Returns the gradient of this stuntdouble
106 * @return the gradient of this stuntdouble
107 */
108 virtual std::vector<RealType> getGrad();
109
110 virtual void accept(BaseVisitor* v);
111
112 void addAtom(Atom* at, AtomStamp* ats);
113
114 /** calculates the reference coordinates */
115 void calcRefCoords();
116
117 /** Converts Atomic forces and torques to total forces and torques */
119
120 /**
121 Converts Atomic forces and torques to total forces and torques
122 and computes the rigid body contribution to the virial.
123 Returns the rigid body contribution to the virial as a 3x3
124 matrix.
125 */
127
128 /** update the positions of atoms belong to this rigidbody */
129 void updateAtoms();
130
131 void updateAtoms(int frame);
132
133 void updateAtomVel();
134
135 void updateAtomVel(int frame);
136
137 Atom* beginAtom(std::vector<Atom*>::iterator& i) {
138 i = atoms_.begin();
139 return i != atoms_.end() ? *i : NULL;
140 }
141
142 Atom* nextAtom(std::vector<Atom*>::iterator& i) {
143 ++i;
144 return i != atoms_.end() ? *i : NULL;
145 }
146
147 std::vector<Atom*>::iterator getBeginAtomIter() { return atoms_.begin(); }
148
149 std::vector<Atom*>::iterator getEndAtomIter() { return atoms_.end(); }
150
151 /**
152 * Returns the atoms of this rigid body
153 * @return the atoms of this rigid body in a vector
154 * @deprecated
155 */
156 std::vector<Atom*> getAtoms() { return atoms_; }
157
158 /**
159 * Returns the number of atoms in this rigid body
160 * @return the number of atoms in this rigid body
161 */
162 size_t getNumAtoms() { return atoms_.size(); }
163
164 /**
165 * Return the position of atom which belongs to this rigid body.
166 * @return true if index is valid otherwise return false
167 * @param pos the position of atom which will be set on return if index is
168 * valid
169 * @param index the index of the atom in rigid body's private data member
170 * atoms_
171 */
172 bool getAtomPos(Vector3d& pos, unsigned int index);
173
174 /**
175 * Return the position of atom which belongs to this rigid body.
176 * @return true if atom belongs to this rigid body,otherwise return false
177 * @param pos position of atom which will be set on return if atom belongs
178 * to this rigid body
179 * @param atom the pointer to an atom
180 */
181 bool getAtomPos(Vector3d& pos, Atom* atom);
182
183 /**
184 * Return the velocity of atom which belongs to this rigid body.
185 * @return true if index is valid otherwise return false
186 * @param vel the velocity of atom which will be set on return if index is
187 * valid
188 * @param index the index of the atom in rigid body's private data member
189 * atoms_
190 */
191 bool getAtomVel(Vector3d& vel, unsigned int index);
192
193 /**
194 * Return the velocity of atom which belongs to this rigid body.
195 * @return true if atom belongs to this rigid body,otherwise return false
196 * @param vel velocity of atom which will be set on return if atom belongs
197 * to this rigid body
198 * @param atom the pointer to an atom
199 */
200 bool getAtomVel(Vector3d& vel, Atom*);
201
202 /**
203 * Return the reference coordinate of atom which belongs to this rigid body.
204 * @return true if index is valid otherwise return false
205 * @param coor the reference coordinate of atom which will be set on return
206 * if index is valid
207 * @param index the index of the atom in rigid body's private data member
208 * atoms_
209 */
210 bool getAtomRefCoor(Vector3d& coor, unsigned int index);
211
212 /**
213 * Return the velocity of atom which belongs to this rigid body.
214 * @return true if atom belongs to this rigid body,otherwise return false
215 * @param coor velocity of atom which will be set on return if atom belongs
216 * to this rigid body
217 * @param atom the pointer to an atom
218 */
219 bool getAtomRefCoor(Vector3d& coor, Atom* atom);
220
221 Vector3d getRefCOM() { return refCOM_; }
222
223 private:
224 std::string name_;
225 Mat3x3d inertiaTensor_;
226 RotMat3x3d sU_; /**< body fixed standard unit vector */
227
228 std::vector<Atom*> atoms_;
229 Vector3d refCOM_; /**< center of mass relative to original coordinates */
230 std::vector<Vector3d> refCoords_;
231 std::vector<RotMat3x3d> refOrients_;
232 };
233} // namespace OpenMD
234
235#endif // PRIMITIVES_RIGIDBODY_HPP
virtual void setType(const std::string &name)
Sets the name of this stuntRealType.
Definition RigidBody.hpp:74
void calcRefCoords()
calculates the reference coordinates
virtual void setPrevA(const RotMat3x3d &a)
Sets the previous rotation matrix of this stuntdouble.
Definition RigidBody.cpp:60
bool getAtomRefCoor(Vector3d &coor, unsigned int index)
Return the reference coordinate of atom which belongs to this rigid body.
virtual void setA(const RotMat3x3d &a)
Sets the current rotation matrix of this stuntdouble.
Definition RigidBody.cpp:70
size_t getNumAtoms()
Returns the number of atoms in this rigid body.
void updateAtoms()
update the positions of atoms belong to this rigidbody
std::vector< Atom * > getAtoms()
Returns the atoms of this rigid body.
virtual std::vector< RealType > getGrad()
Returns the gradient of this stuntdouble.
Definition RigidBody.cpp:92
Mat3x3d calcForcesAndTorquesAndVirial()
Converts Atomic forces and torques to total forces and torques and computes the rigid body contributi...
virtual Mat3x3d getI()
Returns the inertia tensor of this stuntdouble.
Definition RigidBody.cpp:90
void calcForcesAndTorques()
Converts Atomic forces and torques to total forces and torques.
virtual void accept(BaseVisitor *v)
bool getAtomPos(Vector3d &pos, unsigned int index)
Return the position of atom which belongs to this rigid body.
bool getAtomVel(Vector3d &vel, unsigned int index)
Return the velocity of atom which belongs to this rigid body.
virtual std::string getType()
Returns the name of this stuntDouble.
Definition RigidBody.hpp:71
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.