|
@@ -9,6 +9,8 @@ import { PluginCommands } from 'molstar/lib/mol-plugin/commands';
|
|
|
import { PluginContext } from 'molstar/lib/mol-plugin/context';
|
|
|
import { PresetProps, RcsbPreset } from './preset';
|
|
|
import { Asset } from 'molstar/lib/mol-util/assets';
|
|
|
+import { Mat4 } from 'molstar/lib/mol-math/linear-algebra';
|
|
|
+import { StateTransforms } from 'molstar/lib/mol-plugin-state/transforms';
|
|
|
|
|
|
export class ModelLoader {
|
|
|
get customState() {
|
|
@@ -20,21 +22,30 @@ export class ModelLoader {
|
|
|
await PluginCommands.State.RemoveObject(this.plugin, { state, ref: state.tree.root.ref })
|
|
|
}
|
|
|
|
|
|
- async load(load: LoadParams, props?: PresetProps) {
|
|
|
- await this.clear()
|
|
|
-
|
|
|
+ async load(load: LoadParams, props?: PresetProps, matrix?: Mat4) {
|
|
|
const { fileOrUrl, format } = load
|
|
|
const isBinary = format === 'bcif'
|
|
|
|
|
|
const data = fileOrUrl instanceof File
|
|
|
? (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.structure.parseTrajectory(data, 'mmcif')
|
|
|
-
|
|
|
- const mng = this.plugin.managers.structure.hierarchy
|
|
|
- await mng.applyPreset(mng.current.trajectories, RcsbPreset, {
|
|
|
- preset: props || { kind: 'standard', assemblyId: 'deposited' }
|
|
|
- })
|
|
|
+ const trajectory = await this.plugin.builders.structure.parseTrajectory(data, 'mmcif')
|
|
|
+
|
|
|
+ const selector = await this.plugin.builders.structure.hierarchy.applyPreset(trajectory, RcsbPreset, {
|
|
|
+ preset: props || { kind: 'standard', assemblyId: '' }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (matrix && selector) {
|
|
|
+ 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) {
|