molstar
Version:
A comprehensive macromolecular library.
206 lines • 11.4 kB
JavaScript
/**
* 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>
*/
import { __assign, __awaiter, __extends, __generator } from "tslib";
import { ParamDefinition as PD } from '../../mol-util/param-definition';
import { StructureRepresentationPresetProvider, PresetStructureRepresentations } from '../../mol-plugin-state/builder/structure/representation-preset';
import { MembraneOrientationProvider, MembraneOrientation } from './prop';
import { StateObjectRef, StateTransformer } from '../../mol-state';
import { Task } from '../../mol-task';
import { PluginBehavior } from '../../mol-plugin/behavior';
import { MembraneOrientationRepresentationProvider, MembraneOrientationParams, MembraneOrientationRepresentation } from './representation';
import { HydrophobicityColorThemeProvider } from '../../mol-theme/color/hydrophobicity';
import { PluginStateObject, PluginStateTransform } from '../../mol-plugin-state/objects';
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';
var Tag = MembraneOrientation.Tag;
export var ANVILMembraneOrientation = PluginBehavior.create({
name: 'anvil-membrane-orientation-prop',
category: 'custom-props',
display: {
name: 'Membrane Orientation',
description: 'Data calculated with ANVIL algorithm.'
},
ctor: /** @class */ (function (_super) {
__extends(class_1, _super);
function class_1() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.provider = MembraneOrientationProvider;
return _this;
}
class_1.prototype.register = function () {
DefaultQueryRuntimeTable.addCustomProp(this.provider.descriptor);
this.ctx.customStructureProperties.register(this.provider, this.params.autoAttach);
this.ctx.representation.structure.registry.add(MembraneOrientationRepresentationProvider);
this.ctx.query.structure.registry.add(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(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 () {
DefaultQueryRuntimeTable.removeCustomProp(this.provider.descriptor);
this.ctx.customStructureProperties.unregister(this.provider.descriptor.name);
this.ctx.representation.structure.registry.remove(MembraneOrientationRepresentationProvider);
this.ctx.query.structure.registry.remove(isTransmembrane);
this.ctx.genericRepresentationControls.delete(Tag.Representation);
this.ctx.builders.structure.representation.unregisterPreset(MembraneOrientationPreset);
};
return class_1;
}(PluginBehavior.Handler)),
params: function () { return ({
autoAttach: PD.Boolean(false)
}); }
});
//
export var isTransmembrane = StructureSelectionQuery('Residues Embedded in Membrane', 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']),
'atom-test': MembraneOrientation.symbols.isTransmembrane.symbol(),
})
])
])
]), {
description: 'Select residues that are embedded between the membrane layers.',
category: StructureSelectionCategory.Residue,
ensureCustomProperties: function (ctx, structure) {
return MembraneOrientationProvider.attach(ctx, structure);
}
});
//
export { MembraneOrientation3D };
var MembraneOrientation3D = PluginStateTransform.BuiltIn({
name: 'membrane-orientation-3d',
display: {
name: 'Membrane Orientation',
description: 'Membrane Orientation planes and rims. Data calculated with ANVIL algorithm.'
},
from: PluginStateObject.Molecule.Structure,
to: PluginStateObject.Shape.Representation3D,
params: function (a) {
return __assign({}, 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 Task.create('Membrane Orientation', function (ctx) { return __awaiter(_this, void 0, void 0, function () {
var repr;
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, MembraneOrientationProvider.attach({ runtime: ctx, assetManager: plugin.managers.asset }, a.data)];
case 1:
_b.sent();
repr = MembraneOrientationRepresentation(__assign({ webgl: (_a = plugin.canvas3d) === null || _a === void 0 ? void 0 : _a.webgl }, plugin.representation.structure.themes), function () { return MembraneOrientationParams; });
return [4 /*yield*/, repr.createOrUpdate(params, a.data).runInContext(ctx)];
case 2:
_b.sent();
return [2 /*return*/, new 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 Task.create('Membrane Orientation', function (ctx) { return __awaiter(_this, void 0, void 0, function () {
var props;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, MembraneOrientationProvider.attach({ runtime: ctx, assetManager: plugin.managers.asset }, a.data)];
case 1:
_a.sent();
props = __assign(__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*/, StateTransformer.UpdateResult.Updated];
}
});
}); });
},
isApplicable: function (a) {
return MembraneOrientationProvider.isApplicable(a.data);
}
});
export var MembraneOrientationPreset = 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 MembraneOrientationProvider.isApplicable(a.data);
},
params: function () { return StructureRepresentationPresetProvider.CommonParams; },
apply: function (ref, params, plugin) {
var _a;
return __awaiter(this, void 0, void 0, function () {
var structureCell, structure, membraneOrientation, colorTheme, preset;
var _this = this;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
structureCell = 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 (!!MembraneOrientationProvider.get(structure).value) return [3 /*break*/, 2];
return [4 /*yield*/, plugin.runTask(Task.create('Membrane Orientation', function (runtime) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, 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 = HydrophobicityColorThemeProvider.name;
return [4 /*yield*/, PresetStructureRepresentations.auto.apply(ref, __assign(__assign({}, params), { theme: { globalName: colorTheme, focus: { name: colorTheme } } }), plugin)];
case 4:
preset = _b.sent();
return [2 /*return*/, { components: preset.components, representations: __assign(__assign({}, preset.representations), { membraneOrientation: membraneOrientation }) }];
}
});
});
}
});
export 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 });
}
//# sourceMappingURL=behavior.js.map