Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Timestep.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2008 The Board of Trustees of the           
00004  *cr                        University of Illinois                       
00005  *cr                         All Rights Reserved                        
00006  *cr                                                                   
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: Timestep.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.56 $       $Date: 2008/04/24 02:55:36 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *
00019  * The Timestep class, which stores coordinates, energies, etc. for a
00020  * single timestep.
00021  *
00022  * Note: As more data is stored for each step, it should go in here.  For
00023  * example, H-Bonds could be calculated each step.
00024  ***************************************************************************/
00025 
00026 #include <math.h>
00027 #include "Timestep.h"
00028 #include "Inform.h"
00029 #include "Atom.h"
00030 
00032 Timestep::Timestep(int n) {
00033   for(int i=0; i < TSENERGIES; energy[i++] = 0.0);
00034   num = n;
00035   pos = new float[3 * num];
00036   vel = NULL;
00037   force = NULL;
00038   user  = NULL;
00039   user2 = NULL;
00040   user3 = NULL;
00041   user4 = NULL;
00042   a_length = b_length = c_length = 1;
00043   alpha = beta = gamma = 90;
00044   timesteps=0;
00045   physical_time=0;
00046 }
00047 
00048 
00050 Timestep::Timestep(const Timestep& ts) {
00051   num = ts.num;
00052 
00053   pos = new float[3 * num];
00054   memcpy(pos, ts.pos, 3 * num * sizeof(float));
00055 
00056   if (ts.force) {
00057     force = new float[3 * num];
00058     memcpy(force, ts.force, 3 * num * sizeof(float));
00059   } else {
00060     force = NULL;
00061   }
00062 
00063   if (ts.vel) {
00064     vel = new float[3 * num];
00065     memcpy(vel, ts.vel, 3 * num * sizeof(float));
00066   } else {
00067     vel = NULL;
00068   }
00069 
00070   if (ts.user) {
00071     user = new float[num];
00072     memcpy(user, ts.user, num*sizeof(float));
00073   } else {
00074     user = NULL;
00075   }
00076 
00077   if (ts.user2) {
00078     user2 = new float[num];
00079     memcpy(user2, ts.user2, num*sizeof(float));
00080   } else {
00081     user2 = NULL;
00082   }
00083 
00084   if (ts.user3) {
00085     user3 = new float[num];
00086     memcpy(user3, ts.user3, num*sizeof(float));
00087   } else {
00088     user3 = NULL;
00089   }
00090 
00091   if (ts.user4) {
00092     user4 = new float[num];
00093     memcpy(user4, ts.user4, num*sizeof(float));
00094   } else {
00095     user4 = NULL;
00096   }
00097 
00098   memcpy(energy, ts.energy, sizeof(ts.energy));
00099   a_length = ts.a_length;
00100   b_length = ts.b_length;
00101   c_length = ts.c_length;
00102   alpha = ts.alpha;
00103   beta = ts.beta;
00104   gamma = ts.gamma;
00105   timesteps=ts.timesteps;
00106   physical_time=ts.physical_time;
00107 }
00108 
00109 
00111 Timestep::~Timestep() {
00112   delete [] force;
00113   delete [] vel;
00114   delete [] pos;
00115   delete [] user;
00116   delete [] user2;
00117   delete [] user3;
00118   delete [] user4;
00119 }
00120 
00121 // reset coords and related items to 0
00122 void Timestep::zero_values() {
00123   if (num <= 0) 
00124     return;
00125     
00126   memset(pos,0,3*num*sizeof(float));
00127    
00128   for(int i=0; i < TSENERGIES; energy[i++] = 0.0);
00129   timesteps=0;
00130 }
00131 
00132 void Timestep::get_transform_vectors(float A[3], float B[3], float C[3]) const
00133 {
00134   // notes: a, b, c are side lengths of the unit cell
00135   // alpha = angle between b and c
00136   //  beta = angle between a and c
00137   // gamma = angle between a and b
00138 
00139   // convert from degrees to radians
00140   double cosBC = cos(DEGTORAD(alpha));
00141   double cosAC = cos(DEGTORAD(beta));
00142   double cosAB = cos(DEGTORAD(gamma));
00143   double sinAB = sin(DEGTORAD(gamma));
00144 
00145   // A will lie along the positive x axis.
00146   // B will lie in the x-y plane
00147   // The origin will be (0,0,0).
00148   float Ax = (float) (a_length);
00149   float Bx = (float) (b_length * cosAB);
00150   float By = (float) (b_length * sinAB);
00151 
00152   float Cx=0, Cy=0, Cz=0;
00153   // If sinAB is zero, then we can't determine C uniquely since it's defined
00154   // in terms of the angle between A and B.
00155   if (sinAB > 0) {
00156     Cx = (float) cosAC;
00157     Cy = (float) ((cosBC - cosAC * cosAB) / sinAB);
00158     Cz = sqrtf(1.0f - Cx*Cx - Cy*Cy);
00159   }
00160   Cx *= c_length;
00161   Cy *= c_length;
00162   Cz *= c_length;
00163   vec_zero(A); A[0] = Ax;
00164   vec_zero(B); B[0] = Bx; B[1] = By;
00165   vec_zero(C); C[0] = Cx; C[1] = Cy; C[2] = Cz;
00166 }
00167 
00168 void Timestep::get_transforms(Matrix4 &a, Matrix4 &b, Matrix4 &c) const {
00169   float A[3], B[3], C[3];
00170   get_transform_vectors(A, B, C);
00171   a.translate(A);
00172   b.translate(B);
00173   c.translate(C);
00174 }
00175 
00176 void Timestep::get_transform_from_cell(const int *cell, Matrix4 &mat) const {
00177   float A[3], B[3], C[3];
00178   get_transform_vectors(A, B, C);
00179   float Ax=A[0];
00180   float Bx=B[0];
00181   float By=B[1];
00182   float Cx=C[0];
00183   float Cy=C[1];
00184   float Cz=C[2];
00185   mat.identity();
00186   mat.mat[12] = cell[0]*Ax + cell[1]*Bx + cell[2]*Cx;
00187   mat.mat[13] =              cell[1]*By + cell[2]*Cy;            
00188   mat.mat[14] =                           cell[2]*Cz;
00189 }
00190 

Generated on Sat Aug 30 01:27:07 2008 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002