UNPKG

molstar

Version:

A comprehensive macromolecular library.

186 lines (185 loc) 8.76 kB
/** * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ import { __awaiter, __generator } from "tslib"; import { Mat4 } from '../../mol-math/linear-algebra'; import { QueryContext, StructureSelection } from '../../mol-model/structure'; import { superpose } from '../../mol-model/structure/structure/util/superposition'; import { MolScriptBuilder as MS } from '../../mol-script/language/builder'; import { compile } from '../../mol-script/runtime/query/compiler'; import { StateTransforms } from '../../mol-plugin-state/transforms'; import { Asset } from '../../mol-util/assets'; export function buildStaticSuperposition(plugin, src) { var _this = this; return plugin.dataTransaction(function () { return __awaiter(_this, void 0, void 0, function () { var _i, src_1, s, structure, chain; return __generator(this, function (_a) { switch (_a.label) { case 0: _i = 0, src_1 = src; _a.label = 1; case 1: if (!(_i < src_1.length)) return [3 /*break*/, 7]; s = src_1[_i]; return [4 /*yield*/, loadStructure(plugin, "https://www.ebi.ac.uk/pdbe/static/entry/".concat(s.pdbId, "_updated.cif"), 'mmcif')]; case 2: structure = (_a.sent()).structure; return [4 /*yield*/, transform(plugin, structure, s.matrix)]; case 3: _a.sent(); return [4 /*yield*/, plugin.builders.structure.tryCreateComponentFromExpression(structure, chainSelection(s.auth_asym_id), "Chain ".concat(s.auth_asym_id))]; case 4: chain = _a.sent(); if (!chain) return [3 /*break*/, 6]; return [4 /*yield*/, plugin.builders.structure.representation.addRepresentation(chain, { type: 'cartoon' })]; case 5: _a.sent(); _a.label = 6; case 6: _i++; return [3 /*break*/, 1]; case 7: return [2 /*return*/]; } }); }); }); } export var StaticSuperpositionTestData = [ { pdbId: '1aj5', auth_asym_id: 'A', matrix: Mat4.identity() }, { pdbId: '1df0', auth_asym_id: 'B', matrix: Mat4.ofRows([ [0.406, 0.879, 0.248, -200.633], [0.693, -0.473, 0.544, 73.403], [0.596, -0.049, -0.802, -14.209], [0, 0, 0, 1] ]) }, { pdbId: '1dvi', auth_asym_id: 'A', matrix: Mat4.ofRows([ [-0.053, -0.077, 0.996, -45.633], [-0.312, 0.949, 0.057, -12.255], [-0.949, -0.307, -0.074, 53.562], [0, 0, 0, 1] ]) } ]; export function dynamicSuperpositionTest(plugin, src, comp_id) { var _this = this; return plugin.dataTransaction(function () { return __awaiter(_this, void 0, void 0, function () { var _i, src_2, s, pivot, rest, query, xs, selections, transforms, i; return __generator(this, function (_a) { switch (_a.label) { case 0: _i = 0, src_2 = src; _a.label = 1; case 1: if (!(_i < src_2.length)) return [3 /*break*/, 4]; s = src_2[_i]; return [4 /*yield*/, loadStructure(plugin, "https://www.ebi.ac.uk/pdbe/static/entry/".concat(s, "_updated.cif"), 'mmcif')]; case 2: _a.sent(); _a.label = 3; case 3: _i++; return [3 /*break*/, 1]; case 4: pivot = MS.struct.filter.first([ MS.struct.generator.atomGroups({ 'residue-test': MS.core.rel.eq([MS.struct.atomProperty.macromolecular.label_comp_id(), comp_id]), 'group-by': MS.struct.atomProperty.macromolecular.residueKey() }) ]); rest = MS.struct.modifier.exceptBy({ 0: MS.struct.modifier.includeSurroundings({ 0: pivot, radius: 5 }), by: pivot }); query = compile(pivot); xs = plugin.managers.structure.hierarchy.current.structures; selections = xs.map(function (s) { return StructureSelection.toLociWithCurrentUnits(query(new QueryContext(s.cell.obj.data))); }); transforms = superpose(selections); return [4 /*yield*/, siteVisual(plugin, xs[0].cell, pivot, rest)]; case 5: _a.sent(); i = 1; _a.label = 6; case 6: if (!(i < selections.length)) return [3 /*break*/, 10]; return [4 /*yield*/, transform(plugin, xs[i].cell, transforms[i - 1].bTransform)]; case 7: _a.sent(); return [4 /*yield*/, siteVisual(plugin, xs[i].cell, pivot, rest)]; case 8: _a.sent(); _a.label = 9; case 9: i++; return [3 /*break*/, 6]; case 10: return [2 /*return*/]; } }); }); }); } function siteVisual(plugin, s, pivot, rest) { return __awaiter(this, void 0, void 0, function () { var center, surr; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, plugin.builders.structure.tryCreateComponentFromExpression(s, pivot, 'pivot')]; case 1: center = _a.sent(); if (!center) return [3 /*break*/, 3]; return [4 /*yield*/, plugin.builders.structure.representation.addRepresentation(center, { type: 'ball-and-stick', color: 'residue-name' })]; case 2: _a.sent(); _a.label = 3; case 3: return [4 /*yield*/, plugin.builders.structure.tryCreateComponentFromExpression(s, rest, 'rest')]; case 4: surr = _a.sent(); if (!surr) return [3 /*break*/, 6]; return [4 /*yield*/, plugin.builders.structure.representation.addRepresentation(surr, { type: 'ball-and-stick', color: 'uniform', size: 'uniform', sizeParams: { value: 0.33 } })]; case 5: _a.sent(); _a.label = 6; case 6: return [2 /*return*/]; } }); }); } function loadStructure(plugin, url, format, assemblyId) { return __awaiter(this, void 0, void 0, function () { var data, trajectory, model, structure; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, plugin.builders.data.download({ url: Asset.Url(url) })]; case 1: data = _a.sent(); return [4 /*yield*/, plugin.builders.structure.parseTrajectory(data, format)]; case 2: trajectory = _a.sent(); return [4 /*yield*/, plugin.builders.structure.createModel(trajectory)]; case 3: model = _a.sent(); return [4 /*yield*/, plugin.builders.structure.createStructure(model, assemblyId ? { name: 'assembly', params: { id: assemblyId } } : void 0)]; case 4: structure = _a.sent(); return [2 /*return*/, { data: data, trajectory: trajectory, model: model, structure: structure }]; } }); }); } function chainSelection(auth_asym_id) { return MS.struct.generator.atomGroups({ 'chain-test': MS.core.rel.eq([MS.struct.atomProperty.macromolecular.auth_asym_id(), auth_asym_id]) }); } function transform(plugin, s, matrix) { var b = plugin.state.data.build().to(s) .insert(StateTransforms.Model.TransformStructureConformation, { transform: { name: 'matrix', params: { data: matrix, transpose: false } } }); return plugin.runTask(plugin.state.data.updateTree(b)); }