From 464a208a910a4ecffe3638ff13e9b37c172e0804 Mon Sep 17 00:00:00 2001 From: Cameron Gilchrist Date: Mon, 11 Nov 2024 17:11:38 +0900 Subject: [PATCH] don't use worker in local builds --- frontend/StructureViewerMSA.vue | 44 ++++++++++++++++------------- frontend/webpack.frontend.config.js | 32 ++++++++++++++------- 2 files changed, 47 insertions(+), 29 deletions(-) diff --git a/frontend/StructureViewerMSA.vue b/frontend/StructureViewerMSA.vue index 4cbb1ef..e58aa39 100644 --- a/frontend/StructureViewerMSA.vue +++ b/frontend/StructureViewerMSA.vue @@ -24,6 +24,7 @@ import StructureViewerTooltip from './StructureViewerTooltip.vue'; import StructureViewerToolbar from './StructureViewerToolbar.vue'; import StructureViewerMixin from './StructureViewerMixin.vue'; +import { tmalign, parse as parseTMOutput, parseMatrix as parseTMMatrix } from 'tmalign-wasm'; import { mockPDB, makeSubPDB, makeMatrix4, interpolateMatrices, animateMatrix } from './Utilities.js'; import { download, PdbWriter, Matrix4, Quaternion, Vector3, concatStructures } from 'ngl'; import { pulchra } from 'pulchra-wasm'; @@ -192,26 +193,31 @@ ENDMDL makeSubPDB(refComp.structure, aln ? `${aln.qStartPos}-${aln.qEndPos}` : ''), makeSubPDB(newComp.structure, aln ? `${aln.dbStartPos}-${aln.dbEndPos}` : '') ]); - const dataToProcess = { - refPDB: targetPDB, - newPDB: queryPDB, - alnFasta: fasta - }; - return new Promise((resolve, reject) => { + if (!__LOCAL__) { const worker = new Worker(new URL("TMAlignWorker.js", import.meta.url)); - worker.onmessage = function (e) { - const { t, u, tmResults } = e.data; - resolve({ - matrix: makeMatrix4(t, u), - tmResults: tmResults - }); - worker.terminate(); - } - worker.onerror = function (e) { - reject(e); - worker.terminate(); - } - worker.postMessage(dataToProcess); + return new Promise((resolve, reject) => { + worker.onmessage = function (e) { + const { t, u, tmResults } = e.data; + resolve({ + matrix: makeMatrix4(t, u), + tmResults: tmResults + }); + worker.terminate(); + } + worker.onerror = function (e) { + reject(e); + worker.terminate(); + } + worker.postMessage({ refPDB: targetPDB, newPDB: queryPDB, alnFasta: fasta }); + }); + } + const { output, matrix } = await tmalign(targetPDB, queryPDB, fasta); + const { t, u } = parseTMMatrix(matrix); + const tmResults = parseTMOutput(output); + return Promise.resolve({ + matrix: makeMatrix4(t, u), + tmResults: tmResults, + alignment: aln }); }, async addStructureToStage(index, aa, ca) { diff --git a/frontend/webpack.frontend.config.js b/frontend/webpack.frontend.config.js index 41eb9ef..95a4a40 100644 --- a/frontend/webpack.frontend.config.js +++ b/frontend/webpack.frontend.config.js @@ -215,7 +215,7 @@ module.exports = (env, argv) => { }, }) : new NullPlugin(), isLocal ? new webpack.optimize.LimitChunkCountPlugin({ - maxChunks: 2, + maxChunks: 3, }) : new NullPlugin(), !isProduction && isElectron ? new webpack.HotModuleReplacementPlugin() : new NullPlugin(), @@ -234,19 +234,31 @@ module.exports = (env, argv) => { } })], splitChunks: { + minSize: 0, + minSizeReduction: 0, cacheGroups: { vendor: { - test: /[\\/]node_modules[\\/]/, - name: 'vendor', - chunks: 'all', - priority: -10, - reuseExistingChunk: true, + test: /[\\/]node_modules[\\/]/, + name: 'vendor', + chunks: 'all', + priority: -10, + reuseExistingChunk: true, + enforce: true + }, + workerGroup: { + test: /TMAlignWorker\.js$/, + name: 'tmworker', + chunks: 'all', + priority: -15, + reuseExistingChunk: true, + enforce: true }, frontend: { - name: 'frontend', - chunks: 'all', - priority: -20, - reuseExistingChunk: true, + name: 'frontend', + chunks: 'all', + priority: -20, + reuseExistingChunk: true, + enforce: true }, }, }