ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/visitors/AtomVisitor.cpp
Revision: 1927
Committed: Wed Jan 12 17:14:35 2005 UTC (21 years, 1 month ago) by tim
File size: 9007 byte(s)
Log Message:
change license

File Contents

# User Rev Content
1 tim 1927 /*
2     * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3     *
4     * The University of Notre Dame grants you ("Licensee") a
5     * non-exclusive, royalty free, license to use, modify and
6     * redistribute this software in source and binary code form, provided
7     * that the following conditions are met:
8     *
9     * 1. Acknowledgement of the program authors must be made in any
10     * publication of scientific results based in part on use of the
11     * program. An acceptable form of acknowledgement is citation of
12     * the article in which the program was described (Matthew
13     * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14     * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15     * Parallel Simulation Engine for Molecular Dynamics,"
16     * J. Comput. Chem. 26, pp. 252-271 (2005))
17     *
18     * 2. Redistributions of source code must retain the above copyright
19     * notice, this list of conditions and the following disclaimer.
20     *
21     * 3. Redistributions in binary form must reproduce the above copyright
22     * notice, this list of conditions and the following disclaimer in the
23     * documentation and/or other materials provided with the
24     * distribution.
25     *
26     * This software is provided "AS IS," without a warranty of any
27     * kind. All express or implied conditions, representations and
28     * warranties, including any implied warranty of merchantability,
29     * fitness for a particular purpose or non-infringement, are hereby
30     * excluded. The University of Notre Dame and its licensors shall not
31     * be liable for any damages suffered by licensee as a result of
32     * using, modifying or distributing the software or its
33     * derivatives. In no event will the University of Notre Dame or its
34     * licensors be liable for any lost revenue, profit or data, or for
35     * direct, indirect, special, consequential, incidental or punitive
36     * damages, however caused and regardless of the theory of liability,
37     * arising out of the use of or inability to use software, even if the
38     * University of Notre Dame has been advised of the possibility of
39     * such damages.
40     */
41    
42 tim 1725 #include <cstring>
43     #include "visitors/AtomVisitor.hpp"
44     #include "primitives/DirectionalAtom.hpp"
45     #include "math/MatVec3.h"
46     #include "primitives/RigidBody.hpp"
47    
48     namespace oopse {
49     void BaseAtomVisitor::visit(RigidBody *rb) {
50     //vector<Atom*> myAtoms;
51     //vector<Atom*>::iterator atomIter;
52    
53     //myAtoms = rb->getAtoms();
54    
55     //for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter)
56     // (*atomIter)->accept(this);
57     }
58    
59     void BaseAtomVisitor::setVisited(Atom *atom) {
60     GenericData *data;
61     data = atom->getPropertyByName("VISITED");
62    
63     //if visited property is not existed, add it as new property
64     if (data == NULL) {
65     data = new GenericData();
66     data->setID("VISITED");
67     atom->addProperty(data);
68     }
69     }
70    
71     bool BaseAtomVisitor::isVisited(Atom *atom) {
72     GenericData *data;
73     data = atom->getPropertyByName("VISITED");
74     return data == NULL ? false : true;
75     }
76    
77 tim 1832 bool SSDAtomVisitor::isSSDAtom(const std::string&atomType) {
78     std::vector<std::string>::iterator strIter;
79 tim 1725
80     for( strIter = ssdAtomType.begin(); strIter != ssdAtomType.end();
81     ++strIter )
82     if (*strIter == atomType)
83     return true;
84    
85     return false;
86     }
87    
88     void SSDAtomVisitor::visit(DirectionalAtom *datom) {
89 tim 1816 std::vector<AtomInfo *>atoms;
90 tim 1725
91     //we need to convert SSD into 4 differnet atoms
92     //one oxygen atom, two hydrogen atoms and one pseudo atom which is the center of the mass
93     //of the water with a dipole moment
94     Vector3d h1(0.0, -0.75695, 0.5206);
95     Vector3d h2(0.0, 0.75695, 0.5206);
96     Vector3d ox(0.0, 0.0, -0.0654);
97     Vector3d u(0, 0, 1);
98     RotMat3x3d rotMatrix;
99     RotMat3x3d rotTrans;
100     AtomInfo * atomInfo;
101     Vector3d pos;
102     Vector3d newVec;
103     Quat4d q;
104     AtomData * atomData;
105     GenericData *data;
106     bool haveAtomData;
107    
108     //if atom is not SSD atom, just skip it
109     if (!isSSDAtom(datom->getType()))
110     return;
111    
112     data = datom->getPropertyByName("ATOMDATA");
113    
114     if (data != NULL) {
115     atomData = dynamic_cast<AtomData *>(data);
116    
117     if (atomData == NULL) {
118 tim 1830 std::cerr << "can not get Atom Data from " << datom->getType() << std::endl;
119 tim 1725 atomData = new AtomData;
120     haveAtomData = false;
121     } else
122     haveAtomData = true;
123     } else {
124     atomData = new AtomData;
125     haveAtomData = false;
126     }
127    
128     pos = datom->getPos();
129     q = datom->getQ();
130     rotMatrix = datom->getA();
131    
132     // We need A^T to convert from body-fixed to space-fixed:
133     //transposeMat3(rotMatrix, rotTrans);
134     rotTrans = rotMatrix.transpose();
135    
136     //center of mass of the water molecule
137     //matVecMul3(rotTrans, u, newVec);
138     newVec = rotTrans * u;
139    
140     atomInfo = new AtomInfo;
141     atomInfo->AtomType = "X";
142     atomInfo->pos[0] = pos[0];
143     atomInfo->pos[1] = pos[1];
144     atomInfo->pos[2] = pos[2];
145     atomInfo->dipole[0] = newVec[0];
146     atomInfo->dipole[1] = newVec[1];
147     atomInfo->dipole[2] = newVec[2];
148    
149     atomData->addAtomInfo(atomInfo);
150    
151     //oxygen
152     //matVecMul3(rotTrans, ox, newVec);
153     newVec = rotTrans * ox;
154    
155     atomInfo = new AtomInfo;
156     atomInfo->AtomType = "O";
157     atomInfo->pos[0] = pos[0] + newVec[0];
158     atomInfo->pos[1] = pos[1] + newVec[1];
159     atomInfo->pos[2] = pos[2] + newVec[2];
160     atomInfo->dipole[0] = 0.0;
161     atomInfo->dipole[1] = 0.0;
162     atomInfo->dipole[2] = 0.0;
163     atomData->addAtomInfo(atomInfo);
164    
165     //hydrogen1
166     //matVecMul3(rotTrans, h1, newVec);
167     newVec = rotTrans * h1;
168     atomInfo = new AtomInfo;
169     atomInfo->AtomType = "H";
170     atomInfo->pos[0] = pos[0] + newVec[0];
171     atomInfo->pos[1] = pos[1] + newVec[1];
172     atomInfo->pos[2] = pos[2] + newVec[2];
173     atomInfo->dipole[0] = 0.0;
174     atomInfo->dipole[1] = 0.0;
175     atomInfo->dipole[2] = 0.0;
176     atomData->addAtomInfo(atomInfo);
177    
178     //hydrogen2
179     //matVecMul3(rotTrans, h2, newVec);
180     newVec = rotTrans * h2;
181     atomInfo = new AtomInfo;
182     atomInfo->AtomType = "H";
183     atomInfo->pos[0] = pos[0] + newVec[0];
184     atomInfo->pos[1] = pos[1] + newVec[1];
185     atomInfo->pos[2] = pos[2] + newVec[2];
186     atomInfo->dipole[0] = 0.0;
187     atomInfo->dipole[1] = 0.0;
188     atomInfo->dipole[2] = 0.0;
189     atomData->addAtomInfo(atomInfo);
190    
191     //add atom data into atom's property
192    
193     if (!haveAtomData) {
194     atomData->setID("ATOMDATA");
195     datom->addProperty(atomData);
196     }
197    
198     setVisited(datom);
199     }
200    
201 tim 1816 const std::string SSDAtomVisitor::toString() {
202 tim 1725 char buffer[65535];
203 tim 1816 std::string result;
204 tim 1725
205     sprintf(buffer,
206     "------------------------------------------------------------------\n");
207     result += buffer;
208    
209     sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
210     result += buffer;
211    
212     sprintf(buffer,
213     "Visitor Description: Convert SSD into 4 different atoms\n");
214     result += buffer;
215    
216     sprintf(buffer,
217     "------------------------------------------------------------------\n");
218     result += buffer;
219    
220     return result;
221     }
222    
223     //----------------------------------------------------------------------------//
224    
225     void DefaultAtomVisitor::visit(Atom *atom) {
226     AtomData *atomData;
227     AtomInfo *atomInfo;
228     Vector3d pos;
229    
230     if (isVisited(atom))
231     return;
232    
233     atomInfo = new AtomInfo;
234    
235     atomData = new AtomData;
236     atomData->setID("ATOMDATA");
237    
238     pos = atom->getPos();
239     atomInfo->AtomType = atom->getType();
240     atomInfo->pos[0] = pos[0];
241     atomInfo->pos[1] = pos[1];
242     atomInfo->pos[2] = pos[2];
243     atomInfo->dipole[0] = 0.0;
244     atomInfo->dipole[1] = 0.0;
245     atomInfo->dipole[2] = 0.0;
246    
247     atomData->addAtomInfo(atomInfo);
248    
249     atom->addProperty(atomData);
250    
251     setVisited(atom);
252     }
253    
254     void DefaultAtomVisitor::visit(DirectionalAtom *datom) {
255     AtomData *atomData;
256     AtomInfo *atomInfo;
257     Vector3d pos;
258     Vector3d u;
259    
260     if (isVisited(datom))
261     return;
262    
263     pos = datom->getPos();
264 tim 1816 u = datom->getElectroFrame().getColumn(3);
265 tim 1725
266     atomData = new AtomData;
267     atomData->setID("ATOMDATA");
268     atomInfo = new AtomInfo;
269    
270     atomInfo->AtomType = datom->getType();
271     atomInfo->pos[0] = pos[0];
272     atomInfo->pos[1] = pos[1];
273     atomInfo->pos[2] = pos[2];
274     atomInfo->dipole[0] = u[0];
275     atomInfo->dipole[1] = u[1];
276     atomInfo->dipole[2] = u[2];
277    
278     atomData->addAtomInfo(atomInfo);
279    
280     datom->addProperty(atomData);
281    
282     setVisited(datom);
283     }
284    
285 tim 1816 const std::string DefaultAtomVisitor::toString() {
286 tim 1725 char buffer[65535];
287 tim 1816 std::string result;
288 tim 1725
289     sprintf(buffer,
290     "------------------------------------------------------------------\n");
291     result += buffer;
292    
293     sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
294     result += buffer;
295    
296     sprintf(buffer,
297     "Visitor Description: copy atom infomation into atom data\n");
298     result += buffer;
299    
300     sprintf(buffer,
301     "------------------------------------------------------------------\n");
302     result += buffer;
303    
304     return result;
305     }
306     } //namespace oopse

Properties

Name Value
svn:executable *