Browse Source

mol-plugin-state: use 'deposited' as default value for structure if no assembly is present

David Sehnal 5 years ago
parent
commit
8016fcbd54

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

@@ -129,7 +129,7 @@ export const DcdProvider: DataFormatProvider<any> = {
 //
 
 const DownloadModelRepresentationOptions = (plugin: PluginContext) => PD.Group({
-    type: RootStructureDefinition.getParams(void 0, 'assembly').type,
+    type: RootStructureDefinition.getParams(void 0, 'auto').type,
     representation: PD.Select(PresetStructureReprentations.auto.id,
         plugin.builders.structure.representation.getPresets().map(p => [p.id, p.display.name] as any),
         { description: 'Which representation preset to use.' }),
@@ -228,6 +228,8 @@ const DownloadStructure = StateAction.build({
     const representationPreset: any = params.source.params.options.representation || PresetStructureReprentations.auto.id;
     const showUnitcell = representationPreset !== PresetStructureReprentations.empty.id;
 
+    const structure = src.params.options.type.name === 'auto' ? void 0 : src.params.options.type;
+
     await state.transaction(async () => {
         if (downloadParams.length > 0 && asTrajectory) {
             const blob = await plugin.builders.data.downloadBlob({
@@ -237,7 +239,7 @@ const DownloadStructure = StateAction.build({
             const trajectory = await plugin.builders.structure.parseTrajectory(blob, { formats: downloadParams.map((_, i) => ({ id: '' + i, format: 'cif' as 'cif' })) });
 
             await applyTrajectoryHierarchyPreset(plugin, trajectory, 'first-model', {
-                structure: src.params.options.type,
+                structure,
                 showUnitcell,
                 representationPreset
             });
@@ -247,7 +249,7 @@ const DownloadStructure = StateAction.build({
                 const trajectory = await plugin.builders.structure.parseTrajectory(data, format);
 
                 await applyTrajectoryHierarchyPreset(plugin, trajectory, 'first-model', {
-                    structure: src.params.options.type,
+                    structure,
                     showUnitcell,
                     representationPreset
                 });

+ 11 - 2
src/mol-plugin-state/builder/structure.ts

@@ -131,9 +131,18 @@ export class StructureBuilder {
         return unitcell.selector;
     }
 
-    async createStructure(model: StateObjectRef<SO.Molecule.Model>, params?: RootStructureDefinition.Params, initialState?: Partial<StateTransform.State>) {
+    async createStructure(modelRef: StateObjectRef<SO.Molecule.Model>, params?: RootStructureDefinition.Params, initialState?: Partial<StateTransform.State>) {
         const state = this.dataState;
-        const structure = state.build().to(model)
+
+        if (!params) {
+            const model = StateObjectRef.resolveAndCheck(state, modelRef);
+            if (model) {
+                const symm = ModelSymmetry.Provider.get(model.obj?.data!);
+                if (!symm || symm?.assemblies.length === 0) params = { name: 'deposited', params: { } };
+            }
+        }
+
+        const structure = state.build().to(modelRef)
             .apply(StateTransforms.Model.StructureFromModel, { type: params || { name: 'assembly', params: { } } }, { tags: StructureBuilderTags.Structure, state: initialState });
 
         await this.plugin.updateDataState(structure, { revertOnError: true });

+ 18 - 5
src/mol-plugin-state/helpers/root-structure.ts

@@ -17,7 +17,7 @@ import { PluginStateObject as SO } from '../objects';
 import { ModelSymmetry } from '../../mol-model-formats/structure/property/symmetry';
 
 export namespace RootStructureDefinition {
-    export function getParams(model?: Model, defaultValue?: 'deposited' | 'assembly' | 'symmetry' | 'symmetry-mates' | 'symmetry-assembly') {
+    export function getParams(model?: Model, defaultValue?: 'auto' | 'deposited' | 'assembly' | 'symmetry' | 'symmetry-mates' | 'symmetry-assembly') {
         const symmetry = model && ModelSymmetry.Provider.get(model)
 
         const assemblyIds = symmetry ? symmetry.assemblies.map(a => [a.id, `${a.id}: ${stringToWords(a.details)}`] as [string, string]) : [];
@@ -40,6 +40,7 @@ export namespace RootStructureDefinition {
         }
 
         const modes = {
+            auto: PD.EmptyGroup(),
             deposited: PD.EmptyGroup(),
             assembly: PD.Group({
                 id: PD.Optional(model
@@ -68,11 +69,15 @@ export namespace RootStructureDefinition {
             }, { isFlat: true })
         };
 
-        const options: [keyof typeof modes, string][] = [
-            ['deposited', 'Deposited']
-        ];
+        const options: [keyof typeof modes, string][] = [];
 
-        if (assemblyIds) {
+        if (defaultValue === 'auto') {
+            options.push(['auto', 'Auto']);
+        }
+
+        options.push(['deposited', 'Deposited']);
+
+        if (assemblyIds.length > 0) {
             options.push(['assembly', 'Assembly']);
         }
 
@@ -149,6 +154,14 @@ export namespace RootStructureDefinition {
             const s = Structure.ofModel(model);
             return new SO.Molecule.Structure(s, { label: 'Deposited', description: Structure.elementDescription(s) });
         }
+        if (params.name === 'auto') {
+            if (symmetry.assemblies.length === 0) {
+                const s = Structure.ofModel(model);
+                return new SO.Molecule.Structure(s, { label: 'Deposited', description: Structure.elementDescription(s) });
+            } else {
+                return buildAssembly(plugin, ctx, model);
+            }
+        }
         if (params.name === 'assembly') {
             return buildAssembly(plugin, ctx, model, params.params.id)
         }