molstar
Version:
A comprehensive macromolecular library.
344 lines • 18.3 kB
JavaScript
/**
* 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>
*/
import { __assign, __awaiter, __generator, __spreadArray } from "tslib";
import { ANVILMembraneOrientation } from '../../extensions/anvil/behavior';
import { CellPack } from '../../extensions/cellpack';
import { DnatcoConfalPyramids } from '../../extensions/dnatco';
import { G3DFormat, G3dProvider } from '../../extensions/g3d/format';
import { Mp4Export } from '../../extensions/mp4-export';
import { GeometryExport } from '../../extensions/geo-export';
import { PDBeStructureQualityReport } from '../../extensions/pdbe';
import { RCSBAssemblySymmetry, RCSBValidationReport } from '../../extensions/rcsb';
import { DownloadStructure, PdbDownloadProvider } from '../../mol-plugin-state/actions/structure';
import { DownloadDensity } from '../../mol-plugin-state/actions/volume';
import { createVolumeRepresentationParams } from '../../mol-plugin-state/helpers/volume-representation-params';
import { StateTransforms } from '../../mol-plugin-state/transforms';
import { createPlugin } from '../../mol-plugin-ui';
import { DefaultPluginUISpec } from '../../mol-plugin-ui/spec';
import { PluginCommands } from '../../mol-plugin/commands';
import { PluginConfig } from '../../mol-plugin/config';
import { PluginSpec } from '../../mol-plugin/spec';
import { Asset } from '../../mol-util/assets';
import '../../mol-util/polyfill';
import { ObjectKeys } from '../../mol-util/type-helpers';
import './embedded.html';
import './favicon.ico';
import './index.html';
require('mol-plugin-ui/skin/light.scss');
export { PLUGIN_VERSION as version } from '../../mol-plugin/version';
export { setDebugMode, setProductionMode } from '../../mol-util/debug';
var CustomFormats = [
['g3d', G3dProvider]
];
var Extensions = {
'cellpack': PluginSpec.Behavior(CellPack),
'dnatco-confal-pyramids': PluginSpec.Behavior(DnatcoConfalPyramids),
'pdbe-structure-quality-report': PluginSpec.Behavior(PDBeStructureQualityReport),
'rcsb-assembly-symmetry': PluginSpec.Behavior(RCSBAssemblySymmetry),
'rcsb-validation-report': PluginSpec.Behavior(RCSBValidationReport),
'anvil-membrane-orientation': PluginSpec.Behavior(ANVILMembraneOrientation),
'g3d': PluginSpec.Behavior(G3DFormat),
'mp4-export': PluginSpec.Behavior(Mp4Export),
'geo-export': PluginSpec.Behavior(GeometryExport)
};
var DefaultViewerOptions = {
customFormats: CustomFormats,
extensions: ObjectKeys(Extensions),
layoutIsExpanded: true,
layoutShowControls: true,
layoutShowRemoteState: true,
layoutControlsDisplay: 'reactive',
layoutShowSequence: true,
layoutShowLog: true,
layoutShowLeftPanel: true,
collapseLeftPanel: false,
disableAntialiasing: PluginConfig.General.DisableAntialiasing.defaultValue,
pixelScale: PluginConfig.General.PixelScale.defaultValue,
pickScale: PluginConfig.General.PickScale.defaultValue,
pickPadding: PluginConfig.General.PickPadding.defaultValue,
enableWboit: PluginConfig.General.EnableWboit.defaultValue,
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,
volumeStreamingDisabled: !PluginConfig.VolumeStreaming.Enabled.defaultValue,
pdbProvider: PluginConfig.Download.DefaultPdbProvider.defaultValue,
emdbProvider: PluginConfig.Download.DefaultEmdbProvider.defaultValue,
};
var Viewer = /** @class */ (function () {
function Viewer(elementOrId, options) {
if (options === void 0) { options = {}; }
var _a;
var o = __assign(__assign({}, DefaultViewerOptions), options);
var defaultSpec = DefaultPluginUISpec();
var spec = {
actions: defaultSpec.actions,
behaviors: __spreadArray(__spreadArray([], defaultSpec.behaviors, true), o.extensions.map(function (e) { return Extensions[e]; }), true),
animations: __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: __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' }),
config: [
[PluginConfig.General.DisableAntialiasing, o.disableAntialiasing],
[PluginConfig.General.PixelScale, o.pixelScale],
[PluginConfig.General.PickScale, o.pickScale],
[PluginConfig.General.PickPadding, o.pickPadding],
[PluginConfig.General.EnableWboit, o.enableWboit],
[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.VolumeStreaming.Enabled, !o.volumeStreamingDisabled],
[PluginConfig.Download.DefaultPdbProvider, o.pdbProvider],
[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 = createPlugin(element, spec);
}
Viewer.prototype.setRemoteSnapshot = function (id) {
var url = this.plugin.config.get(PluginConfig.State.CurrentServer) + "/get/" + id;
return PluginCommands.State.Snapshots.Fetch(this.plugin, { url: url });
};
Viewer.prototype.loadSnapshotFromUrl = function (url, type) {
return 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 = DownloadStructure.createDefaultParams(this.plugin.state.data.root.obj, this.plugin);
return this.plugin.runTask(this.plugin.state.data.applyAction(DownloadStructure, {
source: {
name: 'url',
params: {
url: Asset.Url(url),
format: format,
isBinary: isBinary,
options: __assign(__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 __awaiter(this, void 0, void 0, function () {
var plugin, data, trajectory;
return __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 __awaiter(this, void 0, void 0, function () {
var _data, trajectory;
return __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 = DownloadStructure.createDefaultParams(this.plugin.state.data.root.obj, this.plugin);
var provider = this.plugin.config.get(PluginConfig.Download.DefaultPdbProvider);
return this.plugin.runTask(this.plugin.state.data.applyAction(DownloadStructure, {
source: {
name: 'pdb',
params: {
provider: {
id: pdb,
server: {
name: provider,
params: PdbDownloadProvider[provider].defaultValue
}
},
options: __assign(__assign({}, params.source.params.options), { representationParams: options === null || options === void 0 ? void 0 : options.representationParams }),
}
}
}));
};
Viewer.prototype.loadPdbDev = function (pdbDev) {
var params = DownloadStructure.createDefaultParams(this.plugin.state.data.root.obj, this.plugin);
return this.plugin.runTask(this.plugin.state.data.applyAction(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(PluginConfig.Download.DefaultEmdbProvider);
return this.plugin.runTask(this.plugin.state.data.applyAction(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 __awaiter(this, void 0, void 0, function () {
var plugin, update;
var _this = this;
return __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(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 (__assign({ alpha: 1, volumeIndex: 0 }, v)); })
});
return [2 /*return*/, update.commit()];
}
return [2 /*return*/, plugin.dataTransaction(function () { return __awaiter(_this, void 0, void 0, function () {
var data, parsed, firstVolume, repr, _i, isovalues_1, iso;
var _a, _b, _c, _d;
return __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(StateTransforms.Representation.VolumeRepresentation3D, 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;
}());
export { Viewer };
//# sourceMappingURL=index.js.map