UNPKG

drugflow-molstar

Version:
776 lines 54.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.initSuperposition = initSuperposition; exports.loadAfStructure = loadAfStructure; exports.superposeAf = superposeAf; exports.renderSuperposition = renderSuperposition; var tslib_1 = require("tslib"); var linear_algebra_1 = require("Molstar/mol-math/linear-algebra"); var builder_1 = require("Molstar/mol-script/language/builder"); var mol_state_1 = require("Molstar/mol-state"); var transforms_1 = require("Molstar/mol-plugin-state/transforms"); var assets_1 = require("Molstar/mol-util/assets"); var helpers_1 = require("./helpers"); var lists_1 = require("Molstar/mol-util/color/lists"); var color_1 = require("Molstar/mol-util/color/color"); var script_1 = require("Molstar/mol-script/script"); var mol_task_1 = require("Molstar/mol-task"); var superposition_sifts_mapping_1 = require("./superposition-sifts-mapping"); var alphafold_transparency_1 = require("./alphafold-transparency"); var structure_1 = require("Molstar/mol-model/structure"); function getRandomColor(plugin, segmentIndex) { var clList = lists_1.ColorLists; var spState = plugin.customState.superpositionState; var palleteIndex = spState.colorState[segmentIndex].palleteIndex; var colorIndex = spState.colorState[segmentIndex].colorIndex; if (clList[spState.colorPalette[palleteIndex]].list[colorIndex + 1]) { colorIndex += 1; } else { colorIndex = 0; palleteIndex = spState.colorPalette[palleteIndex + 1] ? palleteIndex + 1 : 0; } var palleteName = spState.colorPalette[palleteIndex]; plugin.customState.superpositionState.colorState[segmentIndex].palleteIndex = palleteIndex; plugin.customState.superpositionState.colorState[segmentIndex].colorIndex = colorIndex; return clList[palleteName].list[colorIndex]; } function initSuperposition(plugin) { return tslib_1.__awaiter(this, void 0, void 0, function () { var customState, superpositionParams, segmentData, afStrUrls, segmentIndex, clusterIndexs, entryList, clusters; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, plugin.clear()]; case 1: _a.sent(); customState = plugin.customState; superpositionParams = customState.initParams.superpositionParams; plugin.customState.superpositionState = { models: {}, entries: {}, refMaps: {}, segmentData: void 0, matrixData: {}, activeSegment: 0, loadedStructs: [], visibleRefs: [], invalidStruct: [], noMatrixStruct: [], hets: {}, colorPalette: ['dark-2', 'red-yellow-green', 'paired', 'set-1', 'accent', 'set-2', 'rainbow'], colorState: [], alphafold: { apiData: { cif: '', pae: '', length: 0 }, length: 0, ref: '', traceOnly: true, visibility: [], transforms: [], rmsds: [], coordinateSystems: [] } }; // Get segment and cluster information for the given uniprot accession return [4 /*yield*/, getSegmentData(plugin)]; case 2: // Get segment and cluster information for the given uniprot accession _a.sent(); segmentData = plugin.customState.superpositionState.segmentData; if (!segmentData) return [2 /*return*/]; // Load Matrix Data return [4 /*yield*/, getMatrixData(plugin)]; case 3: // Load Matrix Data _a.sent(); if (!plugin.customState.superpositionState.segmentData) return [2 /*return*/]; return [4 /*yield*/, getAfUrl(plugin, customState.initParams.moleculeId)]; case 4: afStrUrls = _a.sent(); if (afStrUrls) customState.superpositionState.alphafold.apiData = afStrUrls; segmentData.forEach(function () { plugin.customState.superpositionState.loadedStructs.push([]); plugin.customState.superpositionState.visibleRefs.push([]); plugin.customState.superpositionState.colorState.push({ palleteIndex: 0, colorIndex: -1 }); }); segmentIndex = (superpositionParams && superpositionParams.segment) ? superpositionParams.segment - 1 : 0; plugin.customState.superpositionState.activeSegment = segmentIndex + 1; clusterIndexs = (superpositionParams && superpositionParams.cluster) ? superpositionParams.cluster : void 0; // Emit segment API data load event plugin.customState.events.superpositionInit.next(true); entryList = []; clusters = segmentData[segmentIndex].clusters; clusters.forEach(function (cluster, clusterIndex) { // Validate for cluster index if provided in superPositionParams if (clusterIndexs && clusterIndexs.indexOf(clusterIndex) === -1) return; // Add respresentative structure to the list if (superpositionParams && superpositionParams.superposeAll) { entryList = entryList.concat(cluster); } else { entryList.push(cluster[0]); } }); return [4 /*yield*/, renderSuperposition(plugin, segmentIndex, entryList)]; case 5: _a.sent(); return [2 /*return*/]; } }); }); } function createCarbVisLabel(carbLigNamesAndCount) { var compList = []; for (var carbCompId in carbLigNamesAndCount) { compList.push("".concat(carbCompId, " (").concat(carbLigNamesAndCount[carbCompId], ")")); } return compList.join(', '); } function getAfUrl(plugin, accession) { return tslib_1.__awaiter(this, void 0, void 0, function () { var apiResponse, apiData; var _this = this; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, plugin.runTask(mol_task_1.Task.create('Get AlphaFold URL', function (ctx) { return tslib_1.__awaiter(_this, void 0, void 0, function () { var e_1; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); return [4 /*yield*/, plugin.fetch({ url: "https://alphafold.ebi.ac.uk/api/prediction/".concat(accession), type: 'json' }).runInContext(ctx)]; case 1: apiResponse = _a.sent(); if (apiResponse && (apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse[0].bcifUrl)) { apiData = { cif: apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse[0].cifUrl, pae: apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse[0].paeImageUrl, length: apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse[0].uniprotEnd }; } return [3 /*break*/, 3]; case 2: e_1 = _a.sent(); return [3 /*break*/, 3]; case 3: return [2 /*return*/]; } }); }); }))]; case 1: _a.sent(); return [2 /*return*/, apiData]; } }); }); } function loadAfStructure(plugin) { return tslib_1.__awaiter(this, void 0, void 0, function () { var customState, structure, strInstance, spState, chainSel; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: customState = plugin.customState; return [4 /*yield*/, loadStructure(plugin, customState.superpositionState.alphafold.apiData.cif, 'mmcif', false)]; case 1: structure = (_a.sent()).structure; strInstance = structure; if (!strInstance) return [2 /*return*/, false]; spState = plugin.customState.superpositionState; spState.alphafold.ref = strInstance === null || strInstance === void 0 ? void 0 : strInstance.ref; spState.models["AF-".concat(customState.initParams.moleculeId)] = strInstance === null || strInstance === void 0 ? void 0 : strInstance.ref; return [4 /*yield*/, plugin.builders.structure.tryCreateComponentStatic(strInstance, 'polymer', { label: "AlphaFold Structure", tags: ["alphafold-chain", "superposition-sel"] })]; case 2: chainSel = _a.sent(); if (!chainSel) return [3 /*break*/, 4]; return [4 /*yield*/, plugin.builders.structure.representation.addRepresentation(chainSel, { type: 'putty', color: 'plddt-confidence', size: 'uniform', sizeParams: { value: 1.5 } }, { tag: "af-superposition-visual" })]; case 3: _a.sent(); return [2 /*return*/, strInstance === null || strInstance === void 0 ? void 0 : strInstance.ref]; case 4: return [2 /*return*/, false]; } }); }); } function superposeAf(plugin, traceOnly, segmentIndex) { return tslib_1.__awaiter(this, void 0, void 0, function () { var customState, spState, afStrRef, _a, afStr, segmentNum, mappingResult_1, coordinateSystems_1, failedPairsResult_1, zeroOverlapPairsResult_1, minRmsd_1, minIndex_1, rmsdList_1, segmentClusters; return tslib_1.__generator(this, function (_b) { switch (_b.label) { case 0: customState = plugin.customState; if (!customState.superpositionState || !customState.superpositionState.segmentData) return [2 /*return*/]; spState = customState.superpositionState; _a = spState.alphafold.ref; if (_a) return [3 /*break*/, 2]; return [4 /*yield*/, loadAfStructure(plugin)]; case 1: _a = (_b.sent()); _b.label = 2; case 2: afStrRef = _a; if (!afStrRef) return [2 /*return*/]; afStr = plugin.managers.structure.hierarchy.current.refs.get(afStrRef); segmentNum = segmentIndex ? segmentIndex : spState.activeSegment - 1; if (!spState.alphafold.transforms[segmentNum]) { mappingResult_1 = []; coordinateSystems_1 = []; failedPairsResult_1 = []; zeroOverlapPairsResult_1 = []; minRmsd_1 = 0; minIndex_1 = 0; rmsdList_1 = []; segmentClusters = spState.segmentData[segmentNum].clusters; segmentClusters.forEach(function (cluster) { var _a, _b, _c; var modelRef = spState.models["".concat(cluster[0].pdb_id, "_").concat(cluster[0].struct_asym_id)]; if (modelRef) { var structHierarchy = plugin.managers.structure.hierarchy.current.refs.get(modelRef); if (structHierarchy) { var input = [structHierarchy.components[0], afStr]; var structures = input.map(function (s) { var _a; return (_a = s.cell.obj) === null || _a === void 0 ? void 0 : _a.data; }); var _d = (0, superposition_sifts_mapping_1.alignAndSuperposeWithSIFTSMapping)(structures, { traceOnly: traceOnly, includeResidueTest: function (loc) { return structure_1.StructureProperties.atom.B_iso_or_equiv(loc) > 70; }, applyTestIndex: [1] }), entries = _d.entries, failedPairs = _d.failedPairs, zeroOverlapPairs = _d.zeroOverlapPairs; if (entries.length === 0 || (entries && entries[0] && entries[0].transform.rmsd.toFixed(1) === '0.0')) { var alignWithoutPlddt = (0, superposition_sifts_mapping_1.alignAndSuperposeWithSIFTSMapping)(structures, { traceOnly: traceOnly }); entries = alignWithoutPlddt.entries; } if (entries && entries[0]) { mappingResult_1.push(entries[0]); coordinateSystems_1.push((_c = (_b = (_a = input[0]) === null || _a === void 0 ? void 0 : _a.transform) === null || _b === void 0 ? void 0 : _b.cell.obj) === null || _c === void 0 ? void 0 : _c.data.coordinateSystem); var totalMappings = mappingResult_1.length; if (totalMappings === 1 || entries[0].transform.rmsd < minRmsd_1) { minRmsd_1 = entries[0].transform.rmsd; minIndex_1 = totalMappings === 1 ? 0 : mappingResult_1.length - 1; } rmsdList_1.push("".concat(cluster[0].pdb_id, " chain ").concat(cluster[0].struct_asym_id, ":").concat(entries[0].transform.rmsd.toFixed(2))); } else { if (failedPairs.length > 0) failedPairsResult_1.push(failedPairs); if (zeroOverlapPairs.length > 0) zeroOverlapPairsResult_1.push(zeroOverlapPairs); // rmsdList.push(`${cluster[0].pdb_id} ${cluster[0].struct_asym_id}:-`) } } } }); // console.log(failedPairsResult); // console.log(zeroOverlapPairsResult); if (mappingResult_1.length > 0) { spState.alphafold.visibility[segmentNum] = true; spState.alphafold.transforms[segmentNum] = mappingResult_1[minIndex_1].transform.bTransform; spState.alphafold.coordinateSystems[segmentNum] = coordinateSystems_1[minIndex_1]; spState.alphafold.rmsds[segmentNum] = rmsdList_1.sort(function (a, b) { return parseFloat(a.split(':')[1]) - parseFloat(b.split(':')[1]); }); } } return [4 /*yield*/, afTransform(plugin, afStr.cell, spState.alphafold.transforms[segmentNum], spState.alphafold.coordinateSystems[segmentNum])]; case 3: _b.sent(); (0, alphafold_transparency_1.applyAFTransparency)(plugin, afStr, 0.8, 70); return [2 /*return*/, true]; } }); }); } function renderSuperposition(plugin, segmentIndex, entryList) { return tslib_1.__awaiter(this, void 0, void 0, function () { var customState, superpositionParams, busyFlagOn; var _this = this; return tslib_1.__generator(this, function (_a) { customState = plugin.customState; superpositionParams = customState.initParams.superpositionParams; busyFlagOn = false; if (entryList.length > 1) { busyFlagOn = true; customState.events.isBusy.next(true); } // Load Coordinates and render respresentations return [2 /*return*/, plugin.dataTransaction(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { var spState, _a, entryList_1, entryList_1_1, s, strUrl, strInstance, modelRef, clearOnFail, polymerInstance, modelInstance, isBinary, _b, model, structure, matrix, chainSel, uniformColor1, uniformColor2, invalidStruct, state, hetInfo, hets, _c, hets_1, hets_1_1, het, ligand, labelTagParams, hetColor, _d, r, g, b, ligandExp, e_2_1, carbEntityCount, allCarbPolymers, polymerChainWithSurroundings, i, _e, _f, carbEntityChainId, carbEntityChain, carbEntityChainInVicinity, data, carbChainSel, carbLigands, carbLigNamesAndCount, carbLigList, _g, _h, carbLigs, ligResDetails, carbVisLabel, branchedEntity, labelTagParams, ligandExp, e_3_1, loadedStructIndex, e_4_1; var e_3, _j, e_5, _k; var _l, e_4, _m, _o, _p, e_2, _q, _r; return tslib_1.__generator(this, function (_s) { switch (_s.label) { case 0: spState = plugin.customState.superpositionState; _s.label = 1; case 1: _s.trys.push([1, 45, 46, 51]); _a = true, entryList_1 = tslib_1.__asyncValues(entryList); _s.label = 2; case 2: return [4 /*yield*/, entryList_1.next()]; case 3: if (!(entryList_1_1 = _s.sent(), _l = entryList_1_1.done, !_l)) return [3 /*break*/, 44]; _o = entryList_1_1.value; _a = false; s = _o; // validate matrix availability if (!spState.matrixData["".concat(s.pdb_id, "_").concat(s.auth_asym_id)]) { spState.noMatrixStruct.push("".concat(s.pdb_id, "_").concat(s.struct_asym_id)); spState.invalidStruct.push("".concat(s.pdb_id, "_").concat(s.struct_asym_id)); return [3 /*break*/, 43]; } spState.loadedStructs[segmentIndex].push("".concat(s.pdb_id, "_").concat(s.struct_asym_id)); strUrl = "".concat(customState.initParams.pdbeUrl, "model-server/v1/").concat(s.pdb_id, "/atoms?auth_asym_id=").concat(s.auth_asym_id, "&encoding=").concat(customState.initParams.encoding); if (superpositionParams && superpositionParams.ligandView) strUrl = "https://www.ebi.ac.uk/pdbe/entry-files/download/".concat(s.pdb_id, ".bcif"); strInstance = void 0; modelRef = void 0; clearOnFail = true; if (!(superpositionParams && superpositionParams.ligandView && spState.entries[s.pdb_id])) return [3 /*break*/, 5]; polymerInstance = plugin.state.data.select(spState.entries[s.pdb_id])[0]; modelRef = polymerInstance.transform.parent; modelInstance = plugin.state.data.select(modelRef)[0]; return [4 /*yield*/, plugin.builders.structure.createStructure(modelInstance, { name: 'model', params: {} })]; case 4: strInstance = _s.sent(); clearOnFail = false; return [3 /*break*/, 7]; case 5: isBinary = customState.initParams.encoding === 'bcif' ? true : false; return [4 /*yield*/, loadStructure(plugin, strUrl, 'mmcif', isBinary)]; case 6: _b = _s.sent(), model = _b.model, structure = _b.structure; strInstance = structure; modelRef = model.ref; _s.label = 7; case 7: if (!strInstance) return [3 /*break*/, 43]; // Store Refs in state if (!spState.models["".concat(s.pdb_id, "_").concat(s.struct_asym_id)]) spState.models["".concat(s.pdb_id, "_").concat(s.struct_asym_id)] = strInstance === null || strInstance === void 0 ? void 0 : strInstance.ref; if (superpositionParams && superpositionParams.ligandView && !spState.entries[s.pdb_id]) spState.entries[s.pdb_id] = strInstance === null || strInstance === void 0 ? void 0 : strInstance.ref; matrix = linear_algebra_1.Mat4.ofRows(plugin.customState.superpositionState.matrixData["".concat(s.pdb_id, "_").concat(s.auth_asym_id)].matrix); return [4 /*yield*/, transform(plugin, strInstance, matrix)]; case 8: _s.sent(); chainSel = void 0; if (!((superpositionParams && superpositionParams.ligandView) && s.is_representative)) return [3 /*break*/, 12]; uniformColor1 = getRandomColor(plugin, segmentIndex); return [4 /*yield*/, plugin.builders.structure.tryCreateComponentFromExpression(strInstance, chainSelection(s.struct_asym_id), "Chain-".concat(segmentIndex), { label: "Chain", tags: ["superposition-sel"] })]; case 9: chainSel = _s.sent(); if (!chainSel) return [3 /*break*/, 11]; return [4 /*yield*/, plugin.builders.structure.representation.addRepresentation(chainSel, { type: 'putty', color: 'uniform', colorParams: { value: uniformColor1 }, size: 'uniform' }, { tag: "superposition-visual" })]; case 10: _s.sent(); spState.refMaps[chainSel.ref] = "".concat(s.pdb_id, "_").concat(s.struct_asym_id); _s.label = 11; case 11: return [3 /*break*/, 16]; case 12: if (!((superpositionParams && superpositionParams.ligandView) && !s.is_representative)) return [3 /*break*/, 13]; return [3 /*break*/, 16]; case 13: uniformColor2 = getRandomColor(plugin, segmentIndex); return [4 /*yield*/, plugin.builders.structure.tryCreateComponentStatic(strInstance, 'polymer', { label: "Chain", tags: ["Chain-".concat(segmentIndex), "superposition-sel"] })]; case 14: chainSel = _s.sent(); if (!chainSel) return [3 /*break*/, 16]; return [4 /*yield*/, plugin.builders.structure.representation.addRepresentation(chainSel, { type: 'putty', color: 'uniform', colorParams: { value: uniformColor2 }, size: 'uniform' }, { tag: "superposition-visual" })]; case 15: _s.sent(); spState.refMaps[chainSel.ref] = "".concat(s.pdb_id, "_").concat(s.struct_asym_id); _s.label = 16; case 16: invalidStruct = chainSel ? false : true; if (!(superpositionParams && superpositionParams.ligandView)) return [3 /*break*/, 43]; state = plugin.state.data; return [4 /*yield*/, getLigandNamesFromModelData(plugin, state, modelRef)]; case 17: hetInfo = _s.sent(); hets = hetInfo ? hetInfo.hetNames : []; if (!(hets && hets.length > 0)) return [3 /*break*/, 31]; _s.label = 18; case 18: _s.trys.push([18, 25, 26, 31]); _c = true, hets_1 = (e_2 = void 0, tslib_1.__asyncValues(hets)); _s.label = 19; case 19: return [4 /*yield*/, hets_1.next()]; case 20: if (!(hets_1_1 = _s.sent(), _p = hets_1_1.done, !_p)) return [3 /*break*/, 24]; _r = hets_1_1.value; _c = false; het = _r; ligand = builder_1.MolScriptBuilder.struct.generator.atomGroups({ 'chain-test': builder_1.MolScriptBuilder.core.rel.eq([builder_1.MolScriptBuilder.struct.atomProperty.macromolecular.auth_asym_id(), s.auth_asym_id]), 'residue-test': builder_1.MolScriptBuilder.core.rel.eq([builder_1.MolScriptBuilder.struct.atomProperty.macromolecular.label_comp_id(), het]), 'group-by': builder_1.MolScriptBuilder.core.str.concat([builder_1.MolScriptBuilder.struct.atomProperty.core.operatorName(), builder_1.MolScriptBuilder.struct.atomProperty.macromolecular.residueKey()]) }); labelTagParams = { label: "".concat(het), tags: ["superposition-ligand-sel"] }; hetColor = color_1.Color.fromRgb(253, 3, 253); if (superpositionParams && superpositionParams.ligandColor) { _d = superpositionParams.ligandColor, r = _d.r, g = _d.g, b = _d.b; hetColor = color_1.Color.fromRgb(r, g, b); } return [4 /*yield*/, plugin.builders.structure.tryCreateComponentFromExpression(strInstance, ligand, "".concat(het, "-").concat(segmentIndex), labelTagParams)]; case 21: ligandExp = _s.sent(); if (!ligandExp) return [3 /*break*/, 23]; return [4 /*yield*/, plugin.builders.structure.representation.addRepresentation(ligandExp, { type: 'ball-and-stick', color: 'uniform', colorParams: { value: hetColor } }, { tag: "superposition-ligand-visual" })]; case 22: _s.sent(); spState.refMaps[ligandExp.ref] = "".concat(s.pdb_id, "_").concat(s.struct_asym_id); invalidStruct = false; _s.label = 23; case 23: _c = true; return [3 /*break*/, 19]; case 24: return [3 /*break*/, 31]; case 25: e_2_1 = _s.sent(); e_2 = { error: e_2_1 }; return [3 /*break*/, 31]; case 26: _s.trys.push([26, , 29, 30]); if (!(!_c && !_p && (_q = hets_1.return))) return [3 /*break*/, 28]; return [4 /*yield*/, _q.call(hets_1)]; case 27: _s.sent(); _s.label = 28; case 28: return [3 /*break*/, 30]; case 29: if (e_2) throw e_2.error; return [7 /*endfinally*/]; case 30: return [7 /*endfinally*/]; case 31: carbEntityCount = hetInfo ? hetInfo.carbEntityCount : 0; if (!(carbEntityCount > 0)) return [3 /*break*/, 42]; return [4 /*yield*/, getCarbPolymerDetailsFromApi(plugin, s.pdb_id)]; case 32: allCarbPolymers = _s.sent(); polymerChainWithSurroundings = builder_1.MolScriptBuilder.struct.modifier.includeSurroundings({ 0: builder_1.MolScriptBuilder.struct.generator.atomGroups({ 'entity-test': builder_1.MolScriptBuilder.core.rel.eq([builder_1.MolScriptBuilder.ammp('entityType'), 'polymer']), 'chain-test': builder_1.MolScriptBuilder.core.rel.eq([builder_1.MolScriptBuilder.struct.atomProperty.macromolecular.auth_asym_id(), s.auth_asym_id]), 'group-by': builder_1.MolScriptBuilder.core.str.concat([builder_1.MolScriptBuilder.struct.atomProperty.core.operatorName(), builder_1.MolScriptBuilder.struct.atomProperty.macromolecular.residueKey()]) }), radius: 5, 'as-whole-residues': true }); i = 0; _s.label = 33; case 33: _s.trys.push([33, 40, 41, 42]); _e = (e_3 = void 0, tslib_1.__values(allCarbPolymers.branchedChains)), _f = _e.next(); _s.label = 34; case 34: if (!!_f.done) return [3 /*break*/, 39]; carbEntityChainId = _f.value; carbEntityChain = builder_1.MolScriptBuilder.struct.generator.atomGroups({ 'entity-test': builder_1.MolScriptBuilder.core.rel.eq([builder_1.MolScriptBuilder.ammp('entityType'), 'branched']), 'chain-test': builder_1.MolScriptBuilder.core.rel.eq([builder_1.MolScriptBuilder.struct.atomProperty.macromolecular.auth_asym_id(), carbEntityChainId]), 'group-by': builder_1.MolScriptBuilder.core.str.concat([builder_1.MolScriptBuilder.struct.atomProperty.core.operatorName(), builder_1.MolScriptBuilder.struct.atomProperty.macromolecular.residueKey()]) }); carbEntityChainInVicinity = builder_1.MolScriptBuilder.struct.filter.intersectedBy({ 0: polymerChainWithSurroundings, by: carbEntityChain }); data = (plugin.state.data.select(strInstance.ref)[0].obj).data; carbChainSel = script_1.Script.getStructureSelection(carbEntityChainInVicinity, data); if (!(carbChainSel && carbChainSel.kind === 'sequence')) return [3 /*break*/, 37]; carbLigands = []; carbLigNamesAndCount = {}; carbLigList = []; try { for (_g = (e_5 = void 0, tslib_1.__values(allCarbPolymers.branchedLigands[i])), _h = _g.next(); !_h.done; _h = _g.next()) { carbLigs = _h.value; ligResDetails = carbLigs.split('-'); carbLigands.push(builder_1.MolScriptBuilder.core.rel.eq([builder_1.MolScriptBuilder.struct.atomProperty.macromolecular.auth_seq_id(), +ligResDetails[1]])); if (carbLigNamesAndCount[ligResDetails[0]]) { carbLigNamesAndCount[ligResDetails[0]]++; } else { carbLigNamesAndCount[ligResDetails[0]] = 1; } carbLigList.push(ligResDetails[0]); } } catch (e_5_1) { e_5 = { error: e_5_1 }; } finally { try { if (_h && !_h.done && (_k = _g.return)) _k.call(_g); } finally { if (e_5) throw e_5.error; } } carbVisLabel = createCarbVisLabel(carbLigNamesAndCount); branchedEntity = builder_1.MolScriptBuilder.struct.generator.atomGroups({ 'entity-test': builder_1.MolScriptBuilder.core.rel.eq([builder_1.MolScriptBuilder.ammp('entityType'), 'branched']), 'group-by': builder_1.MolScriptBuilder.core.str.concat([builder_1.MolScriptBuilder.struct.atomProperty.core.operatorName(), builder_1.MolScriptBuilder.struct.atomProperty.macromolecular.residueKey()]), 'chain-test': builder_1.MolScriptBuilder.core.rel.eq([builder_1.MolScriptBuilder.struct.atomProperty.macromolecular.auth_asym_id(), carbEntityChainId]), 'residue-test': builder_1.MolScriptBuilder.core.logic.or(carbLigands) }); labelTagParams = { label: "".concat(carbVisLabel), tags: ["superposition-carb-sel"] }; return [4 /*yield*/, plugin.builders.structure.tryCreateComponentFromExpression(strInstance, branchedEntity, "".concat(carbLigList.join('-'), "-").concat(segmentIndex), labelTagParams)]; case 35: ligandExp = _s.sent(); if (!ligandExp) return [3 /*break*/, 37]; return [4 /*yield*/, plugin.builders.structure.representation.addRepresentation(ligandExp, { type: 'carbohydrate' }, { tag: "superposition-carb-visual" })]; case 36: _s.sent(); spState.refMaps[ligandExp.ref] = "".concat(s.pdb_id, "_").concat(s.struct_asym_id); invalidStruct = false; _s.label = 37; case 37: i++; _s.label = 38; case 38: _f = _e.next(); return [3 /*break*/, 34]; case 39: return [3 /*break*/, 42]; case 40: e_3_1 = _s.sent(); e_3 = { error: e_3_1 }; return [3 /*break*/, 42]; case 41: try { if (_f && !_f.done && (_j = _e.return)) _j.call(_e); } finally { if (e_3) throw e_3.error; } return [7 /*endfinally*/]; case 42: if (invalidStruct) { spState.invalidStruct.push("".concat(s.pdb_id, "_").concat(s.struct_asym_id)); loadedStructIndex = spState.loadedStructs[segmentIndex].indexOf("".concat(s.pdb_id, "_").concat(s.struct_asym_id)); if (loadedStructIndex > -1) spState.loadedStructs[segmentIndex].splice(loadedStructIndex, 1); // remove downloaded data if (clearOnFail) { // const m = plugin.state.data.select(modelRef)[0]; // const t = plugin.state.data.select(m.transform.parent)[0]; // const d = plugin.state.data.select(t.transform.parent)[0]; // PluginCommands.State.RemoveObject(plugin, { state: d.parent!, ref: d.transform.parent, removeParentGhosts: true }); } } else { // if(interactingHets.length > 0) spState.hets[`${s.pdb_id}_${s.struct_asym_id}`] = interactingHets; } _s.label = 43; case 43: _a = true; return [3 /*break*/, 2]; case 44: return [3 /*break*/, 51]; case 45: e_4_1 = _s.sent(); e_4 = { error: e_4_1 }; return [3 /*break*/, 51]; case 46: _s.trys.push([46, , 49, 50]); if (!(!_a && !_l && (_m = entryList_1.return))) return [3 /*break*/, 48]; return [4 /*yield*/, _m.call(entryList_1)]; case 47: _s.sent(); _s.label = 48; case 48: return [3 /*break*/, 50]; case 49: if (e_4) throw e_4.error; return [7 /*endfinally*/]; case 50: return [7 /*endfinally*/]; case 51: if (busyFlagOn) { busyFlagOn = false; customState.events.isBusy.next(false); } return [2 /*return*/]; } }); }); })]; }); }); } function getLigandNamesFromModelData(plugin, state, modelRef) { return tslib_1.__awaiter(this, void 0, void 0, function () { var cell, model, structures, _a, _b, s, structure, info; var e_6, _c; var _d; return tslib_1.__generator(this, function (_e) { switch (_e.label) { case 0: cell = state.select(modelRef)[0]; if (!cell || !cell.obj) return [2 /*return*/, void 0]; model = cell.obj.data; if (!model) return [2 /*return*/]; structures = []; try { for (_a = tslib_1.__values(plugin.managers.structure.hierarchy.selection.structures), _b = _a.next(); !_b.done; _b = _a.next()) { s = _b.value; structure = (_d = s.cell.obj) === null || _d === void 0 ? void 0 : _d.data; if (structure) structures.push(structure); } } catch (e_6_1) { e_6 = { error: e_6_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_6) throw e_6.error; } } return [4 /*yield*/, helpers_1.ModelInfo.get(model, structures)]; case 1: info = _e.sent(); return [2 /*return*/, info]; } }); }); } function loadStructure(plugin, url, format, isBinary) { return tslib_1.__awaiter(this, void 0, void 0, function () { var data, trajectory, model, modelProperties, structure, e_7; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 7, , 8]); return [4 /*yield*/, plugin.builders.data.download({ url: assets_1.Asset.Url(url), isBinary: isBinary })]; 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.insertModelProperties(model)]; case 4: modelProperties = _a.sent(); return [4 /*yield*/, plugin.builders.structure.createStructure(modelProperties || model, { name: 'model', params: {} })]; case 5: structure = _a.sent(); return [4 /*yield*/, plugin.builders.structure.insertStructureProperties(structure)]; case 6: _a.sent(); return [2 /*return*/, { data: data, trajectory: trajectory, model: model, structure: structure }]; case 7: e_7 = _a.sent(); return [2 /*return*/, { structure: void 0 }]; case 8: return [2 /*return*/]; } }); }); } function chainSelection(struct_asym_id) { return builder_1.MolScriptBuilder.struct.generator.atomGroups({ 'chain-test': builder_1.MolScriptBuilder.core.rel.eq([builder_1.MolScriptBuilder.struct.atomProperty.macromolecular.label_asym_id(), struct_asym_id]) }); } function transform(plugin, s, matrix) { var b = plugin.state.data.build().to(s) .insert(transforms_1.StateTransforms.Model.TransformStructureConformation, { transform: { name: 'matrix', params: { data: matrix, transpose: false } } }); return plugin.runTask(plugin.state.data.updateTree(b)); } function afTransform(plugin, s, matrix, coordinateSystem) { return tslib_1.__awaiter(this, void 0, void 0, function () { var r, o, transform, params, b; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: r = mol_state_1.StateObjectRef.resolveAndCheck(plugin.state.data, s); if (!r) return [2 /*return*/]; o = plugin.state.data.selectQ(function (q) { return q.byRef(r.transform.ref).subtree().withTransformer(transforms_1.StateTransforms.Model.TransformStructureConformation); })[0]; transform = coordinateSystem && !linear_algebra_1.Mat4.isIdentity(coordinateSystem.matrix) ? linear_algebra_1.Mat4.mul((0, linear_algebra_1.Mat4)(), coordinateSystem.matrix, matrix) : matrix; params = { transform: { name: 'matrix', params: { data: transform, transpose: false } } }; b = o ? plugin.state.data.build().to(o).update(params) : plugin.state.data.build().to(s) .insert(transforms_1.StateTransforms.Model.TransformStructureConformation, params, { tags: 'SuperpositionTransform' }); return [4 /*yield*/, plugin.runTask(plugin.state.data.updateTree(b))]; case 1: _a.sent(); return [2 /*return*/]; } }); }); } function getMatrixData(plugin) { return tslib_1.__awaiter(this, void 0, void 0, function () { var customState, matrixAccession, clusterRecUrlStr, assetManager, clusterRecUrl, clusterRecData, e_8; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: customState = plugin.customState; matrixAccession = customState.initParams.superpositionParams.matrixAccession ? customState.initParams.superpositionParams.matrixAccession : customState.initParams.moleculeId; clusterRecUrlStr = "".concat(customState.initParams.pdbeUrl, "static/superpose/matrices/").concat(matrixAccession); assetManager = plugin.managers.asset; clusterRecUrl = assets_1.Asset.getUrlAsset(assetManager, clusterRecUrlStr); _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); return [4 /*yield*/, plugin.runTask(assetManager.resolve(clusterRecUrl, 'json', false))]; case 2: clusterRecData = _a.sent(); if (clusterRecData && clusterRecData.data) { plugin.customState.superpositionState.matrixData = clusterRecData.data; } return [3 /*break*/, 4]; case 3: e_8 = _a.sent(); customState['superpositionError'] = "Matrix data not available for ".concat(matrixAccession); plugin.customState.events.superpositionInit.next(true); // Emit segment API data load event return [3 /*break*/, 4]; case 4: return [2 /*return*/]; } }); }); } function getSegmentData(plugin) { return tslib_1.__awaiter(this, void 0, void 0, function () { var customState, segmentsUrl, assetManager, url, result, e_9; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: customState = plugin.customState; segmentsUrl = "".concat(customState.initParams.pdbeUrl, "graph-api/uniprot/superposition/").concat(customState.initParams.moleculeId); assetManager = plugin.managers.asset; url = assets_1.Asset.getUrlAsset(assetManager, segmentsUrl); _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); return [4 /*yield*/, plugin.runTask(assetManager.resolve(url, 'json', false))]; case 2: result = _a.sent(); if (result && result.data) { customState.superpositionState.segmentData = result.data[customState.initParams.moleculeId]; } return [3 /*break*/, 4]; case 3: e_9 = _a.sent(); customState['superpositionError'] = "Superposition data not available for ".concat(customState.initParams.moleculeId); plugin.customState.events.superpositionInit.next(true); // Emit segment API data load event return [3 /*break*/, 4]; case 4: return [2 /*return*/]; } }); }); } function getChainLigands(carbEntity) { var e_10, _a, e_11, _b, e_12, _c; var ligandChain = []; var ligandLabels = []; var ligands = []; var labelValueArr = []; var ligNameStr = ''; try { for (var _d = tslib_1.__values(carbEntity.chem_comp_list), _e = _d.next(); !_e.done; _e = _d.next()) { var chemComp = _e.value; labelValueArr.push("".concat(chemComp.chem_comp_id, " (")