UNPKG

molstar

Version:

A comprehensive macromolecular library.

70 lines (69 loc) 3.27 kB
"use strict"; /** * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.CarbohydrateSymbolColorThemeProvider = exports.CarbohydrateSymbolColorTheme = exports.getCarbohydrateSymbolColorThemeParams = exports.CarbohydrateSymbolColorThemeParams = void 0; var structure_1 = require("../../mol-model/structure"); var constants_1 = require("../../mol-model/structure/structure/carbohydrates/constants"); var color_1 = require("../../mol-util/color"); var param_definition_1 = require("../../mol-util/param-definition"); var legend_1 = require("../../mol-util/legend"); var DefaultColor = (0, color_1.Color)(0xCCCCCC); var Description = 'Assigns colors according to the Symbol Nomenclature for Glycans (SNFG).'; exports.CarbohydrateSymbolColorThemeParams = {}; function getCarbohydrateSymbolColorThemeParams(ctx) { return exports.CarbohydrateSymbolColorThemeParams; // TODO return copy } exports.getCarbohydrateSymbolColorThemeParams = getCarbohydrateSymbolColorThemeParams; 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 (!structure_1.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 constants_1.SaccharideColors.Secondary; } else { if (structure_1.StructureElement.Location.is(location)) { return getColor_1(location.unit, location.element); } else if (structure_1.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: (0, legend_1.TableLegend)(constants_1.MonosaccharidesColorTable) }; } exports.CarbohydrateSymbolColorTheme = CarbohydrateSymbolColorTheme; exports.CarbohydrateSymbolColorThemeProvider = { name: 'carbohydrate-symbol', label: 'Carbohydrate Symbol', category: "Residue Property" /* ColorTheme.Category.Residue */, factory: CarbohydrateSymbolColorTheme, getParams: getCarbohydrateSymbolColorThemeParams, defaultValues: param_definition_1.ParamDefinition.getDefaultValues(exports.CarbohydrateSymbolColorThemeParams), isApplicable: function (ctx) { return !!ctx.structure && ctx.structure.models.some(function (m) { return structure_1.Model.hasCarbohydrate(m); }); } };