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. Acknowledgement of the program authors must be made in any |
10 |
* publication of scientific results based in part on use of the |
11 |
* program. An acceptable form of acknowledgement is citation of |
12 |
* the article in which the program was described (Matthew |
13 |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 |
* Parallel Simulation Engine for Molecular Dynamics," |
16 |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 |
* |
18 |
* 2. Redistributions of source code must retain the above copyright |
19 |
* notice, this list of conditions and the following disclaimer. |
20 |
* |
21 |
* 3. Redistributions in binary form must reproduce the above copyright |
22 |
* notice, this list of conditions and the following disclaimer in the |
23 |
* documentation and/or other materials provided with the |
24 |
* distribution. |
25 |
* |
26 |
* This software is provided "AS IS," without a warranty of any |
27 |
* kind. All express or implied conditions, representations and |
28 |
* warranties, including any implied warranty of merchantability, |
29 |
* fitness for a particular purpose or non-infringement, are hereby |
30 |
* excluded. The University of Notre Dame and its licensors shall not |
31 |
* be liable for any damages suffered by licensee as a result of |
32 |
* using, modifying or distributing the software or its |
33 |
* derivatives. In no event will the University of Notre Dame or its |
34 |
* licensors be liable for any lost revenue, profit or data, or for |
35 |
* direct, indirect, special, consequential, incidental or punitive |
36 |
* damages, however caused and regardless of the theory of liability, |
37 |
* arising out of the use of or inability to use software, even if the |
38 |
* University of Notre Dame has been advised of the possibility of |
39 |
* such damages. |
40 |
*/ |
41 |
|
42 |
#include <cstring> |
43 |
#include "visitors/AtomVisitor.hpp" |
44 |
#include "primitives/DirectionalAtom.hpp" |
45 |
#include "math/MatVec3.h" |
46 |
#include "primitives/RigidBody.hpp" |
47 |
|
48 |
namespace oopse { |
49 |
void BaseAtomVisitor::visit(RigidBody *rb) { |
50 |
//vector<Atom*> myAtoms; |
51 |
//vector<Atom*>::iterator atomIter; |
52 |
|
53 |
//myAtoms = rb->getAtoms(); |
54 |
|
55 |
//for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter) |
56 |
// (*atomIter)->accept(this); |
57 |
} |
58 |
|
59 |
void BaseAtomVisitor::setVisited(Atom *atom) { |
60 |
GenericData *data; |
61 |
data = atom->getPropertyByName("VISITED"); |
62 |
|
63 |
//if visited property is not existed, add it as new property |
64 |
if (data == NULL) { |
65 |
data = new GenericData(); |
66 |
data->setID("VISITED"); |
67 |
atom->addProperty(data); |
68 |
} |
69 |
} |
70 |
|
71 |
bool BaseAtomVisitor::isVisited(Atom *atom) { |
72 |
GenericData *data; |
73 |
data = atom->getPropertyByName("VISITED"); |
74 |
return data == NULL ? false : true; |
75 |
} |
76 |
|
77 |
bool SSDAtomVisitor::isSSDAtom(const std::string&atomType) { |
78 |
std::vector<std::string>::iterator strIter; |
79 |
|
80 |
for( strIter = ssdAtomType.begin(); strIter != ssdAtomType.end(); |
81 |
++strIter ) |
82 |
if (*strIter == atomType) |
83 |
return true; |
84 |
|
85 |
return false; |
86 |
} |
87 |
|
88 |
void SSDAtomVisitor::visit(DirectionalAtom *datom) { |
89 |
std::vector<AtomInfo *>atoms; |
90 |
|
91 |
//we need to convert SSD into 4 differnet atoms |
92 |
//one oxygen atom, two hydrogen atoms and one pseudo atom which is the center of the mass |
93 |
//of the water with a dipole moment |
94 |
Vector3d h1(0.0, -0.75695, 0.5206); |
95 |
Vector3d h2(0.0, 0.75695, 0.5206); |
96 |
Vector3d ox(0.0, 0.0, -0.0654); |
97 |
Vector3d u(0, 0, 1); |
98 |
RotMat3x3d rotMatrix; |
99 |
RotMat3x3d rotTrans; |
100 |
AtomInfo * atomInfo; |
101 |
Vector3d pos; |
102 |
Vector3d newVec; |
103 |
Quat4d q; |
104 |
AtomData * atomData; |
105 |
GenericData *data; |
106 |
bool haveAtomData; |
107 |
|
108 |
//if atom is not SSD atom, just skip it |
109 |
if (!isSSDAtom(datom->getType())) |
110 |
return; |
111 |
|
112 |
data = datom->getPropertyByName("ATOMDATA"); |
113 |
|
114 |
if (data != NULL) { |
115 |
atomData = dynamic_cast<AtomData *>(data); |
116 |
|
117 |
if (atomData == NULL) { |
118 |
std::cerr << "can not get Atom Data from " << datom->getType() << std::endl; |
119 |
atomData = new AtomData; |
120 |
haveAtomData = false; |
121 |
} else |
122 |
haveAtomData = true; |
123 |
} else { |
124 |
atomData = new AtomData; |
125 |
haveAtomData = false; |
126 |
} |
127 |
|
128 |
pos = datom->getPos(); |
129 |
q = datom->getQ(); |
130 |
rotMatrix = datom->getA(); |
131 |
|
132 |
// We need A^T to convert from body-fixed to space-fixed: |
133 |
//transposeMat3(rotMatrix, rotTrans); |
134 |
rotTrans = rotMatrix.transpose(); |
135 |
|
136 |
//center of mass of the water molecule |
137 |
//matVecMul3(rotTrans, u, newVec); |
138 |
newVec = rotTrans * u; |
139 |
|
140 |
atomInfo = new AtomInfo; |
141 |
atomInfo->AtomType = "X"; |
142 |
atomInfo->pos[0] = pos[0]; |
143 |
atomInfo->pos[1] = pos[1]; |
144 |
atomInfo->pos[2] = pos[2]; |
145 |
atomInfo->dipole[0] = newVec[0]; |
146 |
atomInfo->dipole[1] = newVec[1]; |
147 |
atomInfo->dipole[2] = newVec[2]; |
148 |
|
149 |
atomData->addAtomInfo(atomInfo); |
150 |
|
151 |
//oxygen |
152 |
//matVecMul3(rotTrans, ox, newVec); |
153 |
newVec = rotTrans * ox; |
154 |
|
155 |
atomInfo = new AtomInfo; |
156 |
atomInfo->AtomType = "O"; |
157 |
atomInfo->pos[0] = pos[0] + newVec[0]; |
158 |
atomInfo->pos[1] = pos[1] + newVec[1]; |
159 |
atomInfo->pos[2] = pos[2] + newVec[2]; |
160 |
atomInfo->dipole[0] = 0.0; |
161 |
atomInfo->dipole[1] = 0.0; |
162 |
atomInfo->dipole[2] = 0.0; |
163 |
atomData->addAtomInfo(atomInfo); |
164 |
|
165 |
//hydrogen1 |
166 |
//matVecMul3(rotTrans, h1, newVec); |
167 |
newVec = rotTrans * h1; |
168 |
atomInfo = new AtomInfo; |
169 |
atomInfo->AtomType = "H"; |
170 |
atomInfo->pos[0] = pos[0] + newVec[0]; |
171 |
atomInfo->pos[1] = pos[1] + newVec[1]; |
172 |
atomInfo->pos[2] = pos[2] + newVec[2]; |
173 |
atomInfo->dipole[0] = 0.0; |
174 |
atomInfo->dipole[1] = 0.0; |
175 |
atomInfo->dipole[2] = 0.0; |
176 |
atomData->addAtomInfo(atomInfo); |
177 |
|
178 |
//hydrogen2 |
179 |
//matVecMul3(rotTrans, h2, newVec); |
180 |
newVec = rotTrans * h2; |
181 |
atomInfo = new AtomInfo; |
182 |
atomInfo->AtomType = "H"; |
183 |
atomInfo->pos[0] = pos[0] + newVec[0]; |
184 |
atomInfo->pos[1] = pos[1] + newVec[1]; |
185 |
atomInfo->pos[2] = pos[2] + newVec[2]; |
186 |
atomInfo->dipole[0] = 0.0; |
187 |
atomInfo->dipole[1] = 0.0; |
188 |
atomInfo->dipole[2] = 0.0; |
189 |
atomData->addAtomInfo(atomInfo); |
190 |
|
191 |
//add atom data into atom's property |
192 |
|
193 |
if (!haveAtomData) { |
194 |
atomData->setID("ATOMDATA"); |
195 |
datom->addProperty(atomData); |
196 |
} |
197 |
|
198 |
setVisited(datom); |
199 |
} |
200 |
|
201 |
const std::string SSDAtomVisitor::toString() { |
202 |
char buffer[65535]; |
203 |
std::string result; |
204 |
|
205 |
sprintf(buffer, |
206 |
"------------------------------------------------------------------\n"); |
207 |
result += buffer; |
208 |
|
209 |
sprintf(buffer, "Visitor name: %s\n", visitorName.c_str()); |
210 |
result += buffer; |
211 |
|
212 |
sprintf(buffer, |
213 |
"Visitor Description: Convert SSD into 4 different atoms\n"); |
214 |
result += buffer; |
215 |
|
216 |
sprintf(buffer, |
217 |
"------------------------------------------------------------------\n"); |
218 |
result += buffer; |
219 |
|
220 |
return result; |
221 |
} |
222 |
|
223 |
bool LinearAtomVisitor::isLinearAtom(const string& atomType){ |
224 |
vector<string>::iterator strIter; |
225 |
|
226 |
for(strIter = linearAtomType.begin(); strIter != linearAtomType.end(); |
227 |
++strIter) |
228 |
if(*strIter == atomType) |
229 |
return true; |
230 |
|
231 |
return false; |
232 |
} |
233 |
|
234 |
void LinearAtomVisitor::visit(DirectionalAtom* datom){ |
235 |
|
236 |
vector<AtomInfo*> atoms; |
237 |
|
238 |
//we need to convert linear into 4 different atoms |
239 |
double c1[3] = {0.0, 0.0, -1.8}; |
240 |
double c2[3] = {0.0, 0.0, -0.6}; |
241 |
double c3[3] = {0.0, 0.0, 0.6}; |
242 |
double c4[3] = {0.0, 0.0, 1.8}; |
243 |
double rotMatrix[3][3]; |
244 |
double rotTrans[3][3]; |
245 |
AtomInfo* atomInfo; |
246 |
double pos[3]; |
247 |
double newVec[3]; |
248 |
double q[4]; |
249 |
AtomData* atomData; |
250 |
GenericData* data; |
251 |
bool haveAtomData; |
252 |
|
253 |
//if atom is not SSD atom, just skip it |
254 |
if(!isLinearAtom(datom->getType())) |
255 |
return; |
256 |
|
257 |
data = datom->getProperty("ATOMDATA"); |
258 |
if(data != NULL){ |
259 |
|
260 |
atomData = dynamic_cast<AtomData*>(data); |
261 |
if(atomData == NULL){ |
262 |
cerr << "can not get Atom Data from " << datom->getType() << endl; |
263 |
atomData = new AtomData; |
264 |
haveAtomData = false; |
265 |
} |
266 |
else |
267 |
haveAtomData = true; |
268 |
} |
269 |
else{ |
270 |
atomData = new AtomData; |
271 |
haveAtomData = false; |
272 |
} |
273 |
|
274 |
|
275 |
datom->getPos(pos); |
276 |
datom->getQ(q); |
277 |
datom->getA(rotMatrix); |
278 |
|
279 |
// We need A^T to convert from body-fixed to space-fixed: |
280 |
transposeMat3(rotMatrix, rotTrans); |
281 |
|
282 |
matVecMul3(rotTrans, c1, newVec); |
283 |
atomInfo = new AtomInfo; |
284 |
atomInfo->AtomType = "C"; |
285 |
atomInfo->pos[0] = pos[0] + newVec[0]; |
286 |
atomInfo->pos[1] = pos[1] + newVec[1]; |
287 |
atomInfo->pos[2] = pos[2] + newVec[2]; |
288 |
atomInfo->dipole[0] = 0.0; |
289 |
atomInfo->dipole[1] = 0.0; |
290 |
atomInfo->dipole[2] = 0.0; |
291 |
atomData->addAtomInfo(atomInfo); |
292 |
|
293 |
matVecMul3(rotTrans, c2, newVec); |
294 |
atomInfo = new AtomInfo; |
295 |
atomInfo->AtomType = "C"; |
296 |
atomInfo->pos[0] = pos[0] + newVec[0]; |
297 |
atomInfo->pos[1] = pos[1] + newVec[1]; |
298 |
atomInfo->pos[2] = pos[2] + newVec[2]; |
299 |
atomInfo->dipole[0] = 0.0; |
300 |
atomInfo->dipole[1] = 0.0; |
301 |
atomInfo->dipole[2] = 0.0; |
302 |
atomData->addAtomInfo(atomInfo); |
303 |
|
304 |
matVecMul3(rotTrans, c3, newVec); |
305 |
atomInfo = new AtomInfo; |
306 |
atomInfo->AtomType = "C"; |
307 |
atomInfo->pos[0] = pos[0] + newVec[0]; |
308 |
atomInfo->pos[1] = pos[1] + newVec[1]; |
309 |
atomInfo->pos[2] = pos[2] + newVec[2]; |
310 |
atomInfo->dipole[0] = 0.0; |
311 |
atomInfo->dipole[1] = 0.0; |
312 |
atomInfo->dipole[2] = 0.0; |
313 |
atomData->addAtomInfo(atomInfo); |
314 |
|
315 |
matVecMul3(rotTrans, c4, newVec); |
316 |
atomInfo = new AtomInfo; |
317 |
atomInfo->AtomType = "C"; |
318 |
atomInfo->pos[0] = pos[0] + newVec[0]; |
319 |
atomInfo->pos[1] = pos[1] + newVec[1]; |
320 |
atomInfo->pos[2] = pos[2] + newVec[2]; |
321 |
atomInfo->dipole[0] = 0.0; |
322 |
atomInfo->dipole[1] = 0.0; |
323 |
atomInfo->dipole[2] = 0.0; |
324 |
atomData->addAtomInfo(atomInfo); |
325 |
|
326 |
//add atom data into atom's property |
327 |
|
328 |
if(!haveAtomData){ |
329 |
atomData->setID("ATOMDATA"); |
330 |
datom->addProperty(atomData); |
331 |
} |
332 |
|
333 |
setVisited(datom); |
334 |
|
335 |
} |
336 |
|
337 |
const string LinearAtomVisitor::toString(){ |
338 |
char buffer[65535]; |
339 |
string result; |
340 |
|
341 |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
342 |
result += buffer; |
343 |
|
344 |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
345 |
result += buffer; |
346 |
|
347 |
sprintf(buffer , "Visitor Description: Convert linear into 4 different atoms\n"); |
348 |
result += buffer; |
349 |
|
350 |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
351 |
result += buffer; |
352 |
|
353 |
return result; |
354 |
} |
355 |
|
356 |
//----------------------------------------------------------------------------// |
357 |
|
358 |
void DefaultAtomVisitor::visit(Atom *atom) { |
359 |
AtomData *atomData; |
360 |
AtomInfo *atomInfo; |
361 |
Vector3d pos; |
362 |
|
363 |
if (isVisited(atom)) |
364 |
return; |
365 |
|
366 |
atomInfo = new AtomInfo; |
367 |
|
368 |
atomData = new AtomData; |
369 |
atomData->setID("ATOMDATA"); |
370 |
|
371 |
pos = atom->getPos(); |
372 |
atomInfo->AtomType = atom->getType(); |
373 |
atomInfo->pos[0] = pos[0]; |
374 |
atomInfo->pos[1] = pos[1]; |
375 |
atomInfo->pos[2] = pos[2]; |
376 |
atomInfo->dipole[0] = 0.0; |
377 |
atomInfo->dipole[1] = 0.0; |
378 |
atomInfo->dipole[2] = 0.0; |
379 |
|
380 |
atomData->addAtomInfo(atomInfo); |
381 |
|
382 |
atom->addProperty(atomData); |
383 |
|
384 |
setVisited(atom); |
385 |
} |
386 |
|
387 |
void DefaultAtomVisitor::visit(DirectionalAtom *datom) { |
388 |
AtomData *atomData; |
389 |
AtomInfo *atomInfo; |
390 |
Vector3d pos; |
391 |
Vector3d u; |
392 |
|
393 |
if (isVisited(datom)) |
394 |
return; |
395 |
|
396 |
pos = datom->getPos(); |
397 |
u = datom->getElectroFrame().getColumn(3); |
398 |
|
399 |
atomData = new AtomData; |
400 |
atomData->setID("ATOMDATA"); |
401 |
atomInfo = new AtomInfo; |
402 |
|
403 |
atomInfo->AtomType = datom->getType(); |
404 |
atomInfo->pos[0] = pos[0]; |
405 |
atomInfo->pos[1] = pos[1]; |
406 |
atomInfo->pos[2] = pos[2]; |
407 |
atomInfo->dipole[0] = u[0]; |
408 |
atomInfo->dipole[1] = u[1]; |
409 |
atomInfo->dipole[2] = u[2]; |
410 |
|
411 |
atomData->addAtomInfo(atomInfo); |
412 |
|
413 |
datom->addProperty(atomData); |
414 |
|
415 |
setVisited(datom); |
416 |
} |
417 |
|
418 |
const std::string DefaultAtomVisitor::toString() { |
419 |
char buffer[65535]; |
420 |
std::string result; |
421 |
|
422 |
sprintf(buffer, |
423 |
"------------------------------------------------------------------\n"); |
424 |
result += buffer; |
425 |
|
426 |
sprintf(buffer, "Visitor name: %s\n", visitorName.c_str()); |
427 |
result += buffer; |
428 |
|
429 |
sprintf(buffer, |
430 |
"Visitor Description: copy atom infomation into atom data\n"); |
431 |
result += buffer; |
432 |
|
433 |
sprintf(buffer, |
434 |
"------------------------------------------------------------------\n"); |
435 |
result += buffer; |
436 |
|
437 |
return result; |
438 |
} |
439 |
} //namespace oopse |