UNPKG

molstar

Version:

A comprehensive macromolecular library.

108 lines (107 loc) 4.81 kB
/** * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { Color, ColorMap } from '../../../mol-util/color'; import { ParamDefinition as PD } from '../../../mol-util/param-definition'; import { InteractionsProvider } from '../interactions'; import { TableLegend } from '../../../mol-util/legend'; import { Interactions } from '../interactions/interactions'; import { hash2 } from '../../../mol-data/util'; var DefaultColor = Color(0xCCCCCC); var Description = 'Assigns colors according the interaction type of a link.'; var InteractionTypeColors = ColorMap({ HydrogenBond: 0x2B83BA, Hydrophobic: 0x808080, HalogenBond: 0x40FFBF, Ionic: 0xF0C814, MetalCoordination: 0x8C4099, CationPi: 0xFF8000, PiStacking: 0x8CB366, WeakHydrogenBond: 0xC5DDEC, }); var 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 4 /* InteractionType.HydrogenBond */: return InteractionTypeColors.HydrogenBond; case 6 /* InteractionType.Hydrophobic */: return InteractionTypeColors.Hydrophobic; case 5 /* InteractionType.HalogenBond */: return InteractionTypeColors.HalogenBond; case 1 /* InteractionType.Ionic */: return InteractionTypeColors.Ionic; case 7 /* InteractionType.MetalCoordination */: return InteractionTypeColors.MetalCoordination; case 2 /* InteractionType.CationPi */: return InteractionTypeColors.CationPi; case 3 /* InteractionType.PiStacking */: return InteractionTypeColors.PiStacking; case 8 /* InteractionType.WeakHydrogenBond */: return InteractionTypeColors.WeakHydrogenBond; case 0 /* InteractionType.Unknown */: return DefaultColor; } } export var InteractionTypeColorThemeParams = {}; export function getInteractionTypeColorThemeParams(ctx) { return InteractionTypeColorThemeParams; // TODO return copy } export function InteractionTypeColorTheme(ctx, props) { var color; var interactions = ctx.structure ? InteractionsProvider.get(ctx.structure) : undefined; var contextHash = interactions ? hash2(interactions.id, interactions.version) : -1; if (interactions && interactions.value) { color = function (location) { if (Interactions.isLocation(location)) { var _a = location.data.interactions, unitsContacts = _a.unitsContacts, contacts = _a.contacts; var _b = location.element, unitA = _b.unitA, unitB = _b.unitB, indexA = _b.indexA, indexB = _b.indexB; if (unitA === unitB) { var links = unitsContacts.get(unitA.id); var idx = links.getDirectedEdgeIndex(indexA, indexB); return typeColor(links.edgeProps.type[idx]); } else { var idx = contacts.getEdgeIndex(indexA, unitA.id, indexB, unitB.id); return typeColor(contacts.edges[idx].props.type); } } return DefaultColor; }; } else { color = function () { return DefaultColor; }; } return { factory: InteractionTypeColorTheme, granularity: 'group', color: color, props: props, contextHash: contextHash, description: Description, legend: TableLegend(InteractionTypeColorTable) }; } export var InteractionTypeColorThemeProvider = { name: 'interaction-type', label: 'Interaction Type', category: "Miscellaneous" /* ColorTheme.Category.Misc */, factory: InteractionTypeColorTheme, getParams: getInteractionTypeColorThemeParams, defaultValues: PD.getDefaultValues(InteractionTypeColorThemeParams), isApplicable: function (ctx) { return !!ctx.structure; }, ensureCustomProperties: { attach: function (ctx, data) { return data.structure ? InteractionsProvider.attach(ctx, data.structure, void 0, true) : Promise.resolve(); }, detach: function (data) { return data.structure && InteractionsProvider.ref(data.structure, false); } } };