UNPKG

molstar

Version:

A comprehensive macromolecular library.

67 lines 3.16 kB
"use strict"; /** * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> * @author Alexander Rose <alexander.rose@weirdbyte.de> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Grid = void 0; var geometry_1 = require("../../mol-math/geometry"); var linear_algebra_1 = require("../../mol-math/linear-algebra"); var histogram_1 = require("../../mol-math/histogram"); var Grid; (function (Grid) { Grid.One = { transform: { kind: 'matrix', matrix: linear_algebra_1.Mat4.identity() }, cells: linear_algebra_1.Tensor.create(linear_algebra_1.Tensor.Space([1, 1, 1], [0, 1, 2]), linear_algebra_1.Tensor.Data1([0])), stats: { min: 0, max: 0, mean: 0, sigma: 0 }, }; var _scale = linear_algebra_1.Mat4.zero(), _translate = linear_algebra_1.Mat4.zero(); function getGridToCartesianTransform(grid) { if (grid.transform.kind === 'matrix') { return linear_algebra_1.Mat4.copy((0, linear_algebra_1.Mat4)(), grid.transform.matrix); } if (grid.transform.kind === 'spacegroup') { var space = grid.cells.space; var scale = linear_algebra_1.Mat4.fromScaling(_scale, linear_algebra_1.Vec3.div(linear_algebra_1.Vec3.zero(), geometry_1.Box3D.size(linear_algebra_1.Vec3.zero(), grid.transform.fractionalBox), linear_algebra_1.Vec3.ofArray(space.dimensions))); var translate = linear_algebra_1.Mat4.fromTranslation(_translate, grid.transform.fractionalBox.min); return linear_algebra_1.Mat4.mul3(linear_algebra_1.Mat4.zero(), grid.transform.cell.fromFractional, translate, scale); } return linear_algebra_1.Mat4.identity(); } Grid.getGridToCartesianTransform = getGridToCartesianTransform; function areEquivalent(gridA, gridB) { return gridA === gridB; } Grid.areEquivalent = areEquivalent; function isEmpty(grid) { return grid.cells.data.length === 0; } Grid.isEmpty = isEmpty; function getBoundingSphere(grid, boundingSphere) { if (!boundingSphere) boundingSphere = (0, geometry_1.Sphere3D)(); var dimensions = grid.cells.space.dimensions; var transform = Grid.getGridToCartesianTransform(grid); return geometry_1.Sphere3D.fromDimensionsAndTransform(boundingSphere, dimensions, transform); } Grid.getBoundingSphere = getBoundingSphere; /** * Compute histogram with given bin count. * Cached on the Grid object. */ function getHistogram(grid, binCount) { var histograms = grid._historams; if (!histograms) { histograms = grid._historams = {}; } if (!histograms[binCount]) { histograms[binCount] = (0, histogram_1.calculateHistogram)(grid.cells.data, binCount, { min: grid.stats.min, max: grid.stats.max }); } return histograms[binCount]; } Grid.getHistogram = getHistogram; })(Grid || (Grid = {})); exports.Grid = Grid; //# sourceMappingURL=grid.js.map