moorhen 0.0.1

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 (106) hide show
  1. package/baby-gru/CootWorker.js +1071 -0
  2. package/baby-gru/darkly.css +12 -0
  3. package/baby-gru/flatly.css +12 -0
  4. package/baby-gru/keyboard-blank.svg +3126 -0
  5. package/baby-gru/monomers/a/A.cif +271 -0
  6. package/baby-gru/monomers/a/ALA.cif +164 -0
  7. package/baby-gru/monomers/a/ARG.cif +252 -0
  8. package/baby-gru/monomers/a/ASN.cif +192 -0
  9. package/baby-gru/monomers/a/ASP.cif +178 -0
  10. package/baby-gru/monomers/c/C.cif +255 -0
  11. package/baby-gru/monomers/c/CIT.cif +167 -0
  12. package/baby-gru/monomers/c/CYS.cif +169 -0
  13. package/baby-gru/monomers/d/DA.cif +266 -0
  14. package/baby-gru/monomers/d/DC.cif +250 -0
  15. package/baby-gru/monomers/d/DG.cif +271 -0
  16. package/baby-gru/monomers/d/DT.cif +256 -0
  17. package/baby-gru/monomers/e/EDO.cif +108 -0
  18. package/baby-gru/monomers/g/G.cif +276 -0
  19. package/baby-gru/monomers/g/GLN.cif +208 -0
  20. package/baby-gru/monomers/g/GLU.cif +194 -0
  21. package/baby-gru/monomers/g/GLY.cif +138 -0
  22. package/baby-gru/monomers/g/GOL.cif +134 -0
  23. package/baby-gru/monomers/h/HIS.cif +215 -0
  24. package/baby-gru/monomers/h/HOH.cif +55 -0
  25. package/baby-gru/monomers/i/ILE.cif +213 -0
  26. package/baby-gru/monomers/l/LEU.cif +213 -0
  27. package/baby-gru/monomers/l/LYS.cif +228 -0
  28. package/baby-gru/monomers/m/MET.cif +201 -0
  29. package/baby-gru/monomers/m/MSE.cif +201 -0
  30. package/baby-gru/monomers/n/NA.cif +30 -0
  31. package/baby-gru/monomers/p/PHE.cif +233 -0
  32. package/baby-gru/monomers/p/PO4.cif +86 -0
  33. package/baby-gru/monomers/p/PRO.cif +188 -0
  34. package/baby-gru/monomers/s/SER.cif +169 -0
  35. package/baby-gru/monomers/s/SO4.cif +86 -0
  36. package/baby-gru/monomers/t/THR.cif +186 -0
  37. package/baby-gru/monomers/t/TRP.cif +263 -0
  38. package/baby-gru/monomers/t/TYR.cif +238 -0
  39. package/baby-gru/monomers/u/U.cif +248 -0
  40. package/baby-gru/monomers/v/VAL.cif +197 -0
  41. package/baby-gru/pixmaps/MoorhenLogo.png +0 -0
  42. package/baby-gru/pixmaps/add-alt-conf.svg +127 -0
  43. package/baby-gru/pixmaps/add-peptide-1.svg +257 -0
  44. package/baby-gru/pixmaps/atom-at-pointer.svg +91 -0
  45. package/baby-gru/pixmaps/auto-fit-rotamer.svg +118 -0
  46. package/baby-gru/pixmaps/cis-trans.svg +392 -0
  47. package/baby-gru/pixmaps/delete.svg +94 -0
  48. package/baby-gru/pixmaps/diff-map.png +0 -0
  49. package/baby-gru/pixmaps/drag.svg +253 -0
  50. package/baby-gru/pixmaps/edit-chi.svg +303 -0
  51. package/baby-gru/pixmaps/flip-peptide.svg +169 -0
  52. package/baby-gru/pixmaps/jed-flip-reverse.svg +286 -0
  53. package/baby-gru/pixmaps/map.svg +114 -0
  54. package/baby-gru/pixmaps/mutate.svg +111 -0
  55. package/baby-gru/pixmaps/rama-plot-gly-normal.png +0 -0
  56. package/baby-gru/pixmaps/rama-plot-gly-outlier.png +0 -0
  57. package/baby-gru/pixmaps/rama-plot-other-normal.png +0 -0
  58. package/baby-gru/pixmaps/rama-plot-other-outlier.png +0 -0
  59. package/baby-gru/pixmaps/rama-plot-pro-normal.png +0 -0
  60. package/baby-gru/pixmaps/rama-plot-pro-outlier.png +0 -0
  61. package/baby-gru/pixmaps/rama2_all.png +0 -0
  62. package/baby-gru/pixmaps/rama2_gly.png +0 -0
  63. package/baby-gru/pixmaps/rama2_ileval.png +0 -0
  64. package/baby-gru/pixmaps/rama2_non_gly_pro.png +0 -0
  65. package/baby-gru/pixmaps/rama2_non_gly_pro_pre_pro_ileval.png +0 -0
  66. package/baby-gru/pixmaps/rama2_pre_pro.png +0 -0
  67. package/baby-gru/pixmaps/rama2_pro.png +0 -0
  68. package/baby-gru/pixmaps/refine-1.svg +140 -0
  69. package/baby-gru/pixmaps/rigid-body.svg +124 -0
  70. package/baby-gru/pixmaps/rotamers.svg +78 -0
  71. package/baby-gru/pixmaps/rtz.svg +281 -0
  72. package/baby-gru/pixmaps/side-chain-180.svg +129 -0
  73. package/baby-gru/pixmaps/spin-view.svg +104 -0
  74. package/baby-gru/pixmaps/temperature.svg +92 -0
  75. package/baby-gru/tutorials/NUT.cif +453 -0
  76. package/baby-gru/tutorials/legend.html +3 -0
  77. package/baby-gru/tutorials/moorhen-tutorial-map-number-1.mtz +0 -0
  78. package/baby-gru/tutorials/moorhen-tutorial-map-number-2.mtz +0 -0
  79. package/baby-gru/tutorials/moorhen-tutorial-map-number-3.mtz +0 -0
  80. package/baby-gru/tutorials/moorhen-tutorial-map-number-4.mtz +0 -0
  81. package/baby-gru/tutorials/moorhen-tutorial-structure-number-1.pdb +2211 -0
  82. package/baby-gru/tutorials/moorhen-tutorial-structure-number-2.pdb +2018 -0
  83. package/baby-gru/tutorials/moorhen-tutorial-structure-number-3.pdb +1090 -0
  84. package/baby-gru/tutorials/moorhen-tutorial-structure-number-4.pdb +2801 -0
  85. package/baby-gru/wasm/RDKit_minimal.js +21 -0
  86. package/baby-gru/wasm/RDKit_minimal.wasm +0 -0
  87. package/baby-gru/wasm/cif_pdb_worker.js +33 -0
  88. package/baby-gru/wasm/coot_env_web.js +5 -0
  89. package/baby-gru/wasm/crystallography_worker.js +610 -0
  90. package/baby-gru/wasm/mini_rsr_worker.js +72 -0
  91. package/baby-gru/wasm/monid_to_pdb_worker.js +253 -0
  92. package/baby-gru/wasm/moorhen.data +246292 -0
  93. package/baby-gru/wasm/moorhen.js +21 -0
  94. package/baby-gru/wasm/moorhen.wasm +0 -0
  95. package/baby-gru/wasm/moorhen.worker.js +1 -0
  96. package/baby-gru/wasm/mtz_arraybuffer_worker.js +59 -0
  97. package/baby-gru/wasm/mtz_worker.js +45 -0
  98. package/baby-gru/wasm/nma_worker.js +103 -0
  99. package/baby-gru/wasm/papaparse.min.js +7 -0
  100. package/baby-gru/wasm/pdb_worker.js +282 -0
  101. package/baby-gru/wasm/smiles_to_pdb_worker.js +252 -0
  102. package/baby-gru/wasm/superpose_worker.js +144 -0
  103. package/baby-gru/wasm/web_example.js +21 -0
  104. package/baby-gru/wasm/web_example.wasm +0 -0
  105. package/moorhen.css +418 -0
  106. package/package.json +176 -0
