UNPKG

molstar

Version:

A comprehensive macromolecular library.

127 lines (126 loc) 7.87 kB
/** * Copyright (c) 2018-2021 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { __assign, __awaiter, __generator } from "tslib"; import { ParamDefinition as PD } from '../../../mol-util/param-definition'; import { computeStructureGaussianDensityTexture, computeUnitGaussianDensityTexture, GaussianDensityParams } from './util/gaussian'; import { DirectVolume } from '../../../mol-geo/geometry/direct-volume/direct-volume'; import { ComplexDirectVolumeParams, ComplexDirectVolumeVisual } from '../complex-visual'; import { Mat4, Vec3 } from '../../../mol-math/linear-algebra'; import { eachElement, eachSerialElement, ElementIterator, getElementLoci, getSerialElementLoci } from './util/element'; import { Sphere3D } from '../../../mol-math/geometry'; import { UnitsDirectVolumeParams, UnitsDirectVolumeVisual } from '../units-visual'; function createGaussianDensityVolume(ctx, structure, theme, props, directVolume) { return __awaiter(this, void 0, void 0, function () { var runtime, webgl, oldTexture, densityTextureData, transform, texture, bbox, gridDim, stats, unitToCartn, cellDim, axisOrder, vol, sphere; return __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*/, 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 = Mat4.mul(Mat4(), transform, Mat4.fromScaling(Mat4(), gridDim)); cellDim = Mat4.getScaling(Vec3(), transform); axisOrder = Vec3.create(0, 1, 2); vol = DirectVolume.create(bbox, gridDim, transform, unitToCartn, cellDim, texture, stats, true, axisOrder, directVolume); sphere = Sphere3D.expand(Sphere3D(), structure.boundary.sphere, densityTextureData.maxRadius); vol.setBoundingSphere(sphere); return [2 /*return*/, vol]; } }); }); } export var GaussianDensityVolumeParams = __assign(__assign(__assign({}, ComplexDirectVolumeParams), GaussianDensityParams), { ignoreHydrogens: PD.Boolean(false), includeParent: PD.Boolean(false, { isHidden: true }) }); export function GaussianDensityVolumeVisual(materialId) { return ComplexDirectVolumeVisual({ defaultProps: PD.getDefaultValues(GaussianDensityVolumeParams), createGeometry: createGaussianDensityVolume, createLocationIterator: ElementIterator.fromStructure, getLoci: getSerialElementLoci, eachLocation: 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); } // function createUnitsGaussianDensityVolume(ctx, unit, structure, theme, props, directVolume) { return __awaiter(this, void 0, void 0, function () { var runtime, webgl, oldTexture, densityTextureData, transform, texture, bbox, gridDim, stats, unitToCartn, cellDim, axisOrder, vol, sphere; return __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*/, 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 = Mat4.mul(Mat4(), transform, Mat4.fromScaling(Mat4(), gridDim)); cellDim = Mat4.getScaling(Vec3(), transform); axisOrder = Vec3.create(0, 1, 2); vol = DirectVolume.create(bbox, gridDim, transform, unitToCartn, cellDim, texture, stats, true, axisOrder, directVolume); sphere = Sphere3D.expand(Sphere3D(), unit.boundary.sphere, densityTextureData.maxRadius); vol.setBoundingSphere(sphere); return [2 /*return*/, vol]; } }); }); } export var UnitsGaussianDensityVolumeParams = __assign(__assign(__assign({}, UnitsDirectVolumeParams), GaussianDensityParams), { ignoreHydrogens: PD.Boolean(false), includeParent: PD.Boolean(false, { isHidden: true }) }); export function UnitsGaussianDensityVolumeVisual(materialId) { return UnitsDirectVolumeVisual({ defaultProps: PD.getDefaultValues(UnitsGaussianDensityVolumeParams), createGeometry: createUnitsGaussianDensityVolume, createLocationIterator: ElementIterator.fromGroup, getLoci: getElementLoci, eachLocation: 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); }