UNPKG

molstar

Version:

A comprehensive macromolecular library.

287 lines (286 loc) 16.6 kB
/** * Copyright (c) 2020-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 } from "tslib"; import { ParamDefinition as PD } from '../../../mol-util/param-definition'; import { StateObjectRef, StateTransformer } from '../../../mol-state'; import { StateTransforms } from '../../transforms'; import { RootStructureDefinition } from '../../helpers/root-structure'; import { PresetStructureRepresentations, StructureRepresentationPresetProvider } from './representation-preset'; import { Vec3 } from '../../../mol-math/linear-algebra'; import { Model } from '../../../mol-model/structure'; import { getStructureQuality } from '../../../mol-repr/util'; import { OperatorNameColorThemeProvider } from '../../../mol-theme/color/operator-name'; import { PluginConfig } from '../../../mol-plugin/config'; export function TrajectoryHierarchyPresetProvider(preset) { return preset; } (function (TrajectoryHierarchyPresetProvider) { TrajectoryHierarchyPresetProvider.CommonParams = function (a, plugin) { return ({ modelProperties: PD.Optional(PD.Group(StateTransformer.getParamDefinition(StateTransforms.Model.CustomModelProperties, void 0, plugin))), structureProperties: PD.Optional(PD.Group(StateTransformer.getParamDefinition(StateTransforms.Model.CustomStructureProperties, void 0, plugin))), representationPreset: PD.Optional(PD.Text('auto')) }); }; })(TrajectoryHierarchyPresetProvider || (TrajectoryHierarchyPresetProvider = {})); var CommonParams = TrajectoryHierarchyPresetProvider.CommonParams; var DefaultParams = function (a, plugin) { return (__assign({ model: PD.Optional(PD.Group(StateTransformer.getParamDefinition(StateTransforms.Model.ModelFromTrajectory, a, plugin))), showUnitcell: PD.Optional(PD.Boolean(false)), structure: PD.Optional(RootStructureDefinition.getParams(void 0, 'assembly').type), representationPresetParams: PD.Optional(PD.Group(StructureRepresentationPresetProvider.CommonParams)) }, CommonParams(a, plugin))); }; var defaultPreset = TrajectoryHierarchyPresetProvider({ id: 'preset-trajectory-default', display: { name: 'Default (Assembly)', group: 'Preset', description: 'Shows the first assembly or, if that is unavailable, the first model.' }, isApplicable: function (o) { return true; }, params: DefaultParams, apply: function (trajectory, params, plugin) { return __awaiter(this, void 0, void 0, function () { var builder, model, modelProperties, structure, structureProperties, unitcell, _a, representationPreset, representation; return __generator(this, function (_b) { switch (_b.label) { case 0: builder = plugin.builders.structure; return [4 /*yield*/, builder.createModel(trajectory, params.model)]; case 1: model = _b.sent(); return [4 /*yield*/, builder.insertModelProperties(model, params.modelProperties)]; case 2: modelProperties = _b.sent(); return [4 /*yield*/, builder.createStructure(modelProperties || model, params.structure)]; case 3: structure = _b.sent(); return [4 /*yield*/, builder.insertStructureProperties(structure, params.structureProperties)]; case 4: structureProperties = _b.sent(); if (!(params.showUnitcell === void 0 || !!params.showUnitcell)) return [3 /*break*/, 6]; return [4 /*yield*/, builder.tryCreateUnitcell(modelProperties, undefined, { isHidden: true })]; case 5: _a = _b.sent(); return [3 /*break*/, 7]; case 6: _a = void 0; _b.label = 7; case 7: unitcell = _a; representationPreset = params.representationPreset || plugin.config.get(PluginConfig.Structure.DefaultRepresentationPreset) || PresetStructureRepresentations.auto.id; return [4 /*yield*/, plugin.builders.structure.representation.applyPreset(structureProperties, representationPreset, params.representationPresetParams)]; case 8: representation = _b.sent(); return [2 /*return*/, { model: model, modelProperties: modelProperties, unitcell: unitcell, structure: structure, structureProperties: structureProperties, representation: representation }]; } }); }); } }); var AllModelsParams = function (a, plugin) { return (__assign({ useDefaultIfSingleModel: PD.Optional(PD.Boolean(false)), representationPresetParams: PD.Optional(PD.Group(StructureRepresentationPresetProvider.CommonParams)) }, CommonParams(a, plugin))); }; var allModels = TrajectoryHierarchyPresetProvider({ id: 'preset-trajectory-all-models', display: { name: 'All Models', group: 'Preset', description: 'Shows all models; colored by trajectory-index.' }, isApplicable: function (o) { return o.data.frameCount > 1; }, params: AllModelsParams, apply: function (trajectory, params, plugin) { var _a, _b; return __awaiter(this, void 0, void 0, function () { var tr, builder, models, structures, i, model, modelProperties, structure, structureProperties, quality, representationPreset; return __generator(this, function (_c) { switch (_c.label) { case 0: tr = (_b = (_a = StateObjectRef.resolveAndCheck(plugin.state.data, trajectory)) === null || _a === void 0 ? void 0 : _a.obj) === null || _b === void 0 ? void 0 : _b.data; if (!tr) return [2 /*return*/, {}]; if (tr.frameCount === 1 && params.useDefaultIfSingleModel) { return [2 /*return*/, defaultPreset.apply(trajectory, params, plugin)]; } builder = plugin.builders.structure; models = [], structures = []; i = 0; _c.label = 1; case 1: if (!(i < tr.frameCount)) return [3 /*break*/, 8]; return [4 /*yield*/, builder.createModel(trajectory, { modelIndex: i })]; case 2: model = _c.sent(); return [4 /*yield*/, builder.insertModelProperties(model, params.modelProperties, { isCollapsed: true })]; case 3: modelProperties = _c.sent(); return [4 /*yield*/, builder.createStructure(modelProperties || model, { name: 'model', params: {} })]; case 4: structure = _c.sent(); return [4 /*yield*/, builder.insertStructureProperties(structure, params.structureProperties)]; case 5: structureProperties = _c.sent(); models.push(model); structures.push(structure); quality = structure.obj ? getStructureQuality(structure.obj.data, { elementCountFactor: tr.frameCount }) : 'medium'; representationPreset = params.representationPreset || plugin.config.get(PluginConfig.Structure.DefaultRepresentationPreset) || PresetStructureRepresentations.auto.id; return [4 /*yield*/, builder.representation.applyPreset(structureProperties, representationPreset, { theme: { globalName: 'trajectory-index' }, quality: quality })]; case 6: _c.sent(); _c.label = 7; case 7: i++; return [3 /*break*/, 1]; case 8: return [2 /*return*/, { models: models, structures: structures }]; } }); }); } }); var CrystalSymmetryParams = function (a, plugin) { return (__assign({ model: PD.Optional(PD.Group(StateTransformer.getParamDefinition(StateTransforms.Model.ModelFromTrajectory, a, plugin))) }, CommonParams(a, plugin))); }; function applyCrystalSymmetry(props, trajectory, params, plugin) { return __awaiter(this, void 0, void 0, function () { var builder, model, modelProperties, structure, structureProperties, unitcell, representationPreset, representation; return __generator(this, function (_a) { switch (_a.label) { case 0: builder = plugin.builders.structure; return [4 /*yield*/, builder.createModel(trajectory, params.model)]; case 1: model = _a.sent(); return [4 /*yield*/, builder.insertModelProperties(model, params.modelProperties)]; case 2: modelProperties = _a.sent(); return [4 /*yield*/, builder.createStructure(modelProperties || model, { name: 'symmetry', params: props })]; case 3: structure = _a.sent(); return [4 /*yield*/, builder.insertStructureProperties(structure, params.structureProperties)]; case 4: structureProperties = _a.sent(); return [4 /*yield*/, builder.tryCreateUnitcell(modelProperties, undefined, { isHidden: false })]; case 5: unitcell = _a.sent(); representationPreset = params.representationPreset || plugin.config.get(PluginConfig.Structure.DefaultRepresentationPreset) || PresetStructureRepresentations.auto.id; return [4 /*yield*/, plugin.builders.structure.representation.applyPreset(structureProperties, representationPreset, { theme: { globalName: props.theme } })]; case 6: representation = _a.sent(); return [2 /*return*/, { model: model, modelProperties: modelProperties, unitcell: unitcell, structure: structure, structureProperties: structureProperties, representation: representation }]; } }); }); } var unitcell = TrajectoryHierarchyPresetProvider({ id: 'preset-trajectory-unitcell', display: { name: 'Unit Cell', group: 'Preset', description: 'Shows the fully populated unit cell.' }, isApplicable: function (o) { return Model.hasCrystalSymmetry(o.data.representative); }, params: CrystalSymmetryParams, apply: function (trajectory, params, plugin) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, applyCrystalSymmetry({ ijkMin: Vec3.create(0, 0, 0), ijkMax: Vec3.create(0, 0, 0) }, trajectory, params, plugin)]; case 1: return [2 /*return*/, _a.sent()]; } }); }); } }); var supercell = TrajectoryHierarchyPresetProvider({ id: 'preset-trajectory-supercell', display: { name: 'Super Cell', group: 'Preset', description: 'Shows the super cell, i.e. the central unit cell and all adjacent unit cells.' }, isApplicable: function (o) { return Model.hasCrystalSymmetry(o.data.representative); }, params: CrystalSymmetryParams, apply: function (trajectory, params, plugin) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, applyCrystalSymmetry({ ijkMin: Vec3.create(-1, -1, -1), ijkMax: Vec3.create(1, 1, 1), theme: 'operator-hkl' }, trajectory, params, plugin)]; case 1: return [2 /*return*/, _a.sent()]; } }); }); } }); var CrystalContactsParams = function (a, plugin) { return (__assign({ model: PD.Optional(PD.Group(StateTransformer.getParamDefinition(StateTransforms.Model.ModelFromTrajectory, a, plugin))) }, CommonParams(a, plugin))); }; var crystalContacts = TrajectoryHierarchyPresetProvider({ id: 'preset-trajectory-crystal-contacts', display: { name: 'Crystal Contacts', group: 'Preset', description: 'Showsasymetric unit and chains from neighbours within 5 \u212B, i.e., symmetry mates.' }, isApplicable: function (o) { return Model.hasCrystalSymmetry(o.data.representative); }, params: CrystalContactsParams, apply: function (trajectory, params, plugin) { return __awaiter(this, void 0, void 0, function () { var builder, model, modelProperties, structure, structureProperties, unitcell, representationPreset, representation; return __generator(this, function (_a) { switch (_a.label) { case 0: builder = plugin.builders.structure; return [4 /*yield*/, builder.createModel(trajectory, params.model)]; case 1: model = _a.sent(); return [4 /*yield*/, builder.insertModelProperties(model, params.modelProperties)]; case 2: modelProperties = _a.sent(); return [4 /*yield*/, builder.createStructure(modelProperties || model, { name: 'symmetry-mates', params: { radius: 5 } })]; case 3: structure = _a.sent(); return [4 /*yield*/, builder.insertStructureProperties(structure, params.structureProperties)]; case 4: structureProperties = _a.sent(); return [4 /*yield*/, builder.tryCreateUnitcell(modelProperties, undefined, { isHidden: true })]; case 5: unitcell = _a.sent(); representationPreset = params.representationPreset || plugin.config.get(PluginConfig.Structure.DefaultRepresentationPreset) || PresetStructureRepresentations.auto.id; return [4 /*yield*/, plugin.builders.structure.representation.applyPreset(structureProperties, representationPreset, { theme: { globalName: 'operator-name', carbonColor: 'operator-name', focus: { name: 'element-symbol', params: { carbonColor: { name: 'operator-name', params: OperatorNameColorThemeProvider.defaultValues } } } } })]; case 6: representation = _a.sent(); return [2 /*return*/, { model: model, modelProperties: modelProperties, unitcell: unitcell, structure: structure, structureProperties: structureProperties, representation: representation }]; } }); }); } }); export var PresetTrajectoryHierarchy = { 'default': defaultPreset, 'all-models': allModels, unitcell: unitcell, supercell: supercell, crystalContacts: crystalContacts, };