gro.spec.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. * @author David Sehnal <david.sehnal@gmail.com>
  6. */
  7. import Gro from '../gro/index'
  8. const groString = `MD of 2 waters, t= 4.2
  9. 6
  10. 1WATER OW1 1 0.126 1.624 1.679 0.1227 -0.0580 0.0434
  11. 1WATER HW2 2 0.190 1.661 1.747 0.8085 0.3191 -0.7791
  12. 1WATER HW3 3 0.177 1.568 1.613 -0.9045 -2.6469 1.3180
  13. 2WATER OW1 4 1.275 0.053 0.622 0.2519 0.3140 -0.1734
  14. 2WATER HW2 5 1.337 0.002 0.680 -1.0641 -1.1349 0.0257
  15. 2WATER HW3 6 1.326 0.120 0.568 1.9427 -0.8216 -0.0244
  16. 1.82060 1.82060 1.82060`
  17. const groStringHighPrecision = `Generated by trjconv : 2168 system t= 15.00000
  18. 3
  19. 1ETH C1 1 2.735383 2.672010 1.450194 0.2345 -0.1622 0.2097
  20. 1ETH H11 2 0.015804 2.716597 1.460588 0.8528 -0.7984 0.6605
  21. 1ETH H12 3 2.744822 2.565544 1.409227 -2.3812 2.8618 1.8101
  22. 1.82060 1.82060 1.82060`
  23. describe('gro reader', () => {
  24. it('basic', () => {
  25. const parsed = Gro.parse(groString)
  26. if (parsed.isError) {
  27. console.log(parsed)
  28. } else {
  29. const groFile = parsed.result;
  30. const data = Gro.schema(groFile.blocks[0]);
  31. const { header, atoms } = data;
  32. if (header._isDefined) {
  33. expect(header.title.value(0)).toBe('MD of 2 waters')
  34. expect(header.timeInPs.value(0)).toBeCloseTo(4.2)
  35. expect(header.numberOfAtoms.value(0)).toBe(6)
  36. expect(header.boxX.value(0)).toBeCloseTo(1.82060)
  37. expect(header.boxY.value(0)).toBeCloseTo(1.82060)
  38. expect(header.boxZ.value(0)).toBeCloseTo(1.82060)
  39. } else {
  40. console.error('no header')
  41. }
  42. if (atoms._rowCount === 6) {
  43. expect(atoms.x.value(0)).toBeCloseTo(0.126);
  44. expect(atoms.y.value(0)).toBeCloseTo(1.624);
  45. expect(atoms.z.value(0)).toBeCloseTo(1.679);
  46. // TODO: check velocities when they are parsed.
  47. } else {
  48. console.error('no atoms');
  49. }
  50. }
  51. })
  52. it('high precision', () => {
  53. const parsed = Gro.parse(groStringHighPrecision)
  54. if (parsed.isError) {
  55. console.log(parsed)
  56. } else {
  57. const groFile = parsed.result;
  58. const data = Gro.schema(groFile.blocks[0]);
  59. const { header, atoms } = data;
  60. if (header._isDefined) {
  61. expect(header.title.value(0)).toBe('Generated by trjconv : 2168 system')
  62. expect(header.timeInPs.value(0)).toBeCloseTo(15)
  63. expect(header.numberOfAtoms.value(0)).toBe(3)
  64. expect(header.boxX.value(0)).toBeCloseTo(1.82060)
  65. expect(header.boxY.value(0)).toBeCloseTo(1.82060)
  66. expect(header.boxZ.value(0)).toBeCloseTo(1.82060)
  67. } else {
  68. console.error('no header')
  69. }
  70. if (atoms._rowCount === 3) {
  71. // TODO: test when high-prec parser is available
  72. // expect(atoms.x.value(1)).toBeCloseTo(0.015804, 0.00001);
  73. // expect(atoms.y.value(1)).toBeCloseTo(2.716597, 0.00001);
  74. // expect(atoms.z.value(1)).toBeCloseTo(1.460588, 0.00001);
  75. // TODO: check velocities when they are parsed.
  76. } else {
  77. console.error('no atoms');
  78. }
  79. }
  80. })
  81. });