UNPKG

molstar

Version:

A comprehensive macromolecular library.

76 lines (75 loc) 2.9 kB
/** * Copyright (c) 2019-2025 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Lukáš Polák <admin@lukaspolak.cz> */ import { Color, ColorScale } from '../../mol-util/color'; import { StructureElement, Unit, Bond } from '../../mol-model/structure'; import { ParamDefinition as PD } from '../../mol-util/param-definition'; import { ColorThemeCategory } from './categories'; const DefaultUncertaintyColor = Color(0xffff99); const Description = `Assigns a color based on the uncertainty or disorder of an element's position, e.g. B-factor or RMSF, depending on the data availability and experimental technique.`; export const UncertaintyColorThemeParams = { domain: PD.Interval([0, 100]), list: PD.ColorList('red-white-blue', { presetKind: 'scale' }), }; export function getUncertaintyColorThemeParams(ctx) { return UncertaintyColorThemeParams; // TODO return copy } export function getUncertainty(unit, element) { if (Unit.isAtomic(unit)) { return unit.model.atomicConformation.B_iso_or_equiv.value(element); } else if (Unit.isSpheres(unit)) { return unit.model.coarseConformation.spheres.rmsf[element]; } else { return 0; } } export function UncertaintyColorTheme(ctx, props) { let scale; if (props.list.kind === 'set') { scale = ColorScale.createDiscrete({ reverse: true, domain: props.domain, listOrName: props.list.colors }); } else { scale = ColorScale.create({ reverse: true, domain: props.domain, listOrName: props.list.colors }); } // TODO calc domain based on data, set min/max as 10/90 percentile to be robust against outliers function color(location) { if (StructureElement.Location.is(location)) { return scale.color(getUncertainty(location.unit, location.element)); } else if (Bond.isLocation(location)) { return scale.color(getUncertainty(location.aUnit, location.aUnit.elements[location.aIndex])); } return DefaultUncertaintyColor; } return { factory: UncertaintyColorTheme, granularity: 'group', preferSmoothing: true, color, props, description: Description, legend: scale ? scale.legend : undefined }; } export const UncertaintyColorThemeProvider = { name: 'uncertainty', label: 'Uncertainty/Disorder', category: ColorThemeCategory.Atom, factory: UncertaintyColorTheme, getParams: getUncertaintyColorThemeParams, defaultValues: PD.getDefaultValues(UncertaintyColorThemeParams), isApplicable: (ctx) => !!ctx.structure && ctx.structure.models.some(m => m.atomicConformation.B_iso_or_equiv.isDefined || m.coarseHierarchy.isDefined) };