ソースを参照

mol-plugin: DownloadStructure now uses StructureFromModel

David Sehnal 5 年 前
コミット
fa0c29c1d1

+ 11 - 5
src/mol-plugin/state/actions/structure.ts

@@ -18,6 +18,7 @@ import { FileInfo } from '../../../mol-util/file-info';
 import { Task } from '../../../mol-task';
 import { StructureElement } from '../../../mol-model/structure';
 import { createDefaultStructureComplex } from '../../util/structure-complex-helper';
+import { ModelStructureRepresentation } from '../representation/model';
 
 export const MmcifProvider: DataFormatProvider<any> = {
     label: 'mmCIF',
@@ -90,16 +91,20 @@ type StructureFormat = 'pdb' | 'cif' | 'gro' | '3dg'
 
 //
 
+const DownloadModelRepresentationOptions = ModelStructureRepresentation.getParams(void 0, 'assembly').kind;
+
 const DownloadStructurePdbIdSourceOptions = PD.Group({
+    structure: DownloadModelRepresentationOptions,
     supportProps: PD.Optional(PD.Boolean(false)),
     asTrajectory: PD.Optional(PD.Boolean(false, { description: 'Load all entries into a single trajectory.' }))
 });
 
+
 export { DownloadStructure };
 type DownloadStructure = typeof DownloadStructure
 const DownloadStructure = StateAction.build({
     from: PluginStateObject.Root,
-    display: { name: 'Download Structure', description: 'Load a structure from the provided source and create its default Assembly and visual.' },
+    display: { name: 'Download Structure', description: 'Load a structure from the provided source and create its representation.' },
     params: {
         source: PD.MappedStatic('bcif-static', {
             'pdbe-updated': PD.Group({
@@ -127,6 +132,7 @@ const DownloadStructure = StateAction.build({
                 format: PD.Select('cif', [['cif', 'CIF'], ['pdb', 'PDB']] as ['cif' | 'pdb', string][]),
                 isBinary: PD.Boolean(false),
                 options: PD.Group({
+                    structure: DownloadModelRepresentationOptions,
                     supportProps: PD.Optional(PD.Boolean(false))
                 })
             }, { isFlat: true })
@@ -191,12 +197,12 @@ const DownloadStructure = StateAction.build({
 
     if (downloadParams.length > 0 && asTrajectory) {
         const traj = createSingleTrajectoryModel(downloadParams, b);
-        createStructureTree(ctx, traj, supportProps);
+        createStructureTree(ctx, traj, supportProps, src.params.options.structure);
     } else {
         for (const download of downloadParams) {
             const data = b.toRoot().apply(StateTransforms.Data.Download, download, { state: { isGhost: true } });
             const traj = createModelTree(data, format);
-            createStructureTree(ctx, traj, supportProps)
+            createStructureTree(ctx, traj, supportProps, src.params.options.structure)
         }
     }
     return state.updateTree(b, { revertIfAborted: true });
@@ -246,12 +252,12 @@ export function createModelTree(b: StateBuilder.To<PluginStateObject.Data.Binary
     return parsed.apply(StateTransforms.Model.ModelFromTrajectory, { modelIndex: 0 });
 }
 
-function createStructureTree(ctx: PluginContext, b: StateBuilder.To<PluginStateObject.Molecule.Model>, supportProps: boolean) {
+function createStructureTree(ctx: PluginContext, b: StateBuilder.To<PluginStateObject.Molecule.Model>, supportProps: boolean, params?: ModelStructureRepresentation.Params) {
     let root = b;
     if (supportProps) {
         root = root.apply(StateTransforms.Model.CustomModelProperties);
     }
-    const structure = root.apply(StateTransforms.Model.StructureAssemblyFromModel);
+    const structure = root.apply(StateTransforms.Model.StructureFromModel, { kind: params || { name: 'assembly', params: { } } });
     createDefaultStructureComplex(ctx, structure);
 
     return root;

+ 9 - 9
src/mol-plugin/state/representation/model.ts

@@ -54,7 +54,7 @@ export namespace ModelStructureRepresentation {
         };
     }
 
-    export type Params = PD.Values<ReturnType<typeof getParams>>
+    export type Params = PD.Values<ReturnType<typeof getParams>>['kind']
 
     async function buildAssembly(plugin: PluginContext, ctx: RuntimeContext, model: Model, id?: string) {
         let asm: Assembly | undefined = void 0;
@@ -106,21 +106,21 @@ export namespace ModelStructureRepresentation {
     }
 
     export async function create(plugin: PluginContext, ctx: RuntimeContext, model: Model, params?: Params): Promise<SO.Molecule.Structure> {
-        if (!params || !params.kind || params.kind.name === 'deposited') {
+        if (!params || params.name === 'deposited') {
             const s = Structure.ofModel(model);
             await ensureSecondaryStructure(s);
             return new SO.Molecule.Structure(s, { label: 'Deposited', description: Structure.elementDescription(s) });
         }
-        if (params.kind.name === 'assembly') {
-            return buildAssembly(plugin, ctx, model, params.kind.params.id)
+        if (params.name === 'assembly') {
+            return buildAssembly(plugin, ctx, model, params.params.id)
         }
-        if (params.kind.name === 'symmetry') {
-            return buildSymmetry(ctx, model, params.kind.params.ijkMin, params.kind.params.ijkMax)
+        if (params.name === 'symmetry') {
+            return buildSymmetry(ctx, model, params.params.ijkMin, params.params.ijkMax)
         }
-        if (params.kind.name === 'symmetry-mates') {
-            return buildSymmetryMates(ctx, model, params.kind.params.radius)
+        if (params.name === 'symmetry-mates') {
+            return buildSymmetryMates(ctx, model, params.params.radius)
         }
 
-        throw new Error(`Unknown represetation type: ${(params.kind as any).name}`);
+        throw new Error(`Unknown represetation type: ${(params as any).name}`);
     }
 }

+ 3 - 4
src/mol-plugin/state/transforms/model.ts

@@ -9,8 +9,7 @@ import { parsePDB } from '../../../mol-io/reader/pdb/parser';
 import { Vec3, Mat4, Quat } from '../../../mol-math/linear-algebra';
 import { trajectoryFromMmCIF } from '../../../mol-model-formats/structure/mmcif';
 import { trajectoryFromPDB } from '../../../mol-model-formats/structure/pdb';
-import { Model, ModelSymmetry, Queries, QueryContext, Structure, StructureQuery, StructureSelection as Sel, StructureSymmetry, StructureElement } from '../../../mol-model/structure';
-import { Assembly } from '../../../mol-model/structure/model/properties/symmetry';
+import { Model, Queries, QueryContext, Structure, StructureQuery, StructureSelection as Sel, StructureElement } from '../../../mol-model/structure';
 import { PluginContext } from '../../../mol-plugin/context';
 import { MolScriptBuilder } from '../../../mol-script/language/builder';
 import Expression from '../../../mol-script/language/expression';
@@ -209,7 +208,7 @@ const StructureFromModel = PluginStateTransform.BuiltIn({
 })({
     apply({ a, params }, plugin: PluginContext) {
         return Task.create('Build Structure', async ctx => {
-            return ModelStructureRepresentation.create(plugin, ctx, a.data, params);
+            return ModelStructureRepresentation.create(plugin, ctx, a.data, params && params.kind);
         })
     }
 });
@@ -235,7 +234,7 @@ const StructureAssemblyFromModel = PluginStateTransform.BuiltIn({
 })({
     apply({ a, params }, plugin: PluginContext) {
         return Task.create('Build Assembly', async ctx => {
-            return ModelStructureRepresentation.create(plugin, ctx, a.data, { kind: { name: 'assembly', params } });
+            return ModelStructureRepresentation.create(plugin, ctx, a.data, { name: 'assembly', params });
         })
     }
 });