Explorar el Código

modelMap && modelChangeCallback args

bioinsilico hace 4 años
padre
commit
1f75a3372f

+ 0 - 1
src/RcsbFv3DBuilder.tsx

@@ -5,7 +5,6 @@ import {StructureViewInterface} from "./RcsbFvStructure/RcsbFvStructure";
 import {SequenceViewInterface} from "./RcsbFvSequence/RcsbFvSequence";
 import {EventType, RcsbFvContextManager} from "./RcsbFvContextManager/RcsbFvContextManager";
 import {PluginContext} from "molstar/lib/mol-plugin/context";
-import {RcsbFv, RcsbFvTrackDataElementInterface} from "@rcsb/rcsb-saguaro";
 
 export interface RcsbFv3DBuilderInterface {
     elementId: string;

+ 7 - 4
src/RcsbFvSequence/SequenceViews/AbstractView.tsx

@@ -1,7 +1,10 @@
 import * as React from "react";
 import * as classes from '../../styles/RcsbFvStyle.module.scss';
 import {RcsbFvDOMConstants} from "../../RcsbFvConstants/RcsbFvConstants";
-import {SaguaroPluginInterface} from "../../RcsbFvStructure/StructurePlugins/SaguaroPluginInterface";
+import {
+    SaguaroPluginInterface,
+    SaguaroPluginModelMapType
+} from "../../RcsbFvStructure/StructurePlugins/SaguaroPluginInterface";
 import { RcsbFvSelection} from "../../RcsbFvSelection/RcsbFvSelection";
 
 export interface AbstractViewInterface {
@@ -35,8 +38,8 @@ export abstract class AbstractView<P,S> extends React.Component <P & AbstractVie
     }
 
     componentDidMount() {
-        this.props.plugin.selectCallback(this.structureSelectionCallback.bind(this));
-        this.props.plugin.setObjectChangeCallback(this.objectChangeCallback.bind(this));
+        this.props.plugin.setSelectCallback(this.structureSelectionCallback.bind(this));
+        this.props.plugin.setModelChangeCallback(this.modelChangeCallback.bind(this));
         window.addEventListener('resize', this.updatePfvDimensions.bind(this));
     }
 
@@ -54,7 +57,7 @@ export abstract class AbstractView<P,S> extends React.Component <P & AbstractVie
 
     protected structureSelectionCallback(): void{}
 
-    protected objectChangeCallback(): void{}
+    protected modelChangeCallback(modelMap:SaguaroPluginModelMapType): void{}
 
     protected updatePfvDimensions(): void{}
 

+ 4 - 4
src/RcsbFvSequence/SequenceViews/AssemblyView.tsx

@@ -5,6 +5,7 @@ import {AbstractView, AbstractViewInterface} from "./AbstractView";
 import {InstanceSequenceOnchangeInterface} from "@rcsb/rcsb-saguaro-app/build/dist/RcsbFvWeb/RcsbFvBuilder/RcsbFvInstanceBuilder";
 import {RcsbFvTrackDataElementInterface} from "@rcsb/rcsb-saguaro";
 import {ChainSelectionInterface} from "../../RcsbFvSelection/RcsbFvSelection";
+import {SaguaroPluginModelMapType} from "../../RcsbFvStructure/StructurePlugins/SaguaroPluginInterface";
 
 export interface AssemblyViewInterface {
     entryId: string;
@@ -63,11 +64,10 @@ export class AssemblyView extends AbstractView<AssemblyViewInterface & AbstractV
             getRcsbFv(this.pfvDivId).setSelection(sel.regions);
     }
 
-    protected objectChangeCallback() {
-        const chainMap:Map<string,{entryId: string; chains:Array<{label:string, auth:string}>;}> = this.props.plugin.getChains();
+    protected modelChangeCallback(modelMap:SaguaroPluginModelMapType) {
         const onChangeCallback: Map<string, (x: InstanceSequenceOnchangeInterface)=>void> = new Map<string, (x: InstanceSequenceOnchangeInterface) => {}>();
         const filterInstances: Map<string, Set<string>> = new Map<string, Set<string>>();
-        chainMap.forEach((v,k)=>{
+        modelMap.forEach((v,k)=>{
             onChangeCallback.set(v.entryId,(x)=>{
                 this.currentEntryId = v.entryId;
                 this.currentLabelId = x.asymId;
@@ -83,7 +83,7 @@ export class AssemblyView extends AbstractView<AssemblyViewInterface & AbstractV
             this.pfvDivId,
             RcsbFvDOMConstants.SELECT_ASSEMBLY_PFV_ID,
             RcsbFvDOMConstants.SELECT_INSTANCE_PFV_ID,
-            Array.from(chainMap.values()).map(d=>d.entryId),
+            Array.from(modelMap.values()).map(d=>d.entryId),
             undefined,
             onChangeCallback,
             filterInstances

+ 9 - 4
src/RcsbFvSequence/SequenceViews/CustomView.tsx

@@ -7,11 +7,15 @@ import {
 } from "@rcsb/rcsb-saguaro";
 import * as React from "react";
 import {RcsbFvSelection} from "../../RcsbFvSelection/RcsbFvSelection";
-import {SaguaroPluginPublicInterface} from "../../RcsbFvStructure/StructurePlugins/SaguaroPluginInterface";
+import {
+    SaguaroPluginModelMapType,
+    SaguaroPluginPublicInterface
+} from "../../RcsbFvStructure/StructurePlugins/SaguaroPluginInterface";
 
 export interface CustomViewInterface {
     config: FeatureBlockInterface | Array<FeatureBlockInterface>;
     additionalContent?: (select: BlockViewSelector) => JSX.Element;
+    modelChangeCallback?: (modelMap: SaguaroPluginModelMapType) => void;
 }
 
 export interface FeatureBlockInterface {
@@ -120,7 +124,7 @@ export class CustomView extends AbstractView<CustomViewInterface & AbstractViewI
             });
             this.rcsbFvMap.set(boardId, rcsbFv);
         });
-        this.props.plugin.selectCallback(()=>{
+        this.props.plugin.setSelectCallback(()=>{
            this.structureSelectionCallback();
         });
     }
@@ -140,8 +144,9 @@ export class CustomView extends AbstractView<CustomViewInterface & AbstractViewI
         return this.props.additionalContent(this.blockViewSelector);
     }
 
-    protected objectChangeCallback(): void {
-
+    protected modelChangeCallback(modelMap:SaguaroPluginModelMapType): void {
+        if(typeof this.props.modelChangeCallback === "function")
+            this.props.modelChangeCallback(modelMap);
     }
 
     protected updatePfvDimensions(): void {

+ 1 - 1
src/RcsbFvStructure/RcsbFvStructure.tsx

@@ -22,7 +22,7 @@ export class RcsbFvStructure extends React.Component <StructureViewInterface & {
 
     componentDidMount() {
         this.updatePfvDimensions();
-        this.props.plugin.init(this.props.componentId+"_"+RcsbFvDOMConstants.MOLSTAR_APP_ID);
+        this.props.plugin.init(this.props.componentId+"_"+RcsbFvDOMConstants.MOLSTAR_APP_ID, this.props.pluginConfig);
         this.props.plugin.load(this.props.loadConfig);
         window.addEventListener('resize', this.updatePfvDimensions.bind(this));
     }

+ 12 - 12
src/RcsbFvStructure/StructurePlugins/MolstarPlugin.ts

@@ -1,12 +1,12 @@
 import {Viewer, ViewerProps} from '@rcsb-bioinsilico/rcsb-molstar/build/src/viewer';
 import {PresetProps} from '@rcsb-bioinsilico/rcsb-molstar/build/src/viewer/helpers/preset';
-import {SaguaroPluginInterface, SaguaroPluginPublicInterface} from "./SaguaroPluginInterface";
+import {
+    SaguaroPluginInterface,
+    SaguaroPluginModelMapType,
+    SaguaroPluginPublicInterface
+} from "./SaguaroPluginInterface";
 
 import {PluginContext} from "molstar/lib/mol-plugin/context";
-import {MolScriptBuilder} from "molstar/lib/mol-script/language/builder";
-import {Script} from "molstar/lib/mol-script/script";
-import {SetUtils} from "molstar/lib/mol-util/set";
-import {StructureSelection} from "molstar/lib/mol-model/structure/query";
 import {Loci} from "molstar/lib/mol-model/loci";
 import {Mat4} from "molstar/lib/mol-math/linear-algebra";
 import {BuiltInTrajectoryFormat} from "molstar/lib/mol-plugin-state/formats/trajectory";
@@ -48,7 +48,7 @@ export class MolstarPlugin extends AbstractPlugin implements SaguaroPluginInterf
     private plugin: Viewer;
     private localSelectionFlag: boolean = false;
     private loadingFlag: boolean = false;
-    private objectChangeCallback: ()=>void;
+    private modelChangeCallback: (chainMap:SaguaroPluginModelMapType)=>void;
     private modelMap: Map<string,string|undefined> = new Map<string, string>();
 
     constructor(props: RcsbFvSelection) {
@@ -87,7 +87,7 @@ export class MolstarPlugin extends AbstractPlugin implements SaguaroPluginInterf
         }
         this.loadingFlag = false;
         this.mapModels(loadConfig.params);
-        this.objectChangeCallback();
+        this.modelChangeCallback(this.getChains());
     }
 
     private static checkLoadData(loadConfig: LoadMolstarInterface): boolean{
@@ -124,7 +124,7 @@ export class MolstarPlugin extends AbstractPlugin implements SaguaroPluginInterf
         this.plugin.select(this.getModelId(modelId), asymId, x, y)
     }
 
-    public selectCallback( g:()=>void ){
+    public setSelectCallback(g:()=>void ){
         this.plugin.getPlugin().managers.structure.selection.events.changed.subscribe((()=>{
             if(this.localSelectionFlag) {
                 this.localSelectionFlag = false;
@@ -167,18 +167,18 @@ export class MolstarPlugin extends AbstractPlugin implements SaguaroPluginInterf
         this.plugin.pluginCall(f);
     }
 
-    public setObjectChangeCallback(f:()=>void){
-        this.objectChangeCallback = f;
+    public setModelChangeCallback(f:(modelMap:SaguaroPluginModelMapType)=>void){
+        this.modelChangeCallback = f;
         this.plugin.getPlugin().state.events.object.updated.subscribe((o)=>{
             if(this.loadingFlag)
                 return;
             if(o.action === "in-place" && o.ref === "ms-plugin.create-structure-focus-representation") {
-                f();
+                f(this.getChains());
             }
         });
     }
 
-    public getChains(): Map<string,{entryId: string; chains:Array<{label:string, auth:string}>;}>{
+    private getChains(): SaguaroPluginModelMapType{
         const structureRefList = getStructureOptions(this.plugin.getPlugin().state.data);
         const out: Map<string,{entryId: string; chains:Array<{label:string, auth:string}>;}> = new Map<string, {entryId: string; chains:Array<{label:string, auth:string}>;}>();
         structureRefList.forEach((structureRef,i)=>{

+ 4 - 3
src/RcsbFvStructure/StructurePlugins/SaguaroPluginInterface.ts

@@ -1,16 +1,17 @@
 import {LoadMolstarInterface} from "./MolstarPlugin";
 import {PluginContext} from "molstar/lib/mol-plugin/context";
 
+export type SaguaroPluginModelMapType = Map<string,{entryId: string; chains:Array<{label:string, auth:string}>;}>;
+
 export interface SaguaroPluginInterface {
     init: (elementId: string, props?: any) => void;
     load: (args: LoadMolstarInterface) => void;
     select: (modelId: string, asymId: string, x: number, y: number) => void;
     clearSelect: () => void;
     pluginCall: (f:(plugin: PluginContext)=>void) => void;
-    selectCallback: ( g:()=>void)=>void;
+    setSelectCallback: (g:()=>void)=>void;
     clear: () => void;
-    getChains: () => Map<string,{entryId: string; chains:Array<{label:string, auth:string}>;}>;
-    setObjectChangeCallback: (f:()=>void)=>void;
+    setModelChangeCallback: (f:(modelMap:SaguaroPluginModelMapType)=>void)=>void;
 }
 
 export interface SaguaroPluginPublicInterface {

+ 4 - 0
src/examples/assembly/example.ts

@@ -37,6 +37,10 @@ document.addEventListener("DOMContentLoaded", function(event) {
                 pdbId:"1ash",
                 id:"4"
             }]
+        },
+        pluginConfig: {
+            showImportControls: true,
+            showSessionControls: false
         }
     };
 

+ 29 - 15
src/examples/custom-panel/example.tsx

@@ -17,19 +17,15 @@ import {
     RcsbFvTrackDataElementInterface
 } from "@rcsb/rcsb-saguaro";
 import {ChainSelectionInterface, RcsbFvSelection} from "../../RcsbFvSelection/RcsbFvSelection";
-import {SaguaroPluginPublicInterface} from "../../RcsbFvStructure/StructurePlugins/SaguaroPluginInterface";
+import {
+    SaguaroPluginModelMapType,
+    SaguaroPluginPublicInterface
+} from "../../RcsbFvStructure/StructurePlugins/SaguaroPluginInterface";
 
-const structureConfig:StructureViewInterface = {
-    loadConfig: {
-        method: LoadMethod.loadPdbIds,
-        params: [{
-            pdbId: "101m",
-            id:"model_1"
-        },{
-            pdbId: "1xxx",
-            id:"model_2"
-        }]
-    }
+
+
+const modelChangeCallback = (modelMap: SaguaroPluginModelMapType) => {
+    console.log(modelMap);
 };
 
 const additionalContent: (select: BlockViewSelector) => JSX.Element = (select: BlockViewSelector) => {
@@ -57,7 +53,7 @@ const rowConfig: Array<RcsbFvRowConfigInterface> = [{
     trackColor: "#F9F9F9",
     displayType: RcsbFvDisplayTypes.BLOCK,
     displayColor: "#FF0000",
-    rowTitle: "BLOCK",
+    rowTitle: "101M.A",
     trackData: [{
         begin: 30,
         end: 60
@@ -70,7 +66,7 @@ const rowConfig2: Array<RcsbFvRowConfigInterface> = [{
     trackColor: "#F9F9F9",
     displayType: RcsbFvDisplayTypes.BLOCK,
     displayColor: "#00FF00",
-    rowTitle: "BLOCK",
+    rowTitle: "1XXX.A",
     trackData: [{
         begin: 30,
         end: 60
@@ -139,7 +135,8 @@ const block2: FeatureBlockInterface = {
 
 const customConfig: CustomViewInterface = {
     config:[block, block2],
-    additionalContent:additionalContent
+    additionalContent:additionalContent,
+    modelChangeCallback:modelChangeCallback
 }
 
 const sequenceConfig: SequenceViewInterface = {
@@ -147,6 +144,23 @@ const sequenceConfig: SequenceViewInterface = {
     config: customConfig
 };
 
+const structureConfig:StructureViewInterface = {
+    loadConfig: {
+        method: LoadMethod.loadPdbIds,
+        params: [{
+            pdbId: "101m",
+            id:"model_1"
+        },{
+            pdbId: "1xxx",
+            id:"model_2"
+        }]
+    },
+    pluginConfig: {
+        showImportControls: true,
+        showSessionControls: false
+    }
+};
+
 document.addEventListener("DOMContentLoaded", function(event) {
     const panel3d = new RcsbFv3DBuilder({
         elementId: "pfv",