moorhen 0.0.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +142 -0
  2. package/baby-gru/CootWorker.js +1 -1071
  3. package/baby-gru/CootWorker.ts +1064 -0
  4. package/baby-gru/monomers/h/HIS.cif +5 -5
  5. package/baby-gru/moorhen.css +280 -0
  6. package/baby-gru/pixmaps/{map.svg → map-grey.svg} +38 -28
  7. package/baby-gru/pixmaps/moorhen-ligand.svg +213 -0
  8. package/baby-gru/pixmaps/secondary-structure-grey.svg +158 -0
  9. package/baby-gru/wasm/RDKit_minimal.js +1 -21
  10. package/baby-gru/wasm/RDKit_minimal.wasm +0 -0
  11. package/baby-gru/wasm/cif_pdb_worker.js +1 -33
  12. package/baby-gru/wasm/coot_env_web.js +1 -5
  13. package/baby-gru/wasm/crystallography_worker.js +1 -610
  14. package/baby-gru/wasm/mini_rsr_worker.js +1 -72
  15. package/baby-gru/wasm/monid_to_pdb_worker.js +1 -253
  16. package/baby-gru/wasm/moorhen.data +2580 -739
  17. package/baby-gru/wasm/moorhen.js +1 -21
  18. package/baby-gru/wasm/moorhen.wasm +0 -0
  19. package/baby-gru/wasm/moorhen.worker.js +1 -1
  20. package/baby-gru/wasm/mtz_arraybuffer_worker.js +1 -59
  21. package/baby-gru/wasm/mtz_worker.js +1 -45
  22. package/baby-gru/wasm/nma_worker.js +1 -103
  23. package/baby-gru/wasm/papaparse.min.js +2 -7
  24. package/baby-gru/wasm/papaparse.min.js.LICENSE.txt +6 -0
  25. package/baby-gru/wasm/pdb_worker.js +1 -282
  26. package/baby-gru/wasm/smiles_to_pdb_worker.js +1 -252
  27. package/baby-gru/wasm/superpose_worker.js +1 -144
  28. package/baby-gru/wasm/web_example.js +1 -21
  29. package/baby-gru/wasm/web_example.wasm +0 -0
  30. package/moorhen.css +1 -276
  31. package/moorhen.js +86 -0
  32. package/moorhen.js.LICENSE.txt +101 -0
  33. package/package.json +72 -51
  34. package/types/emscriptem.d.ts +25 -0
  35. package/types/gemmi.d.ts +115 -0
  36. package/types/index.d.ts +18 -0
  37. package/types/libcoot.d.ts +450 -0
  38. package/types/main.d.ts +428 -0
  39. package/types/mgWebGL.d.ts +398 -0
  40. package/types/moorhen.d.ts +815 -0
  41. package/baby-gru/pixmaps/diff-map.png +0 -0
  42. package/baby-gru/tutorials/legend.html +0 -3
  43. /package/baby-gru/{keyboard-blank.svg → pixmaps/keyboard-blank.svg} +0 -0
