molstar
Version:
A comprehensive macromolecular library.
132 lines (131 loc) • 8.82 kB
JavaScript
/**
* Copyright (c) 2018-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.UnitsGaussianDensityVolumeVisual = exports.UnitsGaussianDensityVolumeParams = exports.GaussianDensityVolumeVisual = exports.GaussianDensityVolumeParams = void 0;
var tslib_1 = require("tslib");
var param_definition_1 = require("../../../mol-util/param-definition");
var gaussian_1 = require("./util/gaussian");
var direct_volume_1 = require("../../../mol-geo/geometry/direct-volume/direct-volume");
var complex_visual_1 = require("../complex-visual");
var linear_algebra_1 = require("../../../mol-math/linear-algebra");
var element_1 = require("./util/element");
var geometry_1 = require("../../../mol-math/geometry");
var units_visual_1 = require("../units-visual");
function createGaussianDensityVolume(ctx, structure, theme, props, directVolume) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var runtime, webgl, oldTexture, densityTextureData, transform, texture, bbox, gridDim, stats, unitToCartn, cellDim, axisOrder, vol, sphere;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
runtime = ctx.runtime, webgl = ctx.webgl;
if (!webgl || !webgl.extensions.blendMinMax) {
throw new Error('GaussianDensityVolume requires `webgl` and `blendMinMax` extension');
}
oldTexture = directVolume ? directVolume.gridTexture.ref.value : undefined;
return [4 /*yield*/, (0, gaussian_1.computeStructureGaussianDensityTexture)(structure, theme.size, props, webgl, oldTexture).runInContext(runtime)];
case 1:
densityTextureData = _a.sent();
transform = densityTextureData.transform, texture = densityTextureData.texture, bbox = densityTextureData.bbox, gridDim = densityTextureData.gridDim;
stats = { min: 0, max: 1, mean: 0.04, sigma: 0.01 };
unitToCartn = linear_algebra_1.Mat4.mul((0, linear_algebra_1.Mat4)(), transform, linear_algebra_1.Mat4.fromScaling((0, linear_algebra_1.Mat4)(), gridDim));
cellDim = linear_algebra_1.Mat4.getScaling((0, linear_algebra_1.Vec3)(), transform);
axisOrder = linear_algebra_1.Vec3.create(0, 1, 2);
vol = direct_volume_1.DirectVolume.create(bbox, gridDim, transform, unitToCartn, cellDim, texture, stats, true, axisOrder, directVolume);
sphere = geometry_1.Sphere3D.expand((0, geometry_1.Sphere3D)(), structure.boundary.sphere, densityTextureData.maxRadius);
vol.setBoundingSphere(sphere);
return [2 /*return*/, vol];
}
});
});
}
exports.GaussianDensityVolumeParams = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, complex_visual_1.ComplexDirectVolumeParams), gaussian_1.GaussianDensityParams), { ignoreHydrogens: param_definition_1.ParamDefinition.Boolean(false), includeParent: param_definition_1.ParamDefinition.Boolean(false, { isHidden: true }) });
function GaussianDensityVolumeVisual(materialId) {
return (0, complex_visual_1.ComplexDirectVolumeVisual)({
defaultProps: param_definition_1.ParamDefinition.getDefaultValues(exports.GaussianDensityVolumeParams),
createGeometry: createGaussianDensityVolume,
createLocationIterator: element_1.ElementIterator.fromStructure,
getLoci: element_1.getSerialElementLoci,
eachLocation: element_1.eachSerialElement,
setUpdateState: function (state, newProps, currentProps) {
if (newProps.resolution !== currentProps.resolution)
state.createGeometry = true;
if (newProps.radiusOffset !== currentProps.radiusOffset)
state.createGeometry = true;
if (newProps.smoothness !== currentProps.smoothness)
state.createGeometry = true;
if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens)
state.createGeometry = true;
if (newProps.traceOnly !== currentProps.traceOnly)
state.createGeometry = true;
if (newProps.includeParent !== currentProps.includeParent)
state.createGeometry = true;
},
dispose: function (geometry) {
geometry.gridTexture.ref.value.destroy();
}
}, materialId);
}
exports.GaussianDensityVolumeVisual = GaussianDensityVolumeVisual;
//
function createUnitsGaussianDensityVolume(ctx, unit, structure, theme, props, directVolume) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var runtime, webgl, oldTexture, densityTextureData, transform, texture, bbox, gridDim, stats, unitToCartn, cellDim, axisOrder, vol, sphere;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
runtime = ctx.runtime, webgl = ctx.webgl;
if (!webgl) {
// gpu gaussian density also needs blendMinMax but there is no fallback here so
// we allow it here with the results that there is no group id assignment and
// hence no group-based coloring or picking
throw new Error('GaussianDensityVolume requires `webgl`');
}
oldTexture = directVolume ? directVolume.gridTexture.ref.value : undefined;
return [4 /*yield*/, (0, gaussian_1.computeUnitGaussianDensityTexture)(structure, unit, theme.size, props, webgl, oldTexture).runInContext(runtime)];
case 1:
densityTextureData = _a.sent();
transform = densityTextureData.transform, texture = densityTextureData.texture, bbox = densityTextureData.bbox, gridDim = densityTextureData.gridDim;
stats = { min: 0, max: 1, mean: 0.04, sigma: 0.01 };
unitToCartn = linear_algebra_1.Mat4.mul((0, linear_algebra_1.Mat4)(), transform, linear_algebra_1.Mat4.fromScaling((0, linear_algebra_1.Mat4)(), gridDim));
cellDim = linear_algebra_1.Mat4.getScaling((0, linear_algebra_1.Vec3)(), transform);
axisOrder = linear_algebra_1.Vec3.create(0, 1, 2);
vol = direct_volume_1.DirectVolume.create(bbox, gridDim, transform, unitToCartn, cellDim, texture, stats, true, axisOrder, directVolume);
sphere = geometry_1.Sphere3D.expand((0, geometry_1.Sphere3D)(), unit.boundary.sphere, densityTextureData.maxRadius);
vol.setBoundingSphere(sphere);
return [2 /*return*/, vol];
}
});
});
}
exports.UnitsGaussianDensityVolumeParams = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, units_visual_1.UnitsDirectVolumeParams), gaussian_1.GaussianDensityParams), { ignoreHydrogens: param_definition_1.ParamDefinition.Boolean(false), includeParent: param_definition_1.ParamDefinition.Boolean(false, { isHidden: true }) });
function UnitsGaussianDensityVolumeVisual(materialId) {
return (0, units_visual_1.UnitsDirectVolumeVisual)({
defaultProps: param_definition_1.ParamDefinition.getDefaultValues(exports.UnitsGaussianDensityVolumeParams),
createGeometry: createUnitsGaussianDensityVolume,
createLocationIterator: element_1.ElementIterator.fromGroup,
getLoci: element_1.getElementLoci,
eachLocation: element_1.eachElement,
setUpdateState: function (state, newProps, currentProps) {
if (newProps.resolution !== currentProps.resolution)
state.createGeometry = true;
if (newProps.radiusOffset !== currentProps.radiusOffset)
state.createGeometry = true;
if (newProps.smoothness !== currentProps.smoothness)
state.createGeometry = true;
if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens)
state.createGeometry = true;
if (newProps.traceOnly !== currentProps.traceOnly)
state.createGeometry = true;
if (newProps.includeParent !== currentProps.includeParent)
state.createGeometry = true;
},
dispose: function (geometry) {
geometry.gridTexture.ref.value.destroy();
}
}, materialId);
}
exports.UnitsGaussianDensityVolumeVisual = UnitsGaussianDensityVolumeVisual;
;