trr.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * Copyright (c) 2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { Task } from '../../mol-task';
  7. import { TrrFile } from '../../mol-io/reader/trr/parser';
  8. import { Coordinates, Frame, Time } from '../../mol-model/structure/coordinates';
  9. import { Cell } from '../../mol-math/geometry/spacegroup/cell';
  10. import { Vec3 } from '../../mol-math/linear-algebra';
  11. export function coordinatesFromTrr(file: TrrFile): Task<Coordinates> {
  12. return Task.create('Parse TRR', async ctx => {
  13. await ctx.update('Converting to coordinates');
  14. const deltaTime = Time(file.deltaTime, 'step');
  15. const offsetTime = Time(file.timeOffset, deltaTime.unit);
  16. const frames: Frame[] = [];
  17. for (let i = 0, il = file.frames.length; i < il; ++i) {
  18. const box = file.boxes[i];
  19. const x = Vec3.fromArray(Vec3(), box, 0);
  20. const y = Vec3.fromArray(Vec3(), box, 3);
  21. const z = Vec3.fromArray(Vec3(), box, 6);
  22. frames.push({
  23. elementCount: file.frames[i].count,
  24. cell: Cell.fromBasis(x, y, z),
  25. x: file.frames[i].x,
  26. y: file.frames[i].y,
  27. z: file.frames[i].z,
  28. xyzOrdering: { isIdentity: true },
  29. time: Time(offsetTime.value + deltaTime.value * i, deltaTime.unit)
  30. });
  31. }
  32. return Coordinates.create(frames, deltaTime, offsetTime);
  33. });
  34. }