UNPKG

molstar

Version:

A comprehensive macromolecular library.

81 lines (80 loc) 3.54 kB
/** * Copyright (c) 2019-2021 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { ParamDefinition as PD } from '../../../mol-util/param-definition'; import { Color } from '../../../mol-util/color'; import { getPalette } from '../../../mol-util/color/palette'; import { StructureElement, Bond, Model } from '../../../mol-model/structure'; import { CellPackInfoProvider } from '../property'; import { distinctColors } from '../../../mol-util/color/distinct'; import { Hcl } from '../../../mol-util/color/spaces/hcl'; var DefaultColor = Color(0xCCCCCC); var Description = 'Gives every model in a CellPack packing a unique generated color similar to other models in the packing.'; export var CellPackGenerateColorThemeParams = {}; export function getCellPackGenerateColorThemeParams(ctx) { return CellPackGenerateColorThemeParams; // TODO return copy } export function CellPackGenerateColorTheme(ctx, props) { var color; var legend; var info = ctx.structure && CellPackInfoProvider.get(ctx.structure).value; if (ctx.structure && info) { var colors = distinctColors(info.packingsCount); var hcl = Hcl.fromColor(Hcl(), colors[info.packingIndex]); var hue = [Math.max(0, hcl[0] - 35), Math.min(360, hcl[0] + 35)]; var models = ctx.structure.root.models; var size = 0; for (var _i = 0, models_1 = models; _i < models_1.length; _i++) { var m = models_1[_i]; size = Math.max(size, Model.TrajectoryInfo.get(m).size); } var palette = getPalette(size, { palette: { name: 'generate', params: { hue: hue, chroma: [30, 80], luminance: [15, 85], clusteringStepCount: 50, minSampleCount: 800, maxCount: 75 } } }, { minLabel: 'Min', maxLabel: 'Max' }); legend = palette.legend; var modelColor_1 = new Map(); for (var i = 0, il = models.length; i < il; ++i) { var idx = Model.TrajectoryInfo.get(models[i]).index; modelColor_1.set(Model.TrajectoryInfo.get(models[i]).index, palette.color(idx)); } color = function (location) { if (StructureElement.Location.is(location)) { return modelColor_1.get(Model.TrajectoryInfo.get(location.unit.model).index); } else if (Bond.isLocation(location)) { return modelColor_1.get(Model.TrajectoryInfo.get(location.aUnit.model).index); } return DefaultColor; }; } else { color = function () { return DefaultColor; }; } return { factory: CellPackGenerateColorTheme, granularity: 'instance', color: color, props: props, description: Description, legend: legend }; } export var CellPackGenerateColorThemeProvider = { name: 'cellpack-generate', label: 'CellPack Generate', category: "Chain Property" /* ColorTheme.Category.Chain */, factory: CellPackGenerateColorTheme, getParams: getCellPackGenerateColorThemeParams, defaultValues: PD.getDefaultValues(CellPackGenerateColorThemeParams), isApplicable: function (ctx) { return (!!ctx.structure && ctx.structure.elementCount > 0 && !!CellPackInfoProvider.get(ctx.structure).value); } };