瀏覽代碼

remove unused StructureBuilderTags

David Sehnal 5 年之前
父節點
當前提交
d12d99dcfa

+ 8 - 47
src/mol-plugin-state/builder/structure.ts

@@ -22,13 +22,7 @@ import Expression from '../../mol-script/language/expression';
 export type TrajectoryFormat = 'pdb' | 'cif' | 'gro' | '3dg'
 
 export enum StructureBuilderTags {
-    Trajectory = 'trajectory',
-    Model = 'model',
-    ModelUnitcell = 'model-unitcell',
-    ModelProperties = 'model-properties',
-    ModelGenericRepresentation = 'model-generic-representation',
-    Structure = 'structure',
-    StructureProperties = 'structure-properties',
+    // TODO: this tag might be redundant
     Component = 'structure-component'
 }
 
@@ -40,7 +34,7 @@ export class StructureBuilder {
     private async parseTrajectoryData(data: StateObjectRef<SO.Data.Binary | SO.Data.String>, format: BuiltInTrajectoryFormat | TrajectoryFormatProvider) {
         const provider = typeof format === 'string' ? this.plugin.dataFormat.trajectory.get(format) : format;
         if (!provider) throw new Error(`'${format}' is not a supported data format.`);
-        const { trajectory } = await provider.parse(this.plugin, data, { trajectoryTags: StructureBuilderTags.Trajectory });
+        const { trajectory } = await provider.parse(this.plugin, data);
         return trajectory;
     }
 
@@ -48,46 +42,13 @@ export class StructureBuilder {
         const state = this.dataState;
         const trajectory = state.build().to(data)
             .apply(StateTransforms.Data.ParseBlob, params, { state: { isGhost: true } })
-            .apply(StateTransforms.Model.TrajectoryFromBlob, void 0, { tags: StructureBuilderTags.Trajectory });
+            .apply(StateTransforms.Model.TrajectoryFromBlob, void 0);
         await this.plugin.updateDataState(trajectory, { revertOnError: true });
         return trajectory.selector;
     }
 
     readonly representation = new StructureRepresentationBuilder(this.plugin);
 
-    // async parseStructure(params: {
-    //     data?: StateObjectRef<SO.Data.Binary | SO.Data.String>,
-    //     dataFormat?: BuiltInTrajectoryFormat | TrajectoryFormatProvider,
-    //     blob?: StateObjectRef<SO.Data.Blob>
-    //     blobParams?: StateTransformer.Params<StateTransforms['Data']['ParseBlob']>,
-    //     model?: StateTransformer.Params<StateTransforms['Model']['ModelFromTrajectory']>,
-    //     modelProperties?: boolean | StateTransformer.Params<StateTransforms['Model']['CustomModelProperties']>,
-    //     structure?: RootStructureDefinition.Params,
-    //     structureProperties?: boolean | StateTransformer.Params<StateTransforms['Model']['CustomStructureProperties']>
-    // }) {
-    //     const trajectory = params.data
-    //         ? await this.parseTrajectory(params.data, params.dataFormat! || 'cif')
-    //         : await this.parseTrajectoryBlob(params.blob!, params.blobParams!);
-
-    //     const model = await this.createModel(trajectory, params.model);
-    //     const modelProperties = !!params.modelProperties
-    //         ? await this.insertModelProperties(model, typeof params?.modelProperties !== 'boolean' ? params?.modelProperties : void 0) : void 0;
-
-    //     const structure = await this.createStructure(modelProperties || model, params.structure);
-    //     const structureProperties = !!params.structureProperties
-    //         ? await this.insertStructureProperties(structure, typeof params?.structureProperties !== 'boolean' ? params?.structureProperties : void 0) : void 0;
-
-    //     return {
-    //         trajectory,
-    //         model: modelProperties || model,
-    //         modelRoot: model,
-    //         modelProperties,
-    //         structure: structureProperties || structure,
-    //         structureRoot: structure,
-    //         structureProperties
-    //     };
-    // }
-
     async parseTrajectory(data: StateObjectRef<SO.Data.Binary | SO.Data.String>, format: BuiltInTrajectoryFormat | TrajectoryFormatProvider): Promise<StateObjectSelector<SO.Molecule.Trajectory>>
     async parseTrajectory(blob: StateObjectRef<SO.Data.Blob>, params: StateTransformer.Params<StateTransforms['Data']['ParseBlob']>): Promise<StateObjectSelector<SO.Molecule.Trajectory>>
     async parseTrajectory(data: StateObjectRef, params: any) {
@@ -104,7 +65,7 @@ export class StructureBuilder {
     async createModel(trajectory: StateObjectRef<SO.Molecule.Trajectory>, params?: StateTransformer.Params<StateTransforms['Model']['ModelFromTrajectory']>, initialState?: Partial<StateTransform.State>) {
         const state = this.dataState;
         const model = state.build().to(trajectory)
-            .apply(StateTransforms.Model.ModelFromTrajectory, params || { modelIndex: 0 }, { tags: StructureBuilderTags.Model, state: initialState });
+            .apply(StateTransforms.Model.ModelFromTrajectory, params || { modelIndex: 0 }, { state: initialState });
 
         await this.plugin.updateDataState(model, { revertOnError: true });
         return model.selector;
@@ -113,7 +74,7 @@ export class StructureBuilder {
     async insertModelProperties(model: StateObjectRef<SO.Molecule.Model>, params?: StateTransformer.Params<StateTransforms['Model']['CustomModelProperties']>) {
         const state = this.dataState;
         const props = state.build().to(model)
-            .apply(StateTransforms.Model.CustomModelProperties, params, { tags: StructureBuilderTags.ModelProperties });
+            .apply(StateTransforms.Model.CustomModelProperties, params);
         await this.plugin.updateDataState(props, { revertOnError: true });
         return props.selector;
     }
@@ -126,7 +87,7 @@ export class StructureBuilder {
         if (SpacegroupCell.isZero(cell)) return;
 
         const unitcell = state.build().to(model)
-            .apply(StateTransforms.Representation.ModelUnitcell3D, params, { tags: StructureBuilderTags.ModelUnitcell, state: initialState });
+            .apply(StateTransforms.Representation.ModelUnitcell3D, params, { state: initialState });
         await this.plugin.updateDataState(unitcell, { revertOnError: true });
         return unitcell.selector;
     }
@@ -143,7 +104,7 @@ export class StructureBuilder {
         }
 
         const structure = state.build().to(modelRef)
-            .apply(StateTransforms.Model.StructureFromModel, { type: params || { name: 'assembly', params: { } } }, { tags: StructureBuilderTags.Structure, state: initialState });
+            .apply(StateTransforms.Model.StructureFromModel, { type: params || { name: 'assembly', params: { } } }, { state: initialState });
 
         await this.plugin.updateDataState(structure, { revertOnError: true });
         return structure.selector;
@@ -152,7 +113,7 @@ export class StructureBuilder {
     async insertStructureProperties(structure: StateObjectRef<SO.Molecule.Structure>, params?: StateTransformer.Params<StateTransforms['Model']['CustomStructureProperties']>) {
         const state = this.dataState;
         const props = state.build().to(structure)
-            .apply(StateTransforms.Model.CustomStructureProperties, params, { tags: StructureBuilderTags.StructureProperties });
+            .apply(StateTransforms.Model.CustomStructureProperties, params);
         await this.plugin.updateDataState(props, { revertOnError: true });
         return props.selector;
     }

+ 1 - 1
src/mol-plugin-state/formats/registry.ts

@@ -98,7 +98,7 @@ export interface DataFormatProvider<P = any, R = any> {
     stringExtensions: string[]
     binaryExtensions: string[]
     isApplicable(info: FileInfo, data: string | Uint8Array): boolean
-    parse(plugin: PluginContext, data: StateObjectRef<PluginStateObject.Data.Binary | PluginStateObject.Data.String>, params: P | undefined): Promise<R>
+    parse(plugin: PluginContext, data: StateObjectRef<PluginStateObject.Data.Binary | PluginStateObject.Data.String>, params?: P): Promise<R>
 }
 
 type cifVariants = 'dscif' | -1

+ 37 - 31
src/mol-plugin-state/manager/structure/hierarchy-state.ts

@@ -118,7 +118,7 @@ export interface StructureComponentRef extends RefBase<'structure-component', SO
 }
 
 function componentKey(cell: StateObjectCell<SO.Molecule.Structure>) {
-    if (!cell.transform.tags) return;
+    if (!cell.transform.tags) return cell.transform.ref;
     return [...cell.transform.tags].sort().join();
 }
 
@@ -208,6 +208,8 @@ function isTransformer(t: StateTransformer): TestCell {
     return cell => cell.transform.transformer === t;
 }
 
+function noop() { }
+
 const tagMap: [TestCell, ApplyRef, LeaveRef][] = [
     // Trajectory
     [isType(SO.Molecule.Trajectory), (state, cell) => {
@@ -226,16 +228,11 @@ const tagMap: [TestCell, ApplyRef, LeaveRef][] = [
     [isTransformer(StateTransforms.Model.CustomModelProperties), (state, cell) => {
         if (!state.currentModel) return false;
         state.currentModel.properties = createOrUpdateRef(state, cell, ModelPropertiesRef, cell, state.currentModel);
-    }, state => { }],
-    [isTag(StructureBuilderTags.ModelUnitcell), (state, cell) => {
+    }, noop],
+    [isTransformer(StateTransforms.Representation.ModelUnitcell3D), (state, cell) => {
         if (!state.currentModel) return false;
         state.currentModel.unitcell = createOrUpdateRef(state, cell, ModelUnitcellRef, cell, state.currentModel);
-    }, state => { }],
-    [isTag(StructureBuilderTags.ModelGenericRepresentation), (state, cell) => {
-        if (!state.currentModel) return false;
-        if (!state.currentModel.genericRepresentations) state.currentModel.genericRepresentations = []
-        createOrUpdateRefList(state, cell, state.currentModel.genericRepresentations, GenericRepresentationRef, cell, state.currentModel);
-    }, state => { }],
+    }, noop],
 
     // Structure
     [isTypeRoot(SO.Molecule.Structure, s => s.currentStructure), (state, cell) => {
@@ -249,7 +246,15 @@ const tagMap: [TestCell, ApplyRef, LeaveRef][] = [
     [isTransformer(StateTransforms.Model.CustomStructureProperties), (state, cell) => {
         if (!state.currentStructure) return false;
         state.currentStructure.properties = createOrUpdateRef(state, cell, StructurePropertiesRef, cell, state.currentStructure);
-    }, state => { }],
+    }, noop],
+
+    // Volume Streaming
+    [isType(VolumeStreaming), (state, cell) => {
+        if (!state.currentStructure) return false;
+        state.currentStructure.volumeStreaming = createOrUpdateRef(state, cell, StructureVolumeStreamingRef, cell, state.currentStructure);
+        // Do not continue into VolumeStreaming subtree.
+        return false;
+    }, noop],
 
     // Component
     [(cell, state) => {
@@ -258,17 +263,22 @@ const tagMap: [TestCell, ApplyRef, LeaveRef][] = [
         const parent = state.state.cells.get(cell.transform.parent);
         return SO.Molecule.Structure.is(parent?.obj) && SO.Molecule.Structure.is(cell.obj);
     }, (state, cell) => {
-        if (!state.currentStructure) return false;
-        state.currentComponent = createOrUpdateRefList(state, cell, state.currentStructure.components, StructureComponentRef, cell, state.currentStructure);
+        if (state.currentStructure) {
+            state.currentComponent = createOrUpdateRefList(state, cell, state.currentStructure.components, StructureComponentRef, cell, state.currentStructure);
+        }
     }, state => state.currentComponent = void 0],
 
     // Component Rpresentation
     [(cell, state) => {
         return !cell.state.isGhost && !!state.currentComponent && SO.Molecule.Structure.Representation3D.is(cell.obj)
     }, (state, cell) => {
-        if (!state.currentComponent) return false;
-        createOrUpdateRefList(state, cell, state.currentComponent.representations, StructureRepresentationRef, cell, state.currentComponent);
-    }, state => { }],
+        if (state.currentComponent) {
+            createOrUpdateRefList(state, cell, state.currentComponent.representations, StructureRepresentationRef, cell, state.currentComponent);
+        }
+
+        // Nothing useful down the line;
+        return false;
+    }, noop],
 
     // Current interaction
     [isTag(StructureRepresentationInteractionTags.ResidueSel), (state, cell) => {
@@ -282,7 +292,16 @@ const tagMap: [TestCell, ApplyRef, LeaveRef][] = [
         if (!state.currentStructure.currentFocus) state.currentStructure.currentFocus = { };
         state.currentStructure.currentFocus.surroundings = createOrUpdateRef(state, cell, StructureComponentRef, cell, state.currentStructure);
         state.currentComponent = state.currentStructure.currentFocus.surroundings;
-    }, state => state.currentComponent = void 0]
+    }, state => state.currentComponent = void 0],
+
+    // Generic Representation
+    [cell => !cell.state.isGhost && SO.isRepresentation3D(cell.obj), (state, cell) => {
+        const genericTarget = state.currentComponent || state.currentModel || state.currentStructure;
+        if (genericTarget) {
+            if (!genericTarget.genericRepresentations) genericTarget.genericRepresentations = [];
+            createOrUpdateRefList(state, cell, genericTarget.genericRepresentations, GenericRepresentationRef, cell, genericTarget);
+        }
+    }, noop],
 ]
 
 function isValidCell(cell?: StateObjectCell): cell is StateObjectCell {
@@ -309,8 +328,8 @@ function _doPreOrder(ctx: VisitorCtx, root: StateTransform) {
     let onLeave: undefined | ((state: BuildState) => any) = void 0;
     for (const [test, f, l] of tagMap) {
         if (test(cell, state)) {
-            const stop = f(state, cell);
-            if (stop === false) {
+            const cont = f(state, cell);
+            if (cont === false) {
                 return;
             }
             onLeave = l;
@@ -318,19 +337,6 @@ function _doPreOrder(ctx: VisitorCtx, root: StateTransform) {
         }
     }
 
-    if (!onLeave && !cell.state.isGhost && state.currentComponent && SO.Molecule.Structure.Representation3D.is(cell.obj)) {
-        createOrUpdateRefList(state, cell, state.currentComponent.representations, StructureRepresentationRef, cell, state.currentComponent);
-    } else if (!cell.state.isGhost && SO.isRepresentation3D(cell.obj)) {
-        const genericTarget = state.currentComponent || state.currentModel || state.currentStructure;
-        if (genericTarget) {
-            if (!genericTarget.genericRepresentations) genericTarget.genericRepresentations = [];
-            createOrUpdateRefList(state, cell, genericTarget.genericRepresentations, GenericRepresentationRef, cell, genericTarget);
-        }
-    } else if (state.currentStructure && VolumeStreaming.is(cell.obj)) {
-        state.currentStructure.volumeStreaming = createOrUpdateRef(state, cell, StructureVolumeStreamingRef, cell, state.currentStructure);
-        return;
-    }
-
     const children = ctx.tree.children.get(root.ref);
     if (children && children.size) {
         children.forEach(_preOrderFunc, ctx);