UNPKG

molstar

Version:

A comprehensive macromolecular library.

350 lines 19.6 kB
"use strict"; /** * Copyright (c) 2018-2021 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> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Viewer = exports.setProductionMode = exports.setDebugMode = exports.version = void 0; var tslib_1 = require("tslib"); var behavior_1 = require("../../extensions/anvil/behavior"); var cellpack_1 = require("../../extensions/cellpack"); var dnatco_1 = require("../../extensions/dnatco"); var format_1 = require("../../extensions/g3d/format"); var mp4_export_1 = require("../../extensions/mp4-export"); var geo_export_1 = require("../../extensions/geo-export"); var pdbe_1 = require("../../extensions/pdbe"); var rcsb_1 = require("../../extensions/rcsb"); var structure_1 = require("../../mol-plugin-state/actions/structure"); var volume_1 = require("../../mol-plugin-state/actions/volume"); var volume_representation_params_1 = require("../../mol-plugin-state/helpers/volume-representation-params"); var transforms_1 = require("../../mol-plugin-state/transforms"); var mol_plugin_ui_1 = require("../../mol-plugin-ui"); var spec_1 = require("../../mol-plugin-ui/spec"); var commands_1 = require("../../mol-plugin/commands"); var config_1 = require("../../mol-plugin/config"); var spec_2 = require("../../mol-plugin/spec"); var assets_1 = require("../../mol-util/assets"); require("../../mol-util/polyfill"); var type_helpers_1 = require("../../mol-util/type-helpers"); require("./embedded.html"); require("./favicon.ico"); require("./index.html"); require('mol-plugin-ui/skin/light.scss'); var version_1 = require("../../mol-plugin/version"); Object.defineProperty(exports, "version", { enumerable: true, get: function () { return version_1.PLUGIN_VERSION; } }); var debug_1 = require("../../mol-util/debug"); Object.defineProperty(exports, "setDebugMode", { enumerable: true, get: function () { return debug_1.setDebugMode; } }); Object.defineProperty(exports, "setProductionMode", { enumerable: true, get: function () { return debug_1.setProductionMode; } }); var CustomFormats = [ ['g3d', format_1.G3dProvider] ]; var Extensions = { 'cellpack': spec_2.PluginSpec.Behavior(cellpack_1.CellPack), 'dnatco-confal-pyramids': spec_2.PluginSpec.Behavior(dnatco_1.DnatcoConfalPyramids), 'pdbe-structure-quality-report': spec_2.PluginSpec.Behavior(pdbe_1.PDBeStructureQualityReport), 'rcsb-assembly-symmetry': spec_2.PluginSpec.Behavior(rcsb_1.RCSBAssemblySymmetry), 'rcsb-validation-report': spec_2.PluginSpec.Behavior(rcsb_1.RCSBValidationReport), 'anvil-membrane-orientation': spec_2.PluginSpec.Behavior(behavior_1.ANVILMembraneOrientation), 'g3d': spec_2.PluginSpec.Behavior(format_1.G3DFormat), 'mp4-export': spec_2.PluginSpec.Behavior(mp4_export_1.Mp4Export), 'geo-export': spec_2.PluginSpec.Behavior(geo_export_1.GeometryExport) }; var DefaultViewerOptions = { customFormats: CustomFormats, extensions: (0, type_helpers_1.ObjectKeys)(Extensions), layoutIsExpanded: true, layoutShowControls: true, layoutShowRemoteState: true, layoutControlsDisplay: 'reactive', layoutShowSequence: true, layoutShowLog: true, layoutShowLeftPanel: true, collapseLeftPanel: false, disableAntialiasing: config_1.PluginConfig.General.DisableAntialiasing.defaultValue, pixelScale: config_1.PluginConfig.General.PixelScale.defaultValue, pickScale: config_1.PluginConfig.General.PickScale.defaultValue, pickPadding: config_1.PluginConfig.General.PickPadding.defaultValue, enableWboit: config_1.PluginConfig.General.EnableWboit.defaultValue, viewportShowExpand: config_1.PluginConfig.Viewport.ShowExpand.defaultValue, viewportShowControls: config_1.PluginConfig.Viewport.ShowControls.defaultValue, viewportShowSettings: config_1.PluginConfig.Viewport.ShowSettings.defaultValue, viewportShowSelectionMode: config_1.PluginConfig.Viewport.ShowSelectionMode.defaultValue, viewportShowAnimation: config_1.PluginConfig.Viewport.ShowAnimation.defaultValue, pluginStateServer: config_1.PluginConfig.State.DefaultServer.defaultValue, volumeStreamingServer: config_1.PluginConfig.VolumeStreaming.DefaultServer.defaultValue, volumeStreamingDisabled: !config_1.PluginConfig.VolumeStreaming.Enabled.defaultValue, pdbProvider: config_1.PluginConfig.Download.DefaultPdbProvider.defaultValue, emdbProvider: config_1.PluginConfig.Download.DefaultEmdbProvider.defaultValue, }; var Viewer = /** @class */ (function () { function Viewer(elementOrId, options) { if (options === void 0) { options = {}; } var _a; var o = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, DefaultViewerOptions), options); var defaultSpec = (0, spec_1.DefaultPluginUISpec)(); var spec = { actions: defaultSpec.actions, behaviors: (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], defaultSpec.behaviors, true), o.extensions.map(function (e) { return Extensions[e]; }), true), animations: (0, tslib_1.__spreadArray)([], defaultSpec.animations || [], true), customParamEditors: defaultSpec.customParamEditors, customFormats: o === null || o === void 0 ? void 0 : o.customFormats, layout: { initial: { isExpanded: o.layoutIsExpanded, showControls: o.layoutShowControls, controlsDisplay: o.layoutControlsDisplay, regionState: { bottom: 'full', left: o.collapseLeftPanel ? 'collapsed' : 'full', right: 'full', top: 'full', } }, }, components: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, defaultSpec.components), { controls: (0, tslib_1.__assign)((0, tslib_1.__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' }), config: [ [config_1.PluginConfig.General.DisableAntialiasing, o.disableAntialiasing], [config_1.PluginConfig.General.PixelScale, o.pixelScale], [config_1.PluginConfig.General.PickScale, o.pickScale], [config_1.PluginConfig.General.PickPadding, o.pickPadding], [config_1.PluginConfig.General.EnableWboit, o.enableWboit], [config_1.PluginConfig.Viewport.ShowExpand, o.viewportShowExpand], [config_1.PluginConfig.Viewport.ShowControls, o.viewportShowControls], [config_1.PluginConfig.Viewport.ShowSettings, o.viewportShowSettings], [config_1.PluginConfig.Viewport.ShowSelectionMode, o.viewportShowSelectionMode], [config_1.PluginConfig.Viewport.ShowAnimation, o.viewportShowAnimation], [config_1.PluginConfig.State.DefaultServer, o.pluginStateServer], [config_1.PluginConfig.State.CurrentServer, o.pluginStateServer], [config_1.PluginConfig.VolumeStreaming.DefaultServer, o.volumeStreamingServer], [config_1.PluginConfig.VolumeStreaming.Enabled, !o.volumeStreamingDisabled], [config_1.PluginConfig.Download.DefaultPdbProvider, o.pdbProvider], [config_1.PluginConfig.Download.DefaultEmdbProvider, o.emdbProvider] ] }; var element = typeof elementOrId === 'string' ? document.getElementById(elementOrId) : elementOrId; if (!element) throw new Error("Could not get element with id '" + elementOrId + "'"); this.plugin = (0, mol_plugin_ui_1.createPlugin)(element, spec); } Viewer.prototype.setRemoteSnapshot = function (id) { var url = this.plugin.config.get(config_1.PluginConfig.State.CurrentServer) + "/get/" + id; return commands_1.PluginCommands.State.Snapshots.Fetch(this.plugin, { url: url }); }; Viewer.prototype.loadSnapshotFromUrl = function (url, type) { return commands_1.PluginCommands.State.Snapshots.OpenUrl(this.plugin, { url: url, type: type }); }; Viewer.prototype.loadStructureFromUrl = function (url, format, isBinary, options) { if (format === void 0) { format = 'mmcif'; } if (isBinary === void 0) { isBinary = false; } var params = structure_1.DownloadStructure.createDefaultParams(this.plugin.state.data.root.obj, this.plugin); return this.plugin.runTask(this.plugin.state.data.applyAction(structure_1.DownloadStructure, { source: { name: 'url', params: { url: assets_1.Asset.Url(url), format: format, isBinary: isBinary, options: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, params.source.params.options), { representationParams: options === null || options === void 0 ? void 0 : options.representationParams }), } } })); }; Viewer.prototype.loadAllModelsOrAssemblyFromUrl = function (url, format, isBinary, options) { if (format === void 0) { format = 'mmcif'; } if (isBinary === void 0) { isBinary = false; } return (0, tslib_1.__awaiter)(this, void 0, void 0, function () { var plugin, data, trajectory; return (0, tslib_1.__generator)(this, function (_a) { switch (_a.label) { case 0: plugin = this.plugin; return [4 /*yield*/, plugin.builders.data.download({ url: url, isBinary: isBinary }, { state: { isGhost: true } })]; case 1: data = _a.sent(); return [4 /*yield*/, plugin.builders.structure.parseTrajectory(data, format)]; case 2: trajectory = _a.sent(); return [4 /*yield*/, this.plugin.builders.structure.hierarchy.applyPreset(trajectory, 'all-models', { useDefaultIfSingleModel: true, representationPresetParams: options === null || options === void 0 ? void 0 : options.representationParams })]; case 3: _a.sent(); return [2 /*return*/]; } }); }); }; Viewer.prototype.loadStructureFromData = function (data, format, options) { return (0, tslib_1.__awaiter)(this, void 0, void 0, function () { var _data, trajectory; return (0, tslib_1.__generator)(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.plugin.builders.data.rawData({ data: data, label: options === null || options === void 0 ? void 0 : options.dataLabel })]; case 1: _data = _a.sent(); return [4 /*yield*/, this.plugin.builders.structure.parseTrajectory(_data, format)]; case 2: trajectory = _a.sent(); return [4 /*yield*/, this.plugin.builders.structure.hierarchy.applyPreset(trajectory, 'default')]; case 3: _a.sent(); return [2 /*return*/]; } }); }); }; Viewer.prototype.loadPdb = function (pdb, options) { var params = structure_1.DownloadStructure.createDefaultParams(this.plugin.state.data.root.obj, this.plugin); var provider = this.plugin.config.get(config_1.PluginConfig.Download.DefaultPdbProvider); return this.plugin.runTask(this.plugin.state.data.applyAction(structure_1.DownloadStructure, { source: { name: 'pdb', params: { provider: { id: pdb, server: { name: provider, params: structure_1.PdbDownloadProvider[provider].defaultValue } }, options: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, params.source.params.options), { representationParams: options === null || options === void 0 ? void 0 : options.representationParams }), } } })); }; Viewer.prototype.loadPdbDev = function (pdbDev) { var params = structure_1.DownloadStructure.createDefaultParams(this.plugin.state.data.root.obj, this.plugin); return this.plugin.runTask(this.plugin.state.data.applyAction(structure_1.DownloadStructure, { source: { name: 'pdb-dev', params: { provider: { id: pdbDev, encoding: 'bcif', }, options: params.source.params.options, } } })); }; Viewer.prototype.loadEmdb = function (emdb, options) { var _a; var provider = this.plugin.config.get(config_1.PluginConfig.Download.DefaultEmdbProvider); return this.plugin.runTask(this.plugin.state.data.applyAction(volume_1.DownloadDensity, { source: { name: 'pdb-emd-ds', params: { provider: { id: emdb, server: provider, }, detail: (_a = options === null || options === void 0 ? void 0 : options.detail) !== null && _a !== void 0 ? _a : 3, } } })); }; /** * @example Load X-ray density from volume server viewer.loadVolumeFromUrl({ url: 'https://www.ebi.ac.uk/pdbe/densities/x-ray/1tqn/cell?detail=3', format: 'dscif', isBinary: true }, [{ type: 'relative', value: 1.5, color: 0x3362B2 }, { type: 'relative', value: 3, color: 0x33BB33, volumeIndex: 1 }, { type: 'relative', value: -3, color: 0xBB3333, volumeIndex: 1 }], { entryId: ['2FO-FC', 'FO-FC'], isLazy: true }); * ********************* * @example Load EM density from volume server viewer.loadVolumeFromUrl({ url: 'https://maps.rcsb.org/em/emd-30210/cell?detail=6', format: 'dscif', isBinary: true }, [{ type: 'relative', value: 1, color: 0x3377aa }], { entryId: 'EMD-30210', isLazy: true }); */ Viewer.prototype.loadVolumeFromUrl = function (_a, isovalues, options) { var url = _a.url, format = _a.format, isBinary = _a.isBinary; return (0, tslib_1.__awaiter)(this, void 0, void 0, function () { var plugin, update; var _this = this; return (0, tslib_1.__generator)(this, function (_b) { plugin = this.plugin; if (!plugin.dataFormats.get(format)) { throw new Error("Unknown density format: " + format); } if (options === null || options === void 0 ? void 0 : options.isLazy) { update = this.plugin.build(); update.toRoot().apply(transforms_1.StateTransforms.Data.LazyVolume, { url: url, format: format, entryId: options === null || options === void 0 ? void 0 : options.entryId, isBinary: isBinary, isovalues: isovalues.map(function (v) { return ((0, tslib_1.__assign)({ alpha: 1, volumeIndex: 0 }, v)); }) }); return [2 /*return*/, update.commit()]; } return [2 /*return*/, plugin.dataTransaction(function () { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () { var data, parsed, firstVolume, repr, _i, isovalues_1, iso; var _a, _b, _c, _d; return (0, tslib_1.__generator)(this, function (_e) { switch (_e.label) { case 0: return [4 /*yield*/, plugin.builders.data.download({ url: url, isBinary: isBinary }, { state: { isGhost: true } })]; case 1: data = _e.sent(); return [4 /*yield*/, plugin.dataFormats.get(format).parse(plugin, data, { entryId: options === null || options === void 0 ? void 0 : options.entryId })]; case 2: parsed = _e.sent(); firstVolume = (parsed.volume || parsed.volumes[0]); if (!(firstVolume === null || firstVolume === void 0 ? void 0 : firstVolume.isOk)) throw new Error('Failed to parse any volume.'); repr = plugin.build(); for (_i = 0, isovalues_1 = isovalues; _i < isovalues_1.length; _i++) { iso = isovalues_1[_i]; repr .to((_c = (_a = parsed.volumes) === null || _a === void 0 ? void 0 : _a[(_b = iso.volumeIndex) !== null && _b !== void 0 ? _b : 0]) !== null && _c !== void 0 ? _c : parsed.volume) .apply(transforms_1.StateTransforms.Representation.VolumeRepresentation3D, (0, volume_representation_params_1.createVolumeRepresentationParams)(this.plugin, firstVolume.data, { type: 'isosurface', typeParams: { alpha: (_d = iso.alpha) !== null && _d !== void 0 ? _d : 1, isoValue: iso.type === 'absolute' ? { kind: 'absolute', absoluteValue: iso.value } : { kind: 'relative', relativeValue: iso.value } }, color: 'uniform', colorParams: { value: iso.color } })); } return [4 /*yield*/, repr.commit()]; case 3: _e.sent(); return [2 /*return*/]; } }); }); })]; }); }); }; Viewer.prototype.handleResize = function () { this.plugin.layout.events.updated.next(void 0); }; return Viewer; }()); exports.Viewer = Viewer; //# sourceMappingURL=index.js.map