dcdread.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //////////////////////////////////////////////////////////////////////////////////////////
  2. // Author: Manish Agarwal and Gourav Shrivastava , IIT Delhi
  3. //////////////////////////////////////////////////////////////////////////////////////////
  4. // Copyright (c) 2021 NVIDIA Corporation. All rights reserved.
  5. using namespace std;
  6. void dcdreadhead(int *natom, int *nframes, std::istream &infile)
  7. {
  8. infile.seekg(8, ios::beg);
  9. infile.read((char *)nframes, sizeof(int));
  10. infile.seekg(64 * 4, ios::cur);
  11. infile.read((char *)natom, sizeof(int));
  12. infile.seekg(1 * 8, ios::cur);
  13. return;
  14. }
  15. void dcdreadframe(double *x, double *y, double *z, std::istream &infile,
  16. int natom, double &xbox, double &ybox, double &zbox)
  17. {
  18. double d[6];
  19. for (int i = 0; i < 6; i++)
  20. {
  21. infile.read((char *)&d[i], sizeof(double));
  22. }
  23. xbox = d[0];
  24. ybox = d[2];
  25. zbox = d[5];
  26. float a, b, c;
  27. infile.seekg(1 * 8, ios::cur);
  28. for (int i = 0; i < natom; i++)
  29. {
  30. infile.read((char *)&a, sizeof(float));
  31. x[i] = a;
  32. }
  33. infile.seekg(1 * 8, ios::cur);
  34. for (int i = 0; i < natom; i++)
  35. {
  36. infile.read((char *)&b, sizeof(float));
  37. y[i] = b;
  38. }
  39. infile.seekg(1 * 8, ios::cur);
  40. for (int i = 0; i < natom; i++)
  41. {
  42. infile.read((char *)&c, sizeof(float));
  43. z[i] = c;
  44. }
  45. infile.seekg(1 * 8, ios::cur);
  46. return;
  47. }