1 |
< |
#include "visitors/RigidBodyVisitor.hpp" |
2 |
< |
#include "primitives/RigidBody.hpp" |
3 |
< |
#include "math/MatVec3.h" |
4 |
< |
|
5 |
< |
namespace oopse { |
6 |
< |
|
7 |
< |
void LipidHeadVisitor::visit(RigidBody* rb){ |
8 |
< |
double pos[3]; |
9 |
< |
double u[3] = {0, 0, 1}; |
10 |
< |
double newVec[3]; |
11 |
< |
GenericData* data; |
12 |
< |
AtomData* atomData; |
13 |
< |
AtomInfo* atomInfo; |
14 |
< |
bool haveAtomData; |
15 |
< |
double rotMatrix[3][3]; |
16 |
< |
|
17 |
< |
if(!canVisit(rb->getType())) |
18 |
< |
return; |
19 |
< |
|
20 |
< |
rb->getPos(pos); |
21 |
< |
rb->getA(rotMatrix); |
22 |
< |
matVecMul3(rotMatrix, u, newVec); |
23 |
< |
|
24 |
< |
data = rb->getProperty("ATOMDATA"); |
25 |
< |
if(data != NULL){ |
26 |
< |
|
27 |
< |
atomData = dynamic_cast<AtomData*>(data); |
28 |
< |
if(atomData == NULL){ |
29 |
< |
cerr << "can not get Atom Data from " << rb->getType() << endl; |
30 |
< |
atomData = new AtomData; |
31 |
< |
haveAtomData = false; |
32 |
< |
} |
33 |
< |
else |
34 |
< |
haveAtomData = true; |
35 |
< |
} |
36 |
< |
else{ |
37 |
< |
atomData = new AtomData; |
38 |
< |
haveAtomData = false; |
39 |
< |
} |
40 |
< |
|
41 |
< |
atomInfo = new AtomInfo; |
42 |
< |
atomInfo->AtomType = "X"; |
43 |
< |
atomInfo->pos[0] = pos[0]; |
44 |
< |
atomInfo->pos[1] = pos[1]; |
45 |
< |
atomInfo->pos[2] = pos[2]; |
46 |
< |
atomInfo->dipole[0] = newVec[0]; |
47 |
< |
atomInfo->dipole[1] = newVec[1]; |
48 |
< |
atomInfo->dipole[2] = newVec[2]; |
49 |
< |
|
50 |
< |
atomData->addAtomInfo(atomInfo); |
51 |
< |
|
52 |
< |
if(!haveAtomData){ |
53 |
< |
atomData->setID("ATOMDATA"); |
54 |
< |
rb->addProperty(atomData); |
55 |
< |
} |
56 |
< |
|
57 |
< |
} |
58 |
< |
|
59 |
< |
void LipidHeadVisitor::addLipidHeadName(const string& name){ |
60 |
< |
lipidHeadName.insert(name); |
61 |
< |
|
62 |
< |
} |
63 |
< |
|
64 |
< |
bool LipidHeadVisitor::canVisit(const string& name){ |
65 |
< |
return lipidHeadName.find(name) != lipidHeadName.end() ? true : false; |
66 |
< |
|
67 |
< |
} |
68 |
< |
|
69 |
< |
const string LipidHeadVisitor::toString(){ |
70 |
< |
char buffer[65535]; |
71 |
< |
string result; |
72 |
< |
set<string>::iterator i; |
73 |
< |
|
74 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
75 |
< |
result += buffer; |
76 |
< |
|
77 |
< |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
78 |
< |
result += buffer; |
79 |
< |
|
80 |
< |
//print the ignore type list |
81 |
< |
sprintf(buffer , "lipidHeadName list contains below types:\n"); |
82 |
< |
result += buffer; |
83 |
< |
|
84 |
< |
for(i = lipidHeadName.begin(); i != lipidHeadName.end(); ++i){ |
85 |
< |
sprintf(buffer ,"%s\t", i->c_str()); |
86 |
< |
result += buffer; |
87 |
< |
} |
88 |
< |
|
89 |
< |
sprintf(buffer ,"\n"); |
90 |
< |
result += buffer; |
91 |
< |
|
92 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
93 |
< |
result += buffer; |
94 |
< |
|
95 |
< |
return result; |
96 |
< |
|
97 |
< |
} |
98 |
< |
|
99 |
< |
void RBCOMVisitor::visit(RigidBody* rb){ |
100 |
< |
AtomData* atomData; |
101 |
< |
AtomInfo* atomInfo; |
102 |
< |
double pos[3]; |
103 |
< |
|
104 |
< |
rb->getPos(pos); |
105 |
< |
atomInfo = new AtomInfo; |
106 |
< |
atomInfo->AtomType = "X"; |
107 |
< |
atomInfo->pos[0] = pos[0]; |
108 |
< |
atomInfo->pos[1] = pos[1]; |
109 |
< |
atomInfo->pos[2] = pos[2]; |
110 |
< |
atomInfo->dipole[0] = 0; |
111 |
< |
atomInfo->dipole[1] = 0; |
112 |
< |
atomInfo->dipole[2] = 0; |
113 |
< |
|
114 |
< |
atomData = new AtomData; |
115 |
< |
atomData->setID("ATOMDATA"); |
116 |
< |
atomData->addAtomInfo(atomInfo); |
117 |
< |
|
118 |
< |
rb->addProperty(atomData); |
119 |
< |
} |
120 |
< |
|
121 |
< |
const string RBCOMVisitor::toString(){ |
122 |
< |
char buffer[65535]; |
123 |
< |
string result; |
124 |
< |
|
125 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
126 |
< |
result += buffer; |
127 |
< |
|
128 |
< |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
129 |
< |
result += buffer; |
130 |
< |
|
131 |
< |
//print the ignore type list |
132 |
< |
sprintf(buffer , "Visitor Description: add a pseudo atom at the center of the mass of the rigidbody\n"); |
133 |
< |
result += buffer; |
134 |
< |
|
135 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
136 |
< |
result += buffer; |
137 |
< |
|
138 |
< |
return result; |
139 |
< |
|
140 |
< |
} |
141 |
< |
|
142 |
< |
|
143 |
< |
}//namespace oopse |
1 |
> |
#include "visitors/RigidBodyVisitor.hpp" |
2 |
> |
#include "primitives/RigidBody.hpp" |
3 |
> |
#include "math/MatVec3.h" |
4 |
> |
|
5 |
> |
namespace oopse { |
6 |
> |
|
7 |
> |
void LipidHeadVisitor::visit(RigidBody* rb){ |
8 |
> |
double pos[3]; |
9 |
> |
double u[3] = {0, 0, 1}; |
10 |
> |
double newVec[3]; |
11 |
> |
GenericData* data; |
12 |
> |
AtomData* atomData; |
13 |
> |
AtomInfo* atomInfo; |
14 |
> |
bool haveAtomData; |
15 |
> |
double rotMatrix[3][3]; |
16 |
> |
|
17 |
> |
if(!canVisit(rb->getType())) |
18 |
> |
return; |
19 |
> |
|
20 |
> |
pos = rb->getPos(); |
21 |
> |
rb->getA(rotMatrix); |
22 |
> |
matVecMul3(rotMatrix, u, newVec); |
23 |
> |
|
24 |
> |
data = rb->getProperty("ATOMDATA"); |
25 |
> |
if(data != NULL){ |
26 |
> |
|
27 |
> |
atomData = dynamic_cast<AtomData*>(data); |
28 |
> |
if(atomData == NULL){ |
29 |
> |
cerr << "can not get Atom Data from " << rb->getType() << endl; |
30 |
> |
atomData = new AtomData; |
31 |
> |
haveAtomData = false; |
32 |
> |
} |
33 |
> |
else |
34 |
> |
haveAtomData = true; |
35 |
> |
} |
36 |
> |
else{ |
37 |
> |
atomData = new AtomData; |
38 |
> |
haveAtomData = false; |
39 |
> |
} |
40 |
> |
|
41 |
> |
atomInfo = new AtomInfo; |
42 |
> |
atomInfo->AtomType = "X"; |
43 |
> |
atomInfo->pos[0] = pos[0]; |
44 |
> |
atomInfo->pos[1] = pos[1]; |
45 |
> |
atomInfo->pos[2] = pos[2]; |
46 |
> |
atomInfo->dipole[0] = newVec[0]; |
47 |
> |
atomInfo->dipole[1] = newVec[1]; |
48 |
> |
atomInfo->dipole[2] = newVec[2]; |
49 |
> |
|
50 |
> |
atomData->addAtomInfo(atomInfo); |
51 |
> |
|
52 |
> |
if(!haveAtomData){ |
53 |
> |
atomData->setID("ATOMDATA"); |
54 |
> |
rb->addProperty(atomData); |
55 |
> |
} |
56 |
> |
|
57 |
> |
} |
58 |
> |
|
59 |
> |
void LipidHeadVisitor::addLipidHeadName(const string& name){ |
60 |
> |
lipidHeadName.insert(name); |
61 |
> |
|
62 |
> |
} |
63 |
> |
|
64 |
> |
bool LipidHeadVisitor::canVisit(const string& name){ |
65 |
> |
return lipidHeadName.find(name) != lipidHeadName.end() ? true : false; |
66 |
> |
|
67 |
> |
} |
68 |
> |
|
69 |
> |
const string LipidHeadVisitor::toString(){ |
70 |
> |
char buffer[65535]; |
71 |
> |
string result; |
72 |
> |
set<string>::iterator i; |
73 |
> |
|
74 |
> |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
75 |
> |
result += buffer; |
76 |
> |
|
77 |
> |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
78 |
> |
result += buffer; |
79 |
> |
|
80 |
> |
//print the ignore type list |
81 |
> |
sprintf(buffer , "lipidHeadName list contains below types:\n"); |
82 |
> |
result += buffer; |
83 |
> |
|
84 |
> |
for(i = lipidHeadName.begin(); i != lipidHeadName.end(); ++i){ |
85 |
> |
sprintf(buffer ,"%s\t", i->c_str()); |
86 |
> |
result += buffer; |
87 |
> |
} |
88 |
> |
|
89 |
> |
sprintf(buffer ,"\n"); |
90 |
> |
result += buffer; |
91 |
> |
|
92 |
> |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
93 |
> |
result += buffer; |
94 |
> |
|
95 |
> |
return result; |
96 |
> |
|
97 |
> |
} |
98 |
> |
|
99 |
> |
void RBCOMVisitor::visit(RigidBody* rb){ |
100 |
> |
AtomData* atomData; |
101 |
> |
AtomInfo* atomInfo; |
102 |
> |
double pos[3]; |
103 |
> |
|
104 |
> |
pos = rb->getPos(); |
105 |
> |
atomInfo = new AtomInfo; |
106 |
> |
atomInfo->AtomType = "X"; |
107 |
> |
atomInfo->pos[0] = pos[0]; |
108 |
> |
atomInfo->pos[1] = pos[1]; |
109 |
> |
atomInfo->pos[2] = pos[2]; |
110 |
> |
atomInfo->dipole[0] = 0; |
111 |
> |
atomInfo->dipole[1] = 0; |
112 |
> |
atomInfo->dipole[2] = 0; |
113 |
> |
|
114 |
> |
atomData = new AtomData; |
115 |
> |
atomData->setID("ATOMDATA"); |
116 |
> |
atomData->addAtomInfo(atomInfo); |
117 |
> |
|
118 |
> |
rb->addProperty(atomData); |
119 |
> |
} |
120 |
> |
|
121 |
> |
const string RBCOMVisitor::toString(){ |
122 |
> |
char buffer[65535]; |
123 |
> |
string result; |
124 |
> |
|
125 |
> |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
126 |
> |
result += buffer; |
127 |
> |
|
128 |
> |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
129 |
> |
result += buffer; |
130 |
> |
|
131 |
> |
//print the ignore type list |
132 |
> |
sprintf(buffer , "Visitor Description: add a pseudo atom at the center of the mass of the rigidbody\n"); |
133 |
> |
result += buffer; |
134 |
> |
|
135 |
> |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
136 |
> |
result += buffer; |
137 |
> |
|
138 |
> |
return result; |
139 |
> |
|
140 |
> |
} |
141 |
> |
|
142 |
> |
|
143 |
> |
}//namespace oopse |