Browse Source

Issue #643: excluding HETATM lines

cycle20 1 year ago
parent
commit
4a5085e5e3

+ 12 - 1
package-lock.json

@@ -35,7 +35,8 @@
         "swagger-ui-dist": "^3.37.2",
         "tslib": "^2.4.0",
         "util.promisify": "^1.0.1",
-        "xhr2": "^0.2.0"
+        "xhr2": "^0.2.0",
+        "zlibt2": "^0.6.1"
       },
       "bin": {
         "cif2bcif": "lib/commonjs/cli/cif2bcif/index.js",
@@ -15811,6 +15812,11 @@
       "funding": {
         "url": "https://github.com/sponsors/sindresorhus"
       }
+    },
+    "node_modules/zlibt2": {
+      "version": "0.6.1",
+      "resolved": "https://registry.npmjs.org/zlibt2/-/zlibt2-0.6.1.tgz",
+      "integrity": "sha512-Co0bVG6Bp5Ut7AxrUjM+Q3GMnIXsaWKl/tELbhNohQM8MB9d9ixVXW1Aqbv4o464HCpDsSD//itCnaI6qF8ssg=="
     }
   },
   "dependencies": {
@@ -28396,6 +28402,11 @@
       "version": "0.1.0",
       "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
       "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q=="
+    },
+    "zlibt2": {
+      "version": "0.6.1",
+      "resolved": "https://registry.npmjs.org/zlibt2/-/zlibt2-0.6.1.tgz",
+      "integrity": "sha512-Co0bVG6Bp5Ut7AxrUjM+Q3GMnIXsaWKl/tELbhNohQM8MB9d9ixVXW1Aqbv4o464HCpDsSD//itCnaI6qF8ssg=="
     }
   }
 }

+ 2 - 1
package.json

@@ -157,6 +157,7 @@
     "swagger-ui-dist": "^3.37.2",
     "tslib": "^2.4.0",
     "util.promisify": "^1.0.1",
-    "xhr2": "^0.2.0"
+    "xhr2": "^0.2.0",
+    "zlibt2": "^0.6.1"
   }
 }

+ 46 - 8
src/extensions/tmdet/behavior.ts

@@ -25,7 +25,7 @@ import { StructureSelectionQuery, StructureSelectionCategory } from '../../mol-p
 import { MolScriptBuilder as MS } from '../../mol-script/language/builder';
 import { GenericRepresentationRef } from '../../mol-plugin-state/manager/structure/hierarchy-state';
 import { PluginUIContext } from '../../mol-plugin-ui/context';
-
+// import { Gunzip } from "zlibt2";
 
 
 // TMDET imports
@@ -37,7 +37,7 @@ import { registerTmDetSymmetry } from './symmetry';
 import { TmDetLabelProvider } from './labeling';
 import { TmDetColorThemeProvider, updateSiteColors } from './tmdet-color-theme';
 import { loadInitialSnapshot, rotateCamera, storeCameraSnapshot } from './camera';
-
+import { DebugUtil } from './debug-utils';
 
 const Tag = MembraneOrientation.Tag;
 const TMDET_MEMBRANE_ORIENTATION = 'Membrane Orientation';
@@ -205,13 +205,26 @@ async function loadStructure(ctx: PluginUIContext, params: any, pdbtmDescriptor:
     // replace original symmetry format function
     registerTmDetSymmetry(pdbtmDescriptor);
 
+    let format: "mmcif"|"pdb" = "mmcif";
+    // check url to determine file format and compression
+    const match: string[] = params.structureUrl.match(new RegExp('/(pdb|cif)(.gz)?$/g/'));
+    DebugUtil.log(`format: ${params.format}`);
+    if ((params.format != 'mmcif' || params.format != 'pdb') && match != null) {
+        if (match[0].startsWith('cif')) {
+            format = 'mmcif';
+        }
+        if (match[0].startsWith('pdb')) {
+            format = 'pdb';
+        }
+    } else if (params.format) {
+        format = params.format;
+    }
+
     const builders = ctx.builders;
-    const data = await builders.data.download({
-        url: params.structureUrl,
-        label: `${pdbtmDescriptor.pdb_id}`,
-        isBinary: false
-    }); // , { state: { isGhost: true } });
-    const trajectory = await builders.structure.parseTrajectory(data, 'mmcif');
+    const data = await downloadData(ctx, params, pdbtmDescriptor);
+
+    const trajectory = await builders.structure.parseTrajectory(data, format);
+
 
     // create membrane representation
     await builders.structure.hierarchy.applyPreset(
@@ -219,7 +232,32 @@ async function loadStructure(ctx: PluginUIContext, params: any, pdbtmDescriptor:
 }
 
 
+async function downloadData(ctx: PluginUIContext, params: any, pdbtmDescriptor: PDBTMDescriptor) {
+
+    // let gzipped: boolean = false;
+    // if (params.compression || params.structureUrl.endsWith('gz')) {
+    //     gzipped = true;
+    // }
+
+    const builders = ctx.builders;
+    let downloadResult = await ctx.runTask(ctx.fetch({ url: params.structureUrl, type: "string" }));
+    console.log(downloadResult.slice(0, 100));
+    // TODO: temporary solution
+    downloadResult = downloadResult.replace(/HETATM.+\n/mg, ''); // remove all hetatom stuffs
+    // TODO: const uncompressed: string = await ungzip(downloadResult);
+    // console.log(uncompressed.slice(0, 100));
+
+    return await builders.data.rawData({
+        data: downloadResult,
+        label: `${pdbtmDescriptor.pdb_id}`,
+    }); // , { state: { isGhost: true } });
+
+}
 
+// async function ungzip(data: Uint8Array) {
+//     // TODO: it does not work :(
+//     return new Gunzip(data).decompress();
+// }
 
 //
 // //////////////////////////// END OF TMDET VIEWER SECTION

+ 4 - 0
src/extensions/tmdet/symmetry.ts

@@ -13,6 +13,7 @@ import { mmCIF_Schema } from '../../mol-io/reader/cif/schema/mmcif';
 import { Model } from '../../mol-model/structure';
 import { ModelSymmetry } from '../../mol-model-formats/structure/property/symmetry';
 import { PDBTMDescriptor } from './types';
+import { DebugUtil } from './debug-utils';
 
 
 export function registerTmDetSymmetry(pdbtmDescriptor: PDBTMDescriptor) {
@@ -68,6 +69,9 @@ function tmDetSymmetryFromMmCif(model: Model, chainsForOperExpression: string[])
         }
     );
 
+    DebugUtil.log('Excluded chains:', chainsForOperExpression);
+    DebugUtil.log('Included chains:', result);
+
     return ModelSymmetry.fromData({
         symmetry: data.symmetry,
         cell: data.cell,

+ 1 - 1
src/mol-model-formats/structure/property/symmetry.ts

@@ -88,4 +88,4 @@ function getNcsOperators(struct_ncs_oper: Table<mmCIF_Schema['struct_ncs_oper']>
         opers[opers.length] = SymmetryOperator.ofRotationAndOffset(`ncs_${ncsId}`, m, v, ncsId);
     }
     return opers;
-}
+}