molstar
Version:
A comprehensive macromolecular library.
79 lines • 3.22 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 atom a color based on its `label_atom_id` value.';
export var AtomIdColorThemeParams = __assign({}, getPaletteParams({ type: 'colors', colorList: DefaultList }));
export function getAtomIdColorThemeParams(ctx) {
var params = PD.clone(AtomIdColorThemeParams);
return params;
}
function getAtomIdSerialMap(structure) {
var map = new Map();
for (var _i = 0, _a = structure.models; _i < _a.length; _i++) {
var m = _a[_i];
var label_atom_id = m.atomicHierarchy.atoms.label_atom_id;
for (var i = 0, il = label_atom_id.rowCount; i < il; ++i) {
var id = label_atom_id.value(i);
if (!map.has(id))
map.set(id, map.size);
}
}
return map;
}
export function AtomIdColorTheme(ctx, props) {
var color;
var legend;
if (ctx.structure) {
var l_1 = StructureElement.Location.create(ctx.structure.root);
var atomIdSerialMap_1 = getAtomIdSerialMap(ctx.structure.root);
var labelTable_1 = Array.from(atomIdSerialMap_1.keys());
var valueLabel = function (i) { return labelTable_1[i]; };
var palette_1 = getPalette(atomIdSerialMap_1.size, props, { valueLabel: valueLabel });
legend = palette_1.legend;
color = function (location) {
var serial = undefined;
if (StructureElement.Location.is(location)) {
var id = StructureProperties.atom.label_atom_id(location);
serial = atomIdSerialMap_1.get(id);
}
else if (Bond.isLocation(location)) {
l_1.unit = location.aUnit;
l_1.element = location.aUnit.elements[location.aIndex];
var id = StructureProperties.atom.label_atom_id(l_1);
serial = atomIdSerialMap_1.get(id);
}
return serial === undefined ? DefaultColor : palette_1.color(serial);
};
}
else {
color = function () { return DefaultColor; };
}
return {
factory: AtomIdColorTheme,
granularity: 'group',
preferSmoothing: true,
color: color,
props: props,
description: Description,
legend: legend
};
}
export var AtomIdColorThemeProvider = {
name: 'atom-id',
label: 'Atom Id',
category: "Atom Property" /* Atom */,
factory: AtomIdColorTheme,
getParams: getAtomIdColorThemeParams,
defaultValues: PD.getDefaultValues(AtomIdColorThemeParams),
isApplicable: function (ctx) { return !!ctx.structure; }
};
//# sourceMappingURL=atom-id.js.map