--- trunk/OOPSE-2.0/src/visitors/AtomVisitor.cpp 2004/10/21 16:22:01 1625 +++ trunk/OOPSE-2.0/src/visitors/AtomVisitor.cpp 2004/11/05 21:45:14 1718 @@ -174,6 +174,139 @@ const string SSDAtomVisitor::toString(){ return result; } +bool LinearAtomVisitor::isLinearAtom(const string& atomType){ + vector::iterator strIter; + + for(strIter = linearAtomType.begin(); strIter != linearAtomType.end(); + ++strIter) + if(*strIter == atomType) + return true; + + return false; +} + +void LinearAtomVisitor::visit(DirectionalAtom* datom){ + + vector atoms; + + //we need to convert linear into 4 different atoms + double c1[3] = {0.0, 0.0, -1.8}; + double c2[3] = {0.0, 0.0, -0.6}; + double c3[3] = {0.0, 0.0, 0.6}; + double c4[3] = {0.0, 0.0, 1.8}; + double rotMatrix[3][3]; + double rotTrans[3][3]; + AtomInfo* atomInfo; + double pos[3]; + double newVec[3]; + double q[4]; + AtomData* atomData; + GenericData* data; + bool haveAtomData; + + //if atom is not SSD atom, just skip it + if(!isLinearAtom(datom->getType())) + return; + + data = datom->getProperty("ATOMDATA"); + if(data != NULL){ + + atomData = dynamic_cast(data); + if(atomData == NULL){ + cerr << "can not get Atom Data from " << datom->getType() << endl; + atomData = new AtomData; + haveAtomData = false; + } + else + haveAtomData = true; + } + else{ + atomData = new AtomData; + haveAtomData = false; + } + + + datom->getPos(pos); + datom->getQ(q); + datom->getA(rotMatrix); + + // We need A^T to convert from body-fixed to space-fixed: + transposeMat3(rotMatrix, rotTrans); + + matVecMul3(rotTrans, c1, newVec); + atomInfo = new AtomInfo; + atomInfo->AtomType = "C"; + atomInfo->pos[0] = pos[0] + newVec[0]; + atomInfo->pos[1] = pos[1] + newVec[1]; + atomInfo->pos[2] = pos[2] + newVec[2]; + atomInfo->dipole[0] = 0.0; + atomInfo->dipole[1] = 0.0; + atomInfo->dipole[2] = 0.0; + atomData->addAtomInfo(atomInfo); + + matVecMul3(rotTrans, c2, newVec); + atomInfo = new AtomInfo; + atomInfo->AtomType = "C"; + atomInfo->pos[0] = pos[0] + newVec[0]; + atomInfo->pos[1] = pos[1] + newVec[1]; + atomInfo->pos[2] = pos[2] + newVec[2]; + atomInfo->dipole[0] = 0.0; + atomInfo->dipole[1] = 0.0; + atomInfo->dipole[2] = 0.0; + atomData->addAtomInfo(atomInfo); + + matVecMul3(rotTrans, c3, newVec); + atomInfo = new AtomInfo; + atomInfo->AtomType = "C"; + atomInfo->pos[0] = pos[0] + newVec[0]; + atomInfo->pos[1] = pos[1] + newVec[1]; + atomInfo->pos[2] = pos[2] + newVec[2]; + atomInfo->dipole[0] = 0.0; + atomInfo->dipole[1] = 0.0; + atomInfo->dipole[2] = 0.0; + atomData->addAtomInfo(atomInfo); + + matVecMul3(rotTrans, c4, newVec); + atomInfo = new AtomInfo; + atomInfo->AtomType = "C"; + atomInfo->pos[0] = pos[0] + newVec[0]; + atomInfo->pos[1] = pos[1] + newVec[1]; + atomInfo->pos[2] = pos[2] + newVec[2]; + atomInfo->dipole[0] = 0.0; + atomInfo->dipole[1] = 0.0; + atomInfo->dipole[2] = 0.0; + atomData->addAtomInfo(atomInfo); + + //add atom data into atom's property + + if(!haveAtomData){ + atomData->setID("ATOMDATA"); + datom->addProperty(atomData); + } + + setVisited(datom); + +} + +const string LinearAtomVisitor::toString(){ + char buffer[65535]; + string result; + + sprintf(buffer ,"------------------------------------------------------------------\n"); + result += buffer; + + sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); + result += buffer; + + sprintf(buffer , "Visitor Description: Convert linear into 4 different atoms\n"); + result += buffer; + + sprintf(buffer ,"------------------------------------------------------------------\n"); + result += buffer; + + return result; +} + //----------------------------------------------------------------------------// void DefaultAtomVisitor::visit(Atom* atom){