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, 234107 (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 <cstring> |
44 |
#include "visitors/AtomVisitor.hpp" |
45 |
#include "primitives/DirectionalAtom.hpp" |
46 |
#include "primitives/RigidBody.hpp" |
47 |
#include "types/FixedChargeAdapter.hpp" |
48 |
#include "types/FluctuatingChargeAdapter.hpp" |
49 |
#include "types/MultipoleAdapter.hpp" |
50 |
#include "types/GayBerneAdapter.hpp" |
51 |
|
52 |
namespace OpenMD { |
53 |
|
54 |
BaseAtomVisitor::BaseAtomVisitor(SimInfo* info) : BaseVisitor() { |
55 |
storageLayout_ = info->getStorageLayout(); |
56 |
} |
57 |
|
58 |
void BaseAtomVisitor::visit(RigidBody *rb) { |
59 |
//vector<Atom*> myAtoms; |
60 |
//vector<Atom*>::iterator atomIter; |
61 |
|
62 |
//myAtoms = rb->getAtoms(); |
63 |
|
64 |
//for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter) |
65 |
// (*atomIter)->accept(this); |
66 |
} |
67 |
|
68 |
void BaseAtomVisitor::setVisited(Atom *atom) { |
69 |
GenericData *data; |
70 |
data = atom->getPropertyByName("VISITED"); |
71 |
|
72 |
//if visited property is not existed, add it as new property |
73 |
if (data == NULL) { |
74 |
data = new GenericData(); |
75 |
data->setID("VISITED"); |
76 |
atom->addProperty(data); |
77 |
} |
78 |
} |
79 |
|
80 |
bool BaseAtomVisitor::isVisited(Atom *atom) { |
81 |
GenericData *data; |
82 |
data = atom->getPropertyByName("VISITED"); |
83 |
return data == NULL ? false : true; |
84 |
} |
85 |
|
86 |
//------------------------------------------------------------------------// |
87 |
|
88 |
void DefaultAtomVisitor::visit(Atom *atom) { |
89 |
AtomData *atomData; |
90 |
AtomInfo *atomInfo; |
91 |
AtomType* atype = atom->getAtomType(); |
92 |
|
93 |
if (isVisited(atom)) |
94 |
return; |
95 |
|
96 |
atomInfo = new AtomInfo; |
97 |
atomInfo->atomTypeName = atom->getType(); |
98 |
atomInfo->pos = atom->getPos(); |
99 |
atomInfo->vel = atom->getVel(); |
100 |
atomInfo->frc = atom->getFrc(); |
101 |
atomInfo->vec = V3Zero; |
102 |
atomInfo->hasVelocity = true; |
103 |
atomInfo->hasForce = true; |
104 |
|
105 |
FixedChargeAdapter fca = FixedChargeAdapter(atype); |
106 |
if ( fca.isFixedCharge() ) { |
107 |
atomInfo->hasCharge = true; |
108 |
atomInfo->charge = fca.getCharge(); |
109 |
} |
110 |
|
111 |
FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atype); |
112 |
if ( fqa.isFluctuatingCharge() ) { |
113 |
atomInfo->hasCharge = true; |
114 |
atomInfo->charge += atom->getFlucQPos(); |
115 |
} |
116 |
|
117 |
if ((storageLayout_ & DataStorage::dslElectricField) && |
118 |
(atype->isElectrostatic())) { |
119 |
atomInfo->hasElectricField = true; |
120 |
atomInfo->eField = atom->getElectricField(); |
121 |
} |
122 |
|
123 |
atomData = new AtomData; |
124 |
atomData->setID("ATOMDATA"); |
125 |
atomData->addAtomInfo(atomInfo); |
126 |
|
127 |
atom->addProperty(atomData); |
128 |
|
129 |
setVisited(atom); |
130 |
} |
131 |
|
132 |
void DefaultAtomVisitor::visit(DirectionalAtom *datom) { |
133 |
AtomData *atomData; |
134 |
AtomInfo *atomInfo; |
135 |
AtomType* atype = datom->getAtomType(); |
136 |
|
137 |
if (isVisited(datom)) |
138 |
return; |
139 |
|
140 |
atomInfo = new AtomInfo; |
141 |
atomInfo->atomTypeName = datom->getType(); |
142 |
atomInfo->pos = datom->getPos(); |
143 |
atomInfo->vel = datom->getVel(); |
144 |
atomInfo->frc = datom->getFrc(); |
145 |
atomInfo->hasVelocity = true; |
146 |
atomInfo->hasForce = true; |
147 |
|
148 |
FixedChargeAdapter fca = FixedChargeAdapter(atype); |
149 |
if ( fca.isFixedCharge() ) { |
150 |
atomInfo->hasCharge = true; |
151 |
atomInfo->charge = fca.getCharge(); |
152 |
} |
153 |
|
154 |
FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atype); |
155 |
if ( fqa.isFluctuatingCharge() ) { |
156 |
atomInfo->hasCharge = true; |
157 |
atomInfo->charge += datom->getFlucQPos(); |
158 |
} |
159 |
|
160 |
if ((storageLayout_ & DataStorage::dslElectricField) && |
161 |
(atype->isElectrostatic())) { |
162 |
atomInfo->hasElectricField = true; |
163 |
atomInfo->eField = datom->getElectricField(); |
164 |
} |
165 |
|
166 |
GayBerneAdapter gba = GayBerneAdapter(atype); |
167 |
MultipoleAdapter ma = MultipoleAdapter(atype); |
168 |
|
169 |
if (gba.isGayBerne()) { |
170 |
atomInfo->hasVector = true; |
171 |
atomInfo->vec = datom->getA().transpose()*V3Z; |
172 |
} else if (ma.isDipole()) { |
173 |
atomInfo->hasVector = true; |
174 |
atomInfo->vec = datom->getDipole(); |
175 |
} else if (ma.isQuadrupole()) { |
176 |
atomInfo->hasVector = true; |
177 |
atomInfo->vec = datom->getA().transpose()*V3Z; |
178 |
} |
179 |
|
180 |
atomData = new AtomData; |
181 |
atomData->setID("ATOMDATA"); |
182 |
atomData->addAtomInfo(atomInfo); |
183 |
|
184 |
datom->addProperty(atomData); |
185 |
|
186 |
setVisited(datom); |
187 |
} |
188 |
|
189 |
const std::string DefaultAtomVisitor::toString() { |
190 |
char buffer[65535]; |
191 |
std::string result; |
192 |
|
193 |
sprintf(buffer, |
194 |
"--------------------------------------------------------------\n"); |
195 |
result += buffer; |
196 |
|
197 |
sprintf(buffer, "Visitor name: %s\n", visitorName.c_str()); |
198 |
result += buffer; |
199 |
|
200 |
sprintf(buffer, |
201 |
"Visitor Description: copy atom infomation into atom data\n"); |
202 |
result += buffer; |
203 |
|
204 |
sprintf(buffer, |
205 |
"--------------------------------------------------------------\n"); |
206 |
result += buffer; |
207 |
|
208 |
return result; |
209 |
} |
210 |
} //namespace OpenMD |