ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/AtomVisitor.cpp
Revision: 1126
Committed: Tue Apr 20 05:39:38 2004 UTC (20 years, 2 months ago) by tim
File size: 5822 byte(s)
Log Message:
DUMP2XYZ 0.99 version

File Contents

# User Rev Content
1 tim 1118 #include <cstring>
2     #include "AtomVisitor.hpp"
3     #include "DirectionalAtom.hpp"
4     #include "MatVec3.h"
5 tim 1119 #include "RigidBody.hpp"
6 tim 1118
7 tim 1119 void BaseAtomVisitor::visit(RigidBody* rb){
8     //vector<Atom*> myAtoms;
9     //vector<Atom*>::iterator atomIter;
10    
11     //myAtoms = rb->getAtoms();
12    
13     //for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter)
14     // (*atomIter)->accept(this);
15     }
16    
17 tim 1118 void BaseAtomVisitor::setVisited(Atom* atom){
18     GenericData* data;
19     data = atom->getProperty("VISITED");
20    
21     //if visited property is not existed, add it as new property
22     if(data == NULL){
23     data = new GenericData();
24     data->setID("VISITED");
25     atom->addProperty(data);
26     }
27     }
28    
29     bool BaseAtomVisitor::isVisited(Atom* atom){
30     GenericData* data;
31     data = atom->getProperty("VISITED");
32     return data == NULL ? false : true;
33     }
34    
35     void SSDAtomVisitor::visit(DirectionalAtom* datom){
36    
37     vector<AtomInfo*> atoms;
38    
39     //we need to convert SSD into 4 differnet atoms
40     //one oxygen atom, two hydrogen atoms and one pseudo atom which is the center of the mass
41     //of the water with a dipole moment
42     double h1[3] = {0.0, -0.75695, 0.5206};
43     double h2[3] = {0.0, 0.75695, 0.5206};
44     double ox[3] = {0.0, 0.0, -0.0654};
45     double u[3] = {0, 0, 1};
46     double rotMatrix[3][3];
47     AtomInfo* atomInfo;
48     double pos[3];
49     double vel[3];
50     double newVec[3];
51     double q[4];
52     AtomData* atomData;
53     GenericData* data;
54     bool haveAtomData;
55    
56     //if atom is not SSD atom, just skip it
57 tim 1126 if(strcmp(datom->getType(), "SSD"))
58 tim 1118 return;
59    
60     data = datom->getProperty("ATOMDATA");
61     if(data != NULL){
62    
63     atomData = dynamic_cast<AtomData*>(data);
64     if(atomData == NULL){
65     cerr << "can not get Atom Data from " << datom->getType() << endl;
66     atomData = new AtomData;
67     haveAtomData = false;
68     }
69     else
70     haveAtomData = true;
71     }
72     else{
73     atomData = new AtomData;
74     haveAtomData = false;
75     }
76    
77    
78     datom->getPos(pos);
79     datom->getQ(q);
80     datom->getA(rotMatrix);
81    
82     //center of mass of the water molecule
83     matVecMul3(rotMatrix, u, newVec);
84     atomInfo = new AtomInfo;
85     atomInfo->AtomType = "X";
86     atomInfo->pos[0] = pos[0];
87     atomInfo->pos[1] = pos[1];
88     atomInfo->pos[2] = pos[2];
89     atomInfo->dipole[0] = newVec[0];
90     atomInfo->dipole[1] = newVec[1];
91     atomInfo->dipole[2] = newVec[2];
92    
93     atomData->addAtomInfo(atomInfo);
94    
95     //oxygen
96     matVecMul3(rotMatrix, ox, newVec);
97     atomInfo = new AtomInfo;
98     atomInfo->AtomType = "O";
99     atomInfo->pos[0] = pos[0] + newVec[0];
100     atomInfo->pos[1] = pos[1] + newVec[1];
101     atomInfo->pos[2] = pos[2] + newVec[2];
102     atomInfo->dipole[0] = 0.0;
103     atomInfo->dipole[1] = 0.0;
104     atomInfo->dipole[2] = 0.0;
105     atomData->addAtomInfo(atomInfo);
106    
107    
108     //hydrogen1
109     matVecMul3(rotMatrix, h1, newVec);
110     atomInfo = new AtomInfo;
111     atomInfo->AtomType = "H";
112     atomInfo->pos[0] = pos[0] + newVec[0];
113     atomInfo->pos[1] = pos[1] + newVec[1];
114     atomInfo->pos[2] = pos[2] + newVec[2];
115     atomInfo->dipole[0] = 0.0;
116     atomInfo->dipole[1] = 0.0;
117     atomInfo->dipole[2] = 0.0;
118     atomData->addAtomInfo(atomInfo);
119    
120     //hydrogen2
121     matVecMul3(rotMatrix, h2, newVec);
122     atomInfo = new AtomInfo;
123     atomInfo->AtomType = "H";
124     atomInfo->pos[0] = pos[0] + newVec[0];
125     atomInfo->pos[1] = pos[1] + newVec[1];
126     atomInfo->pos[2] = pos[2] + newVec[2];
127     atomInfo->dipole[0] = 0.0;
128     atomInfo->dipole[1] = 0.0;
129     atomInfo->dipole[2] = 0.0;
130     atomData->addAtomInfo(atomInfo);
131    
132     //add atom data into atom's property
133    
134     if(!haveAtomData){
135     atomData->setID("ATOMDATA");
136     datom->addProperty(atomData);
137     }
138    
139     setVisited(datom);
140    
141     }
142    
143 tim 1126 const string SSDAtomVisitor::toString(){
144     char buffer[65535];
145     string result;
146    
147     sprintf(buffer ,"------------------------------------------------------------------\n");
148     result += buffer;
149    
150     sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
151     result += buffer;
152    
153     sprintf(buffer , "Visitor Description: Convert SSD into 4 differnet atoms\n");
154     result += buffer;
155    
156     sprintf(buffer ,"------------------------------------------------------------------\n");
157     result += buffer;
158    
159     return result;
160     }
161    
162     //----------------------------------------------------------------------------//
163    
164 tim 1118 void DefaultAtomVisitor::visit(Atom* atom){
165     AtomData* atomData;
166     AtomInfo* atomInfo;
167     double pos[3];
168    
169     if(isVisited(atom))
170     return;
171    
172     atomInfo =new AtomInfo;
173 tim 1119
174     atomData = new AtomData;
175     atomData->setID("ATOMDATA");
176 tim 1118
177     atom->getPos(pos);
178     atomInfo->AtomType = atom->getType();
179     atomInfo->pos[0] = pos[0];
180     atomInfo->pos[1] = pos[1];
181     atomInfo->pos[2] = pos[2];
182     atomInfo->dipole[0] = 0.0;
183     atomInfo->dipole[1] = 0.0;
184     atomInfo->dipole[2] = 0.0;
185    
186 tim 1119
187     atomData->addAtomInfo(atomInfo);
188    
189 tim 1118 atom->addProperty(atomData);
190    
191     setVisited(atom);
192     }
193     void DefaultAtomVisitor::visit(DirectionalAtom* datom){
194     AtomData* atomData;
195     AtomInfo* atomInfo;
196     double pos[3];
197     double u[3];
198    
199     if(isVisited(datom))
200     return;
201    
202     datom->getPos(pos);
203     datom->getU(u);
204    
205 tim 1119 atomData = new AtomData;
206     atomData->setID("ATOMDATA");
207 tim 1118 atomInfo =new AtomInfo;
208    
209     atomInfo->AtomType = datom->getType();
210     atomInfo->pos[0] = pos[0];
211     atomInfo->pos[1] = pos[1];
212     atomInfo->pos[2] = pos[2];
213     atomInfo->dipole[0] = u[0];
214     atomInfo->dipole[1] = u[1];
215     atomInfo->dipole[2] = u[2];
216    
217 tim 1119 atomData->addAtomInfo(atomInfo);
218    
219 tim 1118 datom->addProperty(atomData);
220    
221     setVisited(datom);
222     }
223 tim 1126
224    
225     const string DefaultAtomVisitor::toString(){
226     char buffer[65535];
227     string result;
228    
229     sprintf(buffer ,"------------------------------------------------------------------\n");
230     result += buffer;
231    
232     sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
233     result += buffer;
234    
235     sprintf(buffer , "Visitor Description: copy atom infomation into atom data\n");
236     result += buffer;
237    
238     sprintf(buffer ,"------------------------------------------------------------------\n");
239     result += buffer;
240    
241     return result;
242     }

Properties

Name Value
svn:executable *