pdbe-molstar
Version:
Molstar implementation for PDBe
113 lines (112 loc) • 6.27 kB
JavaScript
"use strict";
/** Helper functions to allow showing custom atom interactions */
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadInteractions_example = loadInteractions_example;
exports.loadInteractions = loadInteractions;
exports.clearInteractions = clearInteractions;
const tslib_1 = require("tslib");
const primitives_1 = require("molstar/lib/extensions/mvs/components/primitives");
const mvs_data_1 = require("molstar/lib/extensions/mvs/mvs-data");
const representation_1 = require("molstar/lib/mol-plugin-state/transforms/representation");
const state_1 = require("molstar/lib/mol-plugin/behavior/static/state");
const __1 = require("../..");
const helpers_1 = require("../../helpers");
const plugin_custom_state_1 = require("../../plugin-custom-state");
/** Name used when registering extension, custom state, etc. */
const InteractionsExtensionName = 'pdbe-custom-interactions';
const getExtensionCustomState = plugin_custom_state_1.ExtensionCustomState.getter(InteractionsExtensionName);
const DEFAULT_COLOR = 'white';
const DEFAULT_RADIUS = 0.075;
const DEFAULT_DASH_LENGTH = 0.1;
const DEFAULT_OPACITY = 1;
function loadInteractions_example(viewer, params) {
return loadInteractions(viewer, Object.assign(Object.assign({}, params), { interactions: exampleData }));
}
/** Show custom atom interactions */
function loadInteractions(viewer, params) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
var _a, _b;
var _c;
const structureId = (_a = params.structureId) !== null && _a !== void 0 ? _a : __1.PDBeMolstarPlugin.MAIN_STRUCTURE_ID;
const struct = viewer.getStructure(structureId);
if (!struct)
throw new Error(`Did not find structure with ID "${structureId}"`);
const primitivesMvsNode = interactionsToMvsPrimitiveData(params);
const update = viewer.plugin.build();
const data = update.to(struct.cell).apply(primitives_1.MVSInlinePrimitiveData, { node: primitivesMvsNode }, { tags: ['custom-interactions-data'] });
data.apply(primitives_1.MVSBuildPrimitiveShape, { kind: 'mesh' }).apply(representation_1.ShapeRepresentation3D, {}, { tags: ['custom-interactions-mesh'] });
data.apply(primitives_1.MVSBuildPrimitiveShape, { kind: 'lines' }).apply(representation_1.ShapeRepresentation3D, {}, { tags: ['custom-interactions-lines'] });
data.apply(primitives_1.MVSBuildPrimitiveShape, { kind: 'labels' }).apply(representation_1.ShapeRepresentation3D, {}, { tags: ['custom-interactions-labels'] });
yield update.commit();
const visual = {
ref: data.ref,
setVisibility: (visible) => (0, state_1.setSubtreeVisibility)(viewer.plugin.state.data, data.ref, !visible /* true means hidden */),
delete: () => viewer.plugin.build().delete(data.ref).commit(),
};
const visualsList = (_b = (_c = getExtensionCustomState(viewer.plugin)).visuals) !== null && _b !== void 0 ? _b : (_c.visuals = []);
visualsList.push(visual);
return visual;
});
}
/** Remove any previously added interactions */
function clearInteractions(viewer) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const visuals = getExtensionCustomState(viewer.plugin).visuals;
if (!visuals)
return;
for (const visual of visuals) {
yield visual.delete();
}
visuals.length = 0;
});
}
function interactionsToMvsPrimitiveData(params) {
var _a, _b, _c, _d, _e, _f, _g;
const builder = mvs_data_1.MVSData.createBuilder();
const primitives = builder.primitives({
opacity: (_a = params.opacity) !== null && _a !== void 0 ? _a : DEFAULT_OPACITY,
color: (_b = params.color) !== null && _b !== void 0 ? _b : DEFAULT_COLOR,
});
for (const interaction of params.interactions) {
primitives.tube({
start: { expressions: (0, helpers_1.queryParamsToMvsComponentExpressions)([interaction.start]) },
end: { expressions: (0, helpers_1.queryParamsToMvsComponentExpressions)([interaction.end]) },
radius: (_d = (_c = interaction.radius) !== null && _c !== void 0 ? _c : params.radius) !== null && _d !== void 0 ? _d : DEFAULT_RADIUS,
dash_length: (_f = (_e = interaction.dash_length) !== null && _e !== void 0 ? _e : params.dash_length) !== null && _f !== void 0 ? _f : DEFAULT_DASH_LENGTH,
color: interaction.color,
tooltip: interaction.tooltip,
});
}
const state = builder.getState();
const primitivesNode = (_g = state.root.children) === null || _g === void 0 ? void 0 : _g.find(child => child.kind === 'primitives');
if (!primitivesNode)
throw new Error('AssertionError: Failed to create MVS "primitives" subtree.');
return primitivesNode;
}
/** Selected interactions from https://www.ebi.ac.uk/pdbe/graph-api/pdb/bound_ligand_interactions/1hda/C/143 */
const exampleData = [
{
'start': { 'auth_asym_id': 'C', 'auth_seq_id': 143, 'label_atom_id': 'CBC' },
'end': { 'auth_asym_id': 'C', 'auth_seq_id': 32, 'label_atom_id': 'CE' },
'color': 'yellow',
'tooltip': '<strong>Hydrophobic interaction</strong><br>HEM 143 | CBC — MET 32 | CE',
},
{
'start': { 'auth_asym_id': 'C', 'auth_seq_id': 143, 'label_atom_id': 'CBC' },
'end': { 'auth_asym_id': 'C', 'auth_seq_id': 32, 'label_atom_id': 'SD' },
'color': 'yellow',
'tooltip': '<strong>Hydrophobic interaction</strong><br>HEM 143 | CBC — MET 32 | SD',
},
{
'start': { 'auth_asym_id': 'C', 'auth_seq_id': 143, 'label_atom_id': 'CMD' },
'end': { 'auth_asym_id': 'C', 'auth_seq_id': 42, 'label_atom_id': 'O' },
'color': 'gray',
'tooltip': '<strong>Mixed interaction</strong><br>Vdw, Weak polar<br>HEM 143 | CMD — TYR 42 | O',
},
{
'start': { 'auth_asym_id': 'C', 'auth_seq_id': 143, 'label_atom_id': ['C1B', 'C2B', 'C3B', 'C4B', 'NB'] },
'end': { 'auth_asym_id': 'C', 'auth_seq_id': 136, 'label_atom_id': 'CD1' },
'color': 'magenta',
'tooltip': '<strong>CARBONPI interaction</strong><br>HEM 143 | C1B, C2B, C3B, C4B, NB — LEU 136 | CD1',
},
];