@rcsb/rcsb-saguaro-3d
Version:
RCSB Molstar/Saguaro Web App
83 lines (82 loc) • 4 kB
JavaScript
;
/*
* Copyright (c) 2021 RCSB PDB and contributors, licensed under MIT, See LICENSE file for more info.
* @author Joan Segura Mora <joan.segura@rcsb.org>
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.AlignmentTrajectoryPresetProvider = void 0;
const tslib_1 = require("tslib");
const hierarchy_preset_1 = require("molstar/lib/mol-plugin-state/builder/structure/hierarchy-preset");
const param_definition_1 = require("molstar/lib/mol-util/param-definition");
const AlignmentRepresentationPresetProvider_1 = require("./AlignmentRepresentationPresetProvider");
const FocusColoring_1 = require("./FocusTheme/FocusColoring");
const symmetry_1 = require("molstar/lib/mol-model-formats/structure/property/symmetry");
exports.AlignmentTrajectoryPresetProvider = (0, hierarchy_preset_1.TrajectoryHierarchyPresetProvider)({
id: 'alignment-to-reference',
display: {
name: 'Alignment to Reference'
},
isApplicable: (trajectory, plugin) => true,
params: (trajectory, plugin) => ({
pdb: param_definition_1.ParamDefinition.Value(undefined),
targetAlignment: param_definition_1.ParamDefinition.Value(undefined),
modelIndex: param_definition_1.ParamDefinition.Value(0),
transform: param_definition_1.ParamDefinition.Value(undefined)
}),
apply: (trajectory, params, plugin) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
if (!params.pdb)
return {};
const modelParams = { modelIndex: params.modelIndex };
const builder = plugin.builders.structure;
const model = yield builder.createModel(trajectory, modelParams);
const modelProperties = yield builder.insertModelProperties(model);
let structure;
if (!model.data)
return {};
const structureParams = {
name: 'assembly',
params: { id: findAssembly(model.data, params.pdb) }
};
structure = yield builder.createStructure(modelProperties || model, structureParams);
const structureProperties = yield builder.insertStructureProperties(structure);
if (!plugin.representation.structure.themes.colorThemeRegistry.has(FocusColoring_1.FocusResidueColorThemeProvider))
plugin.representation.structure.themes.colorThemeRegistry.add(FocusColoring_1.FocusResidueColorThemeProvider);
const representation = yield plugin.builders.structure.representation.applyPreset(structureProperties, AlignmentRepresentationPresetProvider_1.AlignmentRepresentationPresetProvider, {
pdb: params.pdb,
targetAlignment: params.targetAlignment,
transform: params.transform
});
//TODO what is the purpose of this return?
return {
model,
modelProperties,
structure,
structureProperties,
representation
};
})
});
function findAssembly(model, pdb) {
if (pdb)
return 'instanceId' in pdb ? findAssemblyByInstance(model, pdb.instanceId) : findAssemblyByEntityId(model, pdb.entityId);
return '1';
}
function findAssemblyByInstance(model, instanceId) {
var _a, _b, _c;
for (const assembly of (_b = (_a = symmetry_1.ModelSymmetry.Provider.get(model)) === null || _a === void 0 ? void 0 : _a.assemblies) !== null && _b !== void 0 ? _b : []) {
for (const operatorGroup of assembly.operatorGroups) {
for (const asymId of (_c = operatorGroup.asymIds) !== null && _c !== void 0 ? _c : []) {
if (asymId === instanceId)
return assembly.id;
}
}
}
return '1';
}
function findAssemblyByEntityId(model, entityId) {
var _a;
const instanceId = (_a = Array.from(model.properties.structAsymMap.values()).find(instance => instance.entity_id === entityId)) === null || _a === void 0 ? void 0 : _a.id;
if (instanceId)
return findAssemblyByInstance(model, instanceId);
return '1';
}