molstar
Version:
A comprehensive macromolecular library.
65 lines (64 loc) • 2.79 kB
JavaScript
/**
* Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { StructureElement, Bond, Unit, Model } from '../../mol-model/structure';
import { SaccharideColors, MonosaccharidesColorTable } from '../../mol-model/structure/structure/carbohydrates/constants';
import { Color } from '../../mol-util/color';
import { ParamDefinition as PD } from '../../mol-util/param-definition';
import { TableLegend } from '../../mol-util/legend';
var DefaultColor = Color(0xCCCCCC);
var Description = 'Assigns colors according to the Symbol Nomenclature for Glycans (SNFG).';
export var CarbohydrateSymbolColorThemeParams = {};
export function getCarbohydrateSymbolColorThemeParams(ctx) {
return CarbohydrateSymbolColorThemeParams; // TODO return copy
}
export function CarbohydrateSymbolColorTheme(ctx, props) {
var color;
if (ctx.structure) {
var _a = ctx.structure.carbohydrates, elements_1 = _a.elements, getElementIndices_1 = _a.getElementIndices;
var getColor_1 = function (unit, index) {
if (!Unit.isAtomic(unit))
return DefaultColor;
var carbs = getElementIndices_1(unit, index);
return carbs.length > 0 ? elements_1[carbs[0]].component.color : DefaultColor;
};
color = function (location, isSecondary) {
if (isSecondary) {
return SaccharideColors.Secondary;
}
else {
if (StructureElement.Location.is(location)) {
return getColor_1(location.unit, location.element);
}
else if (Bond.isLocation(location)) {
return getColor_1(location.aUnit, location.aUnit.elements[location.aIndex]);
}
}
return DefaultColor;
};
}
else {
color = function () { return DefaultColor; };
}
return {
factory: CarbohydrateSymbolColorTheme,
granularity: 'group',
color: color,
props: props,
description: Description,
legend: TableLegend(MonosaccharidesColorTable)
};
}
export var CarbohydrateSymbolColorThemeProvider = {
name: 'carbohydrate-symbol',
label: 'Carbohydrate Symbol',
category: "Residue Property" /* ColorTheme.Category.Residue */,
factory: CarbohydrateSymbolColorTheme,
getParams: getCarbohydrateSymbolColorThemeParams,
defaultValues: PD.getDefaultValues(CarbohydrateSymbolColorThemeParams),
isApplicable: function (ctx) {
return !!ctx.structure && ctx.structure.models.some(function (m) { return Model.hasCarbohydrate(m); });
}
};