Skip to content

Commit 1c75163

Browse files
committed
Interactions extension - add handle to toggle visibility
1 parent d5949ac commit 1c75163

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file, following t
33

44
## [Unreleased]
55
- Mol* core dependency updated to 4.14.1
6+
- Custom interactions extension (PDBeMolstarPlugin.extensions.Interactions)
67

78
## [v3.4.0] - 2025-11-25
89
- Added `.visual.interactivityFocus` method

src/app/extensions/interactions/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { MVSData } from 'molstar/lib/extensions/mvs/mvs-data';
55
import { MolstarSubtree } from 'molstar/lib/extensions/mvs/tree/molstar/molstar-tree';
66
import { ColorT } from 'molstar/lib/extensions/mvs/tree/mvs/param-types';
77
import { ShapeRepresentation3D } from 'molstar/lib/mol-plugin-state/transforms/representation';
8+
import { setSubtreeVisibility } from 'molstar/lib/mol-plugin/behavior/static/state';
89
import { PDBeMolstarPlugin } from '../..';
910
import { QueryParam, queryParamsToMvsComponentExpressions } from '../../helpers';
1011
import { ExtensionCustomState } from '../../plugin-custom-state';
@@ -27,18 +28,20 @@ export interface Interaction {
2728
export interface StateObjectHandle {
2829
/** State transform reference */
2930
ref: string,
31+
/** Set state object visibility on/off */
32+
setVisibility(visible: boolean): void,
3033
/** Remove state object from state hierarchy */
3134
delete: () => Promise<void>,
3235
}
3336

34-
export function loadInteractions_example(viewer: PDBeMolstarPlugin) {
37+
export function loadInteractions_example(viewer: PDBeMolstarPlugin): Promise<StateObjectHandle> {
3538
return loadInteractions(viewer, { interactions: exampleData });
3639
}
3740

38-
export async function loadInteractionsFromApi(viewer: PDBeMolstarPlugin, params: { pdbId: string, authAsymId: string, authSeqId: number, structureId?: string }) {
41+
export async function loadInteractionsFromApi(viewer: PDBeMolstarPlugin, params: { pdbId: string, authAsymId: string, authSeqId: number, structureId?: string }): Promise<StateObjectHandle> {
3942
const data = await getInteractionApiData({ ...params, pdbeBaseUrl: viewer.initParams.pdbeUrl });
4043
const interactions = interactionsFromApiData(data, params.pdbId);
41-
await loadInteractions(viewer, { interactions, structureId: params.structureId });
44+
return await loadInteractions(viewer, { interactions, structureId: params.structureId });
4245
}
4346

4447
/** Show custom atom interactions */
@@ -58,6 +61,7 @@ export async function loadInteractions(viewer: PDBeMolstarPlugin, params: { inte
5861

5962
const visual: StateObjectHandle = {
6063
ref: data.ref,
64+
setVisibility: (visible: boolean) => setSubtreeVisibility(viewer.plugin.state.data, data.ref, !visible /* true means hidden */),
6165
delete: () => viewer.plugin.build().delete(data.ref).commit(),
6266
};
6367
const visualsList = getExtensionCustomState(viewer.plugin).visuals ??= [];

0 commit comments

Comments
 (0)