UNPKG

molstar

Version:

A comprehensive macromolecular library.

126 lines 6.16 kB
/** * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { __assign, __awaiter, __generator } from "tslib"; import { createPlugin } from '../../mol-plugin-ui'; import { DefaultPluginUISpec } from '../../mol-plugin-ui/spec'; import { PluginCommands } from '../../mol-plugin/commands'; import { Asset } from '../../mol-util/assets'; import './index.html'; require('mol-plugin-ui/skin/light.scss'); var Canvas3DPresets = { illustrative: { multiSample: { mode: 'temporal' }, postprocessing: { occlusion: { name: 'on', params: { samples: 32, radius: 6, bias: 1.4, blurKernelSize: 15 } }, outline: { name: 'on', params: { scale: 1, threshold: 0.1 } } }, renderer: { style: { name: 'flat', params: {} } } }, occlusion: { multiSample: { mode: 'temporal' }, postprocessing: { occlusion: { name: 'on', params: { samples: 32, radius: 6, bias: 1.4, blurKernelSize: 15 } }, outline: { name: 'off', params: {} } }, renderer: { style: { name: 'matte', params: {} } } }, standard: { multiSample: { mode: 'off' }, postprocessing: { occlusion: { name: 'off', params: {} }, outline: { name: 'off', params: {} } }, renderer: { style: { name: 'matte', params: {} } } } }; var LightingDemo = /** @class */ (function () { function LightingDemo() { this.radius = 5; this.bias = 1.1; this.preset = 'illustrative'; } LightingDemo.prototype.init = function (target) { this.plugin = createPlugin(typeof target === 'string' ? document.getElementById(target) : target, __assign(__assign({}, DefaultPluginUISpec()), { layout: { initial: { isExpanded: false, showControls: false }, }, components: { controls: { left: 'none', right: 'none', top: 'none', bottom: 'none' } } })); this.setPreset('illustrative'); }; LightingDemo.prototype.setPreset = function (preset) { var _a; var props = Canvas3DPresets[preset]; if (((_a = props.postprocessing.occlusion) === null || _a === void 0 ? void 0 : _a.name) === 'on') { props.postprocessing.occlusion.params.radius = this.radius; props.postprocessing.occlusion.params.bias = this.bias; } PluginCommands.Canvas3D.SetSettings(this.plugin, { settings: __assign(__assign({}, props), { multiSample: __assign(__assign({}, this.plugin.canvas3d.props.multiSample), props.multiSample), renderer: __assign(__assign({}, this.plugin.canvas3d.props.renderer), props.renderer), postprocessing: __assign(__assign({}, this.plugin.canvas3d.props.postprocessing), props.postprocessing) }) }); }; LightingDemo.prototype.load = function (_a, radius, bias) { var url = _a.url, _b = _a.format, format = _b === void 0 ? 'mmcif' : _b, _c = _a.isBinary, isBinary = _c === void 0 ? true : _c, _d = _a.assemblyId, assemblyId = _d === void 0 ? '' : _d; return __awaiter(this, void 0, void 0, function () { var data, trajectory, model, structure, polymer, ligand; return __generator(this, function (_e) { switch (_e.label) { case 0: return [4 /*yield*/, this.plugin.clear()]; case 1: _e.sent(); return [4 /*yield*/, this.plugin.builders.data.download({ url: Asset.Url(url), isBinary: isBinary }, { state: { isGhost: true } })]; case 2: data = _e.sent(); return [4 /*yield*/, this.plugin.builders.structure.parseTrajectory(data, format)]; case 3: trajectory = _e.sent(); return [4 /*yield*/, this.plugin.builders.structure.createModel(trajectory)]; case 4: model = _e.sent(); return [4 /*yield*/, this.plugin.builders.structure.createStructure(model, assemblyId ? { name: 'assembly', params: { id: assemblyId } } : { name: 'model', params: {} })]; case 5: structure = _e.sent(); return [4 /*yield*/, this.plugin.builders.structure.tryCreateComponentStatic(structure, 'polymer')]; case 6: polymer = _e.sent(); if (!polymer) return [3 /*break*/, 8]; return [4 /*yield*/, this.plugin.builders.structure.representation.addRepresentation(polymer, { type: 'spacefill', color: 'illustrative' })]; case 7: _e.sent(); _e.label = 8; case 8: return [4 /*yield*/, this.plugin.builders.structure.tryCreateComponentStatic(structure, 'ligand')]; case 9: ligand = _e.sent(); if (!ligand) return [3 /*break*/, 11]; return [4 /*yield*/, this.plugin.builders.structure.representation.addRepresentation(ligand, { type: 'ball-and-stick', color: 'element-symbol', colorParams: { carbonColor: { name: 'element-symbol', params: {} } } })]; case 10: _e.sent(); _e.label = 11; case 11: this.radius = radius; this.bias = bias; this.setPreset(this.preset); return [2 /*return*/]; } }); }); }; return LightingDemo; }()); window.LightingDemo = new LightingDemo(); //# sourceMappingURL=index.js.map