UNPKG

molstar

Version:

A comprehensive macromolecular library.

136 lines (135 loc) 7.03 kB
/** * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { __extends } from "tslib"; import { PluginBehavior } from '../../../behavior'; import { ParamDefinition as PD } from '../../../../../mol-util/param-definition'; import { AccessibleSurfaceAreaProvider, AccessibleSurfaceAreaSymbols } from '../../../../../mol-model-props/computed/accessible-surface-area'; import { AccessibleSurfaceAreaColorThemeProvider } from '../../../../../mol-model-props/computed/themes/accessible-surface-area'; import { OrderedSet } from '../../../../../mol-data/int'; import { arraySum } from '../../../../../mol-util/array'; import { DefaultQueryRuntimeTable } from '../../../../../mol-script/runtime/query/compiler'; import { StructureSelectionQuery, StructureSelectionCategory } from '../../../../../mol-plugin-state/helpers/structure-selection-query'; import { MolScriptBuilder as MS } from '../../../../../mol-script/language/builder'; export var AccessibleSurfaceArea = PluginBehavior.create({ name: 'computed-accessible-surface-area-prop', category: 'custom-props', display: { name: 'Accessible Surface Area' }, ctor: /** @class */ (function (_super) { __extends(class_1, _super); function class_1() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.provider = AccessibleSurfaceAreaProvider; _this.labelProvider = { label: function (loci) { if (!_this.params.showTooltip) return; return accessibleSurfaceAreaLabel(loci); } }; return _this; } class_1.prototype.update = function (p) { var updated = (this.params.autoAttach !== p.autoAttach || this.params.showTooltip !== p.showTooltip); this.params.autoAttach = p.autoAttach; this.params.showTooltip = p.showTooltip; this.ctx.customStructureProperties.setDefaultAutoAttach(this.provider.descriptor.name, this.params.autoAttach); return updated; }; class_1.prototype.register = function () { DefaultQueryRuntimeTable.addCustomProp(this.provider.descriptor); this.ctx.customStructureProperties.register(this.provider, this.params.autoAttach); this.ctx.representation.structure.themes.colorThemeRegistry.add(AccessibleSurfaceAreaColorThemeProvider); this.ctx.managers.lociLabels.addProvider(this.labelProvider); this.ctx.query.structure.registry.add(isBuried); this.ctx.query.structure.registry.add(isAccessible); }; class_1.prototype.unregister = function () { DefaultQueryRuntimeTable.removeCustomProp(this.provider.descriptor); this.ctx.customStructureProperties.unregister(this.provider.descriptor.name); this.ctx.representation.structure.themes.colorThemeRegistry.remove(AccessibleSurfaceAreaColorThemeProvider); this.ctx.managers.lociLabels.removeProvider(this.labelProvider); this.ctx.query.structure.registry.remove(isBuried); this.ctx.query.structure.registry.remove(isAccessible); }; return class_1; }(PluginBehavior.Handler)), params: function () { return ({ autoAttach: PD.Boolean(false), showTooltip: PD.Boolean(true) }); } }); // function accessibleSurfaceAreaLabel(loci) { if (loci.kind === 'element-loci') { if (loci.elements.length === 0) return; var accessibleSurfaceArea = AccessibleSurfaceAreaProvider.get(loci.structure).value; if (!accessibleSurfaceArea || loci.structure.customPropertyDescriptors.hasReference(AccessibleSurfaceAreaProvider.descriptor)) return; var getSerialIndex_1 = loci.structure.root.serialMapping.getSerialIndex; var area_1 = accessibleSurfaceArea.area, serialResidueIndex_1 = accessibleSurfaceArea.serialResidueIndex; var seen_1 = new Set(); var cummulativeArea_1 = 0; var _loop_1 = function (indices, unit) { var elements = unit.elements; OrderedSet.forEach(indices, function (idx) { var rSI = serialResidueIndex_1[getSerialIndex_1(unit, elements[idx])]; if (rSI !== -1 && !seen_1.has(rSI)) { cummulativeArea_1 += area_1[rSI]; seen_1.add(rSI); } }); }; for (var _i = 0, _a = loci.elements; _i < _a.length; _i++) { var _b = _a[_i], indices = _b.indices, unit = _b.unit; _loop_1(indices, unit); } if (seen_1.size === 0) return; var residueCount = "<small>(".concat(seen_1.size, " ").concat(seen_1.size > 1 ? 'Residues sum' : 'Residue', ")</small>"); return "Accessible Surface Area ".concat(residueCount, ": ").concat(cummulativeArea_1.toFixed(2), " \u212B<sup>2</sup>"); } else if (loci.kind === 'structure-loci') { var accessibleSurfaceArea = AccessibleSurfaceAreaProvider.get(loci.structure).value; if (!accessibleSurfaceArea || loci.structure.customPropertyDescriptors.hasReference(AccessibleSurfaceAreaProvider.descriptor)) return; return "Accessible Surface Area <small>(Whole Structure)</small>: ".concat(arraySum(accessibleSurfaceArea.area).toFixed(2), " \u212B<sup>2</sup>"); } } // var isBuried = StructureSelectionQuery('Buried Protein Residues', MS.struct.modifier.union([ MS.struct.modifier.wholeResidues([ MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'chain-test': MS.core.rel.eq([MS.ammp('objectPrimitive'), 'atomistic']), 'residue-test': AccessibleSurfaceAreaSymbols.isBuried.symbol(), }) ]) ]) ]), { description: 'Select buried protein residues.', category: StructureSelectionCategory.Residue, ensureCustomProperties: function (ctx, structure) { return AccessibleSurfaceAreaProvider.attach(ctx, structure); } }); var isAccessible = StructureSelectionQuery('Accessible Protein Residues', MS.struct.modifier.union([ MS.struct.modifier.wholeResidues([ MS.struct.modifier.union([ MS.struct.generator.atomGroups({ 'chain-test': MS.core.rel.eq([MS.ammp('objectPrimitive'), 'atomistic']), 'residue-test': AccessibleSurfaceAreaSymbols.isAccessible.symbol(), }) ]) ]) ]), { description: 'Select accessible protein residues.', category: StructureSelectionCategory.Residue, ensureCustomProperties: function (ctx, structure) { return AccessibleSurfaceAreaProvider.attach(ctx, structure); } });