|
@@ -11,41 +11,46 @@ import { Asset } from 'molstar/lib/mol-util/assets';
|
|
import { Mat4 } from 'molstar/lib/mol-math/linear-algebra';
|
|
import { Mat4 } from 'molstar/lib/mol-math/linear-algebra';
|
|
import { StateTransforms } from 'molstar/lib/mol-plugin-state/transforms';
|
|
import { StateTransforms } from 'molstar/lib/mol-plugin-state/transforms';
|
|
import { BuiltInTrajectoryFormat } from 'molstar/lib/mol-plugin-state/formats/trajectory';
|
|
import { BuiltInTrajectoryFormat } from 'molstar/lib/mol-plugin-state/formats/trajectory';
|
|
|
|
+import {TrajectoryHierarchyPresetProvider} from 'molstar/lib/mol-plugin-state/builder/structure/hierarchy-preset';
|
|
|
|
|
|
export class ModelLoader {
|
|
export class ModelLoader {
|
|
- async load(load: LoadParams, props?: PresetProps, matrix?: Mat4) {
|
|
|
|
|
|
+ async load<P>(load: LoadParams, props?: PresetProps, matrix?: Mat4, reprProvider?: TrajectoryHierarchyPresetProvider, params?: P) {
|
|
const { fileOrUrl, format, isBinary } = load;
|
|
const { fileOrUrl, format, isBinary } = load;
|
|
|
|
|
|
const data = fileOrUrl instanceof File
|
|
const data = fileOrUrl instanceof File
|
|
? (await this.plugin.builders.data.readFile({ file: Asset.File(fileOrUrl), isBinary })).data
|
|
? (await this.plugin.builders.data.readFile({ file: Asset.File(fileOrUrl), isBinary })).data
|
|
: await this.plugin.builders.data.download({ url: fileOrUrl, isBinary });
|
|
: await this.plugin.builders.data.download({ url: fileOrUrl, isBinary });
|
|
- await this.handleTrajectory(data, format, props, matrix);
|
|
|
|
|
|
+ await this.handleTrajectory<P>(data, format, props, matrix, reprProvider, params);
|
|
}
|
|
}
|
|
|
|
|
|
- async parse(parse: ParseParams, props?: PresetProps & { dataLabel?: string }, matrix?: Mat4) {
|
|
|
|
|
|
+ async parse<P>(parse: ParseParams, props?: PresetProps & { dataLabel?: string }, matrix?: Mat4, reprProvider?: TrajectoryHierarchyPresetProvider, params?: P) {
|
|
const { data, format } = parse;
|
|
const { data, format } = parse;
|
|
const _data = await this.plugin.builders.data.rawData({ data, label: props?.dataLabel });
|
|
const _data = await this.plugin.builders.data.rawData({ data, label: props?.dataLabel });
|
|
- await this.handleTrajectory(_data, format, props, matrix);
|
|
|
|
|
|
+ await this.handleTrajectory(_data, format, props, matrix, reprProvider, params);
|
|
}
|
|
}
|
|
|
|
|
|
- async handleTrajectory(data: any, format: BuiltInTrajectoryFormat, props?: PresetProps, matrix?: Mat4) {
|
|
|
|
|
|
+ private async handleTrajectory<P>(data: any, format: BuiltInTrajectoryFormat, props?: PresetProps, matrix?: Mat4, reprProvider?: TrajectoryHierarchyPresetProvider, params?: P) {
|
|
const trajectory = await this.plugin.builders.structure.parseTrajectory(data, format);
|
|
const trajectory = await this.plugin.builders.structure.parseTrajectory(data, format);
|
|
-
|
|
|
|
- const selector = await this.plugin.builders.structure.hierarchy.applyPreset(trajectory, RcsbPreset, {
|
|
|
|
- preset: props || { kind: 'standard', assemblyId: '' }
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- if (matrix && selector?.structureProperties) {
|
|
|
|
- const params = {
|
|
|
|
- transform: {
|
|
|
|
- name: 'matrix' as const,
|
|
|
|
- params: { data: matrix, transpose: false }
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- const b = this.plugin.state.data.build().to(selector.structureProperties)
|
|
|
|
- .insert(StateTransforms.Model.TransformStructureConformation, params);
|
|
|
|
- await this.plugin.runTask(this.plugin.state.data.updateTree(b));
|
|
|
|
|
|
+ if(reprProvider){
|
|
|
|
+ await this.plugin.builders.structure.hierarchy.applyPreset(trajectory, reprProvider, {...params});
|
|
|
|
+ }else{
|
|
|
|
+ const selector = await this.plugin.builders.structure.hierarchy.applyPreset(trajectory, RcsbPreset, {
|
|
|
|
+ preset: props || { kind: 'standard', assemblyId: '' }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (matrix && selector?.structureProperties) {
|
|
|
|
+ const params = {
|
|
|
|
+ transform: {
|
|
|
|
+ name: 'matrix' as const,
|
|
|
|
+ params: { data: matrix, transpose: false }
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ const b = this.plugin.state.data.build().to(selector.structureProperties)
|
|
|
|
+ .insert(StateTransforms.Model.TransformStructureConformation, params);
|
|
|
|
+ await this.plugin.runTask(this.plugin.state.data.updateTree(b));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
constructor(private plugin: PluginContext) {
|
|
constructor(private plugin: PluginContext) {
|