molstar
Version:
A comprehensive macromolecular library.
81 lines • 3.38 kB
JavaScript
/**
* Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { __assign } from "tslib";
import { Color } from '../../mol-util/color';
import { StructureElement, Bond } from '../../mol-model/structure';
import { ParamDefinition as PD } from '../../mol-util/param-definition';
import { getPaletteParams, getPalette } from '../../mol-util/color/palette';
import { ColorLists, getColorListFromName } from '../../mol-util/color/lists';
var DefaultList = 'dark-2';
var DefaultColor = Color(0xCCCCCC);
var Description = 'Gives every polymer chain instance a unique color based on the position (index) of the polymer in the list of polymers in the structure.';
export var PolymerIndexColorThemeParams = __assign({}, getPaletteParams({ type: 'colors', colorList: DefaultList }));
export function getPolymerIndexColorThemeParams(ctx) {
var params = PD.clone(PolymerIndexColorThemeParams);
if (ctx.structure) {
if (getPolymerChainCount(ctx.structure.root) > ColorLists[DefaultList].list.length) {
params.palette.defaultValue.name = 'colors';
params.palette.defaultValue.params = __assign(__assign({}, params.palette.defaultValue.params), { list: { kind: 'interpolate', colors: getColorListFromName(DefaultList).list } });
}
}
return params;
}
function getPolymerChainCount(structure) {
var polymerChainCount = 0;
var units = structure.units;
for (var i = 0, il = units.length; i < il; ++i) {
if (units[i].polymerElements.length > 0)
++polymerChainCount;
}
return polymerChainCount;
}
export function PolymerIndexColorTheme(ctx, props) {
var color;
var legend;
if (ctx.structure) {
var palette = getPalette(getPolymerChainCount(ctx.structure.root), props);
legend = palette.legend;
var units = ctx.structure.root.units;
var unitIdColor_1 = new Map();
for (var i = 0, j = 0, il = units.length; i < il; ++i) {
if (units[i].polymerElements.length > 0) {
unitIdColor_1.set(units[i].id, palette.color(j));
++j;
}
}
color = function (location) {
var color;
if (StructureElement.Location.is(location)) {
color = unitIdColor_1.get(location.unit.id);
}
else if (Bond.isLocation(location)) {
color = unitIdColor_1.get(location.aUnit.id);
}
return color !== undefined ? color : DefaultColor;
};
}
else {
color = function () { return DefaultColor; };
}
return {
factory: PolymerIndexColorTheme,
granularity: 'instance',
color: color,
props: props,
description: Description,
legend: legend
};
}
export var PolymerIndexColorThemeProvider = {
name: 'polymer-index',
label: 'Polymer Chain Instance',
category: "Chain Property" /* Chain */,
factory: PolymerIndexColorTheme,
getParams: getPolymerIndexColorThemeParams,
defaultValues: PD.getDefaultValues(PolymerIndexColorThemeParams),
isApplicable: function (ctx) { return !!ctx.structure; }
};
//# sourceMappingURL=polymer-index.js.map