UNPKG

pdbe-molstar

Version:
94 lines (93 loc) 5.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.applyAFTransparency = applyAFTransparency; exports.setStructureTransparency = setStructureTransparency; exports.clearStructureTransparency = clearStructureTransparency; const tslib_1 = require("tslib"); const prop_1 = require("molstar/lib/extensions/model-archive/quality-assessment/prop"); const loci_1 = require("molstar/lib/mol-model/loci"); const structure_1 = require("molstar/lib/mol-model/structure"); const transforms_1 = require("molstar/lib/mol-plugin-state/transforms"); const builder_1 = require("molstar/lib/mol-script/language/builder"); const compiler_1 = require("molstar/lib/mol-script/runtime/query/compiler"); const mol_state_1 = require("molstar/lib/mol-state"); const transparency_1 = require("molstar/lib/mol-theme/transparency"); const TransparencyManagerTag = 'transparency-controls'; function getLociByPLDDT(score, contextData) { const queryExp = builder_1.MolScriptBuilder.struct.modifier.union([ builder_1.MolScriptBuilder.struct.modifier.wholeResidues([ builder_1.MolScriptBuilder.struct.modifier.union([ builder_1.MolScriptBuilder.struct.generator.atomGroups({ 'chain-test': builder_1.MolScriptBuilder.core.rel.eq([builder_1.MolScriptBuilder.ammp('objectPrimitive'), 'atomistic']), 'residue-test': builder_1.MolScriptBuilder.core.rel.lte([prop_1.QualityAssessment.symbols.pLDDT.symbol(), score]), }), ]), ]), ]); const query = (0, compiler_1.compile)(queryExp); const sel = query(new structure_1.QueryContext(contextData)); return structure_1.StructureSelection.toLociWithSourceUnits(sel); } function applyAFTransparency(plugin_1, structure_2, transparency_2) { return tslib_1.__awaiter(this, arguments, void 0, function* (plugin, structure, transparency, pLDDT = 70) { return plugin.dataTransaction((ctx) => tslib_1.__awaiter(this, void 0, void 0, function* () { const loci = getLociByPLDDT(pLDDT, structure.cell.obj.data); yield setStructureTransparency(plugin, structure.components, transparency, loci); }), { canUndo: 'Apply Transparency' }); }); } function setStructureTransparency(plugin, components, value, loci, types) { return tslib_1.__awaiter(this, void 0, void 0, function* () { yield eachRepr(plugin, components, (update, repr, transparencyCell) => tslib_1.__awaiter(this, void 0, void 0, function* () { if (types && types.length > 0 && !types.includes(repr.params.values.type.name)) return; const structure = repr.obj.data.sourceData; if (loci_1.Loci.isEmpty(loci) || (0, loci_1.isEmptyLoci)(loci)) return; const layer = { bundle: structure_1.StructureElement.Bundle.fromLoci(loci), value, }; if (transparencyCell) { const bundleLayers = [...transparencyCell.params.values.layers, layer]; const filtered = getFilteredBundle(bundleLayers, structure); update.to(transparencyCell).update(transparency_1.Transparency.toBundle(filtered)); } else { const filtered = getFilteredBundle([layer], structure); update.to(repr.transform.ref) .apply(transforms_1.StateTransforms.Representation.TransparencyStructureRepresentation3DFromBundle, transparency_1.Transparency.toBundle(filtered), { tags: TransparencyManagerTag }); } })); }); } function clearStructureTransparency(plugin, components, types) { return tslib_1.__awaiter(this, void 0, void 0, function* () { yield eachRepr(plugin, components, (update, repr, transparencyCell) => tslib_1.__awaiter(this, void 0, void 0, function* () { if (types && types.length > 0 && !types.includes(repr.params.values.type.name)) return; if (transparencyCell) { update.delete(transparencyCell.transform.ref); } })); }); } function eachRepr(plugin, components, callback) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const state = plugin.state.data; const update = state.build(); for (const c of components) { for (const r of c.representations) { const transparency = state.select(mol_state_1.StateSelection.Generators.ofTransformer(transforms_1.StateTransforms.Representation.TransparencyStructureRepresentation3DFromBundle, r.cell.transform.ref).withTag(TransparencyManagerTag)); yield callback(update, r.cell, transparency[0]); } } return update.commit({ doNotUpdateCurrent: true }); }); } /** filter transparency layers for given structure */ function getFilteredBundle(layers, structure) { const transparency = transparency_1.Transparency.ofBundle(layers, structure.root); const merged = transparency_1.Transparency.merge(transparency); return transparency_1.Transparency.filter(merged, structure); }