UNPKG

@rcsb/rcsb-saguaro-3d

Version:
107 lines (106 loc) 6.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AssemblyRepresentationPresetProvider = void 0; const tslib_1 = require("tslib"); const representation_preset_1 = require("molstar/lib/mol-plugin-state/builder/structure/representation-preset"); const mol_state_1 = require("molstar/lib/mol-state"); const structure_1 = require("molstar/lib/mol-model/structure"); const builder_1 = require("molstar/lib/mol-script/language/builder"); const uniqid_1 = tslib_1.__importDefault(require("uniqid")); const plddt_1 = require("molstar/lib/extensions/model-archive/quality-assessment/color/plddt"); const prop_1 = require("molstar/lib/extensions/model-archive/quality-assessment/prop"); var reprBuilder = representation_preset_1.StructureRepresentationPresetProvider.reprBuilder; const selection_1 = require("@rcsb/rcsb-molstar/build/src/viewer/helpers/selection"); const transform_1 = require("molstar/lib/mol-state/transform"); const FocusColoring_1 = require("./FocusTheme/FocusColoring"); var updateFocusRepr = representation_preset_1.StructureRepresentationPresetProvider.updateFocusRepr; exports.AssemblyRepresentationPresetProvider = (0, representation_preset_1.StructureRepresentationPresetProvider)({ id: "rcsb-saguaro-3d", display: { name: 'Feature View 3D' }, params(a, plugin) { return {}; }, apply(structureRef, params, plugin) { return tslib_1.__awaiter(this, void 0, void 0, function* () { var _a, _b; const structureCell = mol_state_1.StateObjectRef.resolveAndCheck(plugin.state.data, structureRef); if (!structureCell) return {}; const structure = structureCell.obj.data; const l = structure_1.StructureElement.Location.create(structure); const componentMap = {}; const representationMap = {}; const chains = new Set(); for (const unit of structure.units) { structure_1.StructureElement.Location.set(l, structure, unit, unit.elements[0]); const asymId = structure_1.StructureProperties.chain.label_asym_id(l); if (chains.has(asymId)) continue; if (structure_1.StructureProperties.entity.type(l) === "polymer") { chains.add(asymId); const authId = structure_1.Unit.isAtomic(l.unit) ? structure_1.StructureProperties.chain.auth_asym_id(l) : structure_1.StructureProperties.chain.label_asym_id(l); const comp = yield plugin.builders.structure.tryCreateComponentFromExpression(structureCell, builder_1.MolScriptBuilder.struct.generator.atomGroups({ 'chain-test': builder_1.MolScriptBuilder.core.logic.and([ builder_1.MolScriptBuilder.core.rel.eq([builder_1.MolScriptBuilder.ammp('label_asym_id'), asymId]) ]) }), (0, uniqid_1.default)(`${asymId}`), { label: asymId == authId ? asymId : `${asymId} [auth ${authId}]` }); componentMap[asymId] = comp; //TODO This needs to be called after tryCreateComponentFromExpression const { update, builder } = reprBuilder(plugin, { ignoreHydrogens: true, ignoreLight: false, quality: "auto" }); representationMap[asymId] = builder.buildRepresentation(update, comp, { color: structure.models.some(m => prop_1.QualityAssessment.isApplicable(m, 'pLDDT')) ? plddt_1.PLDDTConfidenceColorThemeProvider.name : "chain-id", type: "cartoon" }); yield update.commit({ revertOnError: false }); } } for (const expression of (0, selection_1.createSelectionExpressions)("none")) { if (expression.tag == "polymer") continue; const comp = yield plugin.builders.structure.tryCreateComponentFromExpression(structureCell, expression.expression, (0, uniqid_1.default)(`${expression.tag}`), { label: `${expression.tag}` }); componentMap[expression.tag] = comp; //TODO This needs to be called after tryCreateComponentFromExpression const { update, builder } = reprBuilder(plugin, { ignoreHydrogens: true, ignoreLight: false, quality: "auto" }); representationMap[expression.tag] = builder.buildRepresentation(update, comp, { type: expression.type }, { initialState: { isHidden: expression.tag == "water" } }); if (expression.type !== "ball-and-stick") representationMap[expression.tag + "#ball-and-stick"] = builder.buildRepresentation(update, comp, { type: "ball-and-stick" }, { initialState: { isHidden: expression.tag == "water" } }); if (((_a = comp === null || comp === void 0 ? void 0 : comp.cell) === null || _a === void 0 ? void 0 : _a.state) && expression.tag == "water") { transform_1.StateTransform.assignState((_b = comp === null || comp === void 0 ? void 0 : comp.cell) === null || _b === void 0 ? void 0 : _b.state, { isHidden: true }); } yield update.commit({ revertOnError: false }); } structure.inheritedPropertyData.reprList = Object.values(representationMap).filter(repr => typeof repr != "undefined"); yield updateFocusRepr(plugin, structure, FocusColoring_1.FOCUS_RESIDUE_COLOR, {}); return { components: componentMap, representations: representationMap }; }); } });