ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/utils/MoLocator.cpp
(Generate patch)

Comparing trunk/OOPSE/utils/MoLocator.cpp (file contents):
Revision 501 by mmeineke, Tue Apr 15 21:20:35 2003 UTC vs.
Revision 504 by mmeineke, Thu Apr 17 21:54:18 2003 UTC

# Line 1 | Line 1
1 + #include <iostream>
2 +
3 + #include <cstdlib>
4 + #include <cmath>
5 +
6 + #include "simError.h"
7 +
8   #include "MoLocator.hpp"
9 +
10 +
11 + MoLocator::MoLocator( MoleculeStamp* theStamp ){
12 +
13 +  myStamp = theStamp;
14 +  nAtoms = myStamp->getNAtoms();
15 +
16 +  myCoords = NULL;
17 +  
18 +  calcRefCoords();
19 + }
20 +
21 + MoLocator::~MoLocator(){
22 +  
23 +  if( myCoords != NULL ) delete[] myCoords;
24 + }
25 +
26 + void MoLocator::placeMol( double pos[3], double A[3][3], Atom** atomArray,
27 +                          int atomIndex ){
28 +  
29 +  int i,j,k;
30 +  double r[3];
31 +  double ux, uy, uz, u, uSqr;
32 +  
33 +  AtomStamp* currAtom;
34 +  DirectionalAtom* dAtom;
35 +  
36 +  for(i=0; i<nAtoms; i++){
37 +    
38 +    currAtom = myStamp->getAtom( i );
39 +    j = atomIndex+i;
40 +
41 +    if( currAtom->haveOrientation()){
42 +      
43 +      dAtom = new DirectionalAtom( j );
44 +      atomArray[j] = dAtom;
45 +      
46 +      ux = currAtom->getOrntX();
47 +      uy = currAtom->getOrntY();
48 +      uz = currAtom->getOrntZ();
49 +      
50 +      uSqr = (ux * ux) + (uy * uy) + (uz * uz);
51 +      
52 +      u = sqrt( uSqr );
53 +      ux = ux / u;
54 +      uy = uy / u;
55 +      uz = uz / u;
56 +      
57 +      dAtom->setSUx( ux );
58 +      dAtom->setSUy( uy );
59 +      dAtom->setSUz( uz );
60 +      
61 +      dAtom->setA( A );
62 +      
63 +      dAtom->setJx( 0.0 );
64 +      dAtom->setJy( 0.0 );
65 +      dAtom->setJz( 0.0 );
66 +      
67 +    }
68 +    else{
69 +      atomArray[j] = new GeneralAtom( j );
70 +    }
71 +    
72 +    atomArray[j]->setType( currAtom->getType() );
73 +    
74 +    for(k=0; k<3; k++) r[k] = myCoords[(i*3)+k];
75 +
76 +    rotMe( r, A );
77 +
78 +    for(k=0; k<3; k++) r[k] += pos[k];
79 +
80 +    atomArray[j]->setX( r[0] );
81 +    atomArray[j]->setY( r[1] );
82 +    atomArray[j]->setZ( r[2] );
83 +
84 +    atomArray[j]->set_vx( 0.0 );
85 +    atomArray[j]->set_vy( 0.0 );
86 +    atomArray[j]->set_vz( 0.0 );
87 +  }
88 + }
89 +
90 + void MoLocator::calcRefCoords( void ){
91 +
92 +  int i,j,k;
93 +  AtomStamp* currAtom;
94 +  double centerX, centerY, centerZ;
95 +  double smallX, smallY, smallZ;
96 +  double bigX, bigY, bigZ;
97 +  double dx, dy, dz;
98 +  double dsqr;
99 +
100 +  
101 +  centerX = 0.0;
102 +  centerY = 0.0;
103 +  centerZ = 0.0;
104 +  for(i=0; i<nAtoms; i++){
105 +    
106 +    currAtom = myStamp->getAtom(i);
107 +    if( !currAtom->havePosition() ){
108 +      sprintf( painCave.errMsg,
109 +               "MoLocator error.\n"
110 +               "  Component %s, atom %s does not have a position specified.\n"
111 +               "  This means MoLocator cannot initalize it's position.\n",
112 +               myStamp->getID(),
113 +               currAtom->getType() );
114 +      painCave.isFatal = 1;
115 +      simError();
116 +    }
117 +
118 +    
119 +    centerX += currAtom->getPosX();
120 +    centerY += currAtom->getPosY();
121 +    centerZ += currAtom->getPosZ();
122 +  }
123 +
124 +  centerX /= nAtoms;
125 +  centerY /= nAtoms;
126 +  centerZ /= nAtoms;
127 +  
128 +  myCoords = new double[nAtoms*3];
129 +
130 +  j = 0;
131 +  for(i=0; i<nAtoms; i++){
132 +    
133 +    currAtom = myStamp->getAtom(i);
134 +    j = i*3;
135 +    
136 +    myCoords[j]   = currAtom->getPosX() - centerX;
137 +    myCoords[j+1] = currAtom->getPosY() - centerY;
138 +    myCoords[j+2] = currAtom->getPosZ() - centerZ;
139 +  }
140 +  
141 +  smallX = myCoords[0];
142 +  smallY = myCoords[1];
143 +  smallZ = myCoords[2];
144 +
145 +  bigX = myCoords[0];
146 +  bigY = myCoords[1];
147 +  bigZ = myCoords[2];
148 +
149 +  j=0;
150 +  for(i=1; i<nAtoms; i++){
151 +    j= i*3;
152 +    
153 +    if( myCoords[j]   < smallX ) smallX = myCoords[j];
154 +    if( myCoords[j+1] < smallY ) smallY = myCoords[j+1];
155 +    if( myCoords[j+2] < smallZ ) smallZ = myCoords[j+2];
156 +
157 +    if( myCoords[j]   > bigX ) bigX = myCoords[j];
158 +    if( myCoords[j+1] > bigY ) bigY = myCoords[j+1];
159 +    if( myCoords[j+2] > bigZ ) bigZ = myCoords[j+2];
160 +  }
161 +
162 +
163 +  dx = bigX - smallX;
164 +  dy = bigY - smallY;
165 +  dz = bigZ - smallZ;
166 +
167 +  dsqr = (dx * dx) + (dy * dy) + (dz * dz);
168 +  maxLength = sqrt( dsqr );
169 + }
170 +
171 + void MoLocator::rotMe( double r[3], double A[3][3] ){
172 +
173 +  double rt[3];
174 +  int i,j;
175 +
176 +  for(i=0; i<3; i++) rt[i] = r[i];
177 +
178 +  for(i=0; i<3; i++){
179 +    r[i] = 0.0;
180 +    for(j=0; j<3; j++){
181 +      r[i] += A[i][j] * rt[j];
182 +    }
183 +  }
184 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines