--- trunk/OOPSE/libmdtools/SimInfo.cpp 2003/06/30 22:04:01 568 +++ trunk/OOPSE/libmdtools/SimInfo.cpp 2003/07/01 21:33:45 569 @@ -54,7 +54,7 @@ void SimInfo::setBox(double newBox[3]) { calcHmatI(); calcBoxL(); - setFortranBoxSize(Hmat); + setFortranBoxSize(Hmat, HmatI, &orthoRhombic); smallestBoxL = boxLx; if (boxLy < smallestBoxL) smallestBoxL = boxLy; @@ -110,7 +110,7 @@ void SimInfo::setBoxM( double theBox[9] ){ calcHmatI(); calcBoxL(); - setFortranBoxSize(Hmat); + setFortranBoxSize(Hmat, HmatI, &orthoRhombic); smallestBoxL = boxLx; if (boxLy < smallestBoxL) smallestBoxL = boxLy; @@ -170,6 +170,9 @@ void SimInfo::calcHmatI( void ) { double C[3][3]; double detHmat; int i, j, k; + double smallDiag; + double tol; + double sanity[3][3]; // calculate the adjunct of Hmat; @@ -199,8 +202,43 @@ void SimInfo::calcHmatI( void ) { HmatI[i] = C[j][k] / detHmat; i++; + } + } + + // sanity check + + for(i=0; i<3; i++){ + for(j=0; j<3; j++){ + + sanity[i][j] = 0.0; + for(k=0; k<3; k++){ + sanity[i][j] += Hmat[3*k+i] * HmatI[3*j+k]; + } + } + } + + cerr << "sanity => \n" + << sanity[0][0] << "\t" << sanity[0][1] << "\t" << sanity [0][2] << "\n" + << sanity[1][0] << "\t" << sanity[1][1] << "\t" << sanity [1][2] << "\n" + << sanity[2][0] << "\t" << sanity[2][1] << "\t" << sanity [2][2] + << "\n"; + + + // check to see if Hmat is orthorhombic + + smallDiag = Hmat[0]; + if(smallDiag > Hmat[4]) smallDiag = Hmat[4]; + if(smallDiag > Hmat[8]) smallDiag = Hmat[8]; + tol = smallDiag * 1E-6; + + orthoRhombic = 1; + for(i=0; (i<9) && orthoRhombic; i++){ + + if( (i%4) ){ // ignore the diagonals (0, 4, and 8) + orthoRhombic = (Hmat[i] <= tol); } } + } void SimInfo::calcBoxL( void ){ @@ -241,17 +279,42 @@ void SimInfo::wrapVector( double thePos[3] ){ int i, j, k; double scaled[3]; - // calc the scaled coordinates. - - for(i=0; i<3; i++) - scaled[i] = thePos[0]*Hmat[i] + thePos[1]*Hat[i+3] + thePos[3]*Hmat[i+6]; - - // wrap the scaled coordinates - - for(i=0; i<3; i++) - scaled[i] -= (copysign(1,scaled[i]) * (int)(fabs(scaled[i]) + 0.5)); - - + if( !orthoRhombic ){ + // calc the scaled coordinates. + + for(i=0; i<3; i++) + scaled[i] = + thePos[0]*HmatI[i] + thePos[1]*HmatI[i+3] + thePos[3]*HmatI[i+6]; + + // wrap the scaled coordinates + + for(i=0; i<3; i++) + scaled[i] -= round(scaled[i]); + + // calc the wrapped real coordinates from the wrapped scaled coordinates + + for(i=0; i<3; i++) + thePos[i] = + scaled[0]*Hmat[i] + scaled[1]*Hmat[i+3] + scaled[3]*Hmat[i+6]; + } + else{ + // calc the scaled coordinates. + + for(i=0; i<3; i++) + scaled[i] = thePos[i]*HmatI[i*4]; + + // wrap the scaled coordinates + + for(i=0; i<3; i++) + scaled[i] -= round(scaled[i]); + + // calc the wrapped real coordinates from the wrapped scaled coordinates + + for(i=0; i<3; i++) + thePos[i] = scaled[i]*Hmat[i*4]; + } + + }