| 1 | 
chuckv | 
678 | 
#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 | 
chuckv | 
700 | 
                          int atomIndex, SimState* myConfig ){ | 
| 28 | 
chuckv | 
678 | 
 | 
| 29 | 
  | 
  | 
  int i,j,k; | 
| 30 | 
  | 
  | 
  double r[3]; | 
| 31 | 
  | 
  | 
  double ux, uy, uz, u, uSqr; | 
| 32 | 
  | 
  | 
   | 
| 33 | 
  | 
  | 
  AtomStamp* currAtom; | 
| 34 | 
  | 
  | 
  DirectionalAtom* dAtom; | 
| 35 | 
chuckv | 
700 | 
  double vel[3]; | 
| 36 | 
  | 
  | 
  for(i=0;i<3;i++)vel[i]=0.0; | 
| 37 | 
chuckv | 
678 | 
 | 
| 38 | 
  | 
  | 
  for(i=0; i<nAtoms; i++){ | 
| 39 | 
  | 
  | 
     | 
| 40 | 
  | 
  | 
    currAtom = myStamp->getAtom( i ); | 
| 41 | 
  | 
  | 
    j = atomIndex+i; | 
| 42 | 
  | 
  | 
 | 
| 43 | 
  | 
  | 
    if( currAtom->haveOrientation()){ | 
| 44 | 
  | 
  | 
       | 
| 45 | 
  | 
  | 
      dAtom = new DirectionalAtom( j, myConfig); | 
| 46 | 
  | 
  | 
      atomArray[j] = dAtom; | 
| 47 | 
chuckv | 
700 | 
      atomArray[j]->setCoords(); | 
| 48 | 
chuckv | 
678 | 
           | 
| 49 | 
  | 
  | 
      ux = currAtom->getOrntX(); | 
| 50 | 
  | 
  | 
      uy = currAtom->getOrntY(); | 
| 51 | 
  | 
  | 
      uz = currAtom->getOrntZ(); | 
| 52 | 
  | 
  | 
       | 
| 53 | 
  | 
  | 
      uSqr = (ux * ux) + (uy * uy) + (uz * uz); | 
| 54 | 
  | 
  | 
       | 
| 55 | 
  | 
  | 
      u = sqrt( uSqr ); | 
| 56 | 
  | 
  | 
      ux = ux / u; | 
| 57 | 
  | 
  | 
      uy = uy / u; | 
| 58 | 
  | 
  | 
      uz = uz / u; | 
| 59 | 
  | 
  | 
       | 
| 60 | 
  | 
  | 
      dAtom->setSUx( ux ); | 
| 61 | 
  | 
  | 
      dAtom->setSUy( uy ); | 
| 62 | 
  | 
  | 
      dAtom->setSUz( uz ); | 
| 63 | 
  | 
  | 
       | 
| 64 | 
  | 
  | 
      dAtom->setA( A ); | 
| 65 | 
  | 
  | 
       | 
| 66 | 
  | 
  | 
      dAtom->setJx( 0.0 ); | 
| 67 | 
  | 
  | 
      dAtom->setJy( 0.0 ); | 
| 68 | 
  | 
  | 
      dAtom->setJz( 0.0 ); | 
| 69 | 
  | 
  | 
       | 
| 70 | 
  | 
  | 
    } | 
| 71 | 
  | 
  | 
    else{ | 
| 72 | 
  | 
  | 
      atomArray[j] = new GeneralAtom( j, myConfig); | 
| 73 | 
chuckv | 
700 | 
      atomArray[j]->setCoords(); | 
| 74 | 
chuckv | 
678 | 
    } | 
| 75 | 
  | 
  | 
     | 
| 76 | 
  | 
  | 
    atomArray[j]->setType( currAtom->getType() ); | 
| 77 | 
  | 
  | 
     | 
| 78 | 
  | 
  | 
    for(k=0; k<3; k++) r[k] = myCoords[(i*3)+k]; | 
| 79 | 
  | 
  | 
 | 
| 80 | 
  | 
  | 
    rotMe( r, A ); | 
| 81 | 
  | 
  | 
 | 
| 82 | 
  | 
  | 
    for(k=0; k<3; k++) r[k] += pos[k]; | 
| 83 | 
  | 
  | 
 | 
| 84 | 
chuckv | 
700 | 
    atomArray[j]->setPos( r ); | 
| 85 | 
  | 
  | 
         | 
| 86 | 
  | 
  | 
    atomArray[j]->setVel( vel );; | 
| 87 | 
chuckv | 
678 | 
  } | 
| 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 | 
  | 
  | 
 | 
| 105 | 
  | 
  | 
  for(i=0; i<nAtoms; i++){ | 
| 106 | 
  | 
  | 
     | 
| 107 | 
  | 
  | 
    currAtom = myStamp->getAtom(i); | 
| 108 | 
  | 
  | 
    if( !currAtom->havePosition() ){ | 
| 109 | 
  | 
  | 
      sprintf( painCave.errMsg, | 
| 110 | 
  | 
  | 
               "MoLocator error.\n" | 
| 111 | 
  | 
  | 
               "  Component %s, atom %s does not have a position specified.\n" | 
| 112 | 
  | 
  | 
               "  This means MoLocator cannot initalize it's position.\n", | 
| 113 | 
  | 
  | 
               myStamp->getID(), | 
| 114 | 
  | 
  | 
               currAtom->getType() ); | 
| 115 | 
  | 
  | 
      painCave.isFatal = 1; | 
| 116 | 
  | 
  | 
      simError(); | 
| 117 | 
  | 
  | 
    } | 
| 118 | 
  | 
  | 
 | 
| 119 | 
  | 
  | 
     | 
| 120 | 
  | 
  | 
    centerX += currAtom->getPosX(); | 
| 121 | 
  | 
  | 
    centerY += currAtom->getPosY(); | 
| 122 | 
  | 
  | 
    centerZ += currAtom->getPosZ(); | 
| 123 | 
  | 
  | 
  } | 
| 124 | 
  | 
  | 
 | 
| 125 | 
  | 
  | 
  centerX /= nAtoms; | 
| 126 | 
  | 
  | 
  centerY /= nAtoms; | 
| 127 | 
  | 
  | 
  centerZ /= nAtoms; | 
| 128 | 
  | 
  | 
   | 
| 129 | 
  | 
  | 
  myCoords = new double[nAtoms*3]; | 
| 130 | 
  | 
  | 
 | 
| 131 | 
  | 
  | 
  j = 0; | 
| 132 | 
  | 
  | 
  for(i=0; i<nAtoms; i++){ | 
| 133 | 
  | 
  | 
     | 
| 134 | 
  | 
  | 
    currAtom = myStamp->getAtom(i); | 
| 135 | 
  | 
  | 
    j = i*3; | 
| 136 | 
  | 
  | 
     | 
| 137 | 
  | 
  | 
    myCoords[j]   = currAtom->getPosX() - centerX; | 
| 138 | 
  | 
  | 
    myCoords[j+1] = currAtom->getPosY() - centerY; | 
| 139 | 
  | 
  | 
    myCoords[j+2] = currAtom->getPosZ() - centerZ; | 
| 140 | 
  | 
  | 
  } | 
| 141 | 
  | 
  | 
   | 
| 142 | 
  | 
  | 
  smallX = myCoords[0]; | 
| 143 | 
  | 
  | 
  smallY = myCoords[1]; | 
| 144 | 
  | 
  | 
  smallZ = myCoords[2]; | 
| 145 | 
  | 
  | 
 | 
| 146 | 
  | 
  | 
  bigX = myCoords[0]; | 
| 147 | 
  | 
  | 
  bigY = myCoords[1]; | 
| 148 | 
  | 
  | 
  bigZ = myCoords[2]; | 
| 149 | 
  | 
  | 
 | 
| 150 | 
  | 
  | 
  j=0; | 
| 151 | 
  | 
  | 
  for(i=1; i<nAtoms; i++){ | 
| 152 | 
  | 
  | 
    j= i*3; | 
| 153 | 
  | 
  | 
     | 
| 154 | 
  | 
  | 
    if( myCoords[j]   < smallX ) smallX = myCoords[j]; | 
| 155 | 
  | 
  | 
    if( myCoords[j+1] < smallY ) smallY = myCoords[j+1]; | 
| 156 | 
  | 
  | 
    if( myCoords[j+2] < smallZ ) smallZ = myCoords[j+2]; | 
| 157 | 
  | 
  | 
 | 
| 158 | 
  | 
  | 
    if( myCoords[j]   > bigX ) bigX = myCoords[j]; | 
| 159 | 
  | 
  | 
    if( myCoords[j+1] > bigY ) bigY = myCoords[j+1]; | 
| 160 | 
  | 
  | 
    if( myCoords[j+2] > bigZ ) bigZ = myCoords[j+2]; | 
| 161 | 
  | 
  | 
  } | 
| 162 | 
  | 
  | 
 | 
| 163 | 
  | 
  | 
 | 
| 164 | 
  | 
  | 
  dx = bigX - smallX; | 
| 165 | 
  | 
  | 
  dy = bigY - smallY; | 
| 166 | 
  | 
  | 
  dz = bigZ - smallZ; | 
| 167 | 
  | 
  | 
 | 
| 168 | 
  | 
  | 
  dsqr = (dx * dx) + (dy * dy) + (dz * dz); | 
| 169 | 
  | 
  | 
  maxLength = sqrt( dsqr ); | 
| 170 | 
  | 
  | 
} | 
| 171 | 
  | 
  | 
 | 
| 172 | 
  | 
  | 
void MoLocator::rotMe( double r[3], double A[3][3] ){ | 
| 173 | 
  | 
  | 
 | 
| 174 | 
  | 
  | 
  double rt[3]; | 
| 175 | 
  | 
  | 
  int i,j; | 
| 176 | 
  | 
  | 
 | 
| 177 | 
  | 
  | 
  for(i=0; i<3; i++) rt[i] = r[i]; | 
| 178 | 
  | 
  | 
 | 
| 179 | 
  | 
  | 
  for(i=0; i<3; i++){ | 
| 180 | 
  | 
  | 
    r[i] = 0.0; | 
| 181 | 
  | 
  | 
    for(j=0; j<3; j++){ | 
| 182 | 
  | 
  | 
      r[i] += A[i][j] * rt[j]; | 
| 183 | 
  | 
  | 
    } | 
| 184 | 
  | 
  | 
  } | 
| 185 | 
  | 
  | 
} |