Hey all,<br><br>So after many /head-desk and /head-wall moments these past two weeks I discovered something unusual.  In the PDB format, it ASSUMES (we all know what happens when you assume things) the A-axis is co-linear with the X-axis and the B-axis is in the XY-plane.  CP2K does not make this conversion before printing out Cell Vectors and Coordinates to PDB Format.  Made this discovery trying to figure out why CUBE files visualize correctly but PDB files didn't in VMD.  VMD does not make that assumption when importing CUBE files and performs the Transformation while importing.  Makes visualizing things in VMD interesting to say the least.  So is this a bug with the code or an oversight?  <br><br>Dug through the VMD CUBE Plugin source code and found the relevant code.  The following is in C, but I'm sure someone can convert it to Fortran and implement it into CP2K:<br><br>Finding the Transformation Matrix:<br>// calculate and store origin and rotation matrix to realign everything later.<br>static void cube_buildrotmat(cube_t *cube, float *o, float *a, float *b)<br>{<br>  // we rotate first around y and z to align a along the x-axis...<br>  const double len   = sqrt(a[0]*a[0] + a[1]*a[1]);<br>  const double phi   = atan2((double) a[2], (double) len);<br>  const double theta = atan2((double) a[1], (double) a[0]);<br><br>  const double cph = cos(phi);<br>  const double cth = cos(theta);<br>  const double sph = sin(phi);<br>  const double sth = sin(theta);<br><br>  // ...then we rotate around x to put b into the xy-plane.<br>  const double psi = atan2(-sph*cth*b[0] - sph*sth*b[1] + cph*b[2],-sth*b[0] + cth*b[1]);<br>  const double cps = cos(psi);<br>  const double sps = sin(psi);<br><br>  const double r[3][3] = {<br>    {               cph*cth,                    cph*sth,      sph},<br>    {-sth*cps - sph*cth*sps,      cth*cps - sph*sth*sps,  cph*sps},<br>    { sth*sps - sph*cth*cps,     -cth*sps - sph*sth*cps,  cph*cps}<br>  };<br><br>  for (int i=0; i<3; ++i) {<br>    cube->origin[i] = o[i];<br>    for (int j=0; j<3; ++j) {<br>      cube->rotmat[i][j] = r[i][j];<br>    }<br>  }<br>}<br><br>Rotating Vectors:<br> // store aligned axes.<br>  for (i=0; i<3; ++i) {<br>    voltmpl.xaxis[i] = cube->rotmat[i][0] * a[0]<br>      + cube->rotmat[i][1] * a[1] + cube->rotmat[i][2] * a[2];<br><br>    voltmpl.yaxis[i] = cube->rotmat[i][0] * b[0]<br>      + cube->rotmat[i][1] * b[1] + cube->rotmat[i][2] * b[2];<br><br>    voltmpl.zaxis[i] = cube->rotmat[i][0] * c[0]<br>      + cube->rotmat[i][1] * c[1] + cube->rotmat[i][2] * c[2];<br>  }<br><br>Rotating Coordinates is just [transformation matrix] * [coordinate]<br>