@@ -9,7 +9,6 @@ import { setSubtreeVisibility } from 'molstar/lib/mol-plugin/behavior/static/sta
9
9
import { PDBeMolstarPlugin } from '../..' ;
10
10
import { QueryParam , queryParamsToMvsComponentExpressions } from '../../helpers' ;
11
11
import { ExtensionCustomState } from '../../plugin-custom-state' ;
12
- import { AnyColor } from '../../spec' ;
13
12
import { getInteractionApiData , interactionsFromApiData } from './api' ;
14
13
15
14
@@ -21,10 +20,17 @@ const getExtensionCustomState = ExtensionCustomState.getter<{ visuals: StateObje
21
20
export interface Interaction {
22
21
start : QueryParam ,
23
22
end : QueryParam ,
24
- color ?: AnyColor ,
23
+ color ?: string ,
24
+ radius ?: number ,
25
+ dash_length ?: number ,
25
26
tooltip ?: string ,
26
27
}
27
28
29
+ const DEFAULT_COLOR = 'white' ;
30
+ const DEFAULT_RADIUS = 0.075 ;
31
+ const DEFAULT_DASH_LENGTH = 0.1 ;
32
+ const DEFAULT_OPACITY = 1 ;
33
+
28
34
export interface StateObjectHandle {
29
35
/** State transform reference */
30
36
ref : string ,
@@ -34,23 +40,23 @@ export interface StateObjectHandle {
34
40
delete : ( ) => Promise < void > ,
35
41
}
36
42
37
- export function loadInteractions_example ( viewer : PDBeMolstarPlugin ) : Promise < StateObjectHandle > {
38
- return loadInteractions ( viewer , { interactions : exampleData } ) ;
43
+ export function loadInteractions_example ( viewer : PDBeMolstarPlugin , params ?: { opacity ?: number , color ?: string , radius ?: number , dash_length ?: number } ) : Promise < StateObjectHandle > {
44
+ return loadInteractions ( viewer , { ... params , interactions : exampleData } ) ;
39
45
}
40
46
41
- export async function loadInteractionsFromApi ( viewer : PDBeMolstarPlugin , params : { pdbId : string , authAsymId : string , authSeqId : number , structureId ?: string } ) : Promise < StateObjectHandle > {
47
+ export async function loadInteractionsFromApi ( viewer : PDBeMolstarPlugin , params : { pdbId : string , authAsymId : string , authSeqId : number , structureId ?: string , opacity ?: number , color ?: string , radius ?: number , dash_length ?: number } ) : Promise < StateObjectHandle > {
42
48
const data = await getInteractionApiData ( { ...params , pdbeBaseUrl : viewer . initParams . pdbeUrl } ) ;
43
49
const interactions = interactionsFromApiData ( data , params . pdbId ) ;
44
- return await loadInteractions ( viewer , { interactions , structureId : params . structureId } ) ;
50
+ return await loadInteractions ( viewer , { ... params , interactions } ) ;
45
51
}
46
52
47
53
/** Show custom atom interactions */
48
- export async function loadInteractions ( viewer : PDBeMolstarPlugin , params : { interactions : Interaction [ ] , structureId ?: string } ) : Promise < StateObjectHandle > {
54
+ export async function loadInteractions ( viewer : PDBeMolstarPlugin , params : { interactions : Interaction [ ] , structureId ?: string , opacity ?: number , color ?: string , radius ?: number , dash_length ?: number } ) : Promise < StateObjectHandle > {
49
55
const structureId = params . structureId ?? PDBeMolstarPlugin . MAIN_STRUCTURE_ID ;
50
56
const struct = viewer . getStructure ( structureId ) ;
51
57
if ( ! struct ) throw new Error ( `Did not find structure with ID "${ structureId } "` ) ;
52
58
53
- const primitivesMvsNode = interactionsToMvsPrimitiveData ( params . interactions ) ;
59
+ const primitivesMvsNode = interactionsToMvsPrimitiveData ( params ) ;
54
60
55
61
const update = viewer . plugin . build ( ) ;
56
62
const data = update . to ( struct . cell ) . apply ( MVSInlinePrimitiveData , { node : primitivesMvsNode as any } , { tags : [ 'custom-interactions-data' ] } ) ;
@@ -79,17 +85,20 @@ export async function clearInteractions(viewer: PDBeMolstarPlugin): Promise<void
79
85
visuals . length = 0 ;
80
86
}
81
87
82
- function interactionsToMvsPrimitiveData ( interactions : Interaction [ ] ) : MolstarSubtree < 'primitives' > {
88
+ function interactionsToMvsPrimitiveData ( params : { interactions : Interaction [ ] , opacity ?: number , color ?: string , radius ?: number , dash_length ?: number } ) : MolstarSubtree < 'primitives' > {
83
89
const builder = MVSData . createBuilder ( ) ;
84
- const primitives = builder . primitives ( { opacity : 1 , tooltip : 'Custom interactions' , color : 'white' } ) ;
90
+ const primitives = builder . primitives ( {
91
+ opacity : params . opacity ?? DEFAULT_OPACITY ,
92
+ color : params . color as ColorT ?? DEFAULT_COLOR ,
93
+ } ) ;
85
94
86
- for ( const interaction of interactions ) {
95
+ for ( const interaction of params . interactions ) {
87
96
primitives . tube ( {
88
97
start : { expressions : queryParamsToMvsComponentExpressions ( [ interaction . start ] ) } ,
89
98
end : { expressions : queryParamsToMvsComponentExpressions ( [ interaction . end ] ) } ,
90
- radius : 0.075 ,
91
- dash_length : 0.1 ,
92
- color : interaction . color as ColorT ,
99
+ radius : interaction . radius ?? params . radius ?? DEFAULT_RADIUS ,
100
+ dash_length : interaction . dash_length ?? params . dash_length ?? DEFAULT_DASH_LENGTH ,
101
+ color : interaction . color as ColorT | undefined ,
93
102
tooltip : interaction . tooltip ,
94
103
} ) ;
95
104
}
0 commit comments