molstar
Version:
A comprehensive macromolecular library.
100 lines (99 loc) • 5.18 kB
JavaScript
;
/**
* Copyright (c) 2018-2026 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @author Gianluca Tomasello <giagitom@gmail.com>
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.StructureGaussianWireframeParams = exports.GaussianWireframeParams = void 0;
exports.GaussianWireframeVisual = GaussianWireframeVisual;
exports.StructureGaussianWireframeVisual = StructureGaussianWireframeVisual;
const param_definition_1 = require("../../../mol-util/param-definition.js");
const lines_1 = require("../../../mol-geo/geometry/lines/lines.js");
const gaussian_1 = require("./util/gaussian.js");
const algorithm_1 = require("../../../mol-geo/util/marching-cubes/algorithm.js");
const units_visual_1 = require("../units-visual.js");
const element_1 = require("./util/element.js");
const geometry_1 = require("../../../mol-math/geometry.js");
const complex_visual_1 = require("../complex-visual.js");
const SharedParams = {
...gaussian_1.GaussianDensityParams,
sizeFactor: param_definition_1.ParamDefinition.Numeric(3, { min: 0, max: 10, step: 0.1 }),
lineSizeAttenuation: param_definition_1.ParamDefinition.Boolean(false),
};
exports.GaussianWireframeParams = {
...units_visual_1.UnitsLinesParams,
...SharedParams,
};
exports.StructureGaussianWireframeParams = {
...complex_visual_1.ComplexLinesParams,
...SharedParams,
};
async function createGaussianWireframe(ctx, unit, structure, theme, props, lines) {
const { smoothness } = props;
const { transform, field, idField, maxRadius } = await (0, gaussian_1.computeUnitGaussianDensity)(structure, unit, theme.size, props).runInContext(ctx.runtime);
const params = {
isoLevel: Math.exp(-smoothness),
scalarField: field,
idField
};
const wireframe = await (0, algorithm_1.computeMarchingCubesLines)(params, lines).runAsChild(ctx.runtime);
lines_1.Lines.transform(wireframe, transform);
const sphere = geometry_1.Sphere3D.expand((0, geometry_1.Sphere3D)(), unit.boundary.sphere, maxRadius);
wireframe.setBoundingSphere(sphere);
return wireframe;
}
function GaussianWireframeVisual(materialId) {
return (0, units_visual_1.UnitsLinesVisual)({
defaultProps: param_definition_1.ParamDefinition.getDefaultValues(exports.GaussianWireframeParams),
createGeometry: createGaussianWireframe,
createLocationIterator: element_1.ElementIterator.fromGroup,
getLoci: element_1.getElementLoci,
eachLocation: element_1.eachElement,
setUpdateState: (state, newProps, currentProps) => {
state.createGeometry = (newProps.resolution !== currentProps.resolution ||
newProps.radiusOffset !== currentProps.radiusOffset ||
newProps.smoothness !== currentProps.smoothness ||
newProps.ignoreHydrogens !== currentProps.ignoreHydrogens ||
newProps.ignoreHydrogensVariant !== currentProps.ignoreHydrogensVariant ||
newProps.traceOnly !== currentProps.traceOnly ||
newProps.includeParent !== currentProps.includeParent ||
newProps.floodfill !== currentProps.floodfill);
}
}, materialId);
}
//
async function createStructureGaussianWireframe(ctx, structure, theme, props, lines) {
const { smoothness } = props;
const { transform, field, idField, maxRadius } = await (0, gaussian_1.computeStructureGaussianDensity)(structure, theme.size, props).runInContext(ctx.runtime);
const params = {
isoLevel: Math.exp(-smoothness),
scalarField: field,
idField
};
const wireframe = await (0, algorithm_1.computeMarchingCubesLines)(params, lines).runAsChild(ctx.runtime);
lines_1.Lines.transform(wireframe, transform);
const sphere = geometry_1.Sphere3D.expand((0, geometry_1.Sphere3D)(), structure.boundary.sphere, maxRadius);
wireframe.setBoundingSphere(sphere);
return wireframe;
}
function StructureGaussianWireframeVisual(materialId) {
return (0, complex_visual_1.ComplexLinesVisual)({
defaultProps: param_definition_1.ParamDefinition.getDefaultValues(exports.StructureGaussianWireframeParams),
createGeometry: createStructureGaussianWireframe,
createLocationIterator: element_1.ElementIterator.fromStructure,
getLoci: element_1.getSerialElementLoci,
eachLocation: element_1.eachSerialElement,
setUpdateState: (state, newProps, currentProps) => {
state.createGeometry = (newProps.resolution !== currentProps.resolution ||
newProps.radiusOffset !== currentProps.radiusOffset ||
newProps.smoothness !== currentProps.smoothness ||
newProps.ignoreHydrogens !== currentProps.ignoreHydrogens ||
newProps.ignoreHydrogensVariant !== currentProps.ignoreHydrogensVariant ||
newProps.traceOnly !== currentProps.traceOnly ||
newProps.includeParent !== currentProps.includeParent ||
newProps.floodfill !== currentProps.floodfill);
}
}, materialId);
}