UNPKG

molstar

Version:

A comprehensive macromolecular library.

93 lines 3.94 kB
/** * 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> */ import { StructureProperties, StructureElement, Bond } from '../../mol-model/structure'; import { Color } from '../../mol-util/color'; import { ParamDefinition as PD } from '../../mol-util/param-definition'; var Description = 'Gives every chain a color from a list based on its `asym_id` value.'; export function createProteopediaCustomTheme(colors) { var ProteopediaCustomColorThemeParams = { colors: PD.ObjectList({ color: PD.Color(Color(0xffffff)) }, function (_a) { var color = _a.color; return Color.toHexString(color); }, { defaultValue: colors.map(function (c) { return ({ color: Color(c) }); }) }) }; function getChainIdColorThemeParams(ctx) { return ProteopediaCustomColorThemeParams; // TODO return copy } function getAsymId(unit) { switch (unit.kind) { case 0 /* Atomic */: return StructureProperties.chain.label_asym_id; case 1 /* Spheres */: case 2 /* Gaussians */: return 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 = 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 (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 (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: PD.getDefaultValues(ProteopediaCustomColorThemeParams), isApplicable: function (ctx) { return !!ctx.structure; } }; } //# sourceMappingURL=coloring.js.map