UNPKG

molstar

Version:

A comprehensive macromolecular library.

124 lines 5.03 kB
"use strict"; /** * Copyright (c) 2019-2021 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> * @author David Sehnal <david.sehnal@gmail.com> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Coordinates = exports.Time = void 0; var mol_util_1 = require("../../../mol-util"); var db_1 = require("../../../mol-data/db"); function Time(value, unit) { return { value: value, unit: unit }; } exports.Time = Time; var Coordinates; (function (Coordinates) { function create(frames, deltaTime, timeOffset) { var hasCell = !!frames[0].cell; var hasVelocities = !!frames[0].velocities; var hasForces = !!frames[0].forces; return { id: mol_util_1.UUID.create22(), frames: frames, hasCell: hasCell, hasVelocities: hasVelocities, hasForces: hasForces, deltaTime: deltaTime, timeOffset: timeOffset, }; } Coordinates.create = create; /** * Only use ordering if it's not identity. */ function getAtomicConformation(frame, atomId, ordering) { var x = frame.x, y = frame.y, z = frame.z; if (frame.xyzOrdering.frozen) { if (ordering) { if (frame.xyzOrdering.isIdentity) { // simple list reordering x = getOrderedCoords(x, ordering); y = getOrderedCoords(y, ordering); z = getOrderedCoords(z, ordering); } else if (!(0, mol_util_1.arrayEqual)(frame.xyzOrdering.index, ordering)) { x = getSourceOrderedCoords(x, frame.xyzOrdering.index, ordering); y = getSourceOrderedCoords(y, frame.xyzOrdering.index, ordering); z = getSourceOrderedCoords(z, frame.xyzOrdering.index, ordering); } } else if (!frame.xyzOrdering.isIdentity) { x = getInvertedCoords(x, frame.xyzOrdering.index); y = getInvertedCoords(y, frame.xyzOrdering.index); z = getInvertedCoords(z, frame.xyzOrdering.index); } } else if (ordering) { if (frame.xyzOrdering.isIdentity) { frame.xyzOrdering.isIdentity = false; frame.xyzOrdering.index = ordering; reorderCoordsInPlace(x, ordering); reorderCoordsInPlace(y, ordering); reorderCoordsInPlace(z, ordering); } else { // is current ordering is not the same as requested? // => copy the conformations into a new array if (!(0, mol_util_1.arrayEqual)(frame.xyzOrdering.index, ordering)) { x = getSourceOrderedCoords(x, frame.xyzOrdering.index, ordering); y = getSourceOrderedCoords(y, frame.xyzOrdering.index, ordering); z = getSourceOrderedCoords(z, frame.xyzOrdering.index, ordering); } } } // once the conformation has been accessed at least once, freeze it. // => any other request to the frame with different ordering will result in a copy. frame.xyzOrdering.frozen = true; return { id: mol_util_1.UUID.create22(), atomId: atomId, occupancy: db_1.Column.ofConst(1, frame.elementCount, db_1.Column.Schema.int), B_iso_or_equiv: db_1.Column.ofConst(0, frame.elementCount, db_1.Column.Schema.float), xyzDefined: true, x: x, y: y, z: z, }; } Coordinates.getAtomicConformation = getAtomicConformation; var _reorderBuffer = [0.123]; function reorderCoordsInPlace(xs, index) { var buffer = _reorderBuffer; for (var i = 0, _i = xs.length; i < _i; i++) { buffer[i] = xs[index[i]]; } for (var i = 0, _i = xs.length; i < _i; i++) { xs[i] = buffer[i]; } } function getSourceOrderedCoords(xs, srcIndex, index) { var ret = new Float32Array(xs.length); for (var i = 0, _i = xs.length; i < _i; i++) { ret[i] = xs[srcIndex[index[i]]]; } return ret; } function getOrderedCoords(xs, index) { var ret = new Float32Array(xs.length); for (var i = 0, _i = xs.length; i < _i; i++) { ret[i] = xs[index[i]]; } return ret; } function getInvertedCoords(xs, index) { var ret = new Float32Array(xs.length); for (var i = 0, _i = xs.length; i < _i; i++) { ret[index[i]] = xs[i]; } return ret; } })(Coordinates || (Coordinates = {})); exports.Coordinates = Coordinates; //# sourceMappingURL=coordinates.js.map