UNPKG

molstar

Version:

A comprehensive macromolecular library.

209 lines 12.2 kB
"use strict"; /** * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Sebastian Bittrich <sebastian.bittrich@rcsb.org> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.tryCreateMembraneOrientation = exports.MembraneOrientationPreset = exports.MembraneOrientation3D = exports.isTransmembrane = exports.ANVILMembraneOrientation = void 0; var tslib_1 = require("tslib"); var param_definition_1 = require("../../mol-util/param-definition"); var representation_preset_1 = require("../../mol-plugin-state/builder/structure/representation-preset"); var prop_1 = require("./prop"); var mol_state_1 = require("../../mol-state"); var mol_task_1 = require("../../mol-task"); var behavior_1 = require("../../mol-plugin/behavior"); var representation_1 = require("./representation"); var hydrophobicity_1 = require("../../mol-theme/color/hydrophobicity"); var objects_1 = require("../../mol-plugin-state/objects"); var compiler_1 = require("../../mol-script/runtime/query/compiler"); var structure_selection_query_1 = require("../../mol-plugin-state/helpers/structure-selection-query"); var builder_1 = require("../../mol-script/language/builder"); var Tag = prop_1.MembraneOrientation.Tag; exports.ANVILMembraneOrientation = behavior_1.PluginBehavior.create({ name: 'anvil-membrane-orientation-prop', category: 'custom-props', display: { name: 'Membrane Orientation', description: 'Data calculated with ANVIL algorithm.' }, ctor: /** @class */ (function (_super) { (0, tslib_1.__extends)(class_1, _super); function class_1() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.provider = prop_1.MembraneOrientationProvider; return _this; } class_1.prototype.register = function () { compiler_1.DefaultQueryRuntimeTable.addCustomProp(this.provider.descriptor); this.ctx.customStructureProperties.register(this.provider, this.params.autoAttach); this.ctx.representation.structure.registry.add(representation_1.MembraneOrientationRepresentationProvider); this.ctx.query.structure.registry.add(exports.isTransmembrane); this.ctx.genericRepresentationControls.set(Tag.Representation, function (selection) { var refs = []; selection.structures.forEach(function (structure) { var _a; var memRepr = (_a = structure.genericRepresentations) === null || _a === void 0 ? void 0 : _a.filter(function (r) { return r.cell.transform.transformer.id === MembraneOrientation3D.id; })[0]; if (memRepr) refs.push(memRepr); }); return [refs, 'Membrane Orientation']; }); this.ctx.builders.structure.representation.registerPreset(exports.MembraneOrientationPreset); }; class_1.prototype.update = function (p) { var updated = this.params.autoAttach !== p.autoAttach; this.params.autoAttach = p.autoAttach; this.ctx.customStructureProperties.setDefaultAutoAttach(this.provider.descriptor.name, this.params.autoAttach); return updated; }; class_1.prototype.unregister = function () { compiler_1.DefaultQueryRuntimeTable.removeCustomProp(this.provider.descriptor); this.ctx.customStructureProperties.unregister(this.provider.descriptor.name); this.ctx.representation.structure.registry.remove(representation_1.MembraneOrientationRepresentationProvider); this.ctx.query.structure.registry.remove(exports.isTransmembrane); this.ctx.genericRepresentationControls.delete(Tag.Representation); this.ctx.builders.structure.representation.unregisterPreset(exports.MembraneOrientationPreset); }; return class_1; }(behavior_1.PluginBehavior.Handler)), params: function () { return ({ autoAttach: param_definition_1.ParamDefinition.Boolean(false) }); } }); // exports.isTransmembrane = (0, structure_selection_query_1.StructureSelectionQuery)('Residues Embedded in Membrane', builder_1.MolScriptBuilder.struct.modifier.union([ builder_1.MolScriptBuilder.struct.modifier.wholeResidues([ builder_1.MolScriptBuilder.struct.modifier.union([ builder_1.MolScriptBuilder.struct.generator.atomGroups({ 'chain-test': builder_1.MolScriptBuilder.core.rel.eq([builder_1.MolScriptBuilder.ammp('objectPrimitive'), 'atomistic']), 'atom-test': prop_1.MembraneOrientation.symbols.isTransmembrane.symbol(), }) ]) ]) ]), { description: 'Select residues that are embedded between the membrane layers.', category: structure_selection_query_1.StructureSelectionCategory.Residue, ensureCustomProperties: function (ctx, structure) { return prop_1.MembraneOrientationProvider.attach(ctx, structure); } }); var MembraneOrientation3D = objects_1.PluginStateTransform.BuiltIn({ name: 'membrane-orientation-3d', display: { name: 'Membrane Orientation', description: 'Membrane Orientation planes and rims. Data calculated with ANVIL algorithm.' }, from: objects_1.PluginStateObject.Molecule.Structure, to: objects_1.PluginStateObject.Shape.Representation3D, params: function (a) { return (0, tslib_1.__assign)({}, representation_1.MembraneOrientationParams); } })({ canAutoUpdate: function (_a) { var oldParams = _a.oldParams, newParams = _a.newParams; return true; }, apply: function (_a, plugin) { var _this = this; var a = _a.a, params = _a.params; return mol_task_1.Task.create('Membrane Orientation', function (ctx) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () { var repr; var _a; return (0, tslib_1.__generator)(this, function (_b) { switch (_b.label) { case 0: return [4 /*yield*/, prop_1.MembraneOrientationProvider.attach({ runtime: ctx, assetManager: plugin.managers.asset }, a.data)]; case 1: _b.sent(); repr = (0, representation_1.MembraneOrientationRepresentation)((0, tslib_1.__assign)({ webgl: (_a = plugin.canvas3d) === null || _a === void 0 ? void 0 : _a.webgl }, plugin.representation.structure.themes), function () { return representation_1.MembraneOrientationParams; }); return [4 /*yield*/, repr.createOrUpdate(params, a.data).runInContext(ctx)]; case 2: _b.sent(); return [2 /*return*/, new objects_1.PluginStateObject.Shape.Representation3D({ repr: repr, sourceData: a.data }, { label: 'Membrane Orientation' })]; } }); }); }); }, update: function (_a, plugin) { var _this = this; var a = _a.a, b = _a.b, newParams = _a.newParams; return mol_task_1.Task.create('Membrane Orientation', function (ctx) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () { var props; return (0, tslib_1.__generator)(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, prop_1.MembraneOrientationProvider.attach({ runtime: ctx, assetManager: plugin.managers.asset }, a.data)]; case 1: _a.sent(); props = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, b.data.repr.props), newParams); return [4 /*yield*/, b.data.repr.createOrUpdate(props, a.data).runInContext(ctx)]; case 2: _a.sent(); b.data.sourceData = a.data; return [2 /*return*/, mol_state_1.StateTransformer.UpdateResult.Updated]; } }); }); }); }, isApplicable: function (a) { return prop_1.MembraneOrientationProvider.isApplicable(a.data); } }); exports.MembraneOrientation3D = MembraneOrientation3D; exports.MembraneOrientationPreset = (0, representation_preset_1.StructureRepresentationPresetProvider)({ id: 'preset-membrane-orientation', display: { name: 'Membrane Orientation', group: 'Annotation', description: 'Shows orientation of membrane layers. Data calculated with ANVIL algorithm.' // TODO add ' or obtained via RCSB PDB' }, isApplicable: function (a) { return prop_1.MembraneOrientationProvider.isApplicable(a.data); }, params: function () { return representation_preset_1.StructureRepresentationPresetProvider.CommonParams; }, apply: function (ref, params, plugin) { var _a; return (0, tslib_1.__awaiter)(this, void 0, void 0, function () { var structureCell, structure, membraneOrientation, colorTheme, preset; var _this = this; return (0, tslib_1.__generator)(this, function (_b) { switch (_b.label) { case 0: structureCell = mol_state_1.StateObjectRef.resolveAndCheck(plugin.state.data, ref); structure = (_a = structureCell === null || structureCell === void 0 ? void 0 : structureCell.obj) === null || _a === void 0 ? void 0 : _a.data; if (!structureCell || !structure) return [2 /*return*/, {}]; if (!!prop_1.MembraneOrientationProvider.get(structure).value) return [3 /*break*/, 2]; return [4 /*yield*/, plugin.runTask(mol_task_1.Task.create('Membrane Orientation', function (runtime) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () { return (0, tslib_1.__generator)(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, prop_1.MembraneOrientationProvider.attach({ runtime: runtime, assetManager: plugin.managers.asset }, structure)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }))]; case 1: _b.sent(); _b.label = 2; case 2: return [4 /*yield*/, tryCreateMembraneOrientation(plugin, structureCell)]; case 3: membraneOrientation = _b.sent(); colorTheme = hydrophobicity_1.HydrophobicityColorThemeProvider.name; return [4 /*yield*/, representation_preset_1.PresetStructureRepresentations.auto.apply(ref, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, params), { theme: { globalName: colorTheme, focus: { name: colorTheme } } }), plugin)]; case 4: preset = _b.sent(); return [2 /*return*/, { components: preset.components, representations: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, preset.representations), { membraneOrientation: membraneOrientation }) }]; } }); }); } }); function tryCreateMembraneOrientation(plugin, structure, params, initialState) { var state = plugin.state.data; var membraneOrientation = state.build().to(structure) .applyOrUpdateTagged('membrane-orientation-3d', MembraneOrientation3D, params, { state: initialState }); return membraneOrientation.commit({ revertOnError: true }); } exports.tryCreateMembraneOrientation = tryCreateMembraneOrientation; //# sourceMappingURL=behavior.js.map