molstar
Version:
A comprehensive macromolecular library.
63 lines (62 loc) • 2.7 kB
JavaScript
/**
* 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 { StructureElement, Model, Bond } from '../../../mol-model/structure';
import { CellPackInfoProvider } from '../property';
var DefaultColor = Color(0xCCCCCC);
var Description = 'Gives every model in a CellPack the color provied in the packing data.';
export var CellPackProvidedColorThemeParams = {};
export function getCellPackProvidedColorThemeParams(ctx) {
return CellPackProvidedColorThemeParams; // TODO return copy
}
export function CellPackProvidedColorTheme(ctx, props) {
var color;
var legend;
var info = ctx.structure && CellPackInfoProvider.get(ctx.structure).value;
if (ctx.structure && (info === null || info === void 0 ? void 0 : info.colors)) {
var models = ctx.structure.root.models;
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, info.colors[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: CellPackProvidedColorTheme,
granularity: 'instance',
color: color,
props: props,
description: Description,
legend: legend
};
}
export var CellPackProvidedColorThemeProvider = {
name: 'cellpack-provided',
label: 'CellPack Provided',
category: "Chain Property" /* ColorTheme.Category.Chain */,
factory: CellPackProvidedColorTheme,
getParams: getCellPackProvidedColorThemeParams,
defaultValues: PD.getDefaultValues(CellPackProvidedColorThemeParams),
isApplicable: function (ctx) {
var _a;
return (!!ctx.structure && ctx.structure.elementCount > 0 &&
Model.TrajectoryInfo.get(ctx.structure.models[0]).size > 1 &&
!!((_a = CellPackInfoProvider.get(ctx.structure).value) === null || _a === void 0 ? void 0 : _a.colors));
}
};