1
1
import { GeometryExport } from 'Molstar/extensions/geo-export' ;
2
2
import { MAQualityAssessment } from 'Molstar/extensions/model-archive/quality-assessment/behavior' ;
3
3
import { Mp4Export } from 'Molstar/extensions/mp4-export' ;
4
+ import { MolViewSpec } from 'Molstar/extensions/mvs/behavior' ;
5
+ import { CustomTooltipsProps , CustomTooltipsProvider } from 'Molstar/extensions/mvs/components/custom-tooltips-prop' ;
4
6
import { PDBeStructureQualityReport } from 'Molstar/extensions/pdbe' ;
5
7
import { RCSBAssemblySymmetry , RCSBAssemblySymmetryConfig } from 'Molstar/extensions/rcsb/assembly-symmetry/behavior' ;
6
8
import { Canvas3DProps } from 'Molstar/mol-canvas3d/canvas3d' ;
@@ -18,7 +20,7 @@ import { clearStructureOverpaint } from 'Molstar/mol-plugin-state/helpers/struct
18
20
import { createStructureRepresentationParams } from 'Molstar/mol-plugin-state/helpers/structure-representation-params' ;
19
21
import { PluginStateObject } from 'Molstar/mol-plugin-state/objects' ;
20
22
import { StateTransforms } from 'Molstar/mol-plugin-state/transforms' ;
21
- import { StructureComponent } from 'Molstar/mol-plugin-state/transforms/model' ;
23
+ import { CustomStructureProperties , StructureComponent } from 'Molstar/mol-plugin-state/transforms/model' ;
22
24
import { StructureRepresentation3D } from 'Molstar/mol-plugin-state/transforms/representation' ;
23
25
import { createPluginUI } from 'Molstar/mol-plugin-ui/react18' ;
24
26
import { PluginUISpec } from 'Molstar/mol-plugin-ui/spec' ;
@@ -100,6 +102,8 @@ export class PDBeMolstarPlugin {
100
102
const pdbePluginSpec : PluginUISpec = DefaultPluginUISpec ( ) ;
101
103
pdbePluginSpec . config ??= [ ] ;
102
104
105
+ pdbePluginSpec . behaviors . push ( PluginSpec . Behavior ( MolViewSpec ) ) ;
106
+
103
107
if ( ! this . initParams . ligandView && ! this . initParams . superposition && this . initParams . selectInteraction ) {
104
108
pdbePluginSpec . behaviors . push ( PluginSpec . Behavior ( StructureFocusRepresentation ) ) ;
105
109
}
@@ -531,7 +535,7 @@ export class PDBeMolstarPlugin {
531
535
if ( this . isHighlightColorUpdated ) this . visual . reset ( { highlightColor : true } ) ;
532
536
} ,
533
537
534
- /** `structureNumber` counts from 1; if not provided, select will be applied to all load structures.
538
+ /** `structureNumber` counts from 1; if not provided, select will be applied to all loaded structures.
535
539
* Use `keepColors` and/or `keepRepresentations` to preserve currently active selection.
536
540
*/
537
541
select : async ( params : { data : QueryParam [ ] , nonSelectedColor ?: any , structureNumber ?: number , keepColors ?: boolean , keepRepresentations ?: boolean } ) => {
@@ -767,6 +771,48 @@ export class PDBeMolstarPlugin {
767
771
await PluginCommands . Canvas3D . SetSettings ( this . plugin , { settings : { renderer, marking } } ) ;
768
772
}
769
773
} ,
774
+
775
+ /** Add interactive tooltips to parts of the structure. The added tooltips will be shown on a separate line in the tooltip box.
776
+ * Repeated call to this function removes any previously added tooltips.
777
+ * `structureNumber` counts from 1; if not provided, tooltips will be applied to all loaded structures.
778
+ * Example: `await this.visual.tooltips({ data: [{ struct_asym_id: 'A', tooltip: 'Chain A' }, { struct_asym_id: 'B', tooltip: 'Chain B' }] });`. */
779
+ tooltips : async ( params : { data : QueryParam [ ] , structureNumber ?: number } ) => {
780
+ // Structure list to apply tooltips
781
+ let structures = this . plugin . managers . structure . hierarchy . current . structures . map ( ( structureRef , i ) => ( { structureRef, number : i + 1 } ) ) ;
782
+ if ( params . structureNumber !== undefined ) {
783
+ structures = [ structures [ params . structureNumber - 1 ] ] ;
784
+ }
785
+
786
+ for ( const struct of structures ) {
787
+ const selections = this . getSelections ( params . data , struct . number ) ;
788
+ const customTooltipProps : CustomTooltipsProps = {
789
+ tooltips : selections . map ( s => ( { text : s . param . tooltip ?? '' , selector : { name : 'bundle' , params : s . bundle } } ) ) ,
790
+ } ;
791
+
792
+ const structRef = struct . structureRef . cell . transform . ref ;
793
+ let customPropsCells = this . plugin . state . data . select ( StateSelection . Generators . ofTransformer ( CustomStructureProperties , structRef ) ) ;
794
+ if ( customPropsCells . length === 0 ) {
795
+ await this . plugin . build ( ) . to ( structRef ) . apply ( CustomStructureProperties ) . commit ( ) ;
796
+ customPropsCells = this . plugin . state . data . select ( StateSelection . Generators . ofTransformer ( CustomStructureProperties , structRef ) ) ;
797
+ }
798
+
799
+ await this . plugin . build ( ) . to ( customPropsCells [ 0 ] ) . update ( old => ( {
800
+ properties : {
801
+ ...old . properties ,
802
+ [ CustomTooltipsProvider . descriptor . name ] : customTooltipProps ,
803
+ } ,
804
+ autoAttach : old . autoAttach . includes ( CustomTooltipsProvider . descriptor . name ) ?
805
+ old . autoAttach
806
+ : [ ...old . autoAttach , CustomTooltipsProvider . descriptor . name ] ,
807
+ } ) ) . commit ( ) ;
808
+ }
809
+
810
+ } ,
811
+
812
+ /** Remove any tooltips added by `this.visual.tooltips`. */
813
+ clearTooltips : async ( structureNumber ?: number ) => {
814
+ await this . visual . tooltips ( { data : [ ] , structureNumber } ) ;
815
+ } ,
770
816
} ;
771
817
772
818
async clear ( ) {
0 commit comments