molstar
Version:
A comprehensive macromolecular library.
75 lines • 3.58 kB
JavaScript
/**
* Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.CubeFormat = exports.volumeFromCube = void 0;
var tslib_1 = require("tslib");
var linear_algebra_1 = require("../../mol-math/linear-algebra");
var mol_task_1 = require("../../mol-task");
var array_1 = require("../../mol-util/array");
var custom_property_1 = require("../../mol-model/custom-property");
function volumeFromCube(source, params) {
var _this = this;
return mol_task_1.Task.create('Create Volume', function () { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
var header, sourceValues, space, values, _a, h, k, l, nth, o, s, u, v, w, data, matrix, basis;
return (0, tslib_1.__generator)(this, function (_b) {
header = source.header, sourceValues = source.values;
space = linear_algebra_1.Tensor.Space(header.dim, [0, 1, 2], Float64Array);
if (header.dataSetIds.length === 0) {
values = sourceValues;
}
else {
_a = header.dim, h = _a[0], k = _a[1], l = _a[2];
nth = ((params === null || params === void 0 ? void 0 : params.dataIndex) || 0) + 1;
o = 0, s = 0;
values = new Float64Array(h * k * l);
for (u = 0; u < h; u++) {
for (v = 0; v < k; v++) {
for (w = 0; w < l; w++) {
values[o++] = sourceValues[s];
s += nth;
}
}
}
}
data = linear_algebra_1.Tensor.create(space, linear_algebra_1.Tensor.Data1(values));
matrix = linear_algebra_1.Mat4.fromTranslation((0, linear_algebra_1.Mat4)(), header.origin);
basis = linear_algebra_1.Mat4.fromBasis((0, linear_algebra_1.Mat4)(), header.basisX, header.basisY, header.basisZ);
linear_algebra_1.Mat4.mul(matrix, matrix, basis);
return [2 /*return*/, {
label: params === null || params === void 0 ? void 0 : params.label,
entryId: params === null || params === void 0 ? void 0 : params.entryId,
grid: {
transform: { kind: 'matrix', matrix: matrix },
cells: data,
stats: {
min: (0, array_1.arrayMin)(values),
max: (0, array_1.arrayMax)(values),
mean: (0, array_1.arrayMean)(values),
sigma: (0, array_1.arrayRms)(values)
},
},
sourceData: CubeFormat.create(source),
customProperties: new custom_property_1.CustomProperties(),
_propertyData: Object.create(null),
}];
});
}); });
}
exports.volumeFromCube = volumeFromCube;
var CubeFormat;
(function (CubeFormat) {
function is(x) {
return (x === null || x === void 0 ? void 0 : x.kind) === 'cube';
}
CubeFormat.is = is;
function create(cube) {
return { kind: 'cube', name: cube.name, data: cube };
}
CubeFormat.create = create;
})(CubeFormat || (CubeFormat = {}));
exports.CubeFormat = CubeFormat;
//# sourceMappingURL=cube.js.map
;