ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/AtomVisitor.cpp
Revision: 1118
Committed: Mon Apr 19 03:52:27 2004 UTC (20 years, 2 months ago) by tim
File size: 4357 byte(s)
Log Message:
new implement of quickLate using visitor and composite pattern

File Contents

# User Rev Content
1 tim 1118 #include <cstring>
2     #include "AtomVisitor.hpp"
3     #include "DirectionalAtom.hpp"
4     #include "MatVec3.h"
5    
6     void BaseAtomVisitor::setVisited(Atom* atom){
7     GenericData* data;
8     data = atom->getProperty("VISITED");
9    
10     //if visited property is not existed, add it as new property
11     if(data == NULL){
12     data = new GenericData();
13     data->setID("VISITED");
14     atom->addProperty(data);
15     }
16     }
17    
18     bool BaseAtomVisitor::isVisited(Atom* atom){
19     GenericData* data;
20     data = atom->getProperty("VISITED");
21     return data == NULL ? false : true;
22     }
23    
24     void SSDAtomVisitor::visit(DirectionalAtom* datom){
25    
26     vector<AtomInfo*> atoms;
27    
28     //we need to convert SSD into 4 differnet atoms
29     //one oxygen atom, two hydrogen atoms and one pseudo atom which is the center of the mass
30     //of the water with a dipole moment
31     double h1[3] = {0.0, -0.75695, 0.5206};
32     double h2[3] = {0.0, 0.75695, 0.5206};
33     double ox[3] = {0.0, 0.0, -0.0654};
34     double u[3] = {0, 0, 1};
35     double rotMatrix[3][3];
36     AtomInfo* atomInfo;
37     double pos[3];
38     double vel[3];
39     double newVec[3];
40     double q[4];
41     AtomData* atomData;
42     GenericData* data;
43     bool haveAtomData;
44    
45     //if atom is not SSD atom, just skip it
46     if(!strcmp(datom->getType(), "SSD"))
47     return;
48    
49     data = datom->getProperty("ATOMDATA");
50     if(data != NULL){
51    
52     atomData = dynamic_cast<AtomData*>(data);
53     if(atomData == NULL){
54     cerr << "can not get Atom Data from " << datom->getType() << endl;
55     atomData = new AtomData;
56     haveAtomData = false;
57     }
58     else
59     haveAtomData = true;
60     }
61     else{
62     atomData = new AtomData;
63     haveAtomData = false;
64     }
65    
66    
67     datom->getPos(pos);
68     datom->getQ(q);
69     datom->getA(rotMatrix);
70    
71     //center of mass of the water molecule
72     matVecMul3(rotMatrix, u, newVec);
73     atomInfo = new AtomInfo;
74     atomInfo->AtomType = "X";
75     atomInfo->pos[0] = pos[0];
76     atomInfo->pos[1] = pos[1];
77     atomInfo->pos[2] = pos[2];
78     atomInfo->dipole[0] = newVec[0];
79     atomInfo->dipole[1] = newVec[1];
80     atomInfo->dipole[2] = newVec[2];
81    
82     atomData->addAtomInfo(atomInfo);
83    
84     //oxygen
85     matVecMul3(rotMatrix, ox, newVec);
86     atomInfo = new AtomInfo;
87     atomInfo->AtomType = "O";
88     atomInfo->pos[0] = pos[0] + newVec[0];
89     atomInfo->pos[1] = pos[1] + newVec[1];
90     atomInfo->pos[2] = pos[2] + newVec[2];
91     atomInfo->dipole[0] = 0.0;
92     atomInfo->dipole[1] = 0.0;
93     atomInfo->dipole[2] = 0.0;
94     atomData->addAtomInfo(atomInfo);
95    
96    
97     //hydrogen1
98     matVecMul3(rotMatrix, h1, newVec);
99     atomInfo = new AtomInfo;
100     atomInfo->AtomType = "H";
101     atomInfo->pos[0] = pos[0] + newVec[0];
102     atomInfo->pos[1] = pos[1] + newVec[1];
103     atomInfo->pos[2] = pos[2] + newVec[2];
104     atomInfo->dipole[0] = 0.0;
105     atomInfo->dipole[1] = 0.0;
106     atomInfo->dipole[2] = 0.0;
107     atomData->addAtomInfo(atomInfo);
108    
109     //hydrogen2
110     matVecMul3(rotMatrix, h2, newVec);
111     atomInfo = new AtomInfo;
112     atomInfo->AtomType = "H";
113     atomInfo->pos[0] = pos[0] + newVec[0];
114     atomInfo->pos[1] = pos[1] + newVec[1];
115     atomInfo->pos[2] = pos[2] + newVec[2];
116     atomInfo->dipole[0] = 0.0;
117     atomInfo->dipole[1] = 0.0;
118     atomInfo->dipole[2] = 0.0;
119     atomData->addAtomInfo(atomInfo);
120    
121     //add atom data into atom's property
122    
123     if(!haveAtomData){
124     atomData->setID("ATOMDATA");
125     datom->addProperty(atomData);
126     }
127    
128     setVisited(datom);
129    
130     }
131    
132     void DefaultAtomVisitor::visit(Atom* atom){
133     AtomData* atomData;
134     AtomInfo* atomInfo;
135     double pos[3];
136    
137     if(isVisited(atom))
138     return;
139    
140     atomInfo =new AtomInfo;
141    
142     atom->getPos(pos);
143     atomInfo->AtomType = atom->getType();
144     atomInfo->pos[0] = pos[0];
145     atomInfo->pos[1] = pos[1];
146     atomInfo->pos[2] = pos[2];
147     atomInfo->dipole[0] = 0.0;
148     atomInfo->dipole[1] = 0.0;
149     atomInfo->dipole[2] = 0.0;
150    
151     atomData = new AtomData;
152     atomData->setID("ATOMDATA");
153     atom->addProperty(atomData);
154    
155     setVisited(atom);
156     }
157     void DefaultAtomVisitor::visit(DirectionalAtom* datom){
158     AtomData* atomData;
159     AtomInfo* atomInfo;
160     double pos[3];
161     double u[3];
162    
163     if(isVisited(datom))
164     return;
165    
166     datom->getPos(pos);
167     datom->getU(u);
168    
169     atomInfo =new AtomInfo;
170    
171     atomInfo->AtomType = datom->getType();
172     atomInfo->pos[0] = pos[0];
173     atomInfo->pos[1] = pos[1];
174     atomInfo->pos[2] = pos[2];
175     atomInfo->dipole[0] = u[0];
176     atomInfo->dipole[1] = u[1];
177     atomInfo->dipole[2] = u[2];
178    
179     atomData = new AtomData;
180     atomData->setID("ATOMDATA");
181     datom->addProperty(atomData);
182    
183     setVisited(datom);
184     }
185    

Properties

Name Value
svn:executable *