UNPKG

molstar

Version:

A comprehensive macromolecular library.

234 lines 12.8 kB
/** * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { __assign, __awaiter, __generator } from "tslib"; import { Structure } from '../../mol-model/structure'; import { PluginStateObject as PSO, PluginStateTransform } from '../../mol-plugin-state/objects'; import { createPlugin } from '../../mol-plugin-ui'; import { DefaultPluginUISpec } from '../../mol-plugin-ui/spec'; import { PluginBehaviors } from '../../mol-plugin/behavior'; import { PluginCommands } from '../../mol-plugin/commands'; import { PluginConfig } from '../../mol-plugin/config'; import { PluginSpec } from '../../mol-plugin/spec'; import { StateObject } from '../../mol-state'; import { Task } from '../../mol-task'; import { Color } from '../../mol-util/color'; import { ColorNames } from '../../mol-util/color/names'; import { ParamDefinition as PD } from '../../mol-util/param-definition'; import '../../mol-util/polyfill'; import { ObjectKeys } from '../../mol-util/type-helpers'; import './index.html'; import { ShowButtons, StructurePreset, ViewportComponent } from './viewport'; require('mol-plugin-ui/skin/light.scss'); export { PLUGIN_VERSION as version } from '../../mol-plugin/version'; export { setDebugMode, setProductionMode } from '../../mol-util/debug'; export { Viewer as DockingViewer }; var DefaultViewerOptions = { extensions: ObjectKeys({}), layoutIsExpanded: true, layoutShowControls: true, layoutShowRemoteState: true, layoutControlsDisplay: 'reactive', layoutShowSequence: true, layoutShowLog: true, layoutShowLeftPanel: true, viewportShowExpand: PluginConfig.Viewport.ShowExpand.defaultValue, viewportShowControls: PluginConfig.Viewport.ShowControls.defaultValue, viewportShowSettings: PluginConfig.Viewport.ShowSettings.defaultValue, viewportShowSelectionMode: PluginConfig.Viewport.ShowSelectionMode.defaultValue, viewportShowAnimation: PluginConfig.Viewport.ShowAnimation.defaultValue, pluginStateServer: PluginConfig.State.DefaultServer.defaultValue, volumeStreamingServer: PluginConfig.VolumeStreaming.DefaultServer.defaultValue, pdbProvider: PluginConfig.Download.DefaultPdbProvider.defaultValue, emdbProvider: PluginConfig.Download.DefaultEmdbProvider.defaultValue, }; var Viewer = /** @class */ (function () { function Viewer(elementOrId, colors, showButtons) { var _this = this; if (colors === void 0) { colors = [Color(0x992211), Color(0xDDDDDD)]; } if (showButtons === void 0) { showButtons = true; } var _a; var o = __assign(__assign({}, DefaultViewerOptions), { layoutIsExpanded: false, layoutShowControls: false, layoutShowRemoteState: false, layoutShowSequence: true, layoutShowLog: false, layoutShowLeftPanel: true, viewportShowExpand: true, viewportShowControls: false, viewportShowSettings: false, viewportShowSelectionMode: false, viewportShowAnimation: false, }); var defaultSpec = DefaultPluginUISpec(); var spec = { actions: defaultSpec.actions, behaviors: [ PluginSpec.Behavior(PluginBehaviors.Representation.HighlightLoci, { mark: false }), PluginSpec.Behavior(PluginBehaviors.Representation.DefaultLociLabelProvider), PluginSpec.Behavior(PluginBehaviors.Camera.FocusLoci), PluginSpec.Behavior(PluginBehaviors.CustomProps.StructureInfo), PluginSpec.Behavior(PluginBehaviors.CustomProps.Interactions), PluginSpec.Behavior(PluginBehaviors.CustomProps.SecondaryStructure), ], animations: defaultSpec.animations, customParamEditors: defaultSpec.customParamEditors, layout: { initial: { isExpanded: o.layoutIsExpanded, showControls: o.layoutShowControls, controlsDisplay: o.layoutControlsDisplay, }, }, components: __assign(__assign({}, defaultSpec.components), { controls: __assign(__assign({}, (_a = defaultSpec.components) === null || _a === void 0 ? void 0 : _a.controls), { top: o.layoutShowSequence ? undefined : 'none', bottom: o.layoutShowLog ? undefined : 'none', left: o.layoutShowLeftPanel ? undefined : 'none' }), remoteState: o.layoutShowRemoteState ? 'default' : 'none', viewport: { view: ViewportComponent } }), config: [ [PluginConfig.Viewport.ShowExpand, o.viewportShowExpand], [PluginConfig.Viewport.ShowControls, o.viewportShowControls], [PluginConfig.Viewport.ShowSettings, o.viewportShowSettings], [PluginConfig.Viewport.ShowSelectionMode, o.viewportShowSelectionMode], [PluginConfig.Viewport.ShowAnimation, o.viewportShowAnimation], [PluginConfig.State.DefaultServer, o.pluginStateServer], [PluginConfig.State.CurrentServer, o.pluginStateServer], [PluginConfig.VolumeStreaming.DefaultServer, o.volumeStreamingServer], [PluginConfig.Download.DefaultPdbProvider, o.pdbProvider], [PluginConfig.Download.DefaultEmdbProvider, o.emdbProvider], [ShowButtons, showButtons] ] }; var element = typeof elementOrId === 'string' ? document.getElementById(elementOrId) : elementOrId; if (!element) throw new Error("Could not get element with id '" + elementOrId + "'"); this.plugin = createPlugin(element, spec); this.plugin.customState = { colorPalette: { name: 'colors', params: { list: { colors: colors } } } }; this.plugin.behaviors.canvas3d.initialized.subscribe(function (v) { if (v) { PluginCommands.Canvas3D.SetSettings(_this.plugin, { settings: { renderer: __assign(__assign({}, _this.plugin.canvas3d.props.renderer), { backgroundColor: ColorNames.white }), camera: __assign(__assign({}, _this.plugin.canvas3d.props.camera), { helper: { axes: { name: 'off', params: {} } } }) } }); } }); } Viewer.prototype.loadStructuresFromUrlsAndMerge = function (sources) { return __awaiter(this, void 0, void 0, function () { var structures, _i, sources_1, _a, url, format, isBinary, data_1, trajectory, model, modelProperties, structure_1, structureProperties_1, dependsOn, data, structure, structureProperties; var _this = this; return __generator(this, function (_b) { switch (_b.label) { case 0: structures = []; _i = 0, sources_1 = sources; _b.label = 1; case 1: if (!(_i < sources_1.length)) return [3 /*break*/, 9]; _a = sources_1[_i], url = _a.url, format = _a.format, isBinary = _a.isBinary; return [4 /*yield*/, this.plugin.builders.data.download({ url: url, isBinary: isBinary })]; case 2: data_1 = _b.sent(); return [4 /*yield*/, this.plugin.builders.structure.parseTrajectory(data_1, format)]; case 3: trajectory = _b.sent(); return [4 /*yield*/, this.plugin.builders.structure.createModel(trajectory)]; case 4: model = _b.sent(); return [4 /*yield*/, this.plugin.builders.structure.insertModelProperties(model)]; case 5: modelProperties = _b.sent(); return [4 /*yield*/, this.plugin.builders.structure.createStructure(modelProperties || model)]; case 6: structure_1 = _b.sent(); return [4 /*yield*/, this.plugin.builders.structure.insertStructureProperties(structure_1)]; case 7: structureProperties_1 = _b.sent(); structures.push({ ref: (structureProperties_1 === null || structureProperties_1 === void 0 ? void 0 : structureProperties_1.ref) || structure_1.ref }); _b.label = 8; case 8: _i++; return [3 /*break*/, 1]; case 9: // remove current structuresfrom hierarchy as they will be merged // TODO only works with using loadStructuresFromUrlsAndMerge once // need some more API metho to work with the hierarchy this.plugin.managers.structure.hierarchy.updateCurrent(this.plugin.managers.structure.hierarchy.current.structures, 'remove'); dependsOn = structures.map(function (_a) { var ref = _a.ref; return ref; }); data = this.plugin.state.data.build().toRoot().apply(MergeStructures, { structures: structures }, { dependsOn: dependsOn }); return [4 /*yield*/, data.commit()]; case 10: structure = _b.sent(); return [4 /*yield*/, this.plugin.builders.structure.insertStructureProperties(structure)]; case 11: structureProperties = _b.sent(); this.plugin.behaviors.canvas3d.initialized.subscribe(function (v) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.plugin.builders.structure.representation.applyPreset(structureProperties || structure, StructurePreset)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }); return [2 /*return*/]; } }); }); }; return Viewer; }()); var MergeStructures = PluginStateTransform.BuiltIn({ name: 'merge-structures', display: { name: 'Merge Structures', description: 'Merge Structure' }, from: PSO.Root, to: PSO.Molecule.Structure, params: { structures: PD.ObjectList({ ref: PD.Text('') }, function (_a) { var ref = _a.ref; return ref; }, { isHidden: true }) } })({ apply: function (_a) { var _this = this; var params = _a.params, dependencies = _a.dependencies; return Task.create('Merge Structures', function (ctx) { return __awaiter(_this, void 0, void 0, function () { var first, builder, _i, _a, ref, s, _b, _c, unit, structure; return __generator(this, function (_d) { if (params.structures.length === 0) return [2 /*return*/, StateObject.Null]; first = dependencies[params.structures[0].ref].data; builder = Structure.Builder({ masterModel: first.models[0] }); for (_i = 0, _a = params.structures; _i < _a.length; _i++) { ref = _a[_i].ref; s = dependencies[ref].data; for (_b = 0, _c = s.units; _b < _c.length; _b++) { unit = _c[_b]; // TODO invariantId builder.addUnit(unit.kind, unit.model, unit.conformation.operator, unit.elements, unit.traits); } } structure = builder.getStructure(); return [2 /*return*/, new PSO.Molecule.Structure(structure, { label: 'Merged Structure' })]; }); }); }); } }); window.DockingViewer = Viewer; //# sourceMappingURL=index.js.map