ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/utils/MoLocator.cpp
Revision: 1767
Committed: Fri Jul 6 22:01:58 2012 UTC (12 years, 9 months ago) by gezelter
File size: 7247 byte(s)
Log Message:
Various fixes required to compile OpenMD with the MS Visual C++ compiler

File Contents

# Content
1 /*
2 * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 *
4 * The University of Notre Dame grants you ("Licensee") a
5 * non-exclusive, royalty free, license to use, modify and
6 * redistribute this software in source and binary code form, provided
7 * that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
15 * distribution.
16 *
17 * This software is provided "AS IS," without a warranty of any
18 * kind. All express or implied conditions, representations and
19 * warranties, including any implied warranty of merchantability,
20 * fitness for a particular purpose or non-infringement, are hereby
21 * excluded. The University of Notre Dame and its licensors shall not
22 * be liable for any damages suffered by licensee as a result of
23 * using, modifying or distributing the software or its
24 * derivatives. In no event will the University of Notre Dame or its
25 * licensors be liable for any lost revenue, profit or data, or for
26 * direct, indirect, special, consequential, incidental or punitive
27 * damages, however caused and regardless of the theory of liability,
28 * arising out of the use of or inability to use software, even if the
29 * University of Notre Dame has been advised of the possibility of
30 * such damages.
31 *
32 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
33 * research, please cite the appropriate papers when you publish your
34 * work. Good starting points are:
35 *
36 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
37 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
38 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).
39 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 */
42
43 #include <iostream>
44
45 #include <cstdlib>
46 #include <cmath>
47
48 #include "utils/simError.h"
49 #include "utils/MoLocator.hpp"
50 #include "types/AtomType.hpp"
51
52 namespace OpenMD {
53 MoLocator::MoLocator( MoleculeStamp* theStamp, ForceField* theFF){
54
55 myStamp = theStamp;
56 myFF = theFF;
57 nIntegrableObjects = myStamp->getNIntegrable();
58 calcRef();
59 }
60
61 void MoLocator::placeMol( const Vector3d& offset, const Vector3d& ort, Molecule* mol){
62
63 Vector3d newCoor;
64 Vector3d curRefCoor;
65 RotMat3x3d rotMat = latVec2RotMat(ort);
66
67 if(mol->getNIntegrableObjects() != nIntegrableObjects){
68 sprintf( painCave.errMsg,
69 "MoLocator error.\n"
70 " The number of integrable objects of MoleculeStamp is not the same as that of Molecule\n");
71 painCave.isFatal = 1;
72 simError();
73 }
74
75 Molecule::IntegrableObjectIterator ii;
76 StuntDouble* integrableObject;
77 int i;
78 for (integrableObject = mol->beginIntegrableObject(ii), i = 0; integrableObject != NULL;
79 integrableObject = mol->nextIntegrableObject(ii), ++i) {
80
81 newCoor = rotMat * refCoords[i];
82 newCoor += offset;
83
84 integrableObject->setPos(newCoor);
85 integrableObject->setVel(V3Zero);
86
87 if(integrableObject->isDirectional()){
88 integrableObject->setA(rotMat * integrableObject->getA());
89 integrableObject->setJ(V3Zero);
90 }
91 }
92 }
93
94 void MoLocator::calcRef( void ){
95 AtomStamp* currAtomStamp;
96 RigidBodyStamp* rbStamp;
97 unsigned int nAtoms;
98 int nRigidBodies;
99 std::vector<RealType> mass;
100 Vector3d coor;
101 Vector3d refMolCom;
102 int nAtomsInRb;
103 RealType totMassInRb;
104 RealType currAtomMass;
105 RealType molMass;
106
107 nAtoms= myStamp->getNAtoms();
108 nRigidBodies = myStamp->getNRigidBodies();
109
110 for(unsigned int i = 0; i < nAtoms; i++){
111
112 currAtomStamp = myStamp->getAtomStamp(i);
113
114 if( !currAtomStamp->havePosition() ){
115 sprintf( painCave.errMsg,
116 "MoLocator error.\n"
117 " Component %s, atom %s does not have a position specified.\n"
118 " This means MoLocator cannot initalize it's position.\n",
119 myStamp->getName().c_str(),
120 currAtomStamp->getType().c_str());
121
122 painCave.isFatal = 1;
123 simError();
124 }
125
126 //if atom belongs to rigidbody, just skip it
127 if(myStamp->isAtomInRigidBody(i))
128 continue;
129 //get mass and the reference coordinate
130 else{
131 currAtomMass = getAtomMass(currAtomStamp->getType(), myFF);
132 mass.push_back(currAtomMass);
133 coor.x() = currAtomStamp->getPosX();
134 coor.y() = currAtomStamp->getPosY();
135 coor.z() = currAtomStamp->getPosZ();
136 refCoords.push_back(coor);
137
138 }
139 }
140
141 for(int i = 0; i < nRigidBodies; i++){
142
143 rbStamp = myStamp->getRigidBodyStamp(i);
144 nAtomsInRb = rbStamp->getNMembers();
145
146 coor.x() = 0.0;
147 coor.y() = 0.0;
148 coor.z() = 0.0;
149 totMassInRb = 0.0;
150
151 for(int j = 0; j < nAtomsInRb; j++){
152
153 currAtomStamp = myStamp->getAtomStamp(rbStamp->getMemberAt(j));
154 currAtomMass = getAtomMass(currAtomStamp->getType(), myFF);
155 totMassInRb += currAtomMass;
156
157 coor.x() += currAtomStamp->getPosX() * currAtomMass;
158 coor.y() += currAtomStamp->getPosY() * currAtomMass;
159 coor.z() += currAtomStamp->getPosZ() * currAtomMass;
160 }
161
162 mass.push_back(totMassInRb);
163 coor /= totMassInRb;
164 refCoords.push_back(coor);
165 }
166
167
168 //calculate the reference center of mass
169 molMass = 0;
170 refMolCom.x() = 0;
171 refMolCom.y() = 0;
172 refMolCom.z() = 0;
173
174 for(int i = 0; i < nIntegrableObjects; i++){
175 refMolCom += refCoords[i] * mass[i];
176 molMass += mass[i];
177 }
178
179 refMolCom /= molMass;
180
181 //move the reference center of mass to (0,0,0) and adjust the reference coordinate
182 //of the integrabel objects
183 for(int i = 0; i < nIntegrableObjects; i++)
184 refCoords[i] -= refMolCom;
185 }
186
187 RealType getAtomMass(const std::string& at, ForceField* myFF) {
188 RealType mass;
189 AtomType* atomType= myFF->getAtomType(at);
190 if (atomType != NULL) {
191 mass = atomType->getMass();
192 } else {
193 mass = 0.0;
194 std::cerr << "Can not find AtomType: " << at << std::endl;
195 }
196 return mass;
197 }
198
199 RealType getMolMass(MoleculeStamp *molStamp, ForceField *myFF) {
200 unsigned int nAtoms;
201 RealType totMass = 0;
202 nAtoms = molStamp->getNAtoms();
203
204 for(unsigned int i = 0; i < nAtoms; i++) {
205 AtomStamp *currAtomStamp = molStamp->getAtomStamp(i);
206 totMass += getAtomMass(currAtomStamp->getType(), myFF);
207 }
208 return totMass;
209 }
210 RotMat3x3d latVec2RotMat(const Vector3d& lv){
211
212 RealType theta =acos(lv[2]);
213 RealType phi = atan2(lv[1], lv[0]);
214 RealType psi = 0;
215
216 return RotMat3x3d(phi, theta, psi);
217
218 }
219 }
220

Properties

Name Value
svn:keywords Author Id Revision Date