Skip to content

Commit

Permalink
Fix conversion of hoomd box to vmd (#9)
Browse files Browse the repository at this point in the history
* Fix conversion of hoomd box to vmd

I think the vmd lattice constants (if A, B, and C are indeed lattice constants) should also involve the tilt factors, consistent with HOOMD's definition: https://hoomd-blue.readthedocs.io/en/stable/box.html. (I noticed in some shear simulations that the box looked too small in the gradient direction!)

* Fixed norm of lattice vectors

Realized I did not perform the proper calculation before...

* Ensure orthorhombic boxes read exactly from GSD
  • Loading branch information
ksil authored Sep 27, 2021
1 parent 4448cd2 commit 620d570
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions gsdplugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -841,16 +841,20 @@ static int read_gsd_timestep(void *mydata, int natoms, molfile_timestep_t *ts)
}
else
{
ts->A = box[0]; ts->B = box[1]; ts->C = box[2];
if (box[3] != 0.0f || box[4] != 0.0f || box[5] != 0.0f)
{
// need to resolve the tilt factors into angles
// define lattice constants in terms of box size and tilt factors
const double xy = (double)box[3];
const double xz = (double)box[4];
const double yz = (double)box[5];
const double norm1 = sqrt(1.0 + xy*xy);
const double norm2 = sqrt(1.0 + xz*xz + yz*yz);

ts->A = box[0];
ts->B = (float)(norm1*box[1]);
ts->C = (float)(norm2*box[2]);

// need to resolve the tilt factors into angles
const double cos_gamma= xy / norm1;
const double cos_beta = xz / norm2;
const double cos_alpha = (xy*xz + yz)/(norm1 * norm2);
Expand All @@ -861,6 +865,7 @@ static int read_gsd_timestep(void *mydata, int natoms, molfile_timestep_t *ts)
}
else // orthorhombic
{
ts->A = box[0]; ts->B = box[1]; ts->C = box[2];
ts->alpha = 90.0f; ts->beta = 90.0f; ts->gamma = 90.0f;
}
}
Expand Down

0 comments on commit 620d570

Please sign in to comment.