Browse Source

Apply suggestions from code review

fix bugs and optimizing the code related to iteration over data blocks

Co-authored-by: David Sehnal <dsehnal@users.noreply.github.com>

Aliaksei 2 years ago
parent
commit
0a71b788b3
2 changed files with 4 additions and 5 deletions
  1. 0 1
      CHANGELOG.md
  2. 4 4
      src/mol-plugin-state/formats/volume.ts

+ 0 - 1
CHANGELOG.md

@@ -6,7 +6,6 @@ Note that since we don't clearly distinguish between a public and private interf
 
 ## [Unreleased]
 
-## [v3.8.3] - 2022-05-27
 - Add check that a data block contains volume data before parsing
 
 ## [v3.8.2] - 2022-05-22

+ 4 - 4
src/mol-plugin-state/formats/volume.ts

@@ -198,18 +198,18 @@ export const DscifProvider = DataFormatProvider({
     parse: async (plugin, data, params?: DsCifParams) => {
         const cifCell = await plugin.build().to(data).apply(StateTransforms.Data.ParseCif).commit();
         const b = plugin.build().to(cifCell);
-        const blocks = cifCell.obj!.data.blocks.slice(0); // iterate over all blocks as even 0th can contain data
+        const blocks = cifCell.obj!.data.blocks;
 
-        if (blocks.length !== 1 && blocks.length !== 2 && blocks.length !== 3) throw new Error('unknown number of blocks');
+        if (blocks.length === 0) throw new Error('no data blocks');
 
         const volumes: StateObjectSelector<PluginStateObject.Volume.Data>[] = [];
         let i = 0;
         for (const block of blocks) {
             const entryId = Array.isArray(params?.entryId) ? params?.entryId[i] : params?.entryId;
-            if (block.categories['volume_data_3d']?.rowCount > 0) {
+            if (block.categories['volume_data_3d_info']?.rowCount > 0) {
                 volumes.push(b.apply(StateTransforms.Volume.VolumeFromDensityServerCif, { blockHeader: block.header, entryId }).selector);
+                i++;
             }
-            i++;
         }
 
         await b.commit();