UNPKG

molstar

Version:

A comprehensive macromolecular library.

97 lines 4.28 kB
"use strict"; /** * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> * @author David Sehnal <david.sehnal@gmail.com> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.createProteopediaCustomTheme = void 0; var structure_1 = require("../../mol-model/structure"); var color_1 = require("../../mol-util/color"); var param_definition_1 = require("../../mol-util/param-definition"); var Description = 'Gives every chain a color from a list based on its `asym_id` value.'; function createProteopediaCustomTheme(colors) { var ProteopediaCustomColorThemeParams = { colors: param_definition_1.ParamDefinition.ObjectList({ color: param_definition_1.ParamDefinition.Color((0, color_1.Color)(0xffffff)) }, function (_a) { var color = _a.color; return color_1.Color.toHexString(color); }, { defaultValue: colors.map(function (c) { return ({ color: (0, color_1.Color)(c) }); }) }) }; function getChainIdColorThemeParams(ctx) { return ProteopediaCustomColorThemeParams; // TODO return copy } function getAsymId(unit) { switch (unit.kind) { case 0 /* Atomic */: return structure_1.StructureProperties.chain.label_asym_id; case 1 /* Spheres */: case 2 /* Gaussians */: return structure_1.StructureProperties.coarse.asym_id; } } function addAsymIds(map, data) { var j = map.size; for (var o = 0, ol = data.rowCount; o < ol; ++o) { var k = data.value(o); if (!map.has(k)) { map.set(k, j); j += 1; } } } function ProteopediaCustomColorTheme(ctx, props) { var color; var colors = props.colors, colorCount = colors.length, defaultColor = colors[0].color; if (ctx.structure) { var l_1 = structure_1.StructureElement.Location.create(ctx.structure); var models = ctx.structure.models; var asymIdSerialMap_1 = new Map(); for (var i = 0, il = models.length; i < il; ++i) { var m = models[i]; addAsymIds(asymIdSerialMap_1, m.atomicHierarchy.chains.label_asym_id); if (m.coarseHierarchy.isDefined) { addAsymIds(asymIdSerialMap_1, m.coarseHierarchy.spheres.asym_id); addAsymIds(asymIdSerialMap_1, m.coarseHierarchy.gaussians.asym_id); } } color = function (location) { if (structure_1.StructureElement.Location.is(location)) { var asym_id = getAsymId(location.unit); var o = asymIdSerialMap_1.get(asym_id(location)) || 0; return colors[o % colorCount].color; } else if (structure_1.Bond.isLocation(location)) { var asym_id = getAsymId(location.aUnit); l_1.unit = location.aUnit; l_1.element = location.aUnit.elements[location.aIndex]; var o = asymIdSerialMap_1.get(asym_id(l_1)) || 0; return colors[o % colorCount].color; } return defaultColor; }; } else { color = function () { return defaultColor; }; } return { factory: ProteopediaCustomColorTheme, granularity: 'group', color: color, props: props, description: Description, legend: undefined }; } return { name: 'proteopedia-custom', label: 'Proteopedia Custom', category: 'Custom', factory: ProteopediaCustomColorTheme, getParams: getChainIdColorThemeParams, defaultValues: param_definition_1.ParamDefinition.getDefaultValues(ProteopediaCustomColorThemeParams), isApplicable: function (ctx) { return !!ctx.structure; } }; } exports.createProteopediaCustomTheme = createProteopediaCustomTheme; //# sourceMappingURL=coloring.js.map