UNPKG

molstar

Version:

A comprehensive macromolecular library.

92 lines (91 loc) 3.69 kB
/** * Copyright (c) 2025-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> */ import { ParamDefinition as PD } from '../../mol-util/param-definition.js'; import { Volume } from '../../mol-model/volume/volume.js'; import { isPositionLocation } from '../../mol-geo/util/location-iterator.js'; import { Grid } from '../../mol-model/volume/grid.js'; import { clamp } from '../../mol-math/interpolate.js'; const Description = 'Assign size based on the given value of a volume cell.'; export const VolumeValueSizeThemeParams = { scale: PD.Numeric(1, { min: 0.01, max: 10, step: 0.01 }), transform: PD.Select('linear', [['linear', 'Linear'], ['quadratic', 'Quadratic'], ['cubic', 'Cubic']], { description: 'Linear: value * scale, Quadratic: value * scale^2, Cubic: value * scale^3' }), domain: PD.MappedStatic('auto', { custom: PD.Interval([0, 1], { step: 0.001, min: 0 }), auto: PD.Group({}) }), }; export function getVolumeValueSizeThemeParams(ctx) { return VolumeValueSizeThemeParams; // TODO return copy } export function VolumeValueSizeTheme(ctx, props) { var _a; if (ctx.volume) { const { min, max } = ctx.volume.grid.stats; const domain = props.domain.name === 'custom' ? props.domain.params : [min, max]; const scaleFactor = props.transform === 'cubic' ? props.scale ** 3 : props.transform === 'quadratic' ? props.scale ** 2 : props.scale; if ((_a = ctx.locationKinds) === null || _a === void 0 ? void 0 : _a.includes('cell-location')) { const { data } = ctx.volume.grid.cells; const isLocation = Volume.Cell.isLocation; const size = (location) => { if (isLocation(location)) { const v = clamp(Math.abs(data[location.cell]), domain[0], domain[1]); return v * scaleFactor; } else { return 0; } }; return { factory: VolumeValueSizeTheme, granularity: 'group', size, props, description: Description }; } else { const getTrilinearlyInterpolated = Grid.makeGetTrilinearlyInterpolated(ctx.volume.grid, 'none'); const size = (location) => { if (isPositionLocation(location)) { const value = getTrilinearlyInterpolated(location.position); if (Number.isNaN(value)) return 0; const v = clamp(Math.abs(value), domain[0], domain[1]); return v * scaleFactor; } else { return 0; } }; return { factory: VolumeValueSizeTheme, granularity: 'vertex', size, props, description: Description }; } } else { return { factory: VolumeValueSizeTheme, granularity: 'uniform', size: () => props.scale, props, description: Description }; } } export const VolumeValueSizeThemeProvider = { name: 'volume-value', label: 'Volume Value', category: '', factory: VolumeValueSizeTheme, getParams: getVolumeValueSizeThemeParams, defaultValues: PD.getDefaultValues(VolumeValueSizeThemeParams), isApplicable: (ctx) => !!ctx.volume && !Volume.Segmentation.get(ctx.volume), };