@@ -0,0 +1,1064 @@
1
+ import { libcootApi } from "../../src/types/libcoot"
2
+ import { emscriptem } from "../../src/types/emscriptem"
3
+
4
+ // @ts-ignore
5
+ importScripts('./wasm/moorhen.js')
6
+ // @ts-ignore
7
+ importScripts('./wasm/web_example.js')
8
+
9
+ let cootModule: libcootApi.CootModule;
10
+ let molecules_container: libcootApi.MoleculesContainerJS;
11
+ let ccp4Module: any;
12
+
13
+ const guid = () => {
14
+ var d = Date.now();
15
+ var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
16
+ var r = (d + Math.random() * 16) % 16 | 0;
17
+ d = Math.floor(d / 16);
18
+ return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
19
+ });
20
+ return uuid;
21
+ }
22
+
23
+ // @ts-ignore
24
+ let print = (stuff) => {
25
+ console.log(stuff)
26
+ postMessage({ consoleMessage: JSON.stringify(stuff) })
27
+ }
28
+
29
+ const instancedMeshToMeshData = (instanceMesh: libcootApi.InstancedMeshT, perm: boolean, toSpheres: boolean = false, maxZSize: number = 10000.): libcootApi.InstancedMeshJS => {
30
+ //maxZSize is arguably a hack to deal with overlong bonds. It is set to 5 incall to this function.
31
+
32
+ let totIdxs: number[][] = []
33
+ let totPos: number[][] = []
34
+ let totNorm: number[][] = []
35
+ let totInstance_sizes: number[][] = []
36
+ let totInstance_colours: number[][] = []
37
+ let totInstance_origins: number[][] = []
38
+ let totInstance_orientations: number[][] = []
39
+ let totInstanceUseColours: boolean[] = []
40
+ let totInstancePrimTypes: string[] = []
41
+
42
+ const geom = instanceMesh.geom
43
+ const markup = instanceMesh.markup
44
+ const geomSize = geom.size()
45
+ for (let i = 0; i < geomSize; i++) {
46
+ let thisToSpheres = toSpheres;
47
+ let thisIdxs: number[] = []
48
+ let thisPos: number[] = []
49
+ let thisNorm: number[] = []
50
+ let thisInstance_sizes: number[] = []
51
+ let thisInstance_colours: number[] = []
52
+ let thisInstance_origins: number[] = []
53
+ let thisInstance_orientations: number[] = []
54
+ const inst = geom.get(i);
55
+ if (inst.name === "spherical-atoms") thisToSpheres = true;
56
+ const vertices = inst.vertices;
57
+ const triangles = inst.triangles;
58
+ const trianglesSize = triangles.size()
59
+ for (let i = 0; i < trianglesSize; i++) {
60
+ const triangle = triangles.get(i)
61
+ const idxs = triangle.point_id
62
+ if (perm) {
63
+ thisIdxs.push(idxs[0])
64
+ thisIdxs.push(idxs[2])
65
+ thisIdxs.push(idxs[1])
66
+ } else {
67
+ thisIdxs.push(idxs[0])
68
+ thisIdxs.push(idxs[1])
69
+ thisIdxs.push(idxs[2])
70
+ }
71
+ }
72
+ triangles.delete()
73
+
74
+ const verticesSize = vertices.size()
75
+ for (let i = 0; i < verticesSize; i++) {
76
+ const vert = vertices.get(i);
77
+ const vertPos = vert.pos
78
+ thisPos.push(vertPos[0])
79
+ thisPos.push(vertPos[1])
80
+ thisPos.push(vertPos[2])
81
+ const vertNormal = vert.normal
82
+ thisNorm.push(vertNormal[0])
83
+ thisNorm.push(vertNormal[1])
84
+ thisNorm.push(vertNormal[2])
85
+ vert.delete()
86
+ }
87
+ vertices.delete()
88
+
89
+ const As = inst.instancing_data_A;
90
+ const Asize = As.size();
91
+
92
+ if (Asize > 0) {
93
+ for (let j = 0; j < Asize; j++) {
94
+ const inst_data = As.get(j)
95
+
96
+ const instDataPosition = inst_data.position
97
+ thisInstance_origins.push(instDataPosition[0])
98
+ thisInstance_origins.push(instDataPosition[1])
99
+ thisInstance_origins.push(instDataPosition[2])
100
+
101
+ const instDataColour = inst_data.colour
102
+ thisInstance_colours.push(instDataColour[0])
103
+ thisInstance_colours.push(instDataColour[1])
104
+ thisInstance_colours.push(instDataColour[2])
105
+ thisInstance_colours.push(instDataColour[3])
106
+
107
+ const instDataSize = inst_data.size
108
+ thisInstance_sizes.push(instDataSize[0])
109
+ thisInstance_sizes.push(instDataSize[1])
110
+ thisInstance_sizes.push(instDataSize[2])
111
+
112
+ thisInstance_orientations.push(...[
113
+ 1.0, 0.0, 0.0, 0.0,
114
+ 0.0, 1.0, 0.0, 0.0,
115
+ 0.0, 0.0, 1.0, 0.0,
116
+ 0.0, 0.0, 0.0, 1.0,
117
+ ])
118
+
119
+ inst_data.delete()
120
+ }
121
+ }
122
+ As.delete()
123
+
124
+ const Bs = inst.instancing_data_B;
125
+ const Bsize = Bs.size();
126
+ if (Bsize > 0) {
127
+ for (let j = 0; j < Bsize; j++) {
128
+ const inst_data = Bs.get(j)
129
+
130
+ const instDataSize = inst_data.size
131
+ if (instDataSize[2] > maxZSize) continue;
132
+ thisInstance_sizes.push(instDataSize[0])
133
+ thisInstance_sizes.push(instDataSize[1])
134
+ thisInstance_sizes.push(instDataSize[2])
135
+
136
+ const instDataPosition = inst_data.position
137
+ thisInstance_origins.push(instDataPosition[0])
138
+ thisInstance_origins.push(instDataPosition[1])
139
+ thisInstance_origins.push(instDataPosition[2])
140
+
141
+ const instDataColour = inst_data.colour
142
+ thisInstance_colours.push(instDataColour[0])
143
+ thisInstance_colours.push(instDataColour[1])
144
+ thisInstance_colours.push(instDataColour[2])
145
+ thisInstance_colours.push(instDataColour[3])
146
+
147
+ const instDataOrientation = inst_data.orientation
148
+
149
+ thisInstance_orientations.push(instDataOrientation[0][0])
150
+ thisInstance_orientations.push(instDataOrientation[0][1])
151
+ thisInstance_orientations.push(instDataOrientation[0][2])
152
+ thisInstance_orientations.push(instDataOrientation[0][3])
153
+
154
+ thisInstance_orientations.push(instDataOrientation[1][0])
155
+ thisInstance_orientations.push(instDataOrientation[1][1])
156
+ thisInstance_orientations.push(instDataOrientation[1][2])
157
+ thisInstance_orientations.push(instDataOrientation[1][3])
158
+
159
+ thisInstance_orientations.push(instDataOrientation[2][0])
160
+ thisInstance_orientations.push(instDataOrientation[2][1])
161
+ thisInstance_orientations.push(instDataOrientation[2][2])
162
+ thisInstance_orientations.push(instDataOrientation[2][3])
163
+
164
+ thisInstance_orientations.push(instDataOrientation[3][0])
165
+ thisInstance_orientations.push(instDataOrientation[3][1])
166
+ thisInstance_orientations.push(instDataOrientation[3][2])
167
+ thisInstance_orientations.push(instDataOrientation[3][3])
168
+
169
+ inst_data.delete()
170
+ }
171
+ }
172
+ Bs.delete()
173
+ inst.delete()
174
+
175
+ totNorm.push(thisNorm)
176
+ totPos.push(thisPos)
177
+ totIdxs.push(thisIdxs)
178
+ totInstance_sizes.push(thisInstance_sizes)
179
+ totInstance_origins.push(thisInstance_origins)
180
+ totInstance_orientations.push(thisInstance_orientations)
181
+ totInstance_colours.push(thisInstance_colours)
182
+ totInstanceUseColours.push(true)
183
+ if (thisToSpheres)
184
+ totInstancePrimTypes.push("PERFECT_SPHERES")
185
+ else
186
+ totInstancePrimTypes.push("TRIANGLES")
187
+
188
+ }
189
+
190
+ geom.delete()
191
+ const simpleMeshData = simpleMeshToMeshData(markup) // simpleMeshToMeshData should do the "delete"
192
+ instanceMesh.delete()
193
+
194
+ if (simpleMeshData.idx_tri.length > 0 && simpleMeshData.idx_tri[0].length > 0 && simpleMeshData.idx_tri[0][0].length > 0) {
195
+ if (toSpheres) {
196
+ return {
197
+ prim_types: [totInstancePrimTypes, simpleMeshData.prim_types[0]],
198
+ idx_tri: [totIdxs, simpleMeshData.idx_tri[0]],
199
+ vert_tri: [totInstance_origins, simpleMeshData.vert_tri[0]],
200
+ norm_tri: [totNorm, simpleMeshData.norm_tri[0]],
201
+ col_tri: [totInstance_colours, simpleMeshData.col_tri[0]],
202
+ instance_use_colors: [totInstanceUseColours, null],
203
+ instance_sizes: [totInstance_sizes, null],
204
+ instance_origins: [totInstance_origins, null],
205
+ instance_orientations: [totInstance_orientations, null]
206
+ }
207
+ } else {
208
+ return {
209
+ prim_types: [totInstancePrimTypes, simpleMeshData.prim_types[0]],
210
+ idx_tri: [totIdxs, simpleMeshData.idx_tri[0]],
211
+ vert_tri: [totPos, simpleMeshData.vert_tri[0]],
212
+ norm_tri: [totNorm, simpleMeshData.norm_tri[0]],
213
+ col_tri: [totInstance_colours, simpleMeshData.col_tri[0]],
214
+ instance_use_colors: [totInstanceUseColours, null],
215
+ instance_sizes: [totInstance_sizes, null],
216
+ instance_origins: [totInstance_origins, null],
217
+ instance_orientations: [totInstance_orientations, null]
218
+ }
219
+ }
220
+ } else {
221
+ return {
222
+ prim_types: [totInstancePrimTypes],
223
+ idx_tri: [totIdxs],
224
+ vert_tri: [totPos],
225
+ norm_tri: [totNorm],
226
+ col_tri: [totInstance_colours],
227
+ instance_use_colors: [totInstanceUseColours],
228
+ instance_sizes: [totInstance_sizes],
229
+ instance_origins: [totInstance_origins],
230
+ instance_orientations: [totInstance_orientations]
231
+ }
232
+ }
233
+ }
234
+
235
+ const simpleMeshToMeshData = (simpleMesh: libcootApi.SimpleMeshT, perm: boolean = false): libcootApi.SimpleMeshJS => {
236
+ const vertices = simpleMesh.vertices;
237
+ const triangles = simpleMesh.triangles;
238
+ let totIdxs: number[] = [];
239
+ let totPos: number[] = [];
240
+ let totNorm: number[] = [];
241
+ let totCol: number[] = [];
242
+
243
+ const trianglesSize = triangles.size()
244
+ for (let i = 0; i < trianglesSize; i++) {
245
+ const triangle = triangles.get(i)
246
+ const idxs = triangle.point_id;
247
+ if (perm)
248
+ totIdxs.push(...[idxs[0], idxs[2], idxs[1]]);
249
+ else
250
+ totIdxs.push(...idxs);
251
+ }
252
+ triangles.delete()
253
+
254
+ const verticesSize = vertices.size()
255
+ for (let i = 0; i < verticesSize; i++) {
256
+ const vert = vertices.get(i);
257
+ const vertPos = vert.pos
258
+ const vertNormal = vert.normal
259
+ const vertColor = vert.color
260
+ totPos.push(...vertPos);
261
+ if (perm)
262
+ totNorm.push(...[-vertNormal[0], -vertNormal[1], -vertNormal[2]]);
263
+ else
264
+ totNorm.push(...vertNormal);
265
+ totCol.push(...vertColor);
266
+ vert.delete()
267
+ }
268
+ vertices.delete()
269
+
270
+ simpleMesh.delete()
271
+
272
+ return {
273
+ prim_types: [["TRIANGLES"]],
274
+ idx_tri: [[totIdxs]],
275
+ vert_tri: [[totPos]],
276
+ norm_tri: [[totNorm]],
277
+ col_tri: [[totCol]]
278
+ };
279
+ }
280
+
281
+ const SuperposeResultsToJSArray = (superposeResults: libcootApi.SuperposeResultsT): libcootApi.SuperposeResultsJS => {
282
+ const alignedPairsVec = superposeResults.aligned_pairs
283
+ const alignedPairsVecSize = alignedPairsVec.size()
284
+ let alignedPairsData: { reference: libcootApi.ValidationInformationJS, moving: libcootApi.ValidationInformationJS }[] = []
285
+
286
+ for (let i = 0; i < alignedPairsVecSize; i++) {
287
+ const alignedPairs = alignedPairsVec.get(i)
288
+ const refResidueData = alignedPairs.first
289
+ const refResidueSpec = refResidueData.residue_spec
290
+ const movResidueData = alignedPairs.second
291
+ const movResidueSpec = movResidueData.residue_spec
292
+ const currentPairData = {
293
+ reference: {
294
+ chainId: refResidueSpec.chain_id,
295
+ insCode: refResidueSpec.ins_code,
296
+ seqNum: refResidueSpec.res_no,
297
+ restype: "UNK",
298
+ value: refResidueData.function_value,
299
+ label: refResidueData.label
300
+ },
301
+ moving: {
302
+ chainId: movResidueSpec.chain_id,
303
+ insCode: movResidueSpec.ins_code,
304
+ seqNum: movResidueSpec.res_no,
305
+ restype: "UNK",
306
+ value: movResidueData.function_value,
307
+ label: movResidueData.label,
308
+ }
309
+ }
310
+
311
+ movResidueData.delete()
312
+ movResidueSpec.delete()
313
+ refResidueData.delete()
314
+ refResidueSpec.delete()
315
+
316
+ alignedPairsData.push(currentPairData)
317
+ }
318
+
319
+ alignedPairsVec.delete()
320
+
321
+ return {
322
+ referenceSequence: superposeResults.alignment.first,
323
+ movingSequence: superposeResults.alignment.second,
324
+ supperposeInfo: superposeResults.superpose_info,
325
+ alignedPairsData: alignedPairsData
326
+ }
327
+ }
328
+
329
+ const colourRulesToJSArray = (colourRulesArray: emscriptem.vector<libcootApi.PairType<string, string>>) => {
330
+ let returnResult: libcootApi.PairType<string, string>[] = []
331
+ const colourRulesSize = colourRulesArray.size()
332
+ for (let i = 0; i < colourRulesSize; i++) {
333
+ const rule = colourRulesArray.get(i)
334
+ returnResult.push(rule)
335
+ }
336
+ colourRulesArray.delete()
337
+ return returnResult;
338
+ }
339
+
340
+ const floatArrayToJSArray = (floatArray: emscriptem.vector<number>) => {
341
+ let returnResult: number[] = []
342
+ const floatArraySize = floatArray.size()
343
+ for (let i = 0; i < floatArraySize; i++) {
344
+ const f = floatArray.get(i)
345
+ returnResult.push(f);
346
+ }
347
+ floatArray.delete()
348
+ return returnResult;
349
+ }
350
+
351
+ const mapMoleculeCentreInfoToJSObject = (mapMoleculeCentreInfo: libcootApi.MapMoleculeCentreInfo): libcootApi.MapMoleculeCentreInfoJS => {
352
+ //Takes a coot::util::map_molecule_centre_info and returns a javascript object that resembles it
353
+ //Disposes of the coordOrth
354
+ const updatedCentre = mapMoleculeCentreInfo.updated_centre
355
+ let returnResult = {
356
+ updated_centre: [
357
+ updatedCentre.x(),
358
+ updatedCentre.y(),
359
+ updatedCentre.z()
360
+ ] as [number, number, number],
361
+ success: mapMoleculeCentreInfo.success,
362
+ suggested_radius: mapMoleculeCentreInfo.suggested_radius,
363
+ suggested_contour_level: mapMoleculeCentreInfo.suggested_contour_level
364
+ }
365
+ updatedCentre.delete()
366
+ return returnResult;
367
+ }
368
+
369
+ const intArrayToJSArray = (intArray: emscriptem.vector<number>) => {
370
+ let returnResult: number[] = []
371
+ const intArraySize = intArray.size()
372
+ for (let i = 0; i < intArraySize; i++) {
373
+ const f = intArray.get(i)
374
+ returnResult.push(f);
375
+ }
376
+ intArray.delete()
377
+ return returnResult;
378
+ }
379
+
380
+ const stringArrayToJSArray = (stringArray: emscriptem.vector<string>) => {
381
+ let returnResult: string[] = []
382
+ const stringArraySize = stringArray.size()
383
+ for (let i = 0; i < stringArraySize; i++) {
384
+ const s = stringArray.get(i)
385
+ returnResult.push(s);
386
+ }
387
+ stringArray.delete()
388
+ return returnResult;
389
+ }
390
+
391
+ const symmetryToJSData = (symmetryDataPair: libcootApi.PairType<libcootApi.SymmetryData, emscriptem.vector<number[][]>>) => {
392
+ let result: { x: number; y: number; z: number; asString: string; isym: number; us: number; ws: number; vs: number; matrix: number[][]; }[]= []
393
+ const symmetryData = symmetryDataPair.first
394
+ const symmetryMatrices = symmetryDataPair.second
395
+ const cell = symmetryData.cell
396
+ const symm_trans = symmetryData.symm_trans
397
+ const symmetrySize = symm_trans.size()
398
+
399
+ for (let i = 0; i < symmetrySize; i++) {
400
+ const currentSymmetry = symm_trans.get(i)
401
+ const symTransT = currentSymmetry.first
402
+ const cellTranslation = currentSymmetry.second
403
+ const currentSymmMat = symmetryMatrices.get(i)
404
+
405
+ result.push({
406
+ x: symTransT.x(),
407
+ y: symTransT.y(),
408
+ z: symTransT.z(),
409
+ asString: symTransT.symm_as_string,
410
+ isym: symTransT.isym(),
411
+ us: cellTranslation.us,
412
+ ws: cellTranslation.ws,
413
+ vs: cellTranslation.vs,
414
+ matrix: currentSymmMat
415
+ })
416
+ symTransT.delete()
417
+ }
418
+
419
+ cell.delete()
420
+ symm_trans.delete()
421
+ symmetryMatrices.delete()
422
+ symmetryData.delete()
423
+ return result
424
+ }
425
+
426
+ const mmrrccStatsToJSArray = (mmrrccStats: libcootApi.PairType<emscriptem.map<libcootApi.DensityCorrelationStatsInfoT, libcootApi.ResidueSpecT>, emscriptem.map<libcootApi.DensityCorrelationStatsInfoT, libcootApi.ResidueSpecT>>): libcootApi.MMRCCStatsJS => {
427
+ const parseStats = (stats: emscriptem.map<libcootApi.DensityCorrelationStatsInfoT, libcootApi.ResidueSpecT>) => {
428
+ let result: {resNum: number; insCode: string; modelNumber: number; chainId: string; n: number; correlation: number; }[] = []
429
+ const residueSpecs = stats.keys()
430
+ const mapSize = residueSpecs.size()
431
+ for (let i = 0; i < mapSize; i++) {
432
+ const residueSpec = residueSpecs.get(i)
433
+ const densityCorrStat = stats.get(residueSpec)
434
+ result.push({
435
+ resNum: residueSpec.res_no,
436
+ insCode: residueSpec.ins_code,
437
+ modelNumber: residueSpec.model_number,
438
+ chainId: residueSpec.chain_id,
439
+ n: densityCorrStat.n,
440
+ correlation: densityCorrStat.correlation()
441
+ })
442
+ residueSpec.delete()
443
+ densityCorrStat.delete()
444
+ }
445
+ residueSpecs.delete()
446
+ return result
447
+ }
448
+
449
+ const first = mmrrccStats.first
450
+ const second = mmrrccStats.second
451
+
452
+ const returnResult = {
453
+ "All atoms": parseStats(first),
454
+ "Side-chains": parseStats(second)
455
+ }
456
+
457
+ first.delete()
458
+ second.delete()
459
+ return returnResult
460
+ }
461
+
462
+ const atomSpecToJSArray = (atomSpecs: emscriptem.vector<libcootApi.AtomSpecT>): libcootApi.AtomSpecJS[] => {
463
+ let returnResult: libcootApi.AtomSpecJS[] = []
464
+ const atomsSize = atomSpecs.size()
465
+ for (let ic = 0; ic < atomsSize; ic++) {
466
+ const atom = atomSpecs.get(ic)
467
+ returnResult.push({
468
+ chain_id: atom.chain_id,
469
+ res_no: atom.res_no,
470
+ ins_code: atom.ins_code,
471
+ atom_name: atom.atom_name,
472
+ alt_conf: atom.alt_conf,
473
+ int_user_data: atom.int_user_data,
474
+ float_user_data: atom.float_user_data,
475
+ string_user_data: atom.string_user_data,
476
+ model_number: atom.model_number
477
+ })
478
+ atom.delete()
479
+ }
480
+ atomSpecs.delete()
481
+ return returnResult
482
+ }
483
+
484
+ const residueSpecToJSArray = (residueSpecs: emscriptem.vector<libcootApi.ResidueSpecT>): libcootApi.ResidueSpecJS[] => {
485
+ let returnResult: { resNum: number; insCode: string; modelNumber: number; chainId: string; }[] = []
486
+ const residuesSize = residueSpecs.size()
487
+ for (let ic = 0; ic < residuesSize; ic++) {
488
+ const residue = residueSpecs.get(ic)
489
+ returnResult.push({
490
+ resNum: residue.res_no,
491
+ insCode: residue.ins_code,
492
+ modelNumber: residue.model_number,
493
+ chainId: residue.chain_id
494
+ })
495
+ residue.delete()
496
+ }
497
+ residueSpecs.delete()
498
+ return returnResult
499
+ }
500
+
501
+ const validationDataToJSArray = (validationData: libcootApi.ValidationInformationT, chainID: string | null = null): libcootApi.ValidationInformationJS[] => {
502
+ let returnResult: { chainId: string; insCode: string; seqNum: number; restype: string; value: number; }[] = []
503
+ const cviv = validationData.cviv
504
+ const chainSize = cviv.size()
505
+ for (let chainIndex = 0; chainIndex < chainSize; chainIndex++) {
506
+ const chain = cviv.get(chainIndex)
507
+ if (chainID !== null && chain.chain_id !== chainID) {
508
+ // pass
509
+ } else {
510
+ const resInfo = chain.rviv;
511
+ const resInfoSize = resInfo.size()
512
+ for (let ir = 0; ir < resInfoSize; ir++) {
513
+ const residue = resInfo.get(ir)
514
+ const residueSpec = residue.residue_spec
515
+ returnResult.push({
516
+ chainId: residueSpec.chain_id,
517
+ insCode: residueSpec.ins_code,
518
+ seqNum: residueSpec.res_no,
519
+ restype: "UNK",
520
+ value: residue.function_value
521
+ })
522
+ residue.delete()
523
+ residueSpec.delete()
524
+ }
525
+ resInfo.delete()
526
+ }
527
+ chain.delete()
528
+ }
529
+ cviv.delete()
530
+ validationData.delete()
531
+ return returnResult
532
+ }
533
+
534
+ const linesBoxToJSArray = (BoxData: libcootApi.Generic3dLinesBondsBoxT): libcootApi.Generic3dLinesBondsBoxJS[][] => {
535
+ let envdata: {start: {x: number; y: number; z: number; }; end: {x: number; y: number; z: number; }; dist: number; }[][]= []
536
+ const segments = BoxData.line_segments;
537
+ const nSeg = segments.size()
538
+ for (let i = 0; i < nSeg; i++) {
539
+ let thisEnvdata: {start: {x: number; y: number; z: number; }; end: {x: number; y: number; z: number; }; dist: number; }[] = []
540
+ const segsI = segments.get(i)
541
+ const nSegI = segsI.size()
542
+ for (let j = 0; j < nSegI; j++) {
543
+ const seg = segsI.get(j)
544
+ const start = seg.getStart()
545
+ const end = seg.getFinish()
546
+ const ampl = seg.amplitude()
547
+ const startJS = { x: start.x(), y: start.y(), z: start.z() }
548
+ const endJS = { x: end.x(), y: end.y(), z: end.z() }
549
+ thisEnvdata.push({
550
+ start: startJS,
551
+ end: endJS,
552
+ dist: ampl,
553
+ })
554
+ start.delete()
555
+ end.delete()
556
+ seg.delete()
557
+ }
558
+ segsI.delete()
559
+ envdata.push(thisEnvdata)
560
+ }
561
+ segments.delete()
562
+ BoxData.delete()
563
+
564
+ return envdata
565
+ }
566
+
567
+ const vectorHBondToJSArray = (HBondData: emscriptem.vector<libcootApi.MoorhenHBond>): libcootApi.HBondJS[] => {
568
+ let hbdata: libcootApi.HBondJS[] = []
569
+ const hbondDataSize = HBondData.size()
570
+ for (let ib = 0; ib < hbondDataSize; ib++) {
571
+ const hb = HBondData.get(ib)
572
+ hbdata.push({
573
+ hb_hydrogen: hb.hb_hydrogen,
574
+ donor: hb.donor,
575
+ acceptor: hb.acceptor,
576
+ donor_neigh: hb.donor_neigh,
577
+ acceptor_neigh: hb.acceptor_neigh,
578
+ angle_1: hb.angle_1,
579
+ angle_2: hb.angle_2,
580
+ angle_3: hb.angle_3,
581
+ dist: hb.dist,
582
+ ligand_atom_is_donor: hb.ligand_atom_is_donor,
583
+ hydrogen_is_ligand_atom: hb.hydrogen_is_ligand_atom,
584
+ bond_has_hydrogen_flag: hb.bond_has_hydrogen_flag,
585
+ })
586
+ }
587
+ HBondData.delete()
588
+ return hbdata
589
+ }
590
+
591
+ const interestingPlaceDataToJSArray = (interestingPlaceData: emscriptem.vector<libcootApi.InterestingPlaceT>): libcootApi.InterestingPlaceDataJS[] => {
592
+ let returnResult: {
593
+ modelNumber: number;
594
+ chainId: string;
595
+ insCode: string;
596
+ resNum: number;
597
+ featureType: string;
598
+ featureValue: number;
599
+ buttonLabel: string;
600
+ badness: number;
601
+ coordX: number;
602
+ coordY: number;
603
+ coordZ: number;
604
+ }[] = [];
605
+
606
+ const interestingPlaceDataSize = interestingPlaceData.size()
607
+ for (let ir = 0; ir < interestingPlaceDataSize; ir++) {
608
+ const residue = interestingPlaceData.get(ir)
609
+ const residueSpec = residue.residue_spec
610
+ returnResult.push({
611
+ modelNumber: residueSpec.model_number,
612
+ chainId: residueSpec.chain_id,
613
+ insCode: residueSpec.ins_code,
614
+ resNum: residueSpec.res_no,
615
+ featureType: residue.feature_type,
616
+ featureValue: residue.feature_value,
617
+ buttonLabel: residue.button_label,
618
+ badness: residue.badness,
619
+ coordX: residue.x,
620
+ coordY: residue.y,
621
+ coordZ: residue.z
622
+ })
623
+ residue.delete()
624
+ residueSpec.delete()
625
+ }
626
+ interestingPlaceData.delete()
627
+ return returnResult
628
+ }
629
+
630
+ const histogramInfoToJSData = (histogramInfo: libcootApi.HistogramInfo): libcootApi.HistogramInfoJS => {
631
+ const histogramCounts = histogramInfo.counts
632
+ const counts = intArrayToJSArray(histogramCounts)
633
+ const result: libcootApi.HistogramInfoJS = {
634
+ counts: counts,
635
+ bin_width: histogramInfo.bin_width,
636
+ base: histogramInfo.base
637
+ }
638
+ return result
639
+ }
640
+
641
+ const autoReadMtzInfoVectToJSArray = (autoReadMtzInfoArray: emscriptem.vector<libcootApi.AutoReadMtzInfo>): libcootApi.AutoReadMtzInfoJS[] => {
642
+ let returnResult: {idx: number;
643
+ F: string;
644
+ phi: string;
645
+ w: string;
646
+ F_obs: string;
647
+ sigF_obs: string;
648
+ Rfree: string;
649
+ weights_used: boolean;
650
+ }[] = []
651
+
652
+ const autoReadMtzInfoArraySize = autoReadMtzInfoArray.size()
653
+ for(let i = 0; i < autoReadMtzInfoArraySize; i++) {
654
+ const autoReadMtzInfo = autoReadMtzInfoArray.get(i)
655
+ returnResult.push({
656
+ idx: autoReadMtzInfo.idx,
657
+ F: autoReadMtzInfo.F,
658
+ phi: autoReadMtzInfo.phi,
659
+ w: autoReadMtzInfo.w,
660
+ Rfree: autoReadMtzInfo.Rfree,
661
+ F_obs: autoReadMtzInfo.F_obs,
662
+ sigF_obs: autoReadMtzInfo.sigF_obs,
663
+ weights_used: autoReadMtzInfo.weights_used,
664
+ })
665
+ autoReadMtzInfo.delete()
666
+ }
667
+ autoReadMtzInfoArray.delete()
668
+
669
+ return returnResult
670
+ }
671
+
672
+ const ramachandranDataToJSArray = (ramachandraData: emscriptem.vector<libcootApi.CootPhiPsiProbT>, chainID: string): libcootApi.RamaDataJS[] => {
673
+ let returnResult: { chainId: string; insCode: string; seqNum: number; restype: string; isOutlier: boolean; phi: number; psi: number; is_pre_pro: boolean; }[] = [];
674
+ const ramachandraDataSize = ramachandraData.size()
675
+ for (let ir = 0; ir < ramachandraDataSize; ir++) {
676
+ const residue = ramachandraData.get(ir)
677
+ const phiPsi = residue.phi_psi
678
+ if (phiPsi.chain_id === chainID) {
679
+ returnResult.push({
680
+ chainId: phiPsi.chain_id,
681
+ insCode: phiPsi.ins_code,
682
+ seqNum: phiPsi.residue_number,
683
+ restype: residue.residue_name(),
684
+ isOutlier: !residue.is_allowed_flag,
685
+ phi: phiPsi.phi(),
686
+ psi: phiPsi.psi(),
687
+ is_pre_pro: residue.residue_name() === 'PRO'
688
+ })
689
+ }
690
+ residue.delete()
691
+ phiPsi.delete()
692
+ }
693
+ ramachandraData.delete()
694
+ return returnResult
695
+ }
696
+
697
+ const simpleMeshToLineMeshData = (simpleMesh: libcootApi.SimpleMeshT, normalLighting: boolean): libcootApi.SimpleMeshJS => {
698
+ const vertices = simpleMesh.vertices;
699
+ const triangles = simpleMesh.triangles;
700
+ let totIdxs: number[] = [];
701
+ let totPos: number[] = [];
702
+ let totNorm: number[] = [];
703
+ let totCol: number[] = [];
704
+
705
+ const trianglesSize = triangles.size()
706
+ for (let i = 0; i < trianglesSize; i++) {
707
+ const triangle = triangles.get(i)
708
+ const idxs = triangle.point_id;
709
+ totIdxs.push(...[idxs[0], idxs[1], idxs[0], idxs[2], idxs[1], idxs[2]]);
710
+ }
711
+ triangles.delete()
712
+
713
+ const verticesSize = vertices.size()
714
+ for (let i = 0; i < verticesSize; i++) {
715
+ const vert = vertices.get(i);
716
+ totPos.push(...vert.pos);
717
+ totNorm.push(...vert.normal);
718
+ totCol.push(...vert.color);
719
+ vert.delete()
720
+ }
721
+ vertices.delete()
722
+
723
+ simpleMesh.delete()
724
+
725
+ if (normalLighting)
726
+ return { prim_types: [["NORMALLINES"]], useIndices: [[true]], idx_tri: [[totIdxs]], vert_tri: [[totPos]], additional_norm_tri: [[totNorm]], norm_tri: [[totNorm]], col_tri: [[totCol]] };
727
+ else
728
+ return { prim_types: [["LINES"]], useIndices: [[true]], idx_tri: [[totIdxs]], vert_tri: [[totPos]], norm_tri: [[totNorm]], col_tri: [[totCol]] };
729
+
730
+ }
731
+
732
+ const auto_open_mtz = (mtzData: ArrayBufferLike) => {
733
+ const theGuid = guid()
734
+ const asUint8Array = new Uint8Array(mtzData)
735
+ cootModule.FS_createDataFile(".", `${theGuid}.mtz`, asUint8Array, true, true);
736
+ const tempFilename = `./${theGuid}.mtz`
737
+ const result = molecules_container.auto_read_mtz(tempFilename)
738
+ cootModule.FS_unlink(tempFilename)
739
+ return result
740
+ }
741
+
742
+ const replace_map_by_mtz_from_file = (imol: number, mtzData: ArrayBufferLike, selectedColumns: { F: string; PHI: string; }) => {
743
+ const theGuid = guid()
744
+ const tempFilename = `./${theGuid}.mtz`
745
+ const asUint8Array = new Uint8Array(mtzData)
746
+ cootModule.FS_createDataFile(".", tempFilename, asUint8Array, true, true);
747
+ const readMtzArgs: [number, string, string, string, string, boolean] = [imol, tempFilename, selectedColumns.F, selectedColumns.PHI, "", false]
748
+ const result = molecules_container.replace_map_by_mtz_from_file(...readMtzArgs)
749
+ cootModule.FS_unlink(tempFilename)
750
+ return result
751
+ }
752
+
753
+ const new_positions_for_residue_atoms = (molToUpDate: number, residues: libcootApi.AtomInfo[][]) => {
754
+ let success = 0
755
+ const movedResidueVector = new cootModule.Vectormoved_residue_t()
756
+ residues.forEach(atoms => {
757
+ if (atoms.length > 0) {
758
+ const cidFields = atoms[0].label.split('/')
759
+ let [resNoStr, insCode] = cidFields[3].split(".")
760
+ insCode = insCode ? insCode : ""
761
+ const movedResidue = new cootModule.moved_residue_t(cidFields[2], parseInt(resNoStr), insCode)
762
+ atoms.forEach(atom => {
763
+ const movedAtom = new cootModule.moved_atom_t(atom.name, atom.alt_loc, atom.x, atom.y, atom.z, -1)
764
+ movedResidue.add_atom(movedAtom)
765
+ movedAtom.delete()
766
+ })
767
+ movedResidueVector.push_back(movedResidue)
768
+ movedResidue.delete()
769
+ }
770
+ })
771
+ const thisSuccess = molecules_container.new_positions_for_atoms_in_residues(molToUpDate, movedResidueVector)
772
+ success += thisSuccess
773
+ movedResidueVector.delete()
774
+ return success
775
+ }
776
+
777
+ const read_mtz = (mapData: ArrayBufferLike, name: string, selectedColumns: { F: string; PHI: string; isDifference: boolean; }) => {
778
+ const theGuid = guid()
779
+ const asUint8Array = new Uint8Array(mapData)
780
+ cootModule.FS_createDataFile(".", `${theGuid}.mtz`, asUint8Array, true, true);
781
+ const tempFilename = `./${theGuid}.mtz`
782
+ const read_mtz_args: [string, string, string, string, boolean, boolean] = [tempFilename, selectedColumns.F,
783
+ selectedColumns.PHI, "", false, selectedColumns.isDifference]
784
+ const molNo = molecules_container.read_mtz(...read_mtz_args)
785
+ cootModule.FS_unlink(tempFilename)
786
+ return molNo
787
+ }
788
+
789
+ const associate_data_mtz_file_with_map = (iMol: number, mtzData: { data: ArrayBufferLike; fileName: string; }, F: string, SIGF: string, FREE: string) => {
790
+ const asUint8Array = new Uint8Array(mtzData.data)
791
+ cootModule.FS_createDataFile(".", `${mtzData.fileName}.mtz`, asUint8Array, true, true);
792
+ const mtzFilename = `./${mtzData.fileName}.mtz`
793
+ const args: [number, string, string, string, string] = [iMol, mtzFilename, F, SIGF, FREE]
794
+ molecules_container.associate_data_mtz_file_with_map(...args)
795
+ return mtzFilename
796
+ }
797
+
798
+ const read_ccp4_map = (mapData: ArrayBufferLike, name: string, isDiffMap: boolean) => {
799
+ const theGuid = guid()
800
+ const asUint8Array = new Uint8Array(mapData)
801
+ let fileExtension = ''
802
+ if (name.endsWith('.map.gz')) {
803
+ fileExtension = 'map.gz'
804
+ } else if (name.endsWith('.mrc.gz')) {
805
+ fileExtension = 'mrc.gz'
806
+ }
807
+ cootModule.FS_createDataFile(".", `${theGuid}${fileExtension}`, asUint8Array, true, true);
808
+ const tempFilename = `./${theGuid}${fileExtension}`
809
+ const read_map_args: [string, boolean] = [tempFilename, isDiffMap]
810
+ const molNo = molecules_container.read_ccp4_map(...read_map_args)
811
+ cootModule.FS_unlink(tempFilename)
812
+ return molNo
813
+ }
814
+
815
+ const setUserDefinedBondColours = (imol: number, colours: { cid: string; rgb: [number, number, number] }[], applyColourToNonCarbonAtoms: boolean = false) => {
816
+ let colourMap = new cootModule.MapIntFloat3()
817
+ let indexedResiduesVec = new cootModule.VectorStringUInt_pair()
818
+
819
+ colours.forEach((colour, index) => {
820
+ colourMap.set(index + 51, colour.rgb)
821
+ const i = { first: colour.cid, second: index + 51 }
822
+ indexedResiduesVec.push_back(i)
823
+ })
824
+
825
+ molecules_container.set_user_defined_bond_colours(imol, colourMap)
826
+ molecules_container.set_user_defined_atom_colour_by_selection(imol, indexedResiduesVec, applyColourToNonCarbonAtoms)
827
+
828
+ indexedResiduesVec.delete()
829
+ colourMap.delete()
830
+ }
831
+
832
+ const doCootCommand = (messageData: {
833
+ myTimeStamp: number;
834
+ chainID?: string;
835
+ messageId?: string;
836
+ message: string;
837
+ returnType: string;
838
+ command: string;
839
+ commandArgs: any[];
840
+ }) => {
841
+
842
+ const { returnType, command, commandArgs, messageId, myTimeStamp, message } = messageData
843
+
844
+ try {
845
+
846
+ let cootResult
847
+ switch (command) {
848
+ case 'shim_new_positions_for_residue_atoms':
849
+ cootResult = new_positions_for_residue_atoms(...commandArgs as [number, libcootApi.AtomInfo[][]])
850
+ break
851
+ case 'shim_read_mtz':
852
+ cootResult = read_mtz(...commandArgs as [ArrayBufferLike, string, { F: string; PHI: string; isDifference: boolean; }])
853
+ break
854
+ case 'shim_auto_open_mtz':
855
+ cootResult = auto_open_mtz(...commandArgs as [ArrayBuffer])
856
+ break
857
+ case 'shim_read_ccp4_map':
858
+ cootResult = read_ccp4_map(...commandArgs as [ArrayBuffer, string, boolean])
859
+ break
860
+ case 'shim_associate_data_mtz_file_with_map':
861
+ cootResult = associate_data_mtz_file_with_map(...commandArgs as [number, { data: ArrayBufferLike; fileName: string; }, string, string, string])
862
+ break
863
+ case 'shim_replace_map_by_mtz_from_file':
864
+ cootResult = replace_map_by_mtz_from_file(...commandArgs as [number, ArrayBufferLike, { F: string; PHI: string; }])
865
+ break
866
+ case 'shim_set_bond_colours':
867
+ cootResult = setUserDefinedBondColours(...commandArgs as [number, { cid: string; rgb: [number, number, number] }[], boolean])
868
+ break
869
+ default:
870
+ cootResult = molecules_container[command](...commandArgs)
871
+ break
872
+ }
873
+
874
+ let returnResult;
875
+ switch (returnType) {
876
+ case 'instanced_mesh_perm':
877
+ returnResult = instancedMeshToMeshData(cootResult, true)
878
+ break;
879
+ case 'histogram_info_t':
880
+ returnResult = histogramInfoToJSData(cootResult)
881
+ break
882
+ case 'symmetry':
883
+ returnResult = symmetryToJSData(cootResult)
884
+ break;
885
+ case 'mmrrcc_stats':
886
+ returnResult = mmrrccStatsToJSArray(cootResult)
887
+ break;
888
+ case 'colour_rules':
889
+ returnResult = colourRulesToJSArray(cootResult)
890
+ break;
891
+ case 'instanced_mesh_perfect_spheres':
892
+ returnResult = instancedMeshToMeshData(cootResult, false, true)
893
+ break;
894
+ case 'instanced_mesh':
895
+ returnResult = instancedMeshToMeshData(cootResult, false, false, 5)
896
+ break;
897
+ case 'mesh_perm':
898
+ returnResult = simpleMeshToMeshData(cootResult, true)
899
+ break;
900
+ case 'mesh':
901
+ returnResult = simpleMeshToMeshData(cootResult)
902
+ break;
903
+ case 'lit_lines_mesh':
904
+ returnResult = simpleMeshToLineMeshData(cootResult, true)
905
+ break;
906
+ case 'lines_mesh':
907
+ returnResult = simpleMeshToLineMeshData(cootResult, false)
908
+ break;
909
+ case 'float_array':
910
+ returnResult = floatArrayToJSArray(cootResult)
911
+ break;
912
+ case 'int_array':
913
+ returnResult = intArrayToJSArray(cootResult)
914
+ break;
915
+ case 'auto_read_mtz_info_array':
916
+ returnResult = autoReadMtzInfoVectToJSArray(cootResult)
917
+ break;
918
+ case 'map_molecule_centre_info_t':
919
+ returnResult = mapMoleculeCentreInfoToJSObject(cootResult)
920
+ break;
921
+ case 'string_array':
922
+ returnResult = stringArrayToJSArray(cootResult)
923
+ break;
924
+ case 'residue_specs':
925
+ returnResult = residueSpecToJSArray(cootResult)
926
+ break;
927
+ case 'atom_specs':
928
+ returnResult = atomSpecToJSArray(cootResult)
929
+ break;
930
+ case 'ramachandran_data':
931
+ returnResult = ramachandranDataToJSArray(cootResult, messageData.chainID as string)
932
+ break;
933
+ case 'validation_data':
934
+ returnResult = validationDataToJSArray(cootResult, messageData.chainID)
935
+ break;
936
+ case 'interesting_places_data':
937
+ returnResult = interestingPlaceDataToJSArray(cootResult)
938
+ break;
939
+ case 'superpose_results':
940
+ returnResult = SuperposeResultsToJSArray(cootResult)
941
+ break
942
+ case 'generic_3d_lines_bonds_box':
943
+ returnResult = linesBoxToJSArray(cootResult)
944
+ break;
945
+ case 'vector_hbond':
946
+ returnResult = vectorHBondToJSArray(cootResult)
947
+ break;
948
+ case 'status_instanced_mesh_pair':
949
+ returnResult = { status: cootResult.first, mesh: instancedMeshToMeshData(cootResult.second, false, false, 5) }
950
+ break;
951
+ case 'void':
952
+ returnResult = null
953
+ break
954
+ case 'status':
955
+ default:
956
+ returnResult = cootResult
957
+ break;
958
+ }
959
+
960
+ return {
961
+ messageId, messageSendTime: Date.now(), command: command,
962
+ consoleMessage: `Completed ${command} in ${Date.now() - myTimeStamp} ms`,
963
+ result: { status: 'Completed', result: returnResult }
964
+ }
965
+ }
966
+
967
+ catch (err) {
968
+ console.log(err)
969
+ return {
970
+ messageId, myTimeStamp, message,
971
+ consoleMessage: `EXCEPTION RAISED IN ${command}, ${err}`,
972
+ result: { status: 'Exception' }
973
+ }
974
+ }
975
+ }
976
+
977
+ onmessage = function (e) {
978
+ if (e.data.message === 'CootInitialize') {
979
+ createRSRModule({
980
+ locateFile: (file) => `./wasm/${file}`,
981
+ onRuntimeInitialized: () => { },
982
+ mainScriptUrlOrBlob: "moorhen.js",
983
+ print: print,
984
+ printErr: print,
985
+ })
986
+ .then((returnedModule) => {
987
+ postMessage({ consoleMessage: 'Initialized molecules_container', message: e.data.message, messageId: e.data.messageId })
988
+ cootModule = returnedModule;
989
+ molecules_container = new cootModule.molecules_container_js(false)
990
+ molecules_container.set_show_timings(false)
991
+ molecules_container.fill_rotamer_probability_tables()
992
+ molecules_container.set_map_sampling_rate(1.7)
993
+ cootModule.FS.mkdir("COOT_BACKUP");
994
+ })
995
+ .catch((e) => {
996
+ console.log(e)
997
+ print(e);
998
+ });
999
+
1000
+ createCCP4Module({
1001
+ locateFile: (file) => `./wasm/${file}`,
1002
+ onRuntimeInitialized: () => { },
1003
+ mainScriptUrlOrBlob: "web_example.js",
1004
+ print: print,
1005
+ printErr: print,
1006
+ })
1007
+ .then((returnedModule) => {
1008
+ ccp4Module = returnedModule;
1009
+ })
1010
+ .catch((e) => {
1011
+ console.log(e)
1012
+ print(e);
1013
+ });
1014
+ }
1015
+
1016
+ else if (e.data.message === 'get_mtz_data') {
1017
+ const mtzData = cootModule.FS.readFile(e.data.fileName, { encoding: 'binary' });
1018
+ postMessage({
1019
+ messageId: e.data.messageId,
1020
+ myTimeStamp: e.data.myTimeStamp,
1021
+ consoleMessage: `Fetched mtz data for map ${e.data.molNo}`,
1022
+ message: e.data.message,
1023
+ result: { molNo: e.data.molNo, mtzData: mtzData }
1024
+ })
1025
+ }
1026
+
1027
+ else if (e.data.message === 'get_map') {
1028
+ const theGuid = guid()
1029
+ const tempFilename = `./${theGuid}.map`
1030
+ molecules_container.writeCCP4Map(e.data.molNo, tempFilename)
1031
+
1032
+ const mapData = cootModule.FS.readFile(tempFilename, { encoding: 'binary' }) as Uint8Array;
1033
+ cootModule.FS_unlink(tempFilename)
1034
+ postMessage({
1035
+ messageId: e.data.messageId,
1036
+ myTimeStamp: e.data.myTimeStamp,
1037
+ consoleMessage: `Fetched map of map ${e.data.molNo}`,
1038
+ message: e.data.message,
1039
+ result: { molNo: e.data.molNo, mapData: mapData.buffer }
1040
+ })
1041
+ }
1042
+
1043
+ else if (e.data.message === 'delete_file_name') {
1044
+ const result = cootModule.FS_unlink(e.data.fileName)
1045
+
1046
+ postMessage({
1047
+ messageId: e.data.messageId,
1048
+ myTimeStamp: e.data.myTimeStamp,
1049
+ messageTag: "result",
1050
+ result: result,
1051
+ })
1052
+
1053
+ } else if (e.data.message === 'coot_command_list') {
1054
+ const resultList = e.data.commandList.map(command => doCootCommand({...e.data, ...command}))
1055
+ postMessage({
1056
+ messageId: e.data.messageId, resultList
1057
+ })
1058
+ }
1059
+
1060
+ if (e.data.message === 'coot_command') {
1061
+ const result = doCootCommand(e.data)
1062
+ postMessage(result)
1063
+ }
1064
+ }