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 |
+ |
#include "selection/SelectionManager.hpp" |
42 |
|
#include "visitors/OtherVisitor.hpp" |
43 |
|
#include "primitives/DirectionalAtom.hpp" |
44 |
|
#include "primitives/RigidBody.hpp" |
45 |
|
#include "primitives/Molecule.hpp" |
46 |
|
#include "brains/SimInfo.hpp" |
6 |
– |
|
47 |
|
namespace oopse { |
48 |
|
|
49 |
< |
//----------------------------------------------------------------------------// |
10 |
< |
void IgnoreVisitor::visit(Atom* atom){ |
11 |
< |
if(isIgnoreType(atom->getType())) |
49 |
> |
void WrappingVisitor::visit(Atom *atom) { |
50 |
|
internalVisit(atom); |
51 |
< |
} |
51 |
> |
} |
52 |
|
|
53 |
< |
void IgnoreVisitor::visit(DirectionalAtom* datom){ |
16 |
< |
if(isIgnoreType(datom->getType())) |
53 |
> |
void WrappingVisitor::visit(DirectionalAtom *datom) { |
54 |
|
internalVisit(datom); |
55 |
< |
} |
55 |
> |
} |
56 |
|
|
57 |
< |
void IgnoreVisitor::visit(RigidBody* rb){ |
21 |
< |
vector<Atom*> myAtoms; |
22 |
< |
vector<Atom*>::iterator atomIter; |
23 |
< |
AtomInfo* atomInfo; |
24 |
< |
|
25 |
< |
if(isIgnoreType(rb->getType())){ |
26 |
< |
|
57 |
> |
void WrappingVisitor::visit(RigidBody *rb) { |
58 |
|
internalVisit(rb); |
59 |
+ |
} |
60 |
|
|
61 |
< |
myAtoms = rb->getAtoms(); |
62 |
< |
|
63 |
< |
for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter) |
64 |
< |
internalVisit(*atomIter); |
61 |
> |
void WrappingVisitor::internalVisit(StuntDouble *sd) { |
62 |
> |
GenericData * data; |
63 |
> |
AtomData * atomData; |
64 |
> |
AtomInfo * atomInfo; |
65 |
> |
std::vector<AtomInfo *>::iterator i; |
66 |
|
|
67 |
< |
} |
35 |
< |
|
36 |
< |
} |
67 |
> |
data = sd->getPropertyByName("ATOMDATA"); |
68 |
|
|
69 |
< |
bool IgnoreVisitor::isIgnoreType(const string& name){ |
70 |
< |
return itList.find(name) != itList.end() ? true : false; |
40 |
< |
} |
69 |
> |
if (data != NULL) { |
70 |
> |
atomData = dynamic_cast<AtomData *>(data); |
71 |
|
|
72 |
< |
void IgnoreVisitor::internalVisit(StuntDouble* sd){ |
73 |
< |
GenericData* data; |
74 |
< |
data = sd->getProperty("IGNORE"); |
72 |
> |
if (atomData == NULL) |
73 |
> |
return; |
74 |
> |
} else |
75 |
> |
return; |
76 |
|
|
77 |
< |
//if this stuntdoulbe is already marked as ignore just skip it |
47 |
< |
if (data == NULL){ |
48 |
< |
data = new GenericData; |
49 |
< |
data->setID("IGNORE"); |
50 |
< |
sd->addProperty(data); |
51 |
< |
} |
77 |
> |
Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot(); |
78 |
|
|
79 |
< |
} |
79 |
> |
for( atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i) ) { |
80 |
> |
Vector3d newPos = atomInfo->pos - origin_; |
81 |
> |
currSnapshot->wrapVector(newPos); |
82 |
> |
atomInfo->pos = newPos; |
83 |
> |
} |
84 |
> |
} |
85 |
|
|
86 |
< |
const string IgnoreVisitor::toString(){ |
87 |
< |
char buffer[65535]; |
88 |
< |
string result; |
89 |
< |
set<string>::iterator i; |
86 |
> |
void WrappingVisitor::update() { |
87 |
> |
if (useCom_){ |
88 |
> |
origin_ = info->getCom(); |
89 |
> |
} |
90 |
> |
} |
91 |
|
|
92 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
93 |
< |
result += buffer; |
92 |
> |
const std::string WrappingVisitor::toString() { |
93 |
> |
char buffer[65535]; |
94 |
> |
std::string result; |
95 |
|
|
96 |
< |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
97 |
< |
result += buffer; |
96 |
> |
sprintf(buffer, |
97 |
> |
"------------------------------------------------------------------\n"); |
98 |
> |
result += buffer; |
99 |
|
|
100 |
< |
sprintf(buffer ,"Visitor Description: ignore stuntdoubles\n"); |
101 |
< |
result += buffer; |
100 |
> |
sprintf(buffer, "Visitor name: %s\n", visitorName.c_str()); |
101 |
> |
result += buffer; |
102 |
|
|
103 |
< |
//print the ignore type list |
104 |
< |
sprintf(buffer , "Ignore type list contains below types:\n"); |
105 |
< |
result += buffer; |
103 |
> |
sprintf(buffer, |
104 |
> |
"Visitor Description: wrapping atoms back to periodic box\n"); |
105 |
> |
result += buffer; |
106 |
|
|
107 |
< |
for(i = itList.begin(); i != itList.end(); ++i){ |
108 |
< |
sprintf(buffer ,"%s\t", i->c_str()); |
107 |
> |
sprintf(buffer, |
108 |
> |
"------------------------------------------------------------------\n"); |
109 |
|
result += buffer; |
110 |
|
|
111 |
+ |
return result; |
112 |
|
} |
78 |
– |
sprintf(buffer ,"\n"); |
79 |
– |
result += buffer; |
113 |
|
|
114 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
82 |
< |
result += buffer; |
114 |
> |
//----------------------------------------------------------------------------// |
115 |
|
|
116 |
< |
return result; |
117 |
< |
} |
116 |
> |
ReplicateVisitor::ReplicateVisitor(SimInfo *info, Vector3i opt) : |
117 |
> |
BaseVisitor() { |
118 |
> |
this->info = info; |
119 |
> |
visitorName = "ReplicateVisitor"; |
120 |
> |
this->replicateOpt = opt; |
121 |
|
|
122 |
< |
//----------------------------------------------------------------------------// |
122 |
> |
//generate the replicate directions |
123 |
> |
for( int i = 0; i <= replicateOpt[0]; i++ ) { |
124 |
> |
for( int j = 0; j <= replicateOpt[1]; j++ ) { |
125 |
> |
for( int k = 0; k <= replicateOpt[2]; k++ ) { |
126 |
> |
//skip original frame |
127 |
> |
if (i == 0 && j == 0 && k == 0) { |
128 |
> |
continue; |
129 |
> |
} else { |
130 |
> |
dir.push_back(Vector3i(i, j, k)); |
131 |
> |
} |
132 |
> |
} |
133 |
> |
} |
134 |
> |
} |
135 |
> |
|
136 |
> |
} |
137 |
|
|
138 |
< |
void WrappingVisitor::visit(Atom* atom){ |
139 |
< |
internalVisit(atom); |
140 |
< |
} |
92 |
< |
void WrappingVisitor::visit(DirectionalAtom* datom){ |
93 |
< |
internalVisit(datom); |
94 |
< |
} |
138 |
> |
void ReplicateVisitor::visit(Atom *atom) { |
139 |
> |
internalVisit(atom); |
140 |
> |
} |
141 |
|
|
142 |
< |
void WrappingVisitor::visit(RigidBody* rb){ |
143 |
< |
internalVisit(rb); |
144 |
< |
} |
142 |
> |
void ReplicateVisitor::visit(DirectionalAtom *datom) { |
143 |
> |
internalVisit(datom); |
144 |
> |
} |
145 |
|
|
146 |
< |
void WrappingVisitor::internalVisit(StuntDouble* sd){ |
147 |
< |
GenericData* data; |
102 |
< |
AtomData* atomData; |
103 |
< |
AtomInfo* atomInfo; |
104 |
< |
vector<AtomInfo*>::iterator i; |
105 |
< |
|
106 |
< |
data = sd->getProperty("ATOMDATA"); |
107 |
< |
if(data != NULL){ |
108 |
< |
atomData = dynamic_cast<AtomData*>(data); |
109 |
< |
if(atomData == NULL) |
110 |
< |
return; |
146 |
> |
void ReplicateVisitor::visit(RigidBody *rb) { |
147 |
> |
internalVisit(rb); |
148 |
|
} |
112 |
– |
else |
113 |
– |
return; |
149 |
|
|
150 |
< |
for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)) |
151 |
< |
info->wrapVector(atomInfo->pos); |
150 |
> |
void ReplicateVisitor::internalVisit(StuntDouble *sd) { |
151 |
> |
GenericData * data; |
152 |
> |
AtomData * atomData; |
153 |
|
|
154 |
< |
|
155 |
< |
} |
154 |
> |
//if there is not atom data, just skip it |
155 |
> |
data = sd->getPropertyByName("ATOMDATA"); |
156 |
|
|
157 |
< |
const string WrappingVisitor::toString(){ |
158 |
< |
char buffer[65535]; |
123 |
< |
string result; |
124 |
< |
|
125 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
126 |
< |
result += buffer; |
157 |
> |
if (data != NULL) { |
158 |
> |
atomData = dynamic_cast<AtomData *>(data); |
159 |
|
|
160 |
< |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
161 |
< |
result += buffer; |
160 |
> |
if (atomData == NULL) { |
161 |
> |
return; |
162 |
> |
} |
163 |
> |
} else { |
164 |
> |
return; |
165 |
> |
} |
166 |
|
|
167 |
< |
sprintf(buffer ,"Visitor Description: wrapping atoms back to periodic box\n"); |
168 |
< |
result += buffer; |
133 |
< |
|
134 |
< |
sprintf(buffer,"------------------------------------------------------------------\n"); |
135 |
< |
result += buffer; |
167 |
> |
Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot(); |
168 |
> |
Mat3x3d box = currSnapshot->getHmat(); |
169 |
|
|
170 |
< |
return result; |
138 |
< |
} |
170 |
> |
std::vector<AtomInfo *> atomInfoList = atomData->getData(); |
171 |
|
|
172 |
< |
//----------------------------------------------------------------------------// |
172 |
> |
replicate(atomInfoList, atomData, box); |
173 |
> |
} |
174 |
|
|
175 |
< |
ReplicateVisitor::ReplicateVisitor(SimInfo* info, IntVec3 opt) : BaseVisitor(){ |
176 |
< |
this->info = info; |
177 |
< |
visitorName = "ReplicateVisitor"; |
178 |
< |
this->replicateOpt = opt; |
146 |
< |
//generate the replicate directions |
147 |
< |
for(int i = 0; i <= replicateOpt[0]; i ++) |
148 |
< |
for(int j = 0; j <= replicateOpt[1]; j ++) |
149 |
< |
for(int k = 0; k <= replicateOpt[2]; k ++) |
150 |
< |
//skip original frame |
151 |
< |
if(i == 0 && j ==0 && k ==0) |
152 |
< |
continue; |
153 |
< |
else |
154 |
< |
dir.push_back(IntVec3(i, j, k)); |
155 |
< |
|
156 |
< |
} |
157 |
< |
void ReplicateVisitor::visit(Atom* atom){ |
158 |
< |
internalVisit(atom); |
159 |
< |
} |
160 |
< |
void ReplicateVisitor::visit(DirectionalAtom* datom){ |
161 |
< |
internalVisit(datom); |
162 |
< |
} |
175 |
> |
void ReplicateVisitor::replicate(std::vector<AtomInfo *>&infoList, AtomData *data, const Mat3x3d& box) { |
176 |
> |
AtomInfo* newAtomInfo; |
177 |
> |
std::vector<Vector3i>::iterator dirIter; |
178 |
> |
std::vector<AtomInfo *>::iterator i; |
179 |
|
|
180 |
< |
void ReplicateVisitor::visit(RigidBody* rb){ |
181 |
< |
internalVisit(rb); |
182 |
< |
} |
180 |
> |
for( dirIter = dir.begin(); dirIter != dir.end(); ++dirIter ) { |
181 |
> |
for( i = infoList.begin(); i != infoList.end(); i++ ) { |
182 |
> |
newAtomInfo = new AtomInfo(); |
183 |
> |
*newAtomInfo = *(*i); |
184 |
|
|
185 |
< |
void ReplicateVisitor::internalVisit(StuntDouble* sd){ |
186 |
< |
GenericData* data; |
187 |
< |
AtomData* atomData; |
188 |
< |
AtomInfo* atomInfo; |
189 |
< |
double box[3][3]; |
190 |
< |
vector<AtomInfo*> atomInfoList; |
174 |
< |
IntVec3 dir; |
175 |
< |
|
176 |
< |
//if there is not atom data, just skip it |
177 |
< |
data = sd->getProperty("ATOMDATA"); |
178 |
< |
if(data != NULL){ |
179 |
< |
atomData = dynamic_cast<AtomData*>(data); |
180 |
< |
if(atomData == NULL) |
181 |
< |
return; |
185 |
> |
for( int j = 0; j < 3; j++ ) |
186 |
> |
newAtomInfo->pos[j] += (*dirIter)[0]*box(j, 0) + (*dirIter)[1]*box(j, 1) + (*dirIter)[2]*box(j, 2); |
187 |
> |
|
188 |
> |
data->addAtomInfo(newAtomInfo); |
189 |
> |
} |
190 |
> |
} // end for(dirIter) |
191 |
|
} |
183 |
– |
else |
184 |
– |
return; |
192 |
|
|
193 |
< |
|
194 |
< |
info->getBoxM(box); |
193 |
> |
const std::string ReplicateVisitor::toString() { |
194 |
> |
char buffer[65535]; |
195 |
> |
std::string result; |
196 |
> |
std::set<std::string>::iterator i; |
197 |
|
|
198 |
< |
atomInfoList = atomData->getData(); |
199 |
< |
|
200 |
< |
replicate(atomInfoList, atomData, box); |
198 |
> |
sprintf(buffer, |
199 |
> |
"------------------------------------------------------------------\n"); |
200 |
> |
result += buffer; |
201 |
|
|
202 |
< |
} |
202 |
> |
sprintf(buffer, "Visitor name: %s\n", visitorName.c_str()); |
203 |
> |
result += buffer; |
204 |
|
|
205 |
< |
void ReplicateVisitor::replicate(vector<AtomInfo*>& infoList, AtomData* data, double boxM[3][3]){ |
206 |
< |
AtomInfo * newAtomInfo; |
207 |
< |
vector<IntVec3>::iterator dirIter; |
198 |
< |
vector<AtomInfo*>::iterator i; |
199 |
< |
|
200 |
< |
for(dirIter = dir.begin(); dirIter != dir.end(); ++dirIter){ |
201 |
< |
for(i = infoList.begin(); i != infoList.end(); i++){ |
202 |
< |
newAtomInfo = new AtomInfo; |
203 |
< |
*newAtomInfo = *(*i); |
205 |
> |
sprintf(buffer, |
206 |
> |
"Visitor Description: replicate the atoms in different direction\n"); |
207 |
> |
result += buffer; |
208 |
|
|
209 |
< |
for(int j = 0; j < 3; j++) |
210 |
< |
newAtomInfo->pos[j] += (*dirIter)[0] * boxM[j][0] + (*dirIter)[1]* boxM[j][1] + (*dirIter)[2] * boxM[j][2]; |
209 |
> |
//print the replicate direction |
210 |
> |
sprintf(buffer, "repeatX = %d:\n", replicateOpt[0]); |
211 |
> |
result += buffer; |
212 |
|
|
213 |
< |
data->addAtomInfo(newAtomInfo); |
214 |
< |
} |
210 |
< |
}// end for(dirIter) |
211 |
< |
} |
213 |
> |
sprintf(buffer, "repeatY = %d:\n", replicateOpt[1]); |
214 |
> |
result += buffer; |
215 |
|
|
216 |
< |
const string ReplicateVisitor::toString(){ |
217 |
< |
char buffer[65535]; |
215 |
< |
string result; |
216 |
< |
set<string>::iterator i; |
217 |
< |
|
218 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
219 |
< |
result += buffer; |
216 |
> |
sprintf(buffer, "repeatZ = %d:\n", replicateOpt[2]); |
217 |
> |
result += buffer; |
218 |
|
|
219 |
< |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
220 |
< |
result += buffer; |
219 |
> |
sprintf(buffer, |
220 |
> |
"------------------------------------------------------------------\n"); |
221 |
> |
result += buffer; |
222 |
|
|
223 |
< |
sprintf(buffer ,"Visitor Description: replicate the atoms in different direction\n"); |
224 |
< |
result += buffer; |
226 |
< |
|
227 |
< |
//print the replicate direction |
228 |
< |
sprintf(buffer , "repeatX = %d:\n", replicateOpt[0]); |
229 |
< |
result += buffer; |
223 |
> |
return result; |
224 |
> |
} |
225 |
|
|
226 |
< |
sprintf(buffer , "repeatY = %d:\n", replicateOpt[1]); |
232 |
< |
result += buffer; |
226 |
> |
//----------------------------------------------------------------------------// |
227 |
|
|
228 |
< |
sprintf(buffer , "repeatZ = %d:\n", replicateOpt[2]); |
229 |
< |
result += buffer; |
228 |
> |
XYZVisitor::XYZVisitor(SimInfo *info) : |
229 |
> |
BaseVisitor(), seleMan(info), evaluator(info){ |
230 |
> |
this->info = info; |
231 |
> |
visitorName = "XYZVisitor"; |
232 |
|
|
233 |
+ |
evaluator.loadScriptString("select all"); |
234 |
|
|
235 |
< |
sprintf(buffer,"------------------------------------------------------------------\n"); |
236 |
< |
result += buffer; |
235 |
> |
if (!evaluator.isDynamic()) { |
236 |
> |
seleMan.setSelectionSet(evaluator.evaluate()); |
237 |
> |
} |
238 |
|
|
239 |
< |
return result; |
242 |
< |
} |
239 |
> |
} |
240 |
|
|
241 |
< |
//----------------------------------------------------------------------------// |
241 |
> |
XYZVisitor::XYZVisitor(SimInfo *info, const std::string& script) : |
242 |
> |
BaseVisitor(), seleMan(info), evaluator(info) { |
243 |
> |
this->info = info; |
244 |
> |
visitorName = "XYZVisitor"; |
245 |
|
|
246 |
< |
XYZVisitor::XYZVisitor(SimInfo* info, bool printDipole) : BaseVisitor(){ |
247 |
< |
this->info = info; |
248 |
< |
visitorName = "XYZVisitor"; |
249 |
< |
this->printDipole = printDipole; |
250 |
< |
} |
246 |
> |
evaluator.loadScriptString(script); |
247 |
|
|
248 |
< |
void XYZVisitor::visit(Atom* atom){ |
249 |
< |
if(!isIgnore(atom)) |
250 |
< |
internalVisit(atom); |
251 |
< |
} |
252 |
< |
|
253 |
< |
void XYZVisitor::visit(DirectionalAtom* datom){ |
254 |
< |
if(!isIgnore(datom)) |
255 |
< |
internalVisit(datom); |
256 |
< |
} |
261 |
< |
|
262 |
< |
void XYZVisitor::visit(RigidBody* rb){ |
263 |
< |
if(!isIgnore(rb)) |
264 |
< |
internalVisit(rb); |
265 |
< |
|
266 |
< |
} |
267 |
< |
|
268 |
< |
void XYZVisitor::internalVisit(StuntDouble* sd){ |
269 |
< |
GenericData* data; |
270 |
< |
AtomData* atomData; |
271 |
< |
AtomInfo* atomInfo; |
272 |
< |
vector<AtomInfo*>::iterator i; |
273 |
< |
char buffer[1024]; |
274 |
< |
|
275 |
< |
//if there is not atom data, just skip it |
276 |
< |
data = sd->getProperty("ATOMDATA"); |
277 |
< |
if(data != NULL){ |
278 |
< |
atomData = dynamic_cast<AtomData*>(data); |
279 |
< |
if(atomData == NULL) |
280 |
< |
return; |
248 |
> |
if (!evaluator.isDynamic()) { |
249 |
> |
seleMan.setSelectionSet(evaluator.evaluate()); |
250 |
> |
} |
251 |
> |
|
252 |
> |
} |
253 |
> |
|
254 |
> |
void XYZVisitor::visit(Atom *atom) { |
255 |
> |
if (isSelected(atom)) |
256 |
> |
internalVisit(atom); |
257 |
|
} |
282 |
– |
else |
283 |
– |
return; |
258 |
|
|
259 |
< |
for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)){ |
260 |
< |
|
261 |
< |
if(printDipole) |
262 |
< |
sprintf(buffer, "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f", |
289 |
< |
atomInfo->AtomType.c_str(), |
290 |
< |
atomInfo->pos[0], |
291 |
< |
atomInfo->pos[1], |
292 |
< |
atomInfo->pos[2], |
293 |
< |
atomInfo->dipole[0], |
294 |
< |
atomInfo->dipole[1], |
295 |
< |
atomInfo->dipole[2]); |
296 |
< |
else |
297 |
< |
sprintf(buffer, "%s%15.8f%15.8f%15.8f", |
298 |
< |
atomInfo->AtomType.c_str(), |
299 |
< |
atomInfo->pos[0], |
300 |
< |
atomInfo->pos[1], |
301 |
< |
atomInfo->pos[2]); |
259 |
> |
void XYZVisitor::visit(DirectionalAtom *datom) { |
260 |
> |
if (isSelected(datom)) |
261 |
> |
internalVisit(datom); |
262 |
> |
} |
263 |
|
|
264 |
< |
frame.push_back(buffer); |
265 |
< |
|
264 |
> |
void XYZVisitor::visit(RigidBody *rb) { |
265 |
> |
if (isSelected(rb)) |
266 |
> |
internalVisit(rb); |
267 |
|
} |
268 |
|
|
269 |
< |
} |
269 |
> |
void XYZVisitor::update() { |
270 |
> |
//if dynamic, we need to re-evaluate the selection |
271 |
> |
if (evaluator.isDynamic()) { |
272 |
> |
seleMan.setSelectionSet(evaluator.evaluate()); |
273 |
> |
} |
274 |
> |
} |
275 |
|
|
276 |
< |
bool XYZVisitor::isIgnore(StuntDouble* sd){ |
277 |
< |
GenericData* data; |
278 |
< |
|
279 |
< |
data = sd->getProperty("IGNORE"); |
280 |
< |
return data ==NULL ? false : true; |
281 |
< |
} |
276 |
> |
void XYZVisitor::internalVisit(StuntDouble *sd) { |
277 |
> |
GenericData * data; |
278 |
> |
AtomData * atomData; |
279 |
> |
AtomInfo * atomInfo; |
280 |
> |
std::vector<AtomInfo *>::iterator i; |
281 |
> |
char buffer[1024]; |
282 |
|
|
283 |
< |
void XYZVisitor::writeFrame(ostream& outStream){ |
284 |
< |
vector<string>::iterator i; |
318 |
< |
double box[3][3]; |
319 |
< |
char buffer[1024]; |
283 |
> |
//if there is not atom data, just skip it |
284 |
> |
data = sd->getPropertyByName("ATOMDATA"); |
285 |
|
|
286 |
< |
if(frame.size() == 0) |
287 |
< |
cerr << "Current Frame does not contain any atoms" << endl; |
286 |
> |
if (data != NULL) { |
287 |
> |
atomData = dynamic_cast<AtomData *>(data); |
288 |
|
|
289 |
< |
//total number of atoms |
290 |
< |
outStream << frame.size() << endl; |
289 |
> |
if (atomData == NULL) |
290 |
> |
return; |
291 |
> |
} else |
292 |
> |
return; |
293 |
|
|
294 |
< |
//write comment line |
295 |
< |
info->getBoxM(box); |
296 |
< |
sprintf(buffer,"%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f", |
297 |
< |
info->getTime(), |
298 |
< |
box[0][0], box[0][1], box[0][2], |
299 |
< |
box[1][0], box[1][1], box[1][2], |
300 |
< |
box[2][0], box[2][1], box[2][2]); |
294 |
> |
for( atomInfo = atomData->beginAtomInfo(i); atomInfo; |
295 |
> |
atomInfo = atomData->nextAtomInfo(i) ) { |
296 |
> |
sprintf(buffer, |
297 |
> |
"%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f", |
298 |
> |
atomInfo->atomTypeName.c_str(), |
299 |
> |
atomInfo->pos[0], |
300 |
> |
atomInfo->pos[1], |
301 |
> |
atomInfo->pos[2], |
302 |
> |
atomInfo->dipole[0], |
303 |
> |
atomInfo->dipole[1], |
304 |
> |
atomInfo->dipole[2]); |
305 |
> |
frame.push_back(buffer); |
306 |
> |
} |
307 |
> |
} |
308 |
|
|
309 |
< |
outStream << buffer << endl; |
309 |
> |
bool XYZVisitor::isSelected(StuntDouble *sd) { |
310 |
> |
return seleMan.isSelected(sd); |
311 |
> |
} |
312 |
|
|
313 |
< |
for(i = frame.begin(); i != frame.end(); ++i) |
314 |
< |
outStream << *i << endl; |
315 |
< |
} |
313 |
> |
void XYZVisitor::writeFrame(std::ostream &outStream) { |
314 |
> |
std::vector<std::string>::iterator i; |
315 |
> |
char buffer[1024]; |
316 |
|
|
317 |
< |
const string XYZVisitor::toString(){ |
318 |
< |
char buffer[65535]; |
343 |
< |
string result; |
344 |
< |
|
345 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
346 |
< |
result += buffer; |
317 |
> |
if (frame.size() == 0) |
318 |
> |
std::cerr << "Current Frame does not contain any atoms" << std::endl; |
319 |
|
|
320 |
< |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
321 |
< |
result += buffer; |
320 |
> |
//total number of atoms |
321 |
> |
outStream << frame.size() << std::endl; |
322 |
|
|
323 |
< |
sprintf(buffer ,"Visitor Description: assemble the atom data and output xyz file\n"); |
324 |
< |
result += buffer; |
325 |
< |
|
326 |
< |
sprintf(buffer,"------------------------------------------------------------------\n"); |
327 |
< |
result += buffer; |
323 |
> |
//write comment line |
324 |
> |
Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot(); |
325 |
> |
Mat3x3d box = currSnapshot->getHmat(); |
326 |
> |
|
327 |
> |
sprintf(buffer, |
328 |
> |
"%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f", |
329 |
> |
currSnapshot->getTime(), |
330 |
> |
box(0, 0), box(0, 1), box(0, 2), |
331 |
> |
box(1, 0), box(1, 1), box(1, 2), |
332 |
> |
box(2, 0), box(2, 1), box(2, 2)); |
333 |
|
|
334 |
< |
return result; |
358 |
< |
} |
334 |
> |
outStream << buffer << std::endl; |
335 |
|
|
336 |
< |
//----------------------------------------------------------------------------// |
336 |
> |
for( i = frame.begin(); i != frame.end(); ++i ) |
337 |
> |
outStream << *i << std::endl; |
338 |
> |
} |
339 |
|
|
340 |
< |
void PrepareVisitor::internalVisit(Atom * atom){ |
341 |
< |
GenericData* data; |
342 |
< |
AtomData* atomData; |
340 |
> |
const std::string XYZVisitor::toString() { |
341 |
> |
char buffer[65535]; |
342 |
> |
std::string result; |
343 |
|
|
344 |
< |
//if visited property is existed, remove it |
345 |
< |
data = atom->getProperty("VISITED"); |
346 |
< |
if(data != NULL){ |
369 |
< |
atom->removeProperty("VISITED"); |
370 |
< |
} |
344 |
> |
sprintf(buffer, |
345 |
> |
"------------------------------------------------------------------\n"); |
346 |
> |
result += buffer; |
347 |
|
|
348 |
< |
//remove atomdata |
349 |
< |
data = atom->getProperty("ATOMDATA"); |
374 |
< |
if(data != NULL){ |
375 |
< |
atomData = dynamic_cast<AtomData*>(data); |
376 |
< |
if(atomData != NULL) |
377 |
< |
atom->removeProperty("ATOMDATA"); |
378 |
< |
} |
379 |
< |
|
380 |
< |
} |
348 |
> |
sprintf(buffer, "Visitor name: %s\n", visitorName.c_str()); |
349 |
> |
result += buffer; |
350 |
|
|
351 |
< |
void PrepareVisitor::internalVisit(RigidBody * rb){ |
352 |
< |
GenericData* data; |
353 |
< |
AtomData* atomData; |
354 |
< |
vector<Atom*> myAtoms; |
355 |
< |
vector<Atom*>::iterator atomIter; |
356 |
< |
|
357 |
< |
//if visited property is existed, remove it |
358 |
< |
data = rb->getProperty("VISITED"); |
359 |
< |
if(data != NULL){ |
391 |
< |
rb->removeProperty("VISITED"); |
351 |
> |
sprintf(buffer, |
352 |
> |
"Visitor Description: assemble the atom data and output xyz file\n"); |
353 |
> |
result += buffer; |
354 |
> |
|
355 |
> |
sprintf(buffer, |
356 |
> |
"------------------------------------------------------------------\n"); |
357 |
> |
result += buffer; |
358 |
> |
|
359 |
> |
return result; |
360 |
|
} |
361 |
|
|
362 |
< |
//remove atomdata |
363 |
< |
data = rb->getProperty("ATOMDATA"); |
364 |
< |
if(data != NULL){ |
365 |
< |
atomData = dynamic_cast<AtomData*>(data); |
366 |
< |
if(atomData != NULL) |
367 |
< |
rb->removeProperty("ATOMDATA"); |
362 |
> |
//----------------------------------------------------------------------------// |
363 |
> |
|
364 |
> |
void PrepareVisitor::internalVisit(Atom *atom) { |
365 |
> |
GenericData *data; |
366 |
> |
AtomData * atomData; |
367 |
> |
|
368 |
> |
//if visited property is existed, remove it |
369 |
> |
data = atom->getPropertyByName("VISITED"); |
370 |
> |
|
371 |
> |
if (data != NULL) { |
372 |
> |
atom->removeProperty("VISITED"); |
373 |
> |
} |
374 |
> |
|
375 |
> |
//remove atomdata |
376 |
> |
data = atom->getPropertyByName("ATOMDATA"); |
377 |
> |
|
378 |
> |
if (data != NULL) { |
379 |
> |
atomData = dynamic_cast<AtomData *>(data); |
380 |
> |
|
381 |
> |
if (atomData != NULL) |
382 |
> |
atom->removeProperty("ATOMDATA"); |
383 |
> |
} |
384 |
|
} |
385 |
|
|
386 |
< |
myAtoms = rb->getAtoms(); |
387 |
< |
|
388 |
< |
for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter) |
389 |
< |
internalVisit (*atomIter); |
390 |
< |
} |
386 |
> |
void PrepareVisitor::internalVisit(RigidBody *rb) { |
387 |
> |
GenericData* data; |
388 |
> |
AtomData* atomData; |
389 |
> |
std::vector<Atom *> myAtoms; |
390 |
> |
std::vector<Atom *>::iterator atomIter; |
391 |
|
|
392 |
< |
const string PrepareVisitor::toString(){ |
393 |
< |
char buffer[65535]; |
410 |
< |
string result; |
411 |
< |
|
412 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
413 |
< |
result += buffer; |
392 |
> |
//if visited property is existed, remove it |
393 |
> |
data = rb->getPropertyByName("VISITED"); |
394 |
|
|
395 |
< |
sprintf(buffer ,"Visitor name: %s", visitorName.c_str()); |
396 |
< |
result += buffer; |
395 |
> |
if (data != NULL) { |
396 |
> |
rb->removeProperty("VISITED"); |
397 |
> |
} |
398 |
|
|
399 |
< |
sprintf(buffer ,"Visitor Description: prepare for operation of other vistors\n"); |
400 |
< |
result += buffer; |
399 |
> |
//remove atomdata |
400 |
> |
data = rb->getPropertyByName("ATOMDATA"); |
401 |
|
|
402 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
403 |
< |
result += buffer; |
402 |
> |
if (data != NULL) { |
403 |
> |
atomData = dynamic_cast<AtomData *>(data); |
404 |
|
|
405 |
< |
return result; |
406 |
< |
} |
405 |
> |
if (atomData != NULL) |
406 |
> |
rb->removeProperty("ATOMDATA"); |
407 |
> |
} |
408 |
|
|
409 |
< |
//----------------------------------------------------------------------------// |
409 |
> |
myAtoms = rb->getAtoms(); |
410 |
|
|
411 |
< |
WaterTypeVisitor:: WaterTypeVisitor(){ |
412 |
< |
visitorName = "WaterTypeVisitor"; |
413 |
< |
waterTypeList.insert("TIP3P_RB_0"); |
432 |
< |
waterTypeList.insert("TIP4P_RB_0"); |
433 |
< |
waterTypeList.insert("TIP5P_RB_0"); |
434 |
< |
waterTypeList.insert("SPCE_RB_0"); |
435 |
< |
} |
411 |
> |
for( atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter ) |
412 |
> |
internalVisit(*atomIter); |
413 |
> |
} |
414 |
|
|
415 |
+ |
const std::string PrepareVisitor::toString() { |
416 |
+ |
char buffer[65535]; |
417 |
+ |
std::string result; |
418 |
+ |
|
419 |
+ |
sprintf(buffer, |
420 |
+ |
"------------------------------------------------------------------\n"); |
421 |
+ |
result += buffer; |
422 |
+ |
|
423 |
+ |
sprintf(buffer, "Visitor name: %s", visitorName.c_str()); |
424 |
+ |
result += buffer; |
425 |
+ |
|
426 |
+ |
sprintf(buffer, |
427 |
+ |
"Visitor Description: prepare for operation of other vistors\n"); |
428 |
+ |
result += buffer; |
429 |
+ |
|
430 |
+ |
sprintf(buffer, |
431 |
+ |
"------------------------------------------------------------------\n"); |
432 |
+ |
result += buffer; |
433 |
+ |
|
434 |
+ |
return result; |
435 |
+ |
} |
436 |
|
|
437 |
< |
void WaterTypeVisitor:: visit(RigidBody* rb){ |
439 |
< |
string rbName; |
440 |
< |
vector<Atom*> myAtoms; |
441 |
< |
vector<Atom*>::iterator atomIter; |
442 |
< |
GenericData* data; |
443 |
< |
AtomData* atomData; |
444 |
< |
AtomInfo* atomInfo; |
445 |
< |
vector<AtomInfo*>::iterator i; |
446 |
< |
|
447 |
< |
rbName = rb->getType(); |
437 |
> |
//----------------------------------------------------------------------------// |
438 |
|
|
439 |
< |
if(waterTypeList.find(rbName) != waterTypeList.end()){ |
439 |
> |
WaterTypeVisitor::WaterTypeVisitor() { |
440 |
> |
visitorName = "WaterTypeVisitor"; |
441 |
> |
waterTypeList.insert("TIP3P_RB_0"); |
442 |
> |
waterTypeList.insert("TIP4P_RB_0"); |
443 |
> |
waterTypeList.insert("TIP5P_RB_0"); |
444 |
> |
waterTypeList.insert("SPCE_RB_0"); |
445 |
> |
} |
446 |
|
|
447 |
< |
myAtoms = rb->getAtoms(); |
448 |
< |
for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter){ |
447 |
> |
void WaterTypeVisitor::visit(RigidBody *rb) { |
448 |
> |
std::string rbName; |
449 |
> |
std::vector<Atom *> myAtoms; |
450 |
> |
std::vector<Atom *>::iterator atomIter; |
451 |
> |
GenericData* data; |
452 |
> |
AtomData* atomData; |
453 |
> |
AtomInfo* atomInfo; |
454 |
> |
std::vector<AtomInfo *>::iterator i; |
455 |
|
|
456 |
< |
data = (*atomIter)->getProperty("ATOMDATA"); |
455 |
< |
if(data != NULL){ |
456 |
< |
atomData = dynamic_cast<AtomData*>(data); |
457 |
< |
if(atomData == NULL) |
458 |
< |
continue; |
459 |
< |
} |
460 |
< |
else |
461 |
< |
continue; |
462 |
< |
|
463 |
< |
for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)){ |
464 |
< |
replaceType(atomInfo->AtomType); |
465 |
< |
}//end for(atomInfo) |
456 |
> |
rbName = rb->getType(); |
457 |
|
|
458 |
< |
}//end for(atomIter) |
459 |
< |
|
469 |
< |
}//end if (waterTypeList.find(rbName) != waterTypeList.end()) |
470 |
< |
|
471 |
< |
} |
458 |
> |
if (waterTypeList.find(rbName) != waterTypeList.end()) { |
459 |
> |
myAtoms = rb->getAtoms(); |
460 |
|
|
461 |
< |
void WaterTypeVisitor:: replaceType(string& atomType){ |
462 |
< |
atomType = atomType.substr(0, atomType.find('_')); |
463 |
< |
} |
461 |
> |
for( atomIter = myAtoms.begin(); atomIter != myAtoms.end(); |
462 |
> |
++atomIter ) { |
463 |
> |
data = (*atomIter)->getPropertyByName("ATOMDATA"); |
464 |
|
|
465 |
< |
const string WaterTypeVisitor:: toString(){ |
466 |
< |
char buffer[65535]; |
479 |
< |
string result; |
480 |
< |
|
481 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
482 |
< |
result += buffer; |
465 |
> |
if (data != NULL) { |
466 |
> |
atomData = dynamic_cast<AtomData *>(data); |
467 |
|
|
468 |
< |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
469 |
< |
result += buffer; |
468 |
> |
if (atomData == NULL) |
469 |
> |
continue; |
470 |
> |
} else |
471 |
> |
continue; |
472 |
|
|
473 |
< |
sprintf(buffer ,"Visitor Description: Replace the atom type in water model\n"); |
474 |
< |
result += buffer; |
473 |
> |
for( atomInfo = atomData->beginAtomInfo(i); atomInfo; |
474 |
> |
atomInfo = atomData->nextAtomInfo(i) ) { |
475 |
> |
atomInfo->atomTypeName = trimmedName(atomInfo->atomTypeName); |
476 |
> |
} //end for(atomInfo) |
477 |
> |
} //end for(atomIter) |
478 |
> |
} //end if (waterTypeList.find(rbName) != waterTypeList.end()) |
479 |
> |
} |
480 |
|
|
481 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
482 |
< |
result += buffer; |
481 |
> |
std::string WaterTypeVisitor::trimmedName(const std::string&atomTypeName) { |
482 |
> |
return atomTypeName.substr(0, atomTypeName.find('_')); |
483 |
> |
} |
484 |
|
|
485 |
< |
return result; |
486 |
< |
} |
485 |
> |
const std::string WaterTypeVisitor::toString() { |
486 |
> |
char buffer[65535]; |
487 |
> |
std::string result; |
488 |
|
|
489 |
+ |
sprintf(buffer, |
490 |
+ |
"------------------------------------------------------------------\n"); |
491 |
+ |
result += buffer; |
492 |
|
|
493 |
< |
}//namespace oopse |
493 |
> |
sprintf(buffer, "Visitor name: %s\n", visitorName.c_str()); |
494 |
> |
result += buffer; |
495 |
> |
|
496 |
> |
sprintf(buffer, |
497 |
> |
"Visitor Description: Replace the atom type in water model\n"); |
498 |
> |
result += buffer; |
499 |
> |
|
500 |
> |
sprintf(buffer, |
501 |
> |
"------------------------------------------------------------------\n"); |
502 |
> |
result += buffer; |
503 |
> |
|
504 |
> |
return result; |
505 |
> |
} |
506 |
> |
|
507 |
> |
} //namespace oopse |