@@ -0,0 +1,610 @@
1
+ // FIXME - Handle mmCIF, data cif, monomers(?)
2
+ // FIXME - We may not want multiple modules (CCP4Module,RSRModule) since files have to be loaded into FS of each one.
3
+ // FIXME - Does not seem to work in Safari. Importing moorhen.js is *not possible* in a thread on Safari, because it uses
4
+ // Workers internally to do the threading. And Safari does not support nested Workers, not even in technology preview.
5
+
6
+ let currentTaskName = "";
7
+ function rsrPrint(t){
8
+ postMessage({
9
+ messageTag: "output",
10
+ result: t,
11
+ taskName: currentTaskName
12
+ })
13
+ }
14
+
15
+ let CCP4Module;
16
+ let RSRModule;
17
+ let molecules_container = null;
18
+
19
+ importScripts('./web_example.js');
20
+ importScripts('./pako.js');
21
+
22
+ createCCP4Module({print: rsrPrint,printErr: rsrPrint})
23
+ .then(function(CCP4Mod) {
24
+ CCP4Module = CCP4Mod;
25
+ })
26
+ .catch((e) => {
27
+ console.log("CCP4 problem :(");
28
+ console.log(e);
29
+ });
30
+
31
+ importScripts('./moorhen.js');
32
+
33
+ const Lib = {
34
+ locateFile: (file) => file,
35
+ onRuntimeInitialized: () => {
36
+ console.log('onRuntimeInitialized');
37
+ },
38
+ mainScriptUrlOrBlob: "./moorhen.js",
39
+ print: rsrPrint,
40
+ printErr: rsrPrint,
41
+ };
42
+
43
+ createRSRModule(Lib)
44
+ .then(function(CCP4Mod) {
45
+ RSRModule = CCP4Mod;
46
+ molecules_container = new RSRModule.molecules_container_js();
47
+ molecules_container.geometry_init_standard();
48
+ molecules_container.fill_rotamer_probability_tables();
49
+ console.log("##################################################");
50
+ console.log(molecules_container);
51
+ console.log("##################################################");
52
+ })
53
+ .catch((e) => {
54
+ console.log("RSR problem :(");
55
+ console.log(e);
56
+ });
57
+
58
+
59
+ let dataObjects = {pdbFiles:{}, mtzFiles:{}, cifFiles:{}};
60
+ let dataObjectsNames = {pdbFiles:{}, mtzFiles:{}, cifFiles:{}, ramaInfo:{}, bvalInfo:{}, mol_cont_idx:{}, map_cont_idx:{}, densityFitInfo:{}, rotamersInfo:{}};
61
+
62
+ function guid(){
63
+ var d = Date.now();
64
+ var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
65
+ var r = (d + Math.random()*16)%16 | 0;
66
+ d = Math.floor(d/16);
67
+ return (c==='x' ? r : (r&0x3|0x8)).toString(16);
68
+ });
69
+ return uuid;
70
+ }
71
+
72
+ //TODO
73
+ // * Make files loaded from PDB available to MiniRSR/Flip and Ramachandran plot. Do not know why they are not ...
74
+ // * Create method to get Rama data from a PDB file,
75
+ // * Change dataObjectsNames to globalCache or something
76
+ // * Add Rama data to the globalCache
77
+
78
+ function updateDataObjectsNames(){
79
+ postMessage({
80
+ messageTag: "dataObjectsNames",
81
+ result: dataObjectsNames,
82
+ })
83
+ }
84
+
85
+ function downLoadFiles(files){
86
+ let CIFfiles = [];
87
+ let gzCIFfiles = [];
88
+ let PDBfiles = [];
89
+ let gzPDBfiles = [];
90
+ let MTZfiles = [];
91
+
92
+ for(let x=0;x<files.length;x++){
93
+ if(files[x].endsWith(".mtz")){
94
+ MTZfiles.push(files[x]);
95
+ } else if(files[x].endsWith(".pdb")||files[x].endsWith(".ent")){
96
+ PDBfiles.push(files[x]);
97
+ } else if(files[x].endsWith(".cif")){
98
+ CIFfiles.push(files[x]);
99
+ } else if(files[x].endsWith(".pdb.gz")||files[x].endsWith(".ent.gz")){
100
+ gzPDBfiles.push(files[x]);
101
+ } else if(files[x].endsWith(".cif.gz")){
102
+ gzCIFfiles.push(files[x]);
103
+ } else {
104
+ console.log("Unknown file suffix");
105
+ }
106
+ }
107
+
108
+ console.log(gzCIFfiles);
109
+
110
+ Promise.all(gzCIFfiles.map(function(url) {
111
+ return fetch(url).then(resp => resp.blob()).then(data => [url, data]);
112
+ })).then(results => {
113
+ for(ires=0;ires<results.length;ires++){
114
+ const thisResult = results[ires];
115
+ console.log(thisResult);
116
+ const key = guid();
117
+ //Now gunzip, etc...
118
+ }
119
+ })
120
+
121
+ /*
122
+ Promise.all(gzPDBfiles.map(function(file) {
123
+ return fetch(file).then(resp => resp.blob())
124
+ .then(data => [file, data]);
125
+ })).then(function(results){
126
+ for(ires=0;ires<results.length;ires++){
127
+ const thisResult = results[ires];
128
+ console.log(thisResult);
129
+ const key = guid();
130
+ CCP4Module.FS_createDataFile(".", key + ".pdb", thisResult[1], true, true);
131
+ RSRModule.FS_createDataFile(".", key + ".pdb", thisResult[1], true, true);
132
+ //TODO - parsePDB is now in a react-app/src. How do I get at it from here?
133
+ //const dataSplit = thisResult[1].split("\n");
134
+ //const hierarchy = parsePDB(dataSplit,name);
135
+ //dataObjects.pdbFiles[key] = {hierarchy:hierarchy, fileName:key + ".pdb", originalFileName:thisResult[0], contents:thisResult[1]};
136
+ dataObjects.pdbFiles[key] = {fileName:key + ".pdb", originalFileName:thisResult[0], contents:thisResult[1]};
137
+ dataObjectsNames.pdbFiles[key] = {fileName:key + ".pdb", originalFileName:thisResult[0]};
138
+ }
139
+ updateShareArrayBuffer();
140
+ }) .catch(function(err) {
141
+ console.log(err);
142
+ });
143
+ */
144
+
145
+
146
+ }
147
+
148
+ function loadFiles(files){
149
+
150
+ let PDBfiles = [];
151
+ let MTZfiles = [];
152
+
153
+ for(let x=0;x<files.length;x++){
154
+ if(files[x].name.endsWith(".mtz")){
155
+ MTZfiles.push(files[x]);
156
+ } else if(files[x].name.endsWith(".pdb")||files[x].name.endsWith(".ent")){
157
+ PDBfiles.push(files[x]);
158
+ }
159
+ }
160
+
161
+ Promise.all(PDBfiles.map(function(file) {
162
+ return file.text()
163
+ .then(data => [file.name, data]);
164
+ })).then(function(results){
165
+ for(ires=0;ires<results.length;ires++){
166
+ const thisResult = results[ires];
167
+ const key = guid();
168
+ CCP4Module.FS_createDataFile(".", key + ".pdb", thisResult[1], true, true);
169
+ RSRModule.FS_createDataFile(".", key + ".pdb", thisResult[1], true, true);
170
+ //TODO - parsePDB is now in a react-app/src. How do I get at it from here?
171
+ //const dataSplit = thisResult[1].split("\n");
172
+ //const hierarchy = parsePDB(dataSplit,name);
173
+ //dataObjects.pdbFiles[key] = {hierarchy:hierarchy, fileName:key + ".pdb", originalFileName:thisResult[0], contents:thisResult[1]};
174
+ dataObjects.pdbFiles[key] = {fileName:key + ".pdb", originalFileName:thisResult[0], contents:thisResult[1]};
175
+ dataObjectsNames.pdbFiles[key] = {fileName:key + ".pdb", originalFileName:thisResult[0]};
176
+ const result = molecules_container.read_pdb(key + ".pdb");
177
+ dataObjectsNames.mol_cont_idx[key] = result;
178
+ }
179
+ updateDataObjectsNames();
180
+ }) .catch(function(err) {
181
+ console.log(err);
182
+ });
183
+
184
+
185
+ Promise.all(MTZfiles.map(function(file) {
186
+ return file.arrayBuffer()
187
+ .then(data => [file.name, data]);
188
+ })).then(function(results){
189
+ for(ires=0;ires<results.length;ires++){
190
+ const thisResult = results[ires];
191
+ const key = guid();
192
+ const byteArray = new Uint8Array(thisResult[1]);
193
+ CCP4Module.FS_createDataFile(".", key + ".mtz", byteArray, true, true);
194
+ RSRModule.FS_createDataFile(".", key + ".mtz", byteArray, true, true);
195
+ dataObjects.mtzFiles[key] = {fileName:key + ".mtz", originalFileName:thisResult[0], contents:byteArray};
196
+ dataObjectsNames.mtzFiles[key] = {fileName:key + ".mtz", originalFileName:thisResult[0]};
197
+ //TODO - work out what columns to use ...
198
+ const f = "FC";
199
+ const phi = "PHIC";
200
+ const wt = "";
201
+ const use_wt = false;
202
+ const is_diff = false;
203
+ const result = molecules_container.read_mtz(key + ".mtz",f,phi,wt,use_wt,is_diff);
204
+ dataObjectsNames.map_cont_idx[key] = result;
205
+ }
206
+ updateDataObjectsNames();
207
+ }).catch(function(err) {
208
+ console.log(err);
209
+ });
210
+
211
+ }
212
+
213
+
214
+ function getDensityFit(e) {
215
+ console.log(e.data);
216
+ const jobId = e.data.jobId;
217
+ const pdbin = dataObjects.pdbFiles[e.data.pdbinKey].fileName;
218
+ const chainId = e.data["chainId"];
219
+ const hklin = dataObjects.mtzFiles[e.data.hklinKey].fileName;
220
+ const imol_model = dataObjectsNames.mol_cont_idx[e.data.pdbinKey];
221
+ const imol_map = dataObjectsNames.map_cont_idx[e.data.hklinKey];
222
+ console.log(imol_model,imol_map);
223
+ const result = molecules_container.density_fit_analysis(imol_model, imol_map);
224
+ console.log(result);
225
+ const index_for_chain = result.get_index_for_chain(chainId);
226
+ console.log(index_for_chain);
227
+ console.log(result.cviv.get(index_for_chain));
228
+ const resInfo = result.cviv.get(index_for_chain).rviv;
229
+ console.log(resInfo);
230
+ console.log(resInfo.size());
231
+ let resInfoJS = [];
232
+ for(let ir=0;ir<resInfo.size();ir++){
233
+ const CPPchainId = resInfo.get(ir).residue_spec.chain_id;
234
+ const seqNum = resInfo.get(ir).residue_spec.res_no;
235
+ const value = resInfo.get(ir).distortion;
236
+ const insCode = resInfo.get(ir).residue_spec.ins_code;
237
+ //FIXME - It would be nice to know.
238
+ const restype = "UNK";
239
+ const jsres = {chainId:CPPchainId,insCode:insCode,seqNum:seqNum,restype:restype,density_fit:1./value};
240
+ resInfoJS.push(jsres);
241
+ }
242
+ postMessage({
243
+ messageId: e.data.messageId,
244
+ messageTag: "result",
245
+ result: resInfoJS,
246
+ taskName: currentTaskName
247
+ })
248
+ }
249
+
250
+ function getBVals(e) {
251
+ console.log(e.data);
252
+ const jobId = e.data.jobId;
253
+ const pdbin = dataObjects.pdbFiles[e.data.pdbinKey].fileName;
254
+ const chainId = e.data["chainId"];
255
+ const result = RSRModule.getBVals(pdbin,chainId);
256
+ let resInfo = [];
257
+ for(let ir=0;ir<result.size();ir++){
258
+ const cppres = result.get(ir);
259
+ //TODO - Is there a nicer way to do this?
260
+ const jsres = {chainId:cppres.chainId,insCode:cppres.insCode,seqNum:cppres.seqNum,restype:cppres.restype,bval:cppres.property};
261
+ resInfo.push(jsres);
262
+ }
263
+ postMessage({
264
+ messageId: e.data.messageId,
265
+ messageTag: "result",
266
+ result: resInfo,
267
+ taskName: currentTaskName
268
+ })
269
+ }
270
+
271
+ function getRama(e) {
272
+ console.log(e.data);
273
+ const jobId = e.data.jobId;
274
+ const pdbin = dataObjects.pdbFiles[e.data.pdbinKey].fileName;
275
+ const chainId = e.data["chainId"];
276
+ const result = RSRModule.getRamachandranData(pdbin,chainId);
277
+ console.log(result);
278
+ let resInfo = [];
279
+ for(let ir=0;ir<result.size();ir++){
280
+ const cppres = result.get(ir);
281
+ //TODO - Is there a nicer way to do this?
282
+ const jsres = {chainId:cppres.chainId,insCode:cppres.insCode,seqNum:cppres.seqNum,restype:cppres.restype,phi:cppres.phi,psi:cppres.psi,isOutlier:cppres.isOutlier,is_pre_pro:cppres.is_pre_pro};
283
+ resInfo.push(jsres);
284
+ }
285
+ postMessage({
286
+ messageId: e.data.messageId,
287
+ messageTag: "result",
288
+ result: resInfo,
289
+ taskName: currentTaskName
290
+ })
291
+ }
292
+
293
+ function drawMesh(simpleMesh,e) {
294
+ const nVertices = molecules_container.count_simple_mesh_vertices(simpleMesh);
295
+ const vertices = simpleMesh.vertices;
296
+ const nVerticesDirect = vertices.size();
297
+ const triangles = simpleMesh.triangles;
298
+ const nTriangles = triangles.size();
299
+ let totIdxs = [];
300
+ let totPos = [];
301
+ let totNorm = [];
302
+ let totCol = [];
303
+ for(let i=0;i<triangles.size();i++){
304
+ const idxs = triangles.get(i).point_id;
305
+ totIdxs.push(...idxs);
306
+ }
307
+ for(let i=0;i<vertices.size();i++){
308
+ const vert = vertices.get(i);
309
+ totPos.push(...vert.pos);
310
+ totNorm.push(...vert.normal);
311
+ totCol.push(...vert.color);
312
+ }
313
+ const cubeInfo = {prim_types:[["TRIANGLES"]],idx_tri:[[totIdxs]],vert_tri:[[totPos]],norm_tri:[[totNorm]],col_tri:[[totCol]]};
314
+ postMessage({
315
+ messageId: e.data.messageId,
316
+ messageTag: "result",
317
+ result: cubeInfo,
318
+ taskName: currentTaskName
319
+ })
320
+ }
321
+
322
+ function drawDodos(e) {
323
+
324
+ //This is not yet used
325
+ //const chainId = e.data["chainId"];
326
+
327
+ const idx = dataObjectsNames.mol_cont_idx[e.data.pdbinKey];
328
+ const simpleMesh = molecules_container.get_rotamer_dodecs(idx);
329
+ drawMesh(simpleMesh,e);
330
+ }
331
+
332
+ function drawRamaBalls(e) {
333
+
334
+ //This is not yet used
335
+ //const chainId = e.data["chainId"];
336
+
337
+ const idx = dataObjectsNames.mol_cont_idx[e.data.pdbinKey];
338
+ const simpleMesh = molecules_container.ramachandran_validation_markup_mesh(idx);
339
+ drawMesh(simpleMesh,e);
340
+ }
341
+
342
+ function drawCube(e) {
343
+ const simpleMesh = molecules_container.test_origin_cube();
344
+ drawMesh(simpleMesh,e);
345
+ }
346
+
347
+
348
+ function getRotamers(e) {
349
+ const jobId = e.data.jobId;
350
+ const pdbin = dataObjects.pdbFiles[e.data.pdbinKey].fileName;
351
+ const chainId = e.data["chainId"];
352
+
353
+ const rotamersMap = RSRModule.getRotamersMap();
354
+
355
+ let rotamersInfo = [];
356
+ const residueList = RSRModule.getResidueListForChain(pdbin,chainId);
357
+ const residueSpecList = RSRModule.getResidueSpecListForChain(pdbin,chainId);
358
+ for(let i=0;i<residueList.size();i++){
359
+ const resRot = rotamersMap.get(residueList.get(i));
360
+ if(resRot){
361
+ let irot = 0;
362
+ let resRots = [];
363
+ for(irot=0;irot<resRot.size();irot++){
364
+ const rotamer = resRot.get(irot);
365
+ const chi1 = rotamer.get_chi(1);
366
+ const chi2 = rotamer.get_chi(2);
367
+ const chi3 = rotamer.get_chi(3);
368
+ const chi4 = rotamer.get_chi(4);
369
+ resRots.push([chi1,chi2,chi3,chi4]);
370
+ }
371
+ rotamersInfo.push({chainId:chainId,seqNum:residueSpecList.get(i).res_no,insCode:residueSpecList.get(i).ins_code,restype:residueList.get(i),data:resRots});
372
+ } else {
373
+ rotamersInfo.push({chainId:chainId,seqNum:residueSpecList.get(i).res_no,insCode:residueSpecList.get(i).ins_code,restype:residueList.get(i),data:[]});
374
+ }
375
+ }
376
+ postMessage({
377
+ messageId: e.data.messageId,
378
+ messageTag: "result",
379
+ result: rotamersInfo,
380
+ taskName: currentTaskName
381
+ })
382
+ }
383
+
384
+ function autoFitRotamer(e) {
385
+
386
+ const jobId = e.data.jobId;
387
+
388
+ const pdbin = dataObjects.pdbFiles[e.data.pdbinKey].fileName;
389
+ const chainId = e.data["chainId"];
390
+ const resno = e.data["resno"];
391
+ const pdbout = jobId+"out.pdb";
392
+ const imol_model = dataObjectsNames.mol_cont_idx[e.data.pdbinKey];
393
+ const imol_map = dataObjectsNames.map_cont_idx[e.data.hklinKey];
394
+
395
+ const resultMolCont = molecules_container.auto_fit_rotamer(imol_model,chainId,resno,"","",imol_map)
396
+
397
+ const write_result = molecules_container.writePDBASCII(dataObjectsNames.mol_cont_idx[e.data.pdbinKey],pdbout);
398
+ console.log("result of which is",resultMolCont,write_result);
399
+ var pdb_out = RSRModule.FS.readFile(pdbout, { encoding: 'utf8' });
400
+
401
+ //postMessage(["result",result,currentTaskName]);
402
+ postMessage({
403
+ messageId: e.data.messageId,
404
+ messageTag: "result",
405
+ result: resultMolCont,
406
+ taskName: currentTaskName
407
+ })
408
+ postMessage({
409
+ messageId: e.data.messageId,
410
+ messageTag: "pdb_out",
411
+ jobId: jobId,
412
+ result: pdb_out,
413
+ taskName: currentTaskName
414
+ })
415
+ }
416
+
417
+ function flipPeptide(e) {
418
+
419
+ const jobId = e.data.jobId;
420
+
421
+ const pdbin = dataObjects.pdbFiles[e.data.pdbinKey].fileName;
422
+ const chainId = e.data["chainId"];
423
+ const resno = e.data["resnoFlip"];
424
+ const pdbout = jobId+"out.pdb";
425
+
426
+ const resSpec = new RSRModule.residue_spec_t(chainId,resno,"");
427
+
428
+ /*
429
+ var result = RSRModule.flipPeptide(pdbin,resSpec,pdbout);
430
+ var pdb_out = RSRModule.FS.readFile(pdbout, { encoding: 'utf8' });
431
+ */
432
+
433
+ console.log("Should in fact call molecules_container.flipPeptide_rs with", dataObjectsNames.mol_cont_idx[e.data.pdbinKey]);
434
+ const resultMolCont = molecules_container.flipPeptide_rs(dataObjectsNames.mol_cont_idx[e.data.pdbinKey],resSpec,"");
435
+ const write_result = molecules_container.writePDBASCII(dataObjectsNames.mol_cont_idx[e.data.pdbinKey],pdbout);
436
+ console.log("result of which is",resultMolCont,write_result);
437
+ var pdb_out = RSRModule.FS.readFile(pdbout, { encoding: 'utf8' });
438
+
439
+ //postMessage(["result",result,currentTaskName]);
440
+ postMessage({
441
+ messageId: e.data.messageId,
442
+ messageTag: "result",
443
+ result: resultMolCont,
444
+ taskName: currentTaskName
445
+ })
446
+ postMessage({
447
+ messageId: e.data.messageId,
448
+ messageTag: "pdb_out",
449
+ jobId: jobId,
450
+ result: pdb_out,
451
+ taskName: currentTaskName
452
+ })
453
+ }
454
+
455
+ function miniRSR(e) {
456
+
457
+ console.log(e.data);
458
+
459
+ const jobId = e.data.jobId;
460
+
461
+ var args = new RSRModule.VectorString();
462
+ args.push_back("mini_rsr");
463
+
464
+ //mini_rsr --pdbin /Users/stuart/CCP4MG_DOWNLOAD/5a3h.pdb --hklin /Users/stuart/CCP4MG_DOWNLOAD/5a3h_final.mtz --pdbout mini_rsr_out.pdb --resno-start 27 --resno-end 37 --chain-id A --debug
465
+
466
+ args.push_back("--pdbin");
467
+ args.push_back(dataObjects.pdbFiles[e.data.pdbinKey].fileName);
468
+
469
+ args.push_back("--hklin");
470
+ args.push_back(dataObjects.mtzFiles[e.data.hklinKey].fileName);
471
+
472
+ args.push_back("--pdbout");
473
+ args.push_back(jobId+"out.pdb");
474
+
475
+ args.push_back("--resno-start");
476
+ args.push_back((e.data["resnoStart"]).toString());
477
+ args.push_back("--resno-end");
478
+ args.push_back((e.data["resnoEnd"]).toString());
479
+ args.push_back("--chain-id");
480
+ args.push_back(e.data["chainId"]);
481
+
482
+ args.push_back("--debug");
483
+
484
+ console.log("Calling");
485
+
486
+ var result = RSRModule.mini_rsr(args);
487
+ var pdb_out = RSRModule.FS.readFile(jobId+"out.pdb", { encoding: 'utf8' });
488
+ //TODO We need to store pdb_out! (and cache with updateShareArrayBuffer)
489
+ postMessage({
490
+ messageId: e.data.messageId,
491
+ messageTag: "result",
492
+ result: result,
493
+ taskName: currentTaskName
494
+ })
495
+ postMessage({
496
+ messageId: e.data.messageId,
497
+ messageTag: "pdb_out",
498
+ jobId: jobId,
499
+ result: pdb_out,
500
+ taskName: currentTaskName
501
+ })}
502
+
503
+
504
+ onmessage = function(e) {
505
+
506
+ switch(e.data.method){
507
+ case "loadFile":
508
+ console.log("Load file(s)",e.data.files);
509
+ loadFiles(e.data.files);
510
+ break;
511
+ case "loadUrl":
512
+ console.log("Download file(s)",e.data.urls);
513
+ downLoadFiles(e.data.urls);
514
+ break;
515
+ case "get_rama":
516
+ currentTaskName = "get_rama";
517
+ getRama(e);
518
+ currentTaskName = "";
519
+ break;
520
+ case "flip_peptide":
521
+ console.log("Do peptide-flip in cryst worker ...");
522
+ currentTaskName = "flip_peptide";
523
+ flipPeptide(e);
524
+ currentTaskName = "";
525
+ break;
526
+ case "mini_rsr":
527
+ console.log("Do mini-rsr in cryst worker ...");
528
+ currentTaskName = "mini_rsr";
529
+ miniRSR(e);
530
+ currentTaskName = "";
531
+ break;
532
+ case "auto_fit_rotamer":
533
+ console.log("Do auto-fit rotamer in cryst worker ...");
534
+ currentTaskName = "mini_rsr";
535
+ autoFitRotamer(e);
536
+ currentTaskName = "";
537
+ break;
538
+ case "get_bvals":
539
+ currentTaskName = "get_bvals";
540
+ getBVals(e);
541
+ currentTaskName = "";
542
+ break;
543
+ case "density_fit":
544
+ currentTaskName = "density_fit";
545
+ getDensityFit(e);
546
+ currentTaskName = "";
547
+ break;
548
+ case "get_xyz":
549
+ currentTaskName = "get_xyz";
550
+ const pdbRegex = /.pdb$/;
551
+ const pdbKeys = Object.keys(dataObjectsNames.pdbFiles);
552
+ let theData_id;
553
+ if(e.data.resInfo.molKey){
554
+ theData_id = e.data.resInfo.molKey
555
+ } else {
556
+ for(let iobj=0;iobj<pdbKeys.length;iobj++){
557
+ const data_id = pdbKeys[iobj];
558
+ const name = dataObjectsNames.pdbFiles[data_id].originalFileName;
559
+ const shortName = name.replace(pdbRegex,"");
560
+ if(shortName===e.data.resInfo.molName){
561
+ console.log("Use",data_id,dataObjects.pdbFiles[data_id]);
562
+ theData_id = data_id;
563
+ break;
564
+ }
565
+ }
566
+ }
567
+ if(theData_id){
568
+ let result;
569
+ if(e.data.resInfo.seqNum){
570
+ //FIXME - this is almost certainly dodgy. Ignoring insCode is probably a bad idea.
571
+ result = CCP4Module.getXYZSeqNumInsCode(dataObjects.pdbFiles[theData_id].fileName,e.data.resInfo.chain,e.data.resInfo.seqNum,"");
572
+ } else {
573
+ result = CCP4Module.getXYZResNo(dataObjects.pdbFiles[theData_id].fileName,e.data.resInfo.chain,e.data.resInfo.resNo);
574
+ }
575
+ if(result.size()===3){
576
+ postMessage({
577
+ messageId: e.data.messageId,
578
+ messageTag: "result",
579
+ result: [-result.get(0),-result.get(1),-result.get(2)],
580
+ taskName: currentTaskName
581
+ })
582
+ }
583
+ }
584
+ currentTaskName = "";
585
+ break;
586
+ case "get_rotamers":
587
+ currentTaskName = "rotamers";
588
+ getRotamers(e);
589
+ currentTaskName = "";
590
+ break;
591
+ case "draw_cube":
592
+ currentTaskName = "draw_cube";
593
+ drawCube(e);
594
+ currentTaskName = "";
595
+ break;
596
+ case "rotamer_dodecs":
597
+ currentTaskName = "rotamer_dodecs";
598
+ drawDodos(e);
599
+ currentTaskName = "";
600
+ break;
601
+ case "rama_balls":
602
+ currentTaskName = "rama_balls";
603
+ drawRamaBalls(e);
604
+ currentTaskName = "";
605
+ break;
606
+ default:
607
+ console.log("default, do nothing",e.data.method);
608
+ }
609
+
610
+ }
@@ -0,0 +1,72 @@
1
+ var CCP4Module;
2
+
3
+ importScripts('./mini-rsr-web.js');
4
+
5
+ const Lib = {
6
+ locateFile: (file) => file,
7
+ onRuntimeInitialized: () => {
8
+ console.log('onRuntimeInitialized');
9
+ },
10
+ mainScriptUrlOrBlob: "./mini-rsr-web.js",
11
+ print(t){postMessage(["output",t])},
12
+ printErr(t){postMessage(["output",t])},
13
+ };
14
+
15
+ createRSRModule(Lib)
16
+ .then(function(CCP4Mod) {
17
+ CCP4Module = CCP4Mod;
18
+ })
19
+ .catch((e) => {
20
+ console.log("CCP4 problem :(");
21
+ console.log(e);
22
+ });
23
+
24
+ onmessage = function(e) {
25
+
26
+ console.log(e.data);
27
+
28
+ const jobId = e.data.jobId;
29
+
30
+ var args = new CCP4Module.VectorString();
31
+ args.push_back("mini_rsr");
32
+
33
+ //mini_rsr --pdbin /Users/stuart/CCP4MG_DOWNLOAD/5a3h.pdb --hklin /Users/stuart/CCP4MG_DOWNLOAD/5a3h_final.mtz --pdbout mini_rsr_out.pdb --resno-start 27 --resno-end 37 --chain-id A --debug
34
+
35
+ //try {
36
+ CCP4Module.FS_createDataFile(".", jobId+e.data["pdbinName"], e.data["pdbinData"], true, true);
37
+ //} catch(e) {
38
+ //This happens when we supply same file name on subsequent calls to this function?
39
+ //}
40
+ args.push_back("--pdbin");
41
+ args.push_back(jobId+e.data["pdbinName"]);
42
+
43
+ //try {
44
+ CCP4Module.FS_createDataFile(".", jobId+e.data["hklinName"], e.data["hklinData"], true, true);
45
+ //} catch(e) {
46
+ //This happens when we supply same file name on subsequent calls to this function?
47
+ //}
48
+ args.push_back("--hklin");
49
+ args.push_back(jobId+e.data["hklinName"]);
50
+
51
+ args.push_back("--pdbout");
52
+ args.push_back(jobId+"out.pdb");
53
+
54
+ args.push_back("--resno-start");
55
+ args.push_back((e.data["resnoStart"]).toString());
56
+ args.push_back("--resno-end");
57
+ args.push_back((e.data["resnoEnd"]).toString());
58
+ args.push_back("--chain-id");
59
+ args.push_back(e.data["chainId"]);
60
+
61
+ args.push_back("--debug");
62
+
63
+ console.log(args);
64
+ var result = CCP4Module.mini_rsr(args);
65
+ var pdb_out = CCP4Module.FS.readFile(jobId+"out.pdb", { encoding: 'utf8' });
66
+ CCP4Module.FS_unlink(jobId+e.data["pdbinName"])
67
+ CCP4Module.FS_unlink(jobId+e.data["hklinName"])
68
+ CCP4Module.FS_unlink(jobId+"out.pdb")
69
+
70
+ postMessage(["result",result]);
71
+ postMessage(["pdb_out",pdb_out,jobId]);
72
+ }