@rcsb/rcsb-saguaro-3d
Version:
RCSB Molstar/Saguaro Web App
80 lines • 3.72 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>
*/
import { __awaiter } from "tslib";
import { TrajectoryHierarchyPresetProvider } from "molstar/lib/mol-plugin-state/builder/structure/hierarchy-preset";
import { ParamDefinition as PD } from "molstar/lib/mol-util/param-definition";
import { AlignmentRepresentationPresetProvider } from "./AlignmentRepresentationPresetProvider";
import { FocusResidueColorThemeProvider } from "./FocusTheme/FocusColoring";
import { ModelSymmetry } from "molstar/lib/mol-model-formats/structure/property/symmetry";
export const AlignmentTrajectoryPresetProvider = TrajectoryHierarchyPresetProvider({
id: 'alignment-to-reference',
display: {
name: 'Alignment to Reference'
},
isApplicable: (trajectory, plugin) => true,
params: (trajectory, plugin) => ({
pdb: PD.Value(undefined),
targetAlignment: PD.Value(undefined),
modelIndex: PD.Value(0),
transform: PD.Value(undefined)
}),
apply: (trajectory, params, plugin) => __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(FocusResidueColorThemeProvider))
plugin.representation.structure.themes.colorThemeRegistry.add(FocusResidueColorThemeProvider);
const representation = yield plugin.builders.structure.representation.applyPreset(structureProperties, 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 = 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';
}
//# sourceMappingURL=AlignmentTrajectoryPresetProvider.js.map