molstar
Version:
A comprehensive macromolecular library.
77 lines • 3.64 kB
JavaScript
/**
* Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Sebastian Bittrich <sebastian.bittrich@rcsb.org>
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { ParamDefinition as PD } from '../../../mol-util/param-definition';
import { Color, ColorScale } from '../../../mol-util/color';
import { Bond, StructureElement, Unit } from '../../../mol-model/structure';
import { AccessibleSurfaceAreaProvider } from '../accessible-surface-area';
import { AccessibleSurfaceArea } from '../accessible-surface-area/shrake-rupley';
import { hash2 } from '../../../mol-data/util';
var DefaultColor = Color(0xFAFAFA);
var Description = 'Assigns a color based on the relative accessible surface area of a residue.';
export var AccessibleSurfaceAreaColorThemeParams = {
list: PD.ColorList('rainbow', { presetKind: 'scale' })
};
export function getAccessibleSurfaceAreaColorThemeParams(ctx) {
return AccessibleSurfaceAreaColorThemeParams; // TODO return copy
}
export function AccessibleSurfaceAreaColorTheme(ctx, props) {
var color;
var scale = ColorScale.create({
listOrName: props.list.colors,
minLabel: 'buried',
maxLabel: 'exposed',
domain: [0.0, 1.0]
});
var accessibleSurfaceArea = ctx.structure && AccessibleSurfaceAreaProvider.get(ctx.structure);
var contextHash = accessibleSurfaceArea ? hash2(accessibleSurfaceArea.id, accessibleSurfaceArea.version) : -1;
if ((accessibleSurfaceArea === null || accessibleSurfaceArea === void 0 ? void 0 : accessibleSurfaceArea.value) && ctx.structure) {
var l_1 = StructureElement.Location.create(ctx.structure);
var asa_1 = accessibleSurfaceArea.value;
var getColor_1 = function (location) {
var value = AccessibleSurfaceArea.getNormalizedValue(location, asa_1);
return value === -1 ? DefaultColor : scale.color(value);
};
color = function (location) {
if (StructureElement.Location.is(location) && Unit.isAtomic(location.unit)) {
return getColor_1(location);
}
else if (Bond.isLocation(location)) {
l_1.unit = location.aUnit;
l_1.element = location.aUnit.elements[location.aIndex];
return getColor_1(l_1);
}
return DefaultColor;
};
}
else {
color = function () { return DefaultColor; };
}
return {
factory: AccessibleSurfaceAreaColorTheme,
granularity: 'group',
preferSmoothing: true,
color: color,
props: props,
contextHash: contextHash,
description: Description,
legend: scale ? scale.legend : undefined
};
}
export var AccessibleSurfaceAreaColorThemeProvider = {
name: 'accessible-surface-area',
label: 'Accessible Surface Area',
category: "Residue Property" /* Residue */,
factory: AccessibleSurfaceAreaColorTheme,
getParams: getAccessibleSurfaceAreaColorThemeParams,
defaultValues: PD.getDefaultValues(AccessibleSurfaceAreaColorThemeParams),
isApplicable: function (ctx) { return !!ctx.structure; },
ensureCustomProperties: {
attach: function (ctx, data) { return data.structure ? AccessibleSurfaceAreaProvider.attach(ctx, data.structure, void 0, true) : Promise.resolve(); },
detach: function (data) { return data.structure && AccessibleSurfaceAreaProvider.ref(data.structure, false); }
}
};
//# sourceMappingURL=accessible-surface-area.js.map