molstar
Version:
A comprehensive macromolecular library.
286 lines • 17.2 kB
JavaScript
"use strict";
/**
* 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>
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.PresetTrajectoryHierarchy = exports.TrajectoryHierarchyPresetProvider = void 0;
var tslib_1 = require("tslib");
var param_definition_1 = require("../../../mol-util/param-definition");
var mol_state_1 = require("../../../mol-state");
var transforms_1 = require("../../transforms");
var root_structure_1 = require("../../helpers/root-structure");
var representation_preset_1 = require("./representation-preset");
var linear_algebra_1 = require("../../../mol-math/linear-algebra");
var structure_1 = require("../../../mol-model/structure");
var util_1 = require("../../../mol-repr/util");
var operator_name_1 = require("../../../mol-theme/color/operator-name");
function TrajectoryHierarchyPresetProvider(preset) { return preset; }
exports.TrajectoryHierarchyPresetProvider = TrajectoryHierarchyPresetProvider;
(function (TrajectoryHierarchyPresetProvider) {
TrajectoryHierarchyPresetProvider.CommonParams = function (a, plugin) { return ({
modelProperties: param_definition_1.ParamDefinition.Optional(param_definition_1.ParamDefinition.Group(mol_state_1.StateTransformer.getParamDefinition(transforms_1.StateTransforms.Model.CustomModelProperties, void 0, plugin))),
structureProperties: param_definition_1.ParamDefinition.Optional(param_definition_1.ParamDefinition.Group(mol_state_1.StateTransformer.getParamDefinition(transforms_1.StateTransforms.Model.CustomStructureProperties, void 0, plugin))),
representationPreset: param_definition_1.ParamDefinition.Optional(param_definition_1.ParamDefinition.Text('auto'))
}); };
})(TrajectoryHierarchyPresetProvider = exports.TrajectoryHierarchyPresetProvider || (exports.TrajectoryHierarchyPresetProvider = {}));
var CommonParams = TrajectoryHierarchyPresetProvider.CommonParams;
var DefaultParams = function (a, plugin) { return ((0, tslib_1.__assign)({ model: param_definition_1.ParamDefinition.Optional(param_definition_1.ParamDefinition.Group(mol_state_1.StateTransformer.getParamDefinition(transforms_1.StateTransforms.Model.ModelFromTrajectory, a, plugin))), showUnitcell: param_definition_1.ParamDefinition.Optional(param_definition_1.ParamDefinition.Boolean(false)), structure: param_definition_1.ParamDefinition.Optional(root_structure_1.RootStructureDefinition.getParams(void 0, 'assembly').type), representationPresetParams: param_definition_1.ParamDefinition.Optional(param_definition_1.ParamDefinition.Group(representation_preset_1.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 (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var builder, model, modelProperties, structure, structureProperties, unitcell, _a, representation;
return (0, tslib_1.__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;
return [4 /*yield*/, plugin.builders.structure.representation.applyPreset(structureProperties, params.representationPreset || 'auto', 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 ((0, tslib_1.__assign)({ useDefaultIfSingleModel: param_definition_1.ParamDefinition.Optional(param_definition_1.ParamDefinition.Boolean(false)), representationPresetParams: param_definition_1.ParamDefinition.Optional(param_definition_1.ParamDefinition.Group(representation_preset_1.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 model-index.'
},
isApplicable: function (o) {
return o.data.frameCount > 1;
},
params: AllModelsParams,
apply: function (trajectory, params, plugin) {
var _a, _b;
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var tr, builder, models, structures, i, model, modelProperties, structure, structureProperties, quality;
return (0, tslib_1.__generator)(this, function (_c) {
switch (_c.label) {
case 0:
tr = (_b = (_a = mol_state_1.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 ? (0, util_1.getStructureQuality)(structure.obj.data, { elementCountFactor: tr.frameCount }) : 'medium';
return [4 /*yield*/, builder.representation.applyPreset(structureProperties, params.representationPreset || 'auto', { theme: { globalName: 'model-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 ((0, tslib_1.__assign)({ model: param_definition_1.ParamDefinition.Optional(param_definition_1.ParamDefinition.Group(mol_state_1.StateTransformer.getParamDefinition(transforms_1.StateTransforms.Model.ModelFromTrajectory, a, plugin))) }, CommonParams(a, plugin))); };
function applyCrystalSymmetry(props, trajectory, params, plugin) {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var builder, model, modelProperties, structure, structureProperties, unitcell, representation;
return (0, tslib_1.__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();
return [4 /*yield*/, plugin.builders.structure.representation.applyPreset(structureProperties, params.representationPreset || 'auto', { 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 structure_1.Model.hasCrystalSymmetry(o.data.representative);
},
params: CrystalSymmetryParams,
apply: function (trajectory, params, plugin) {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, applyCrystalSymmetry({ ijkMin: linear_algebra_1.Vec3.create(0, 0, 0), ijkMax: linear_algebra_1.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 structure_1.Model.hasCrystalSymmetry(o.data.representative);
},
params: CrystalSymmetryParams,
apply: function (trajectory, params, plugin) {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, applyCrystalSymmetry({ ijkMin: linear_algebra_1.Vec3.create(-1, -1, -1), ijkMax: linear_algebra_1.Vec3.create(1, 1, 1), theme: 'operator-hkl' }, trajectory, params, plugin)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
}
});
var CrystalContactsParams = function (a, plugin) { return ((0, tslib_1.__assign)({ model: param_definition_1.ParamDefinition.Optional(param_definition_1.ParamDefinition.Group(mol_state_1.StateTransformer.getParamDefinition(transforms_1.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 structure_1.Model.hasCrystalSymmetry(o.data.representative);
},
params: CrystalContactsParams,
apply: function (trajectory, params, plugin) {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var builder, model, modelProperties, structure, structureProperties, unitcell, representation;
return (0, tslib_1.__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();
return [4 /*yield*/, plugin.builders.structure.representation.applyPreset(structureProperties, params.representationPreset || 'auto', { theme: { globalName: 'operator-name', carbonColor: 'operator-name', focus: { name: 'element-symbol', params: { carbonColor: { name: 'operator-name', params: operator_name_1.OperatorNameColorThemeProvider.defaultValues } } } } })];
case 6:
representation = _a.sent();
return [2 /*return*/, {
model: model,
modelProperties: modelProperties,
unitcell: unitcell,
structure: structure,
structureProperties: structureProperties,
representation: representation
}];
}
});
});
}
});
exports.PresetTrajectoryHierarchy = {
'default': defaultPreset,
'all-models': allModels,
unitcell: unitcell,
supercell: supercell,
crystalContacts: crystalContacts,
};
//# sourceMappingURL=hierarchy-preset.js.map