molstar
Version:
A comprehensive macromolecular library.
84 lines • 3.6 kB
JavaScript
/**
* Copyright (c) 2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { __assign } from "tslib";
import { StructureProperties, StructureElement, Bond } from '../../mol-model/structure';
import { Color } from '../../mol-util/color';
import { ParamDefinition as PD } from '../../mol-util/param-definition';
import { getPaletteParams, getPalette } from '../../mol-util/color/palette';
var DefaultList = 'many-distinct';
var DefaultColor = Color(0xFAFAFA);
var Description = 'Gives every chain a color based on its `label_entity_id` value.';
export var EntityIdColorThemeParams = __assign({}, getPaletteParams({ type: 'colors', colorList: DefaultList }));
export function getEntityIdColorThemeParams(ctx) {
var params = PD.clone(EntityIdColorThemeParams);
return params;
}
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;
}
export function EntityIdColorTheme(ctx, props) {
var color;
var legend;
if (ctx.structure) {
var l_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_1 = getPalette(entityIdSerialMap_1.size, props, { valueLabel: valueLabel });
legend = palette_1.legend;
color = function (location) {
var serial = undefined;
if (StructureElement.Location.is(location)) {
var atomId = 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 (Bond.isLocation(location)) {
l_1.unit = location.aUnit;
l_1.element = location.aUnit.elements[location.aIndex];
var atomId = 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_1.color(serial);
};
}
else {
color = function () { return DefaultColor; };
}
return {
factory: EntityIdColorTheme,
granularity: 'group',
color: color,
props: props,
description: Description,
legend: legend
};
}
export var EntityIdColorThemeProvider = {
name: 'entity-id',
label: 'Entity Id',
category: "Chain Property" /* Chain */,
factory: EntityIdColorTheme,
getParams: getEntityIdColorThemeParams,
defaultValues: PD.getDefaultValues(EntityIdColorThemeParams),
isApplicable: function (ctx) { return !!ctx.structure; }
};
//# sourceMappingURL=entity-id.js.map