molstar
Version:
A comprehensive macromolecular library.
89 lines • 4.06 kB
JavaScript
/**
* Copyright (c) 2021 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.EntityIdColorThemeProvider = exports.EntityIdColorTheme = exports.getEntityIdColorThemeParams = exports.EntityIdColorThemeParams = void 0;
var tslib_1 = require("tslib");
var structure_1 = require("../../mol-model/structure");
var color_1 = require("../../mol-util/color");
var param_definition_1 = require("../../mol-util/param-definition");
var palette_1 = require("../../mol-util/color/palette");
var DefaultList = 'many-distinct';
var DefaultColor = (0, color_1.Color)(0xFAFAFA);
var Description = 'Gives every chain a color based on its `label_entity_id` value.';
exports.EntityIdColorThemeParams = (0, tslib_1.__assign)({}, (0, palette_1.getPaletteParams)({ type: 'colors', colorList: DefaultList }));
function getEntityIdColorThemeParams(ctx) {
var params = param_definition_1.ParamDefinition.clone(exports.EntityIdColorThemeParams);
return params;
}
exports.getEntityIdColorThemeParams = getEntityIdColorThemeParams;
function key(entityId, modelIndex) {
return entityId + "|" + modelIndex;
}
function getEntityIdSerialMap(structure) {
var map = new Map();
for (var i = 0, il = structure.models.length; i < il; ++i) {
var label_entity_id = structure.models[i].atomicHierarchy.chains.label_entity_id;
for (var j = 0, jl = label_entity_id.rowCount; j < jl; ++j) {
var k = key(label_entity_id.value(j), i);
if (!map.has(k))
map.set(k, map.size);
}
}
return map;
}
function EntityIdColorTheme(ctx, props) {
var color;
var legend;
if (ctx.structure) {
var l_1 = structure_1.StructureElement.Location.create(ctx.structure.root);
var entityIdSerialMap_1 = getEntityIdSerialMap(ctx.structure.root);
var labelTable_1 = Array.from(entityIdSerialMap_1.keys());
var valueLabel = function (i) { return labelTable_1[i]; };
var palette_2 = (0, palette_1.getPalette)(entityIdSerialMap_1.size, props, { valueLabel: valueLabel });
legend = palette_2.legend;
color = function (location) {
var serial = undefined;
if (structure_1.StructureElement.Location.is(location)) {
var atomId = structure_1.StructureProperties.chain.label_entity_id(location);
var modelIndex = location.structure.models.indexOf(location.unit.model);
var k = key(atomId, modelIndex);
serial = entityIdSerialMap_1.get(k);
}
else if (structure_1.Bond.isLocation(location)) {
l_1.unit = location.aUnit;
l_1.element = location.aUnit.elements[location.aIndex];
var atomId = structure_1.StructureProperties.chain.label_entity_id(l_1);
var modelIndex = l_1.structure.models.indexOf(l_1.unit.model);
var k = key(atomId, modelIndex);
serial = entityIdSerialMap_1.get(k);
}
return serial === undefined ? DefaultColor : palette_2.color(serial);
};
}
else {
color = function () { return DefaultColor; };
}
return {
factory: EntityIdColorTheme,
granularity: 'group',
color: color,
props: props,
description: Description,
legend: legend
};
}
exports.EntityIdColorTheme = EntityIdColorTheme;
exports.EntityIdColorThemeProvider = {
name: 'entity-id',
label: 'Entity Id',
category: "Chain Property" /* Chain */,
factory: EntityIdColorTheme,
getParams: getEntityIdColorThemeParams,
defaultValues: param_definition_1.ParamDefinition.getDefaultValues(exports.EntityIdColorThemeParams),
isApplicable: function (ctx) { return !!ctx.structure; }
};
//# sourceMappingURL=entity-id.js.map
;