molstar
Version:
A comprehensive macromolecular library.
125 lines • 6.45 kB
JavaScript
"use strict";
/**
* Copyright (c) 2018-2019 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.SecondaryStructureColorThemeProvider = exports.SecondaryStructureColorTheme = exports.secondaryStructureColor = exports.getSecondaryStructureColorThemeParams = exports.SecondaryStructureColorThemeParams = void 0;
var color_1 = require("../../mol-util/color");
var structure_1 = require("../../mol-model/structure");
var types_1 = require("../../mol-model/structure/model/types");
var util_1 = require("../../mol-model/structure/util");
var param_definition_1 = require("../../mol-util/param-definition");
var legend_1 = require("../../mol-util/legend");
var secondary_structure_1 = require("../../mol-model-props/computed/secondary-structure");
var color_2 = require("../../mol-util/color/color");
var util_2 = require("../../mol-data/util");
// from Jmol http://jmol.sourceforge.net/jscolors/ (shapely)
var SecondaryStructureColors = (0, color_1.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 = (0, color_1.Color)(0x808080);
var Description = 'Assigns a color based on the type of secondary structure and basic molecule type.';
exports.SecondaryStructureColorThemeParams = {
saturation: param_definition_1.ParamDefinition.Numeric(-1, { min: -6, max: 6, step: 0.1 }),
lightness: param_definition_1.ParamDefinition.Numeric(0, { min: -6, max: 6, step: 0.1 })
};
function getSecondaryStructureColorThemeParams(ctx) {
return exports.SecondaryStructureColorThemeParams; // TODO return copy
}
exports.getSecondaryStructureColorThemeParams = getSecondaryStructureColorThemeParams;
function secondaryStructureColor(colorMap, unit, element, computedSecondaryStructure) {
var secStrucType = types_1.SecondaryStructureType.create(0 /* None */);
if (computedSecondaryStructure && structure_1.Unit.isAtomic(unit)) {
var secondaryStructure = computedSecondaryStructure.get(unit.invariantId);
if (secondaryStructure)
secStrucType = secondaryStructure.type[secondaryStructure.getIndex(unit.residueIndex[element])];
}
if (types_1.SecondaryStructureType.is(secStrucType, 2 /* Helix */)) {
if (types_1.SecondaryStructureType.is(secStrucType, 2048 /* Helix3Ten */)) {
return colorMap.threeTenHelix;
}
else if (types_1.SecondaryStructureType.is(secStrucType, 32768 /* HelixPi */)) {
return colorMap.piHelix;
}
return colorMap.alphaHelix;
}
else if (types_1.SecondaryStructureType.is(secStrucType, 4 /* Beta */)) {
return colorMap.betaStrand;
}
else if (types_1.SecondaryStructureType.is(secStrucType, 8 /* Bend */)) {
return colorMap.bend;
}
else if (types_1.SecondaryStructureType.is(secStrucType, 16 /* Turn */)) {
return colorMap.turn;
}
else {
var moleculeType = (0, util_1.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;
}
exports.secondaryStructureColor = secondaryStructureColor;
function SecondaryStructureColorTheme(ctx, props) {
var computedSecondaryStructure = ctx.structure && secondary_structure_1.SecondaryStructureProvider.get(ctx.structure);
var contextHash = computedSecondaryStructure ? (0, util_2.hash2)(computedSecondaryStructure.id, computedSecondaryStructure.version) : -1;
var colorMap = (0, color_2.getAdjustedColorMap)(SecondaryStructureColors, props.saturation, props.lightness);
function color(location) {
if (structure_1.StructureElement.Location.is(location)) {
return secondaryStructureColor(colorMap, location.unit, location.element, computedSecondaryStructure === null || computedSecondaryStructure === void 0 ? void 0 : computedSecondaryStructure.value);
}
else if (structure_1.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: (0, legend_1.TableLegend)(Object.keys(SecondaryStructureColors).map(function (name) {
return [name, SecondaryStructureColors[name]];
}).concat([['Other', DefaultSecondaryStructureColor]]))
};
}
exports.SecondaryStructureColorTheme = SecondaryStructureColorTheme;
exports.SecondaryStructureColorThemeProvider = {
name: 'secondary-structure',
label: 'Secondary Structure',
category: "Residue Property" /* Residue */,
factory: SecondaryStructureColorTheme,
getParams: getSecondaryStructureColorThemeParams,
defaultValues: param_definition_1.ParamDefinition.getDefaultValues(exports.SecondaryStructureColorThemeParams),
isApplicable: function (ctx) { return !!ctx.structure; },
ensureCustomProperties: {
attach: function (ctx, data) { return data.structure ? secondary_structure_1.SecondaryStructureProvider.attach(ctx, data.structure, void 0, true) : Promise.resolve(); },
detach: function (data) { return data.structure && secondary_structure_1.SecondaryStructureProvider.ref(data.structure, false); }
}
};
//# sourceMappingURL=secondary-structure.js.map