molstar
Version:
A comprehensive macromolecular library.
120 lines (119 loc) • 5.12 kB
JavaScript
/**
* Copyright (c) 2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Mandar Deshpande <mandar@ebi.ac.uk>
* @author Sebastian Bittrich <sebastian.bittrich@rcsb.org>
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { __awaiter, __generator } from "tslib";
import { QualityAssessment, QualityAssessmentProvider } from '../prop';
import { Bond, StructureElement, Unit } from '../../../../mol-model/structure';
import { Color } from '../../../../mol-util/color';
import { ParamDefinition as PD } from '../../../../mol-util/param-definition';
import { TableLegend } from '../../../../mol-util/legend';
var DefaultColor = Color(0xaaaaaa);
var ConfidenceColors = {
'No Score': DefaultColor,
'Very Low': Color(0xff7d45),
'Low': Color(0xffdb13),
'Confident': Color(0x65cbf3),
'Very High': Color(0x0053d6)
};
var ConfidenceColorLegend = TableLegend(Object.entries(ConfidenceColors));
export function getPLDDTConfidenceColorThemeParams(ctx) {
return {};
}
export function PLDDTConfidenceColorTheme(ctx, props) {
var color = function () { return DefaultColor; };
if (ctx.structure) {
var l_1 = StructureElement.Location.create(ctx.structure.root);
var getColor_1 = function (location) {
var _a, _b;
var unit = location.unit, element = location.element;
if (!Unit.isAtomic(unit))
return DefaultColor;
var qualityAssessment = QualityAssessmentProvider.get(unit.model).value;
var score = (_b = (_a = qualityAssessment === null || qualityAssessment === void 0 ? void 0 : qualityAssessment.pLDDT) === null || _a === void 0 ? void 0 : _a.get(unit.model.atomicHierarchy.residueAtomSegments.index[element])) !== null && _b !== void 0 ? _b : -1;
if (score < 0) {
return DefaultColor;
}
else if (score <= 50) {
return Color(0xff7d45);
}
else if (score <= 70) {
return Color(0xffdb13);
}
else if (score <= 90) {
return Color(0x65cbf3);
}
else {
return Color(0x0053d6);
}
};
color = function (location) {
if (StructureElement.Location.is(location)) {
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;
};
}
return {
factory: PLDDTConfidenceColorTheme,
granularity: 'group',
preferSmoothing: true,
color: color,
props: props,
description: 'Assigns residue colors according to the pLDDT Confidence score.',
legend: ConfidenceColorLegend
};
}
export var PLDDTConfidenceColorThemeProvider = {
name: 'plddt-confidence',
label: 'pLDDT Confidence',
category: "Validation" /* ColorTheme.Category.Validation */,
factory: PLDDTConfidenceColorTheme,
getParams: getPLDDTConfidenceColorThemeParams,
defaultValues: PD.getDefaultValues(getPLDDTConfidenceColorThemeParams({})),
isApplicable: function (ctx) { var _a; return !!((_a = ctx.structure) === null || _a === void 0 ? void 0 : _a.models.some(function (m) { return QualityAssessment.isApplicable(m, 'pLDDT'); })); },
ensureCustomProperties: {
attach: function (ctx, data) { return __awaiter(void 0, void 0, void 0, function () {
var _i, _a, m;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
if (!data.structure) return [3 /*break*/, 4];
_i = 0, _a = data.structure.models;
_b.label = 1;
case 1:
if (!(_i < _a.length)) return [3 /*break*/, 4];
m = _a[_i];
return [4 /*yield*/, QualityAssessmentProvider.attach(ctx, m, void 0, true)];
case 2:
_b.sent();
_b.label = 3;
case 3:
_i++;
return [3 /*break*/, 1];
case 4: return [2 /*return*/];
}
});
}); },
detach: function (data) { return __awaiter(void 0, void 0, void 0, function () {
var _i, _a, m;
return __generator(this, function (_b) {
if (data.structure) {
for (_i = 0, _a = data.structure.models; _i < _a.length; _i++) {
m = _a[_i];
QualityAssessmentProvider.ref(m, false);
}
}
return [2 /*return*/];
});
}); }
}
};