ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/visitors/AtomVisitor.cpp
(Generate patch)

Comparing trunk/OOPSE-2.0/src/visitors/AtomVisitor.cpp (file contents):
Revision 1930 by gezelter, Wed Jan 12 22:41:40 2005 UTC vs.
Revision 2091 by gezelter, Tue Mar 8 21:07:49 2005 UTC

# Line 42 | Line 42
42   #include <cstring>
43   #include "visitors/AtomVisitor.hpp"
44   #include "primitives/DirectionalAtom.hpp"
45 #include "math/MatVec3.h"
45   #include "primitives/RigidBody.hpp"
46  
47   namespace oopse {
# Line 75 | Line 74 | bool SSDAtomVisitor::isSSDAtom(const std::string&atomT
74   }
75  
76   bool SSDAtomVisitor::isSSDAtom(const std::string&atomType) {
77 <    std::vector<std::string>::iterator strIter;
78 <
79 <    for( strIter = ssdAtomType.begin(); strIter != ssdAtomType.end();
81 <        ++strIter )
82 <  if (*strIter == atomType)
83 <      return true;
84 <
85 <    return false;
77 >    std::set<std::string>::iterator strIter;
78 >    strIter = ssdAtomType.find(atomType);
79 >    return strIter != ssdAtomType.end() ? true : false;
80   }
81  
82   void SSDAtomVisitor::visit(DirectionalAtom *datom) {
83 <    std::vector<AtomInfo *>atoms;
83 >    std::vector<AtomInfo*>atoms;
84  
85      //we need to convert SSD into 4 differnet atoms
86      //one oxygen atom, two hydrogen atoms and one pseudo atom which is the center of the mass
# Line 138 | Line 132 | void SSDAtomVisitor::visit(DirectionalAtom *datom) {
132      newVec = rotTrans * u;
133  
134      atomInfo = new AtomInfo;
135 <    atomInfo->AtomType = "X";
135 >    atomInfo->atomTypeName = "X";
136      atomInfo->pos[0] = pos[0];
137      atomInfo->pos[1] = pos[1];
138      atomInfo->pos[2] = pos[2];
# Line 153 | Line 147 | void SSDAtomVisitor::visit(DirectionalAtom *datom) {
147      newVec = rotTrans * ox;
148  
149      atomInfo = new AtomInfo;
150 <    atomInfo->AtomType = "O";
150 >    atomInfo->atomTypeName = "O";
151      atomInfo->pos[0] = pos[0] + newVec[0];
152      atomInfo->pos[1] = pos[1] + newVec[1];
153      atomInfo->pos[2] = pos[2] + newVec[2];
# Line 166 | Line 160 | void SSDAtomVisitor::visit(DirectionalAtom *datom) {
160      //matVecMul3(rotTrans, h1, newVec);
161      newVec = rotTrans * h1;
162      atomInfo = new AtomInfo;
163 <    atomInfo->AtomType = "H";
163 >    atomInfo->atomTypeName = "H";
164      atomInfo->pos[0] = pos[0] + newVec[0];
165      atomInfo->pos[1] = pos[1] + newVec[1];
166      atomInfo->pos[2] = pos[2] + newVec[2];
# Line 179 | Line 173 | void SSDAtomVisitor::visit(DirectionalAtom *datom) {
173      //matVecMul3(rotTrans, h2, newVec);
174      newVec = rotTrans * h2;
175      atomInfo = new AtomInfo;
176 <    atomInfo->AtomType = "H";
176 >    atomInfo->atomTypeName = "H";
177      atomInfo->pos[0] = pos[0] + newVec[0];
178      atomInfo->pos[1] = pos[1] + newVec[1];
179      atomInfo->pos[2] = pos[2] + newVec[2];
# Line 220 | Line 214 | bool LinearAtomVisitor::isLinearAtom(const string& ato
214      return result;
215   }
216  
217 < bool LinearAtomVisitor::isLinearAtom(const string& atomType){
218 <  vector<string>::iterator strIter;
219 <  
220 <  for(strIter = linearAtomType.begin(); strIter != linearAtomType.end();
221 <      ++strIter)
228 <    if(*strIter == atomType)
229 <      return true;
230 <  
231 <  return false;  
217 > bool LinearAtomVisitor::isLinearAtom(const std::string& atomType){
218 >    std::set<std::string>::iterator strIter;
219 >    strIter = linearAtomType.find(atomType);
220 >
221 >    return strIter != linearAtomType.end() ? true : false;
222   }
223  
224   void LinearAtomVisitor::visit(DirectionalAtom* datom){
225 +    std::vector<AtomInfo*> atoms;
226 +    //we need to convert linear into 4 different atoms
227 +    Vector3d c1(0.0, 0.0, -1.8);
228 +    Vector3d c2(0.0, 0.0, -0.6);
229 +    Vector3d c3(0.0, 0.0,  0.6);
230 +    Vector3d c4(0.0, 0.0,  1.8);
231 +    RotMat3x3d rotMatrix;
232 +    RotMat3x3d rotTrans;
233 +    AtomInfo* atomInfo;
234 +    Vector3d pos;
235 +    Vector3d newVec;
236 +    Quat4d q;
237 +    AtomData* atomData;
238 +    GenericData* data;
239 +    bool haveAtomData;
240  
241 <  vector<AtomInfo*> atoms;
241 >    //if atom is not SSD atom, just skip it
242 >    if(!isLinearAtom(datom->getType()))
243 >        return;
244  
245 <  //we need to convert linear into 4 different atoms
246 <  double c1[3] = {0.0, 0.0, -1.8};
247 <  double c2[3] = {0.0, 0.0, -0.6};
248 <  double c3[3] = {0.0, 0.0,  0.6};
249 <  double c4[3] = {0.0, 0.0,  1.8};
250 <  double rotMatrix[3][3];
251 <  double rotTrans[3][3];
252 <  AtomInfo* atomInfo;
253 <  double pos[3];
254 <  double newVec[3];
255 <  double q[4];
256 <  AtomData* atomData;
257 <  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;      
245 >    data = datom->getPropertyByName("ATOMDATA");
246 >    if(data != NULL){
247 >        atomData = dynamic_cast<AtomData*>(data);  
248 >        if(atomData == NULL){
249 >            std::cerr << "can not get Atom Data from " << datom->getType() << std::endl;
250 >            atomData = new AtomData;
251 >            haveAtomData = false;      
252 >        } else {
253 >            haveAtomData = true;
254 >        }
255 >    } else {
256 >        atomData = new AtomData;
257 >        haveAtomData = false;
258      }
266    else
267      haveAtomData = true;
268  }
269  else{
270    atomData = new AtomData;
271    haveAtomData = false;
272  }
259    
260    
261 <  datom->getPos(pos);
262 <  datom->getQ(q);
263 <  datom->getA(rotMatrix);
261 >    pos = datom->getPos();
262 >    q = datom->getQ();
263 >    rotMatrix = datom->getA();
264  
265 <  // We need A^T to convert from body-fixed to space-fixed:
266 <  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);
265 >    // We need A^T to convert from body-fixed to space-fixed:  
266 >    rotTrans = rotMatrix.transpose();
267  
268 <  matVecMul3(rotTrans, c2, newVec);
269 <  atomInfo = new AtomInfo;
270 <  atomInfo->AtomType = "C";
271 <  atomInfo->pos[0] = pos[0] + newVec[0];
272 <  atomInfo->pos[1] = pos[1] + newVec[1];
273 <  atomInfo->pos[2] = pos[2] + newVec[2];
274 <  atomInfo->dipole[0] = 0.0;
275 <  atomInfo->dipole[1] = 0.0;
276 <  atomInfo->dipole[2] = 0.0;
277 <  atomData->addAtomInfo(atomInfo);
268 >    newVec = rotTrans * c1;
269 >    atomInfo = new AtomInfo;
270 >    atomInfo->atomTypeName = "C";
271 >    atomInfo->pos[0] = pos[0] + newVec[0];
272 >    atomInfo->pos[1] = pos[1] + newVec[1];
273 >    atomInfo->pos[2] = pos[2] + newVec[2];
274 >    atomInfo->dipole[0] = 0.0;
275 >    atomInfo->dipole[1] = 0.0;
276 >    atomInfo->dipole[2] = 0.0;
277 >    atomData->addAtomInfo(atomInfo);
278  
279 <  matVecMul3(rotTrans, c3, newVec);
280 <  atomInfo = new AtomInfo;
281 <  atomInfo->AtomType = "C";
282 <  atomInfo->pos[0] = pos[0] + newVec[0];
283 <  atomInfo->pos[1] = pos[1] + newVec[1];
284 <  atomInfo->pos[2] = pos[2] + newVec[2];
285 <  atomInfo->dipole[0] = 0.0;
286 <  atomInfo->dipole[1] = 0.0;
287 <  atomInfo->dipole[2] = 0.0;
288 <  atomData->addAtomInfo(atomInfo);
279 >    newVec = rotTrans * c2;
280 >    atomInfo = new AtomInfo;
281 >    atomInfo->atomTypeName = "C";
282 >    atomInfo->pos[0] = pos[0] + newVec[0];
283 >    atomInfo->pos[1] = pos[1] + newVec[1];
284 >    atomInfo->pos[2] = pos[2] + newVec[2];
285 >    atomInfo->dipole[0] = 0.0;
286 >    atomInfo->dipole[1] = 0.0;
287 >    atomInfo->dipole[2] = 0.0;
288 >    atomData->addAtomInfo(atomInfo);
289  
290 <  matVecMul3(rotTrans, c4, newVec);
291 <  atomInfo = new AtomInfo;
292 <  atomInfo->AtomType = "C";
293 <  atomInfo->pos[0] = pos[0] + newVec[0];
294 <  atomInfo->pos[1] = pos[1] + newVec[1];
295 <  atomInfo->pos[2] = pos[2] + newVec[2];
296 <  atomInfo->dipole[0] = 0.0;
297 <  atomInfo->dipole[1] = 0.0;
298 <  atomInfo->dipole[2] = 0.0;
299 <  atomData->addAtomInfo(atomInfo);
290 >    newVec = rotTrans * c3;
291 >    atomInfo = new AtomInfo;
292 >    atomInfo->atomTypeName = "C";
293 >    atomInfo->pos[0] = pos[0] + newVec[0];
294 >    atomInfo->pos[1] = pos[1] + newVec[1];
295 >    atomInfo->pos[2] = pos[2] + newVec[2];
296 >    atomInfo->dipole[0] = 0.0;
297 >    atomInfo->dipole[1] = 0.0;
298 >    atomInfo->dipole[2] = 0.0;
299 >    atomData->addAtomInfo(atomInfo);
300  
301 <  //add atom data into atom's property
301 >    newVec = rotTrans * c4;
302 >    atomInfo = new AtomInfo;
303 >    atomInfo->atomTypeName = "C";
304 >    atomInfo->pos[0] = pos[0] + newVec[0];
305 >    atomInfo->pos[1] = pos[1] + newVec[1];
306 >    atomInfo->pos[2] = pos[2] + newVec[2];
307 >    atomInfo->dipole[0] = 0.0;
308 >    atomInfo->dipole[1] = 0.0;
309 >    atomInfo->dipole[2] = 0.0;
310 >    atomData->addAtomInfo(atomInfo);
311  
312 <  if(!haveAtomData){
329 <    atomData->setID("ATOMDATA");
330 <    datom->addProperty(atomData);
331 <  }
312 >    //add atom data into atom's property
313  
314 <  setVisited(datom);
314 >    if(!haveAtomData){
315 >        atomData->setID("ATOMDATA");
316 >        datom->addProperty(atomData);
317 >    }
318  
319 +    setVisited(datom);
320 +
321   }
322  
323 < const string LinearAtomVisitor::toString(){
323 > const std::string LinearAtomVisitor::toString(){
324    char buffer[65535];
325 <  string result;
325 >  std::string result;
326    
327    sprintf(buffer ,"------------------------------------------------------------------\n");
328    result += buffer;
# Line 369 | Line 355 | void DefaultAtomVisitor::visit(Atom *atom) {
355      atomData->setID("ATOMDATA");
356  
357      pos = atom->getPos();
358 <    atomInfo->AtomType = atom->getType();
358 >    atomInfo->atomTypeName = atom->getType();
359 >    printf("setting a type to %s\n", atom->getType().c_str());
360      atomInfo->pos[0] = pos[0];
361      atomInfo->pos[1] = pos[1];
362      atomInfo->pos[2] = pos[2];
# Line 394 | Line 381 | void DefaultAtomVisitor::visit(DirectionalAtom *datom)
381          return;
382  
383      pos = datom->getPos();
384 <    u = datom->getElectroFrame().getColumn(3);
384 >    u = datom->getElectroFrame().getColumn(2);
385  
386      atomData = new AtomData;
387      atomData->setID("ATOMDATA");
388      atomInfo = new AtomInfo;
389  
390 <    atomInfo->AtomType = datom->getType();
390 >    atomInfo->atomTypeName = datom->getType();
391      atomInfo->pos[0] = pos[0];
392      atomInfo->pos[1] = pos[1];
393      atomInfo->pos[2] = pos[2];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines