Browse Source

allowing to set the label via load from url api

Yana Rose 1 year ago
parent
commit
71253cfbe5
4 changed files with 513 additions and 141 deletions
  1. 498 132
      package-lock.json
  2. 1 1
      package.json
  3. 13 7
      src/viewer/helpers/model.ts
  4. 1 1
      src/viewer/index.ts

File diff suppressed because it is too large
+ 498 - 132
package-lock.json


+ 1 - 1
package.json

@@ -62,7 +62,7 @@
     "dependencies": {
         "@types/react": "^18.0.28",
         "@types/react-dom": "^18.0.11",
-        "molstar": "^3.31.4",
+        "molstar": "^3.37.1",
         "react": "^18.2.0",
         "react-dom": "^18.2.0",
         "rxjs": "^7.8.0",

+ 13 - 7
src/viewer/helpers/model.ts

@@ -12,25 +12,31 @@ import { Mat4 } from 'molstar/lib/mol-math/linear-algebra';
 import { StateTransforms } from 'molstar/lib/mol-plugin-state/transforms';
 import { BuiltInTrajectoryFormat } from 'molstar/lib/mol-plugin-state/formats/trajectory';
 import { TrajectoryHierarchyPresetProvider } from 'molstar/lib/mol-plugin-state/builder/structure/hierarchy-preset';
+import { StateObjectRef } from 'molstar/lib/mol-state';
+import { ModelExport } from 'molstar/lib/extensions/model-export/export';
 
 export class ModelLoader {
-    async load<P = {}, S={}>(load: LoadParams, props?: PresetProps, matrix?: Mat4, reprProvider?: TrajectoryHierarchyPresetProvider<P, S>, params?: P) {
-        const { fileOrUrl, format, isBinary, label } = load;
+    async load<P = any, S = {}>(load: LoadParams, props?: PresetProps & { structureLabel?: string }, matrix?: Mat4, reprProvider?: TrajectoryHierarchyPresetProvider<P, S>, params?: P) {
+        const { fileOrUrl, format, isBinary } = load;
 
         const data = fileOrUrl instanceof File
-            ? (await this.plugin.builders.data.readFile({ file: Asset.File(fileOrUrl), isBinary, label })).data
-            : await this.plugin.builders.data.download({ url: fileOrUrl, isBinary, label });
+            ? (await this.plugin.builders.data.readFile({ file: Asset.File(fileOrUrl), isBinary, label: props?.structureLabel })).data
+            : await this.plugin.builders.data.download({ url: fileOrUrl, isBinary, label: props?.structureLabel });
 
-        return await this.handleTrajectory<P, S>(data, format, props, matrix, reprProvider, params);
+        const hierarchy = await this.handleTrajectory<P, S>(data, format, props, matrix, reprProvider, params) as any;
+        const structureCell = StateObjectRef.resolveAndCheck(this.plugin.state.data, hierarchy.structure);
+        ModelExport.setStructureName(structureCell?.obj?.data, props?.structureLabel || '');
+
+        return hierarchy;
     }
 
-    async parse<P = {}, S={}>(parse: ParseParams, props?: PresetProps & { dataLabel?: string }, matrix?: Mat4, reprProvider?: TrajectoryHierarchyPresetProvider<P, S>, params?: P) {
+    async parse<P = any, S = {}>(parse: ParseParams, props?: PresetProps & { dataLabel?: string }, matrix?: Mat4, reprProvider?: TrajectoryHierarchyPresetProvider<P, S>, params?: P) {
         const { data, format } = parse;
         const _data = await this.plugin.builders.data.rawData({ data, label: props?.dataLabel });
         return await this.handleTrajectory(_data, format, props, matrix, reprProvider, params);
     }
 
-    private async handleTrajectory<P = {}, S = {}>(
+    private async handleTrajectory<P = any, S = {}>(
         data: any,
         format: BuiltInTrajectoryFormat,
         props?: PresetProps,

+ 1 - 1
src/viewer/index.ts

@@ -297,7 +297,7 @@ export class Viewer {
         return out;
     }
 
-    loadStructureFromUrl<P, S>(url: string, format: BuiltInTrajectoryFormat, isBinary: boolean, config?: {props?: PresetProps; matrix?: Mat4; reprProvider?: TrajectoryHierarchyPresetProvider<P, S>, params?: P}) {
+    loadStructureFromUrl<P, S>(url: string, format: BuiltInTrajectoryFormat, isBinary: boolean, config?: {props?: PresetProps & { structureLabel?: string }; matrix?: Mat4; reprProvider?: TrajectoryHierarchyPresetProvider<P, S>, params?: P}) {
         return this.customState.modelLoader.load({ fileOrUrl: url, format, isBinary }, config?.props, config?.matrix, config?.reprProvider, config?.params);
     }
 

Some files were not shown because too many files changed in this diff