UNPKG

molstar

Version:

A comprehensive macromolecular library.

328 lines (327 loc) 18.2 kB
"use strict"; /** * Copyright (c) 2018-2022 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> * @author Aliaksei Chareshneu <chareshneu.tech@gmail.com> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.BuiltInVolumeFormats = exports.DscifProvider = exports.CubeProvider = exports.DxProvider = exports.Dsn6Provider = exports.Ccp4Provider = exports.VolumeFormatCategory = void 0; var tslib_1 = require("tslib"); var transforms_1 = require("../transforms"); var provider_1 = require("./provider"); var representation_1 = require("../transforms/representation"); var names_1 = require("../../mol-util/color/names"); var volume_1 = require("../../mol-model/volume"); var volume_representation_params_1 = require("../helpers/volume-representation-params"); var object_1 = require("../../mol-util/object"); var property_1 = require("../../mol-model-formats/volume/property"); var util_1 = require("../../mol-plugin/behavior/dynamic/volume-streaming/util"); var mol_task_1 = require("../../mol-task"); exports.VolumeFormatCategory = 'Volume'; function tryObtainRecommendedIsoValue(plugin, volume) { return tslib_1.__awaiter(this, void 0, void 0, function () { var entryId; var _this = this; return tslib_1.__generator(this, function (_a) { if (!volume) return [2 /*return*/]; entryId = volume.entryId; if (!entryId || !entryId.toLowerCase().startsWith('emd')) return [2 /*return*/]; return [2 /*return*/, plugin.runTask(mol_task_1.Task.create('Try Set Recommended IsoValue', function (ctx) { return tslib_1.__awaiter(_this, void 0, void 0, function () { var absIsoLevel, e_1; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); return [4 /*yield*/, (0, util_1.getContourLevelEmdb)(plugin, ctx, entryId)]; case 1: absIsoLevel = _a.sent(); property_1.RecommendedIsoValue.Provider.set(volume, volume_1.Volume.IsoValue.absolute(absIsoLevel)); return [3 /*break*/, 3]; case 2: e_1 = _a.sent(); console.warn(e_1); return [3 /*break*/, 3]; case 3: return [2 /*return*/]; } }); }); }))]; }); }); } function tryGetRecomendedIsoValue(volume) { var recommendedIsoValue = property_1.RecommendedIsoValue.Provider.get(volume); if (!recommendedIsoValue) return; if (recommendedIsoValue.kind === 'relative') return recommendedIsoValue; return volume_1.Volume.adjustedIsoValue(volume, recommendedIsoValue.absoluteValue, 'absolute'); } function defaultVisuals(plugin, data) { return tslib_1.__awaiter(this, void 0, void 0, function () { var typeParams, isoValue, visual; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: typeParams = {}; isoValue = data.volume.data && tryGetRecomendedIsoValue(data.volume.data); if (isoValue) typeParams.isoValue = isoValue; visual = plugin.build().to(data.volume).apply(transforms_1.StateTransforms.Representation.VolumeRepresentation3D, (0, volume_representation_params_1.createVolumeRepresentationParams)(plugin, data.volume.data, { type: 'isosurface', typeParams: typeParams, })); return [4 /*yield*/, visual.commit()]; case 1: return [2 /*return*/, [_a.sent()]]; } }); }); } exports.Ccp4Provider = (0, provider_1.DataFormatProvider)({ label: 'CCP4/MRC/MAP', description: 'CCP4/MRC/MAP', category: exports.VolumeFormatCategory, binaryExtensions: ['ccp4', 'mrc', 'map'], parse: function (plugin, data, params) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var format, volume; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: format = plugin.build() .to(data) .apply(transforms_1.StateTransforms.Data.ParseCcp4, {}, { state: { isGhost: true } }); volume = format.apply(transforms_1.StateTransforms.Volume.VolumeFromCcp4, { entryId: params === null || params === void 0 ? void 0 : params.entryId }); return [4 /*yield*/, format.commit({ revertOnError: true })]; case 1: _a.sent(); return [4 /*yield*/, tryObtainRecommendedIsoValue(plugin, volume.selector.data)]; case 2: _a.sent(); return [2 /*return*/, { format: format.selector, volume: volume.selector }]; } }); }); }, visuals: defaultVisuals }); exports.Dsn6Provider = (0, provider_1.DataFormatProvider)({ label: 'DSN6/BRIX', description: 'DSN6/BRIX', category: exports.VolumeFormatCategory, binaryExtensions: ['dsn6', 'brix'], parse: function (plugin, data, params) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var format, volume; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: format = plugin.build() .to(data) .apply(transforms_1.StateTransforms.Data.ParseDsn6, {}, { state: { isGhost: true } }); volume = format.apply(transforms_1.StateTransforms.Volume.VolumeFromDsn6, { entryId: params === null || params === void 0 ? void 0 : params.entryId }); return [4 /*yield*/, format.commit({ revertOnError: true })]; case 1: _a.sent(); return [4 /*yield*/, tryObtainRecommendedIsoValue(plugin, volume.selector.data)]; case 2: _a.sent(); return [2 /*return*/, { format: format.selector, volume: volume.selector }]; } }); }); }, visuals: defaultVisuals }); exports.DxProvider = (0, provider_1.DataFormatProvider)({ label: 'DX', description: 'DX', category: exports.VolumeFormatCategory, stringExtensions: ['dx'], binaryExtensions: ['dxbin'], parse: function (plugin, data, params) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var format, volume; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: format = plugin.build() .to(data) .apply(transforms_1.StateTransforms.Data.ParseDx, {}, { state: { isGhost: true } }); volume = format.apply(transforms_1.StateTransforms.Volume.VolumeFromDx, { entryId: params === null || params === void 0 ? void 0 : params.entryId }); return [4 /*yield*/, volume.commit({ revertOnError: true })]; case 1: _a.sent(); return [4 /*yield*/, tryObtainRecommendedIsoValue(plugin, volume.selector.data)]; case 2: _a.sent(); return [2 /*return*/, { volume: volume.selector }]; } }); }); }, visuals: defaultVisuals }); exports.CubeProvider = (0, provider_1.DataFormatProvider)({ label: 'Cube', description: 'Cube', category: exports.VolumeFormatCategory, stringExtensions: ['cub', 'cube'], parse: function (plugin, data, params) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var format, volume, structure; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: format = plugin.build() .to(data) .apply(transforms_1.StateTransforms.Data.ParseCube, {}, { state: { isGhost: true } }); volume = format.apply(transforms_1.StateTransforms.Volume.VolumeFromCube, { entryId: params === null || params === void 0 ? void 0 : params.entryId }); structure = format .apply(transforms_1.StateTransforms.Model.TrajectoryFromCube, void 0, { state: { isGhost: true } }) .apply(transforms_1.StateTransforms.Model.ModelFromTrajectory) .apply(transforms_1.StateTransforms.Model.StructureFromModel); return [4 /*yield*/, format.commit({ revertOnError: true })]; case 1: _a.sent(); return [4 /*yield*/, tryObtainRecommendedIsoValue(plugin, volume.selector.data)]; case 2: _a.sent(); return [2 /*return*/, { format: format.selector, volume: volume.selector, structure: structure.selector }]; } }); }); }, visuals: function (plugin, data) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var surfaces, volumeReprs, volumeData, volumePos, volumeNeg, volume, structure, structureReprs; var _a, _b; return tslib_1.__generator(this, function (_c) { switch (_c.label) { case 0: surfaces = plugin.build(); volumeReprs = []; volumeData = (_b = (_a = data.volume.cell) === null || _a === void 0 ? void 0 : _a.obj) === null || _b === void 0 ? void 0 : _b.data; if (volumeData && volume_1.Volume.isOrbitals(volumeData)) { volumePos = surfaces.to(data.volume).apply(transforms_1.StateTransforms.Representation.VolumeRepresentation3D, (0, volume_representation_params_1.createVolumeRepresentationParams)(plugin, volumeData, { type: 'isosurface', typeParams: { isoValue: volume_1.Volume.IsoValue.relative(1), alpha: 0.4 }, color: 'uniform', colorParams: { value: names_1.ColorNames.blue } })); volumeNeg = surfaces.to(data.volume).apply(transforms_1.StateTransforms.Representation.VolumeRepresentation3D, (0, volume_representation_params_1.createVolumeRepresentationParams)(plugin, volumeData, { type: 'isosurface', typeParams: { isoValue: volume_1.Volume.IsoValue.relative(-1), alpha: 0.4 }, color: 'uniform', colorParams: { value: names_1.ColorNames.red } })); volumeReprs.push(volumePos.selector, volumeNeg.selector); } else { volume = surfaces.to(data.volume).apply(transforms_1.StateTransforms.Representation.VolumeRepresentation3D, (0, volume_representation_params_1.createVolumeRepresentationParams)(plugin, volumeData, { type: 'isosurface', typeParams: { isoValue: volume_1.Volume.IsoValue.relative(2), alpha: 0.4 }, color: 'uniform', colorParams: { value: names_1.ColorNames.grey } })); volumeReprs.push(volume.selector); } return [4 /*yield*/, plugin.builders.structure.representation.applyPreset(data.structure, 'auto')]; case 1: structure = _c.sent(); return [4 /*yield*/, surfaces.commit()]; case 2: _c.sent(); structureReprs = []; (0, object_1.objectForEach)(structure === null || structure === void 0 ? void 0 : structure.representations, function (r) { if (r) structureReprs.push(r); }); return [2 /*return*/, tslib_1.__spreadArray(tslib_1.__spreadArray([], volumeReprs, true), structureReprs, true)]; } }); }); } }); exports.DscifProvider = (0, provider_1.DataFormatProvider)({ label: 'DensityServer CIF', description: 'DensityServer CIF', category: exports.VolumeFormatCategory, stringExtensions: ['cif'], binaryExtensions: ['bcif'], isApplicable: function (info, data) { return (0, provider_1.guessCifVariant)(info, data) === 'dscif' ? true : false; }, parse: function (plugin, data, params) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var cifCell, b, blocks, volumes, i, _i, blocks_1, block, entryId, _a, volumes_1, v; var _b; return tslib_1.__generator(this, function (_c) { switch (_c.label) { case 0: return [4 /*yield*/, plugin.build().to(data).apply(transforms_1.StateTransforms.Data.ParseCif).commit()]; case 1: cifCell = _c.sent(); b = plugin.build().to(cifCell); blocks = cifCell.obj.data.blocks; if (blocks.length === 0) throw new Error('no data blocks'); volumes = []; i = 0; for (_i = 0, blocks_1 = blocks; _i < blocks_1.length; _i++) { block = blocks_1[_i]; // Skip "server" data block. if (block.header.toUpperCase() === 'SERVER') continue; entryId = Array.isArray(params === null || params === void 0 ? void 0 : params.entryId) ? params === null || params === void 0 ? void 0 : params.entryId[i] : params === null || params === void 0 ? void 0 : params.entryId; if (((_b = block.categories['volume_data_3d_info']) === null || _b === void 0 ? void 0 : _b.rowCount) > 0) { volumes.push(b.apply(transforms_1.StateTransforms.Volume.VolumeFromDensityServerCif, { blockHeader: block.header, entryId: entryId }).selector); i++; } } return [4 /*yield*/, b.commit()]; case 2: _c.sent(); _a = 0, volumes_1 = volumes; _c.label = 3; case 3: if (!(_a < volumes_1.length)) return [3 /*break*/, 6]; v = volumes_1[_a]; return [4 /*yield*/, tryObtainRecommendedIsoValue(plugin, v.data)]; case 4: _c.sent(); _c.label = 5; case 5: _a++; return [3 /*break*/, 3]; case 6: return [2 /*return*/, { volumes: volumes }]; } }); }); }, visuals: function (plugin, data) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var volumes, tree, visuals, isoValue, posParams, negParams; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: volumes = data.volumes; tree = plugin.build(); visuals = []; if (volumes.length > 0) { isoValue = (volumes[0].data && tryGetRecomendedIsoValue(volumes[0].data)) || volume_1.Volume.IsoValue.relative(1.5); visuals[0] = tree .to(volumes[0]) .apply(transforms_1.StateTransforms.Representation.VolumeRepresentation3D, representation_1.VolumeRepresentation3DHelpers.getDefaultParamsStatic(plugin, 'isosurface', { isoValue: isoValue, alpha: 1 }, 'uniform', { value: names_1.ColorNames.teal })) .selector; } if (volumes.length > 1) { posParams = representation_1.VolumeRepresentation3DHelpers.getDefaultParamsStatic(plugin, 'isosurface', { isoValue: volume_1.Volume.IsoValue.relative(3), alpha: 0.3 }, 'uniform', { value: names_1.ColorNames.green }); negParams = representation_1.VolumeRepresentation3DHelpers.getDefaultParamsStatic(plugin, 'isosurface', { isoValue: volume_1.Volume.IsoValue.relative(-3), alpha: 0.3 }, 'uniform', { value: names_1.ColorNames.red }); visuals[visuals.length] = tree.to(volumes[1]).apply(transforms_1.StateTransforms.Representation.VolumeRepresentation3D, posParams).selector; visuals[visuals.length] = tree.to(volumes[1]).apply(transforms_1.StateTransforms.Representation.VolumeRepresentation3D, negParams).selector; } return [4 /*yield*/, tree.commit()]; case 1: _a.sent(); return [2 /*return*/, visuals]; } }); }); } }); exports.BuiltInVolumeFormats = [ ['ccp4', exports.Ccp4Provider], ['dsn6', exports.Dsn6Provider], ['cube', exports.CubeProvider], ['dx', exports.DxProvider], ['dscif', exports.DscifProvider], ];