UNPKG

molstar

Version:

A comprehensive macromolecular library.

115 lines (114 loc) 5.12 kB
"use strict"; /** * Copyright (c) 2019-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.InteractionTypeColorThemeProvider = exports.InteractionTypeColorThemeParams = void 0; exports.getInteractionTypeColorThemeParams = getInteractionTypeColorThemeParams; exports.InteractionTypeColorTheme = InteractionTypeColorTheme; const color_1 = require("../../../mol-util/color"); const param_definition_1 = require("../../../mol-util/param-definition"); const interactions_1 = require("../interactions"); const common_1 = require("../interactions/common"); const legend_1 = require("../../../mol-util/legend"); const interactions_2 = require("../interactions/interactions"); const util_1 = require("../../../mol-data/util"); const categories_1 = require("../../../mol-theme/color/categories"); const DefaultColor = (0, color_1.Color)(0xCCCCCC); const Description = 'Assigns colors according the interaction type of a link.'; const InteractionTypeColors = (0, color_1.ColorMap)({ HydrogenBond: 0x2B83BA, Hydrophobic: 0x808080, HalogenBond: 0x40FFBF, Ionic: 0xF0C814, MetalCoordination: 0x8C4099, CationPi: 0xFF8000, PiStacking: 0x8CB366, WeakHydrogenBond: 0xC5DDEC, }); const InteractionTypeColorTable = [ ['Hydrogen Bond', InteractionTypeColors.HydrogenBond], ['Hydrophobic', InteractionTypeColors.Hydrophobic], ['Halogen Bond', InteractionTypeColors.HalogenBond], ['Ionic', InteractionTypeColors.Ionic], ['Metal Coordination', InteractionTypeColors.MetalCoordination], ['Cation Pi', InteractionTypeColors.CationPi], ['Pi Stacking', InteractionTypeColors.PiStacking], ['Weak HydrogenBond', InteractionTypeColors.WeakHydrogenBond], ]; function typeColor(type) { switch (type) { case common_1.InteractionType.HydrogenBond: return InteractionTypeColors.HydrogenBond; case common_1.InteractionType.Hydrophobic: return InteractionTypeColors.Hydrophobic; case common_1.InteractionType.HalogenBond: return InteractionTypeColors.HalogenBond; case common_1.InteractionType.Ionic: return InteractionTypeColors.Ionic; case common_1.InteractionType.MetalCoordination: return InteractionTypeColors.MetalCoordination; case common_1.InteractionType.CationPi: return InteractionTypeColors.CationPi; case common_1.InteractionType.PiStacking: return InteractionTypeColors.PiStacking; case common_1.InteractionType.WeakHydrogenBond: return InteractionTypeColors.WeakHydrogenBond; case common_1.InteractionType.Unknown: return DefaultColor; } } exports.InteractionTypeColorThemeParams = {}; function getInteractionTypeColorThemeParams(ctx) { return exports.InteractionTypeColorThemeParams; // TODO return copy } function InteractionTypeColorTheme(ctx, props) { let color; const interactions = ctx.structure ? interactions_1.InteractionsProvider.get(ctx.structure) : undefined; const contextHash = interactions ? (0, util_1.hash2)(interactions.id, interactions.version) : -1; if (interactions && interactions.value) { color = (location) => { if (interactions_2.Interactions.isLocation(location)) { const { unitsContacts, contacts } = location.data.interactions; const { unitA, unitB, indexA, indexB } = location.element; if (unitA === unitB) { const links = unitsContacts.get(unitA.id); const idx = links.getDirectedEdgeIndex(indexA, indexB); return typeColor(links.edgeProps.type[idx]); } else { const idx = contacts.getEdgeIndex(indexA, unitA.id, indexB, unitB.id); return typeColor(contacts.edges[idx].props.type); } } return DefaultColor; }; } else { color = () => DefaultColor; } return { factory: InteractionTypeColorTheme, granularity: 'group', color: color, props: props, contextHash, description: Description, legend: (0, legend_1.TableLegend)(InteractionTypeColorTable) }; } exports.InteractionTypeColorThemeProvider = { name: 'interaction-type', label: 'Interaction Type', category: categories_1.ColorThemeCategory.Misc, factory: InteractionTypeColorTheme, getParams: getInteractionTypeColorThemeParams, defaultValues: param_definition_1.ParamDefinition.getDefaultValues(exports.InteractionTypeColorThemeParams), isApplicable: (ctx) => !!ctx.structure, ensureCustomProperties: { attach: (ctx, data) => data.structure ? interactions_1.InteractionsProvider.attach(ctx, data.structure, void 0, true) : Promise.resolve(), detach: (data) => data.structure && interactions_1.InteractionsProvider.ref(data.structure, false) } };