Browse Source

mol-plugin: return deposited structure if assemly is not found

David Sehnal 6 years ago
parent
commit
1cc4a05020
2 changed files with 20 additions and 4 deletions
  1. 1 0
      src/apps/basic-wrapper/index.html
  2. 19 4
      src/mol-plugin/state/transforms/model.ts

+ 1 - 0
src/apps/basic-wrapper/index.html

@@ -50,6 +50,7 @@
 
             // var url = 'https://www.ebi.ac.uk/pdbe/entry-files/pdb' + pdbId + '.ent';
             // var format = 'pdb';
+            // var assemblyId = 'deposited';
 
             BasicMolStarWrapper.init('app' /** or document.getElementById('app') */);
             BasicMolStarWrapper.setBackground(0xffffff);

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

@@ -22,6 +22,7 @@ import { volumeFromDsn6 } from 'mol-model-formats/volume/dsn6';
 import { trajectoryFromMmCIF } from 'mol-model-formats/structure/mmcif';
 import { parsePDB } from 'mol-io/reader/pdb/parser';
 import { trajectoryFromPDB } from 'mol-model-formats/structure/pdb';
+import { Assembly } from 'mol-model/structure/model/properties/symmetry';
 
 export { TrajectoryFromMmCif }
 type TrajectoryFromMmCif = typeof TrajectoryFromMmCif
@@ -141,12 +142,26 @@ const StructureAssemblyFromModel = PluginStateTransform.BuiltIn({
         return Task.create('Build Assembly', async ctx => {
             const model = a.data;
             let id = params.id;
-            let asm = ModelSymmetry.findAssembly(model, id || '');
-            if (!!id && id !== 'deposited' && !asm) throw new Error(`Assembly '${id}' not found`);
+            let asm: Assembly | undefined = void 0;
+
+            // if no id is specified, use the 1st assembly.
+            if (!id && model.symmetry.assemblies.length !== 0) {
+                id = model.symmetry.assemblies[0].id;
+            }
+
+            if (model.symmetry.assemblies.length === 0) {
+                if (id !== 'deposited') {
+                    plugin.log.warn(`Model '${a.label}' has no assembly, returning deposited structure.`);
+                }
+            } else {
+                asm = ModelSymmetry.findAssembly(model, id || '');
+                if (!asm) {
+                    plugin.log.warn(`Model '${a.label}' has no assembly called '${id}', returning deposited structure.`);
+                }
+            }
 
             const base = Structure.ofModel(model);
-            if ((id && !asm) || model.symmetry.assemblies.length === 0) {
-                if (!!id && id !== 'deposited') plugin.log.warn(`Model '${a.label}' has no assembly, returning deposited structure.`);
+            if (!asm) {
                 const label = { label: a.data.label, description: structureDesc(base) };
                 return new SO.Molecule.Structure(base, label);
             }