UNPKG

molstar

Version:

A comprehensive macromolecular library.

119 lines 5.7 kB
/** * Copyright (c) 2018-2019 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 { StructureElement, Unit, Bond } from '../../mol-model/structure'; import { SecondaryStructureType } from '../../mol-model/structure/model/types'; import { getElementMoleculeType } from '../../mol-model/structure/util'; import { ParamDefinition as PD } from '../../mol-util/param-definition'; import { TableLegend } from '../../mol-util/legend'; import { SecondaryStructureProvider } from '../../mol-model-props/computed/secondary-structure'; import { getAdjustedColorMap } from '../../mol-util/color/color'; import { hash2 } from '../../mol-data/util'; // from Jmol http://jmol.sourceforge.net/jscolors/ (shapely) var SecondaryStructureColors = ColorMap({ 'alphaHelix': 0xFF0080, 'threeTenHelix': 0xA00080, 'piHelix': 0x600080, 'betaTurn': 0x6080FF, 'betaStrand': 0xFFC800, 'coil': 0xFFFFFF, 'bend': 0x66D8C9 /* biting original color used 0x00FF00 */, 'turn': 0x00B266, 'dna': 0xAE00FE, 'rna': 0xFD0162, 'carbohydrate': 0xA6A6FA }); var DefaultSecondaryStructureColor = Color(0x808080); var Description = 'Assigns a color based on the type of secondary structure and basic molecule type.'; export var SecondaryStructureColorThemeParams = { saturation: PD.Numeric(-1, { min: -6, max: 6, step: 0.1 }), lightness: PD.Numeric(0, { min: -6, max: 6, step: 0.1 }) }; export function getSecondaryStructureColorThemeParams(ctx) { return SecondaryStructureColorThemeParams; // TODO return copy } export function secondaryStructureColor(colorMap, unit, element, computedSecondaryStructure) { var secStrucType = SecondaryStructureType.create(0 /* None */); if (computedSecondaryStructure && Unit.isAtomic(unit)) { var secondaryStructure = computedSecondaryStructure.get(unit.invariantId); if (secondaryStructure) secStrucType = secondaryStructure.type[secondaryStructure.getIndex(unit.residueIndex[element])]; } if (SecondaryStructureType.is(secStrucType, 2 /* Helix */)) { if (SecondaryStructureType.is(secStrucType, 2048 /* Helix3Ten */)) { return colorMap.threeTenHelix; } else if (SecondaryStructureType.is(secStrucType, 32768 /* HelixPi */)) { return colorMap.piHelix; } return colorMap.alphaHelix; } else if (SecondaryStructureType.is(secStrucType, 4 /* Beta */)) { return colorMap.betaStrand; } else if (SecondaryStructureType.is(secStrucType, 8 /* Bend */)) { return colorMap.bend; } else if (SecondaryStructureType.is(secStrucType, 16 /* Turn */)) { return colorMap.turn; } else { var moleculeType = getElementMoleculeType(unit, element); if (moleculeType === 7 /* DNA */) { return colorMap.dna; } else if (moleculeType === 6 /* RNA */) { return colorMap.rna; } else if (moleculeType === 9 /* Saccharide */) { return colorMap.carbohydrate; } else if (moleculeType === 5 /* Protein */) { return colorMap.coil; } } return DefaultSecondaryStructureColor; } export function SecondaryStructureColorTheme(ctx, props) { var computedSecondaryStructure = ctx.structure && SecondaryStructureProvider.get(ctx.structure); var contextHash = computedSecondaryStructure ? hash2(computedSecondaryStructure.id, computedSecondaryStructure.version) : -1; var colorMap = getAdjustedColorMap(SecondaryStructureColors, props.saturation, props.lightness); function color(location) { if (StructureElement.Location.is(location)) { return secondaryStructureColor(colorMap, location.unit, location.element, computedSecondaryStructure === null || computedSecondaryStructure === void 0 ? void 0 : computedSecondaryStructure.value); } else if (Bond.isLocation(location)) { return secondaryStructureColor(colorMap, location.aUnit, location.aUnit.elements[location.aIndex], computedSecondaryStructure === null || computedSecondaryStructure === void 0 ? void 0 : computedSecondaryStructure.value); } return DefaultSecondaryStructureColor; } return { factory: SecondaryStructureColorTheme, granularity: 'group', preferSmoothing: true, color: color, props: props, contextHash: contextHash, description: Description, legend: TableLegend(Object.keys(SecondaryStructureColors).map(function (name) { return [name, SecondaryStructureColors[name]]; }).concat([['Other', DefaultSecondaryStructureColor]])) }; } export var SecondaryStructureColorThemeProvider = { name: 'secondary-structure', label: 'Secondary Structure', category: "Residue Property" /* Residue */, factory: SecondaryStructureColorTheme, getParams: getSecondaryStructureColorThemeParams, defaultValues: PD.getDefaultValues(SecondaryStructureColorThemeParams), isApplicable: function (ctx) { return !!ctx.structure; }, ensureCustomProperties: { attach: function (ctx, data) { return data.structure ? SecondaryStructureProvider.attach(ctx, data.structure, void 0, true) : Promise.resolve(); }, detach: function (data) { return data.structure && SecondaryStructureProvider.ref(data.structure, false); } } }; //# sourceMappingURL=secondary-structure.js.map