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
Binary file
@@ -0,0 +1 @@
1
+ "use strict";var Module={};var ENVIRONMENT_IS_NODE=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string";if(ENVIRONMENT_IS_NODE){var nodeWorkerThreads=require("worker_threads");var parentPort=nodeWorkerThreads.parentPort;parentPort.on("message",data=>onmessage({data:data}));var fs=require("fs");Object.assign(global,{self:global,require:require,Module:Module,location:{href:__filename},Worker:nodeWorkerThreads.Worker,importScripts:function(f){(0,eval)(fs.readFileSync(f,"utf8")+"//# sourceURL="+f)},postMessage:function(msg){parentPort.postMessage(msg)},performance:global.performance||{now:function(){return Date.now()}}})}var initializedJS=false;var pendingNotifiedProxyingQueues=[];function assert(condition,text){if(!condition)abort("Assertion failed: "+text)}function threadPrintErr(){var text=Array.prototype.slice.call(arguments).join(" ");if(ENVIRONMENT_IS_NODE){fs.writeSync(2,text+"\n");return}console.error(text)}function threadAlert(){var text=Array.prototype.slice.call(arguments).join(" ");postMessage({cmd:"alert",text:text,threadId:Module["_pthread_self"]()})}var out=()=>{throw"out() is not defined in worker.js."};var err=threadPrintErr;self.alert=threadAlert;Module["instantiateWasm"]=(info,receiveInstance)=>{var instance=new WebAssembly.Instance(Module["wasmModule"],info);receiveInstance(instance);Module["wasmModule"]=null;return instance.exports};self.onunhandledrejection=e=>{throw e.reason??e};self.onmessage=e=>{try{if(e.data.cmd==="load"){Module["wasmModule"]=e.data.wasmModule;for(const handler of e.data.handlers){Module[handler]=function(){postMessage({cmd:"callHandler",handler:handler,args:[...arguments]})}}Module["wasmMemory"]=e.data.wasmMemory;Module["buffer"]=Module["wasmMemory"].buffer;Module["ENVIRONMENT_IS_PTHREAD"]=true;if(typeof e.data.urlOrBlob=="string"){importScripts(e.data.urlOrBlob)}else{var objectUrl=URL.createObjectURL(e.data.urlOrBlob);importScripts(objectUrl);URL.revokeObjectURL(objectUrl)}createRSRModule(Module).then(function(instance){Module=instance})}else if(e.data.cmd==="run"){Module["__performance_now_clock_drift"]=performance.now()-e.data.time;Module["__emscripten_thread_init"](e.data.pthread_ptr,0,0,1);assert(e.data.pthread_ptr);Module["establishStackSpace"]();Module["PThread"].receiveObjectTransfer(e.data);Module["PThread"].threadInitTLS();if(!initializedJS){Module["__embind_initialize_bindings"]();pendingNotifiedProxyingQueues.forEach(queue=>{Module["executeNotifiedProxyingQueue"](queue)});pendingNotifiedProxyingQueues=[];initializedJS=true}try{Module["invokeEntryPoint"](e.data.start_routine,e.data.arg)}catch(ex){if(ex!="unwind"){if(ex instanceof Module["ExitStatus"]){if(Module["keepRuntimeAlive"]()){err("Pthread 0x"+Module["_pthread_self"]().toString(16)+" called exit(), staying alive due to noExitRuntime.")}else{err("Pthread 0x"+Module["_pthread_self"]().toString(16)+" called exit(), calling _emscripten_thread_exit.");Module["__emscripten_thread_exit"](ex.status)}}else{throw ex}}else{err("Pthread 0x"+Module["_pthread_self"]().toString(16)+" completed its main entry point with an `unwind`, keeping the worker alive for asynchronous operation.")}}}else if(e.data.cmd==="cancel"){if(Module["_pthread_self"]()){Module["__emscripten_thread_exit"](-1)}}else if(e.data.target==="setimmediate"){}else if(e.data.cmd==="processProxyingQueue"){if(initializedJS){Module["executeNotifiedProxyingQueue"](e.data.queue)}else{pendingNotifiedProxyingQueues.push(e.data.queue)}}else if(e.data.cmd){err("worker.js received unknown command "+e.data.cmd);err(e.data)}}catch(ex){err("worker.js onmessage() captured an uncaught exception: "+ex);if(ex&&ex.stack)err(ex.stack);if(Module["__emscripten_thread_crashed"]){Module["__emscripten_thread_crashed"]()}throw ex}};
@@ -0,0 +1,59 @@
1
+ var CCP4Module;
2
+
3
+ importScripts('web_example.js');
4
+
5
+ createCCP4Module({print(t){postMessage(["output",t])},printErr(t){postMessage(["output",t]);}})
6
+ .then(function(CCP4Mod) {
7
+ CCP4Module = CCP4Mod;
8
+ })
9
+ .catch((e) => {
10
+ console.log("CCP4 problem :(");
11
+ console.log(e);
12
+ });
13
+
14
+ onmessage = function(e) {
15
+ var arrayBuffer = e.data[0];
16
+ const byteArray = new Uint8Array(arrayBuffer);
17
+ var selectedFileName = e.data[1];
18
+
19
+ let f_col = "FC";
20
+ let phi_col = "PHIC";
21
+ if(e.data[2]!==undefined && e.data[3]!==undefined){
22
+ f_col = e.data[2];
23
+ phi_col = e.data[3];
24
+ }
25
+
26
+ try {
27
+ CCP4Module.FS_createDataFile(".", selectedFileName, byteArray, true, true);
28
+ } catch(e) {
29
+ }
30
+
31
+ //FIXME - This is not used. It is intended to allow auto-open mtz
32
+ const header_info = CCP4Module.get_mtz_columns(selectedFileName);
33
+ console.log(header_info);
34
+ for(let ih=0;ih<header_info.size();ih+=2){
35
+ console.log(header_info.get(ih),header_info.get(ih+1));
36
+ }
37
+
38
+ console.log("Send",selectedFileName,"to clipper");
39
+ var result = CCP4Module.clipper_example_with_cols(selectedFileName,f_col,phi_col,2.0);
40
+ console.log("In the worker...");
41
+ console.log(result);
42
+ console.log(result.cell());
43
+ console.log(result.cell().a());
44
+ console.log(result.cell().b());
45
+ console.log(result.cell().c());
46
+ console.log(result.cell().alpha());
47
+ console.log(result.cell().beta());
48
+ console.log(result.cell().gamma());
49
+ CCP4Module.printMapStats(result);
50
+ var fout = new CCP4Module.CCP4MAPfile();
51
+ var outpath = new CCP4Module.Clipper_String("mapout.map");
52
+ fout.open_write(outpath);
53
+ CCP4Module.exportXMapToMapFile(fout,result);
54
+ fout.close_write();
55
+ console.log("Written",CCP4Module.clipperStringToString(outpath));
56
+ var mapasstr = CCP4Module.FS.readFile(CCP4Module.clipperStringToString(outpath));
57
+ postMessage(["result",mapasstr,selectedFileName,byteArray]);
58
+
59
+ }
@@ -0,0 +1,45 @@
1
+ var CCP4Module;
2
+
3
+ importScripts('web_example.js');
4
+
5
+ createCCP4Module({print(t){postMessage(["output",t])},printErr(t){postMessage(["output",t]);}})
6
+ .then(function(CCP4Mod) {
7
+ CCP4Module = CCP4Mod;
8
+ })
9
+ .catch((e) => {
10
+ console.log("CCP4 problem :(");
11
+ console.log(e);
12
+ });
13
+
14
+ onmessage = function(e) {
15
+ var byteCharacters = atob(e.data[0]);
16
+ var selectedFileName = e.data[1];
17
+
18
+ const byteNumbers = new Array(byteCharacters.length);
19
+ for (let i = 0; i < byteCharacters.length; i++) {
20
+ byteNumbers[i] = byteCharacters.charCodeAt(i);
21
+ }
22
+ const byteArray = new Uint8Array(byteNumbers);
23
+
24
+ try {
25
+ CCP4Module.FS_createDataFile(".", selectedFileName, byteArray, true, true);
26
+ } catch(e) {
27
+ }
28
+
29
+ console.log("Send",selectedFileName,"to clipper");
30
+ var result = CCP4Module.clipper_example(selectedFileName);
31
+ console.log("In the worker...");
32
+ console.log(result);
33
+ console.log(result.cell());
34
+ console.log(result.cell().a());
35
+ CCP4Module.printMapStats(result);
36
+ var fout = new CCP4Module.CCP4MAPfile();
37
+ var outpath = new CCP4Module.Clipper_String("mapout.map");
38
+ fout.open_write(outpath);
39
+ CCP4Module.exportXMapToMapFile(fout,result);
40
+ fout.close_write();
41
+ console.log("Written",CCP4Module.clipperStringToString(outpath));
42
+ var mapasstr = CCP4Module.FS.readFile(CCP4Module.clipperStringToString(outpath));
43
+ postMessage(["result",mapasstr]);
44
+
45
+ }
@@ -0,0 +1,103 @@
1
+ var CCP4Module;
2
+
3
+ importScripts('web_example.js');
4
+ importScripts('papaparse.min.js');
5
+
6
+ createCCP4Module({print(t){postMessage(["output",t])},printErr(t){postMessage(["output",t]);}})
7
+ .then(function(CCP4Mod) {
8
+ CCP4Module = CCP4Mod;
9
+ })
10
+ .catch((e) => {
11
+ console.log("CCP4 problem :(");
12
+ console.log(e);
13
+ });
14
+
15
+ onmessage = function(e) {
16
+
17
+ var args = new CCP4Module.VectorString();
18
+
19
+ try {
20
+ CCP4Module.FS_createDataFile(".", e.data[1], e.data[0], true, true);
21
+ } catch(e) {
22
+ //This happens when we supply sme file name on subsequent calls to this function?:w
23
+ }
24
+
25
+ var nma = CCP4Module.calculate_normal_modes(e.data[1],1);
26
+
27
+ const bvalc = nma.GetBValues();
28
+ const nbval = bvalc.size();
29
+
30
+ let bvals = [];
31
+ let bvals_exptl = [];
32
+
33
+ const bval_exptl = CCP4Module.get_CA_bvalues_from_file(e.data[1]);
34
+ let norm;
35
+ if(nbval>0){
36
+ norm = 0.0;
37
+ for(let i=0;i<nbval;i++){
38
+ const theo_bval = bvalc.get(i);
39
+ const expr_bval = bval_exptl.get(i);
40
+ norm += theo_bval/expr_bval;
41
+ }
42
+ norm /= nbval;
43
+ norm = 1/norm;
44
+ }else{
45
+ norm = 1.0;
46
+ }
47
+
48
+ const norm_matrix = CCP4Module.GetCorrelations(nma,norm);
49
+
50
+ //FIXME - (possible) x should be sequence number?
51
+ for(let i=0;i<nbval;i++){
52
+ bvals.push({x:i+1,y:bvalc.get(i)*norm});
53
+ bvals_exptl.push({x:i+1,y:bval_exptl.get(i)});
54
+ }
55
+
56
+ const nrows = norm_matrix.get_rows();
57
+ const ncols = norm_matrix.get_columns();
58
+ let corrMat = {x:[],y:[],z:[]};
59
+ for(let i=0;i<nrows;i++){
60
+ for(let j=0;j<ncols;j++){
61
+ corrMat.x.push(i);
62
+ corrMat.y.push(j);
63
+ corrMat.z.push(norm_matrix.get(i,j));
64
+ }
65
+ }
66
+
67
+ let result = 0;
68
+
69
+ postMessage(["corrMat",corrMat]);
70
+ postMessage(["bvalues",[bvals,bvals_exptl]]);
71
+ postMessage(["result",result]);
72
+
73
+ let nma_anm = CCP4Module.calculate_normal_modes(e.data[1],0);
74
+ const eigens = CCP4Module.GetEigen(nma_anm);
75
+ const evalMat = eigens.get(1);
76
+ const nrows_e = evalMat.get_rows();
77
+ const ncols_e = evalMat.get_columns();
78
+ postMessage(["output","Normal modes"]);
79
+ let energies = [];
80
+
81
+ for(let i=6;i<nrows_e;i++){
82
+ energies.push(evalMat.get(i,0));
83
+ }
84
+
85
+ postMessage(["energies",energies]);
86
+ const displacements = CCP4Module.GetDisplacements(nma_anm);
87
+ const nModes = displacements.nModes();
88
+ const nSteps = displacements.nSteps();
89
+
90
+ let dispMessage = {modes:[]};
91
+ for(let imode=0;imode<nModes;imode++){
92
+ dispMessage.modes.push({steps:[]});
93
+ for(let istep=0;istep<nSteps;istep++){
94
+ dispMessage.modes[imode].steps.push({xyz:[]});
95
+ const disp = displacements.getDisplacements(imode,istep);
96
+ const dispSize = disp.size();
97
+ for(let idisp=0;idisp<dispSize;idisp++){
98
+ dispMessage.modes[imode].steps[istep].xyz.push(disp.get(idisp));
99
+ }
100
+ }
101
+ }
102
+ postMessage(["displacements",dispMessage]);
103
+ }
@@ -0,0 +1,7 @@
1
+ /* @license
2
+ Papa Parse
3
+ v5.3.2
4
+ https://github.com/mholt/PapaParse
5
+ License: MIT
6
+ */
7
+ !function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&"undefined"!=typeof exports?module.exports=t():e.Papa=t()}(this,function s(){"use strict";var f="undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==f?f:{};var n=!f.document&&!!f.postMessage,o=n&&/blob:/i.test((f.location||{}).protocol),a={},h=0,b={parse:function(e,t){var i=(t=t||{}).dynamicTyping||!1;M(i)&&(t.dynamicTypingFunction=i,i={});if(t.dynamicTyping=i,t.transform=!!M(t.transform)&&t.transform,t.worker&&b.WORKERS_SUPPORTED){var r=function(){if(!b.WORKERS_SUPPORTED)return!1;var e=(i=f.URL||f.webkitURL||null,r=s.toString(),b.BLOB_URL||(b.BLOB_URL=i.createObjectURL(new Blob(["(",r,")();"],{type:"text/javascript"})))),t=new f.Worker(e);var i,r;return t.onmessage=_,t.id=h++,a[t.id]=t}();return r.userStep=t.step,r.userChunk=t.chunk,r.userComplete=t.complete,r.userError=t.error,t.step=M(t.step),t.chunk=M(t.chunk),t.complete=M(t.complete),t.error=M(t.error),delete t.worker,void r.postMessage({input:e,config:t,workerId:r.id})}var n=null;b.NODE_STREAM_INPUT,"string"==typeof e?n=t.download?new l(t):new p(t):!0===e.readable&&M(e.read)&&M(e.on)?n=new g(t):(f.File&&e instanceof File||e instanceof Object)&&(n=new c(t));return n.stream(e)},unparse:function(e,t){var n=!1,_=!0,m=",",y="\r\n",s='"',a=s+s,i=!1,r=null,o=!1;!function(){if("object"!=typeof t)return;"string"!=typeof t.delimiter||b.BAD_DELIMITERS.filter(function(e){return-1!==t.delimiter.indexOf(e)}).length||(m=t.delimiter);("boolean"==typeof t.quotes||"function"==typeof t.quotes||Array.isArray(t.quotes))&&(n=t.quotes);"boolean"!=typeof t.skipEmptyLines&&"string"!=typeof t.skipEmptyLines||(i=t.skipEmptyLines);"string"==typeof t.newline&&(y=t.newline);"string"==typeof t.quoteChar&&(s=t.quoteChar);"boolean"==typeof t.header&&(_=t.header);if(Array.isArray(t.columns)){if(0===t.columns.length)throw new Error("Option columns is empty");r=t.columns}void 0!==t.escapeChar&&(a=t.escapeChar+s);("boolean"==typeof t.escapeFormulae||t.escapeFormulae instanceof RegExp)&&(o=t.escapeFormulae instanceof RegExp?t.escapeFormulae:/^[=+\-@\t\r].*$/)}();var h=new RegExp(j(s),"g");"string"==typeof e&&(e=JSON.parse(e));if(Array.isArray(e)){if(!e.length||Array.isArray(e[0]))return u(null,e,i);if("object"==typeof e[0])return u(r||Object.keys(e[0]),e,i)}else if("object"==typeof e)return"string"==typeof e.data&&(e.data=JSON.parse(e.data)),Array.isArray(e.data)&&(e.fields||(e.fields=e.meta&&e.meta.fields||r),e.fields||(e.fields=Array.isArray(e.data[0])?e.fields:"object"==typeof e.data[0]?Object.keys(e.data[0]):[]),Array.isArray(e.data[0])||"object"==typeof e.data[0]||(e.data=[e.data])),u(e.fields||[],e.data||[],i);throw new Error("Unable to serialize unrecognized input");function u(e,t,i){var r="";"string"==typeof e&&(e=JSON.parse(e)),"string"==typeof t&&(t=JSON.parse(t));var n=Array.isArray(e)&&0<e.length,s=!Array.isArray(t[0]);if(n&&_){for(var a=0;a<e.length;a++)0<a&&(r+=m),r+=v(e[a],a);0<t.length&&(r+=y)}for(var o=0;o<t.length;o++){var h=n?e.length:t[o].length,u=!1,f=n?0===Object.keys(t[o]).length:0===t[o].length;if(i&&!n&&(u="greedy"===i?""===t[o].join("").trim():1===t[o].length&&0===t[o][0].length),"greedy"===i&&n){for(var d=[],l=0;l<h;l++){var c=s?e[l]:l;d.push(t[o][c])}u=""===d.join("").trim()}if(!u){for(var p=0;p<h;p++){0<p&&!f&&(r+=m);var g=n&&s?e[p]:p;r+=v(t[o][g],p)}o<t.length-1&&(!i||0<h&&!f)&&(r+=y)}}return r}function v(e,t){if(null==e)return"";if(e.constructor===Date)return JSON.stringify(e).slice(1,25);var i=!1;o&&"string"==typeof e&&o.test(e)&&(e="'"+e,i=!0);var r=e.toString().replace(h,a);return(i=i||!0===n||"function"==typeof n&&n(e,t)||Array.isArray(n)&&n[t]||function(e,t){for(var i=0;i<t.length;i++)if(-1<e.indexOf(t[i]))return!0;return!1}(r,b.BAD_DELIMITERS)||-1<r.indexOf(m)||" "===r.charAt(0)||" "===r.charAt(r.length-1))?s+r+s:r}}};if(b.RECORD_SEP=String.fromCharCode(30),b.UNIT_SEP=String.fromCharCode(31),b.BYTE_ORDER_MARK="\ufeff",b.BAD_DELIMITERS=["\r","\n",'"',b.BYTE_ORDER_MARK],b.WORKERS_SUPPORTED=!n&&!!f.Worker,b.NODE_STREAM_INPUT=1,b.LocalChunkSize=10485760,b.RemoteChunkSize=5242880,b.DefaultDelimiter=",",b.Parser=E,b.ParserHandle=i,b.NetworkStreamer=l,b.FileStreamer=c,b.StringStreamer=p,b.ReadableStreamStreamer=g,f.jQuery){var d=f.jQuery;d.fn.parse=function(o){var i=o.config||{},h=[];return this.each(function(e){if(!("INPUT"===d(this).prop("tagName").toUpperCase()&&"file"===d(this).attr("type").toLowerCase()&&f.FileReader)||!this.files||0===this.files.length)return!0;for(var t=0;t<this.files.length;t++)h.push({file:this.files[t],inputElem:this,instanceConfig:d.extend({},i)})}),e(),this;function e(){if(0!==h.length){var e,t,i,r,n=h[0];if(M(o.before)){var s=o.before(n.file,n.inputElem);if("object"==typeof s){if("abort"===s.action)return e="AbortError",t=n.file,i=n.inputElem,r=s.reason,void(M(o.error)&&o.error({name:e},t,i,r));if("skip"===s.action)return void u();"object"==typeof s.config&&(n.instanceConfig=d.extend(n.instanceConfig,s.config))}else if("skip"===s)return void u()}var a=n.instanceConfig.complete;n.instanceConfig.complete=function(e){M(a)&&a(e,n.file,n.inputElem),u()},b.parse(n.file,n.instanceConfig)}else M(o.complete)&&o.complete()}function u(){h.splice(0,1),e()}}}function u(e){this._handle=null,this._finished=!1,this._completed=!1,this._halted=!1,this._input=null,this._baseIndex=0,this._partialLine="",this._rowCount=0,this._start=0,this._nextChunk=null,this.isFirstChunk=!0,this._completeResults={data:[],errors:[],meta:{}},function(e){var t=w(e);t.chunkSize=parseInt(t.chunkSize),e.step||e.chunk||(t.chunkSize=null);this._handle=new i(t),(this._handle.streamer=this)._config=t}.call(this,e),this.parseChunk=function(e,t){if(this.isFirstChunk&&M(this._config.beforeFirstChunk)){var i=this._config.beforeFirstChunk(e);void 0!==i&&(e=i)}this.isFirstChunk=!1,this._halted=!1;var r=this._partialLine+e;this._partialLine="";var n=this._handle.parse(r,this._baseIndex,!this._finished);if(!this._handle.paused()&&!this._handle.aborted()){var s=n.meta.cursor;this._finished||(this._partialLine=r.substring(s-this._baseIndex),this._baseIndex=s),n&&n.data&&(this._rowCount+=n.data.length);var a=this._finished||this._config.preview&&this._rowCount>=this._config.preview;if(o)f.postMessage({results:n,workerId:b.WORKER_ID,finished:a});else if(M(this._config.chunk)&&!t){if(this._config.chunk(n,this._handle),this._handle.paused()||this._handle.aborted())return void(this._halted=!0);n=void 0,this._completeResults=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(n.data),this._completeResults.errors=this._completeResults.errors.concat(n.errors),this._completeResults.meta=n.meta),this._completed||!a||!M(this._config.complete)||n&&n.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),a||n&&n.meta.paused||this._nextChunk(),n}this._halted=!0},this._sendError=function(e){M(this._config.error)?this._config.error(e):o&&this._config.error&&f.postMessage({workerId:b.WORKER_ID,error:e,finished:!1})}}function l(e){var r;(e=e||{}).chunkSize||(e.chunkSize=b.RemoteChunkSize),u.call(this,e),this._nextChunk=n?function(){this._readChunk(),this._chunkLoaded()}:function(){this._readChunk()},this.stream=function(e){this._input=e,this._nextChunk()},this._readChunk=function(){if(this._finished)this._chunkLoaded();else{if(r=new XMLHttpRequest,this._config.withCredentials&&(r.withCredentials=this._config.withCredentials),n||(r.onload=v(this._chunkLoaded,this),r.onerror=v(this._chunkError,this)),r.open(this._config.downloadRequestBody?"POST":"GET",this._input,!n),this._config.downloadRequestHeaders){var e=this._config.downloadRequestHeaders;for(var t in e)r.setRequestHeader(t,e[t])}if(this._config.chunkSize){var i=this._start+this._config.chunkSize-1;r.setRequestHeader("Range","bytes="+this._start+"-"+i)}try{r.send(this._config.downloadRequestBody)}catch(e){this._chunkError(e.message)}n&&0===r.status&&this._chunkError()}},this._chunkLoaded=function(){4===r.readyState&&(r.status<200||400<=r.status?this._chunkError():(this._start+=this._config.chunkSize?this._config.chunkSize:r.responseText.length,this._finished=!this._config.chunkSize||this._start>=function(e){var t=e.getResponseHeader("Content-Range");if(null===t)return-1;return parseInt(t.substring(t.lastIndexOf("/")+1))}(r),this.parseChunk(r.responseText)))},this._chunkError=function(e){var t=r.statusText||e;this._sendError(new Error(t))}}function c(e){var r,n;(e=e||{}).chunkSize||(e.chunkSize=b.LocalChunkSize),u.call(this,e);var s="undefined"!=typeof FileReader;this.stream=function(e){this._input=e,n=e.slice||e.webkitSlice||e.mozSlice,s?((r=new FileReader).onload=v(this._chunkLoaded,this),r.onerror=v(this._chunkError,this)):r=new FileReaderSync,this._nextChunk()},this._nextChunk=function(){this._finished||this._config.preview&&!(this._rowCount<this._config.preview)||this._readChunk()},this._readChunk=function(){var e=this._input;if(this._config.chunkSize){var t=Math.min(this._start+this._config.chunkSize,this._input.size);e=n.call(e,this._start,t)}var i=r.readAsText(e,this._config.encoding);s||this._chunkLoaded({target:{result:i}})},this._chunkLoaded=function(e){this._start+=this._config.chunkSize,this._finished=!this._config.chunkSize||this._start>=this._input.size,this.parseChunk(e.target.result)},this._chunkError=function(){this._sendError(r.error)}}function p(e){var i;u.call(this,e=e||{}),this.stream=function(e){return i=e,this._nextChunk()},this._nextChunk=function(){if(!this._finished){var e,t=this._config.chunkSize;return t?(e=i.substring(0,t),i=i.substring(t)):(e=i,i=""),this._finished=!i,this.parseChunk(e)}}}function g(e){u.call(this,e=e||{});var t=[],i=!0,r=!1;this.pause=function(){u.prototype.pause.apply(this,arguments),this._input.pause()},this.resume=function(){u.prototype.resume.apply(this,arguments),this._input.resume()},this.stream=function(e){this._input=e,this._input.on("data",this._streamData),this._input.on("end",this._streamEnd),this._input.on("error",this._streamError)},this._checkIsFinished=function(){r&&1===t.length&&(this._finished=!0)},this._nextChunk=function(){this._checkIsFinished(),t.length?this.parseChunk(t.shift()):i=!0},this._streamData=v(function(e){try{t.push("string"==typeof e?e:e.toString(this._config.encoding)),i&&(i=!1,this._checkIsFinished(),this.parseChunk(t.shift()))}catch(e){this._streamError(e)}},this),this._streamError=v(function(e){this._streamCleanUp(),this._sendError(e)},this),this._streamEnd=v(function(){this._streamCleanUp(),r=!0,this._streamData("")},this),this._streamCleanUp=v(function(){this._input.removeListener("data",this._streamData),this._input.removeListener("end",this._streamEnd),this._input.removeListener("error",this._streamError)},this)}function i(m){var a,o,h,r=Math.pow(2,53),n=-r,s=/^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/,u=/^(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))$/,t=this,i=0,f=0,d=!1,e=!1,l=[],c={data:[],errors:[],meta:{}};if(M(m.step)){var p=m.step;m.step=function(e){if(c=e,_())g();else{if(g(),0===c.data.length)return;i+=e.data.length,m.preview&&i>m.preview?o.abort():(c.data=c.data[0],p(c,t))}}}function y(e){return"greedy"===m.skipEmptyLines?""===e.join("").trim():1===e.length&&0===e[0].length}function g(){return c&&h&&(k("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+b.DefaultDelimiter+"'"),h=!1),m.skipEmptyLines&&(c.data=c.data.filter(function(e){return!y(e)})),_()&&function(){if(!c)return;function e(e,t){M(m.transformHeader)&&(e=m.transformHeader(e,t)),l.push(e)}if(Array.isArray(c.data[0])){for(var t=0;_()&&t<c.data.length;t++)c.data[t].forEach(e);c.data.splice(0,1)}else c.data.forEach(e)}(),function(){if(!c||!m.header&&!m.dynamicTyping&&!m.transform)return c;function e(e,t){var i,r=m.header?{}:[];for(i=0;i<e.length;i++){var n=i,s=e[i];m.header&&(n=i>=l.length?"__parsed_extra":l[i]),m.transform&&(s=m.transform(s,n)),s=v(n,s),"__parsed_extra"===n?(r[n]=r[n]||[],r[n].push(s)):r[n]=s}return m.header&&(i>l.length?k("FieldMismatch","TooManyFields","Too many fields: expected "+l.length+" fields but parsed "+i,f+t):i<l.length&&k("FieldMismatch","TooFewFields","Too few fields: expected "+l.length+" fields but parsed "+i,f+t)),r}var t=1;!c.data.length||Array.isArray(c.data[0])?(c.data=c.data.map(e),t=c.data.length):c.data=e(c.data,0);m.header&&c.meta&&(c.meta.fields=l);return f+=t,c}()}function _(){return m.header&&0===l.length}function v(e,t){return i=e,m.dynamicTypingFunction&&void 0===m.dynamicTyping[i]&&(m.dynamicTyping[i]=m.dynamicTypingFunction(i)),!0===(m.dynamicTyping[i]||m.dynamicTyping)?"true"===t||"TRUE"===t||"false"!==t&&"FALSE"!==t&&(function(e){if(s.test(e)){var t=parseFloat(e);if(n<t&&t<r)return!0}return!1}(t)?parseFloat(t):u.test(t)?new Date(t):""===t?null:t):t;var i}function k(e,t,i,r){var n={type:e,code:t,message:i};void 0!==r&&(n.row=r),c.errors.push(n)}this.parse=function(e,t,i){var r=m.quoteChar||'"';if(m.newline||(m.newline=function(e,t){e=e.substring(0,1048576);var i=new RegExp(j(t)+"([^]*?)"+j(t),"gm"),r=(e=e.replace(i,"")).split("\r"),n=e.split("\n"),s=1<n.length&&n[0].length<r[0].length;if(1===r.length||s)return"\n";for(var a=0,o=0;o<r.length;o++)"\n"===r[o][0]&&a++;return a>=r.length/2?"\r\n":"\r"}(e,r)),h=!1,m.delimiter)M(m.delimiter)&&(m.delimiter=m.delimiter(e),c.meta.delimiter=m.delimiter);else{var n=function(e,t,i,r,n){var s,a,o,h;n=n||[",","\t","|",";",b.RECORD_SEP,b.UNIT_SEP];for(var u=0;u<n.length;u++){var f=n[u],d=0,l=0,c=0;o=void 0;for(var p=new E({comments:r,delimiter:f,newline:t,preview:10}).parse(e),g=0;g<p.data.length;g++)if(i&&y(p.data[g]))c++;else{var _=p.data[g].length;l+=_,void 0!==o?0<_&&(d+=Math.abs(_-o),o=_):o=_}0<p.data.length&&(l/=p.data.length-c),(void 0===a||d<=a)&&(void 0===h||h<l)&&1.99<l&&(a=d,s=f,h=l)}return{successful:!!(m.delimiter=s),bestDelimiter:s}}(e,m.newline,m.skipEmptyLines,m.comments,m.delimitersToGuess);n.successful?m.delimiter=n.bestDelimiter:(h=!0,m.delimiter=b.DefaultDelimiter),c.meta.delimiter=m.delimiter}var s=w(m);return m.preview&&m.header&&s.preview++,a=e,o=new E(s),c=o.parse(a,t,i),g(),d?{meta:{paused:!0}}:c||{meta:{paused:!1}}},this.paused=function(){return d},this.pause=function(){d=!0,o.abort(),a=M(m.chunk)?"":a.substring(o.getCharIndex())},this.resume=function(){t.streamer._halted?(d=!1,t.streamer.parseChunk(a,!0)):setTimeout(t.resume,3)},this.aborted=function(){return e},this.abort=function(){e=!0,o.abort(),c.meta.aborted=!0,M(m.complete)&&m.complete(c),a=""}}function j(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function E(e){var S,O=(e=e||{}).delimiter,x=e.newline,I=e.comments,T=e.step,D=e.preview,A=e.fastMode,L=S=void 0===e.quoteChar||null===e.quoteChar?'"':e.quoteChar;if(void 0!==e.escapeChar&&(L=e.escapeChar),("string"!=typeof O||-1<b.BAD_DELIMITERS.indexOf(O))&&(O=","),I===O)throw new Error("Comment character same as delimiter");!0===I?I="#":("string"!=typeof I||-1<b.BAD_DELIMITERS.indexOf(I))&&(I=!1),"\n"!==x&&"\r"!==x&&"\r\n"!==x&&(x="\n");var F=0,z=!1;this.parse=function(r,t,i){if("string"!=typeof r)throw new Error("Input must be a string");var n=r.length,e=O.length,s=x.length,a=I.length,o=M(T),h=[],u=[],f=[],d=F=0;if(!r)return C();if(A||!1!==A&&-1===r.indexOf(S)){for(var l=r.split(x),c=0;c<l.length;c++){if(f=l[c],F+=f.length,c!==l.length-1)F+=x.length;else if(i)return C();if(!I||f.substring(0,a)!==I){if(o){if(h=[],k(f.split(O)),R(),z)return C()}else k(f.split(O));if(D&&D<=c)return h=h.slice(0,D),C(!0)}}return C()}for(var p=r.indexOf(O,F),g=r.indexOf(x,F),_=new RegExp(j(L)+j(S),"g"),m=r.indexOf(S,F);;)if(r[F]!==S)if(I&&0===f.length&&r.substring(F,F+a)===I){if(-1===g)return C();F=g+s,g=r.indexOf(x,F),p=r.indexOf(O,F)}else if(-1!==p&&(p<g||-1===g))f.push(r.substring(F,p)),F=p+e,p=r.indexOf(O,F);else{if(-1===g)break;if(f.push(r.substring(F,g)),w(g+s),o&&(R(),z))return C();if(D&&h.length>=D)return C(!0)}else for(m=F,F++;;){if(-1===(m=r.indexOf(S,m+1)))return i||u.push({type:"Quotes",code:"MissingQuotes",message:"Quoted field unterminated",row:h.length,index:F}),E();if(m===n-1)return E(r.substring(F,m).replace(_,S));if(S!==L||r[m+1]!==L){if(S===L||0===m||r[m-1]!==L){-1!==p&&p<m+1&&(p=r.indexOf(O,m+1)),-1!==g&&g<m+1&&(g=r.indexOf(x,m+1));var y=b(-1===g?p:Math.min(p,g));if(r.substr(m+1+y,e)===O){f.push(r.substring(F,m).replace(_,S)),r[F=m+1+y+e]!==S&&(m=r.indexOf(S,F)),p=r.indexOf(O,F),g=r.indexOf(x,F);break}var v=b(g);if(r.substring(m+1+v,m+1+v+s)===x){if(f.push(r.substring(F,m).replace(_,S)),w(m+1+v+s),p=r.indexOf(O,F),m=r.indexOf(S,F),o&&(R(),z))return C();if(D&&h.length>=D)return C(!0);break}u.push({type:"Quotes",code:"InvalidQuotes",message:"Trailing quote on quoted field is malformed",row:h.length,index:F}),m++}}else m++}return E();function k(e){h.push(e),d=F}function b(e){var t=0;if(-1!==e){var i=r.substring(m+1,e);i&&""===i.trim()&&(t=i.length)}return t}function E(e){return i||(void 0===e&&(e=r.substring(F)),f.push(e),F=n,k(f),o&&R()),C()}function w(e){F=e,k(f),f=[],g=r.indexOf(x,F)}function C(e){return{data:h,errors:u,meta:{delimiter:O,linebreak:x,aborted:z,truncated:!!e,cursor:d+(t||0)}}}function R(){T(C()),h=[],u=[]}},this.abort=function(){z=!0},this.getCharIndex=function(){return F}}function _(e){var t=e.data,i=a[t.workerId],r=!1;if(t.error)i.userError(t.error,t.file);else if(t.results&&t.results.data){var n={abort:function(){r=!0,m(t.workerId,{data:[],errors:[],meta:{aborted:!0}})},pause:y,resume:y};if(M(i.userStep)){for(var s=0;s<t.results.data.length&&(i.userStep({data:t.results.data[s],errors:t.results.errors,meta:t.results.meta},n),!r);s++);delete t.results}else M(i.userChunk)&&(i.userChunk(t.results,n,t.file),delete t.results)}t.finished&&!r&&m(t.workerId,t.results)}function m(e,t){var i=a[e];M(i.userComplete)&&i.userComplete(t),i.terminate(),delete a[e]}function y(){throw new Error("Not implemented.")}function w(e){if("object"!=typeof e||null===e)return e;var t=Array.isArray(e)?[]:{};for(var i in e)t[i]=w(e[i]);return t}function v(e,t){return function(){e.apply(t,arguments)}}function M(e){return"function"==typeof e}return o&&(f.onmessage=function(e){var t=e.data;void 0===b.WORKER_ID&&t&&(b.WORKER_ID=t.workerId);if("string"==typeof t.input)f.postMessage({workerId:b.WORKER_ID,results:b.parse(t.input,t.config),finished:!0});else if(f.File&&t.input instanceof File||t.input instanceof Object){var i=b.parse(t.input,t.config);i&&f.postMessage({workerId:b.WORKER_ID,results:i,finished:!0})}}),(l.prototype=Object.create(u.prototype)).constructor=l,(c.prototype=Object.create(u.prototype)).constructor=c,(p.prototype=Object.create(p.prototype)).constructor=p,(g.prototype=Object.create(u.prototype)).constructor=g,b});
@@ -0,0 +1,282 @@
1
+ var CCP4Module;
2
+ var RDKit;
3
+
4
+ importScripts('web_example.js','RDKit_minimal.js');
5
+
6
+ createCCP4Module({print(t){postMessage(["output",t])},printErr(t){postMessage(["output",t]);}})
7
+ .then(function(CCP4Mod) {
8
+ CCP4Module = CCP4Mod;
9
+ })
10
+ .catch((e) => {
11
+ console.log("CCP4 problem :(");
12
+ console.log(e);
13
+ });
14
+
15
+ initRDKitModule({print(t){postMessage(["output",t])},printErr(t){postMessage(["output",t]);}})
16
+ .then(function(RDKitMod) {
17
+ RDKit = RDKitMod;
18
+ })
19
+ .catch((e) => {
20
+ console.log("RDKit problem :(");
21
+ console.log(e);
22
+ });
23
+
24
+ function makeRequest (method, url) {
25
+ return new Promise(function (resolve, reject) {
26
+ var xhr = new XMLHttpRequest();
27
+ xhr.open(method, url, true);
28
+ xhr.onload = function () {
29
+ if (this.status >= 200 && this.status < 300) {
30
+ resolve(xhr.response);
31
+ } else {
32
+ reject({
33
+ status: this.status,
34
+ statusText: xhr.statusText
35
+ });
36
+ }
37
+ };
38
+ xhr.onerror = function () {
39
+ reject({
40
+ status: this.status,
41
+ statusText: xhr.statusText
42
+ });
43
+ };
44
+ xhr.send();
45
+ });
46
+ }
47
+
48
+ function onlyUnique(value, index, self) {
49
+ return self.indexOf(value) === index;
50
+ }
51
+
52
+ function getLoop(lines,loopName_in){
53
+ let loopName = loopName_in+".";
54
+ let inWantedLoop = false;
55
+ let loopLines = [];
56
+ let len = lines.length;
57
+ for(let il=0;il<len;il++){
58
+ let l = lines[il].replace(/(^\s+|\s+$)/g,'');
59
+ if(l === "loop_"||(l.substring(0,1)==="_"&&l.substring(0,loopName.length)!==loopName)){
60
+ if(inWantedLoop){
61
+ break;
62
+ }else{
63
+ if(il<lines.length){
64
+ if(lines[il+1].substring(0,loopName.length) === loopName){
65
+ inWantedLoop = true;
66
+ }
67
+ }
68
+ }
69
+ }else{
70
+ if(inWantedLoop){
71
+ loopLines.push(l);
72
+ }
73
+ }
74
+ }
75
+ return loopLines;
76
+ }
77
+
78
+ function splitQuotedCIFString(stringToSplit){
79
+ if(stringToSplit.length===0) return [];
80
+ return stringToSplit.match(/(?:[^\s"]+|"[^"]*")+/g);
81
+ }
82
+
83
+ function addCIFAtomTypes(resname,cif) {
84
+
85
+ let ener_lib_lines = cif.split("\n");
86
+ let libAtomTypes = [];
87
+ let libAtomLines = getLoop(ener_lib_lines,"_chem_comp_atom");
88
+ let atoms = [];
89
+ for(let il=0;il<libAtomLines.length;il++){
90
+ // We are only interested in atom_id and type_energy, so we do not worry about float and int types.
91
+ if(libAtomLines[il].substr(0,1)==="#"||libAtomLines[il].trim()===""){
92
+ continue;
93
+ } else if(libAtomLines[il].substr(0,1)==="_"){
94
+ libAtomTypes.push(libAtomLines[il]);
95
+ } else {
96
+ let split = splitQuotedCIFString(libAtomLines[il]);
97
+ if(split[0]!=="."){
98
+ let atom = {};
99
+ for(let iprop=0;iprop<split.length;iprop++){
100
+ atom[libAtomTypes[iprop]] = split[iprop];
101
+ }
102
+ atoms.push(atom);
103
+ }
104
+ }
105
+ }
106
+ return atoms;
107
+ }
108
+
109
+ function addCIFBondTypes(resname,cif) {
110
+ let ener_lib_lines = cif.split("\n");
111
+ let libAtomTypes = [];
112
+ let libAtomLines = getLoop(ener_lib_lines,"_chem_comp_bond");
113
+ let bonds = [];
114
+ for(let il=0;il<libAtomLines.length;il++){
115
+ // We are only interested in bond_id, atom_id and type, so we do not worry about float and int types.
116
+ if(libAtomLines[il].substr(0,1)==="#"||libAtomLines[il].trim()===""){
117
+ continue;
118
+ } else if(libAtomLines[il].substr(0,1)==="_"){
119
+ libAtomTypes.push(libAtomLines[il]);
120
+ } else {
121
+ let split = libAtomLines[il].match(/(?:[^\s"]+|"[^"]*")+/g);
122
+ if(split[0]!=="."){
123
+ let bond = {};
124
+ for(let iprop=0;iprop<split.length;iprop++){
125
+ bond[libAtomTypes[iprop]] = split[iprop];
126
+ }
127
+ if(typeof(bond["_chem_comp_bond.type"])!=="undefined"&&bond["_chem_comp_bond.type"].length>0&&typeof(bond["_chem_comp_bond.comp_id"])!=="undefined"&&bond["_chem_comp_bond.comp_id"].length>0&&typeof(bond["_chem_comp_bond.atom_id_1"])!=="undefined"&&bond["_chem_comp_bond.atom_id_1"].length>0&&typeof(bond["_chem_comp_bond.atom_id_2"])!=="undefined"&&bond["_chem_comp_bond.atom_id_2"].length>0){
128
+ bonds.push(bond);
129
+ } else if(typeof(bond["_chem_comp_bond.value_order"])!=="undefined"&&bond["_chem_comp_bond.value_order"].length>0&&typeof(bond["_chem_comp_bond.comp_id"])!=="undefined"&&bond["_chem_comp_bond.comp_id"].length>0&&typeof(bond["_chem_comp_bond.atom_id_1"])!=="undefined"&&bond["_chem_comp_bond.atom_id_1"].length>0&&typeof(bond["_chem_comp_bond.atom_id_2"])!=="undefined"&&bond["_chem_comp_bond.atom_id_2"].length>0){
130
+ if(bond["_chem_comp_bond.pdbx_aromatic_flag"]==="Y"){
131
+ bond["_chem_comp_bond.type"] = "aromatic";
132
+ } else if(bond["_chem_comp_bond.value_order"]==="SING"||bond["_chem_comp_bond.value_order"]==="SINGLE"){
133
+ bond["_chem_comp_bond.type"] = "single";
134
+ } else if(bond["_chem_comp_bond.value_order"]==="DOUB"||bond["_chem_comp_bond.value_order"]==="DOUBLE"){
135
+ bond["_chem_comp_bond.type"] = "double";
136
+ } else if(bond["_chem_comp_bond.value_order"]==="TRIP"||bond["_chem_comp_bond.value_order"]==="TRIPLE"){
137
+ bond["_chem_comp_bond.type"] = "triple";
138
+ } else {
139
+ bond["_chem_comp_bond.type"] = "single";
140
+ }
141
+ bonds.push(bond);
142
+ }
143
+ }
144
+ }
145
+ }
146
+
147
+ return bonds;
148
+ }
149
+
150
+ function dictToMolBlock(name,dictLines){
151
+
152
+ let atoms = addCIFAtomTypes(name,dictLines);
153
+ let bonds = addCIFBondTypes(name,dictLines);
154
+
155
+ let nAtoms = atoms.length;
156
+ let nBonds = bonds.length;
157
+
158
+ let nAtomsString = (" " + nAtoms).slice(-3);
159
+ let nBondsString = (" " + nBonds).slice(-3);
160
+
161
+ let molblock = name+`
162
+ CCP4-MonomerLibrary-WebToCif
163
+
164
+ `
165
+
166
+ molblock += nAtomsString+nBondsString+" 0 0 0 0 0 0 0 0999 V2000\n"
167
+ let ncharged = 0;
168
+ let chargeStr = "";
169
+ for(let iat=0;iat<nAtoms;iat++){
170
+ let x = parseFloat(atoms[iat]["_chem_comp_atom.x"]);
171
+ let y = parseFloat(atoms[iat]["_chem_comp_atom.y"]);
172
+ let z = parseFloat(atoms[iat]["_chem_comp_atom.z"]);
173
+ if(atoms[iat]["_chem_comp_atom.charge"]!="."&&atoms[iat]["_chem_comp_atom.charge"]!="0"){
174
+ ncharged++;
175
+ chargeStr += (" "+(iat+1)).slice(-4)+(" "+atoms[iat]["_chem_comp_atom.charge"]).slice(-4);
176
+ }
177
+ let symbol = atoms[iat]["_chem_comp_atom.type_symbol"];
178
+ let xString = (" "+x.toFixed(4)).slice(-10)
179
+ let yString = (" "+y.toFixed(4)).slice(-10)
180
+ let zString = (" "+z.toFixed(4)).slice(-10)
181
+ let symbolString = (" "+symbol).slice(-3);
182
+ molblock += xString+yString+zString+symbolString+" 0 0 0 0 0 0 0 0 0 0 0 0\n";
183
+ }
184
+
185
+ for(let ib=0;ib<nBonds;ib++){
186
+ let atom1 = atoms.find(obj => {
187
+ return obj["_chem_comp_atom.atom_id"] === bonds[ib]["_chem_comp_bond.atom_id_1"]
188
+ })
189
+ let atom2 = atoms.find(obj => {
190
+ return obj["_chem_comp_atom.atom_id"] === bonds[ib]["_chem_comp_bond.atom_id_2"]
191
+ })
192
+ let idx1 = atoms.indexOf(atom1);
193
+ let idx2 = atoms.indexOf(atom2);
194
+ let atom1String = (" " + (idx1+1)).slice(-3);
195
+ let atom2String = (" " + (idx2+1)).slice(-3);
196
+ let bondType = 1;
197
+ //FIXME - I am not sure this is handled by RDKit.
198
+ if(["_chem_comp_bond.aromatic"] in bonds[ib] && (bonds[ib]["_chem_comp_bond.aromatic"]==='y_XXX'||bonds[ib]["_chem_comp_bond.aromatic"]==='Y_XXX')){
199
+ bondType = 4;
200
+ } else if(["_chem_comp_bond.type"] in bonds[ib] && (bonds[ib]["_chem_comp_bond.type"]==='TRIPLE'||bonds[ib]["_chem_comp_bond.type"]==='triple')) {
201
+ bondType = 3;
202
+ } else if(["_chem_comp_bond.type"] in bonds[ib] && (bonds[ib]["_chem_comp_bond.type"]==='DOUBLE'||bonds[ib]["_chem_comp_bond.type"]==='double')) {
203
+ bondType = 2;
204
+ } else if(["_chem_comp_bond.type"] in bonds[ib] && (bonds[ib]["_chem_comp_bond.type"]==='SINGLE'||bonds[ib]["_chem_comp_bond.type"]==='single')) {
205
+ bondType = 1;
206
+ } else {
207
+ console.log("Unknown bond type");
208
+ console.log(bonds[ib]);
209
+ }
210
+ let bondTypeString = (" " + (bondType)).slice(-2);
211
+
212
+ molblock += atom1String+atom2String+bondTypeString+" 0 0 0 0\n";
213
+ }
214
+
215
+ if(ncharged>0){
216
+ molblock += "M CHG"+((" "+ncharged).slice(-3))+chargeStr+"\n";
217
+ }
218
+ molblock += "M END";
219
+
220
+ return molblock;
221
+
222
+ }
223
+
224
+ onmessage = function(e) {
225
+ let contents = e.data[0];
226
+ let selectedFileName = e.data[1];
227
+
228
+ try {
229
+ CCP4Module.FS_createDataFile(".", selectedFileName, contents, true, true);
230
+ } catch(e) {
231
+ }
232
+
233
+ let svgTree = CCP4Module.get_annotated_glycans_hierarchical(selectedFileName,false,"undefined");
234
+ let glycanResult = {};
235
+ glycanResult[selectedFileName] = svgTree;
236
+ postMessage(["glycan_result",glycanResult]);
237
+
238
+ let result = CCP4Module.mmdb2_example(selectedFileName);
239
+ let resultJS = [];
240
+ for(let ir=0;ir<result.size();ir++){
241
+ resultJS.push(result.get(ir));
242
+ }
243
+
244
+ let unique = resultJS.filter(onlyUnique);
245
+
246
+ //let ligandServer = "http://192.168.1.242:8000/";
247
+ let ligandServer = "/monomers/";
248
+
249
+ let promises = [];
250
+
251
+ for(ilig=0;ilig<unique.length;ilig++){
252
+ let ligType = unique[ilig];
253
+ let theUrl = ligandServer+ligType.toLowerCase()[0]+"/"+ligType.toUpperCase()+".cif";
254
+ promises.push(makeRequest('GET',theUrl,true));
255
+ }
256
+
257
+ let svgResult = {};
258
+
259
+ if(promises.length>0){
260
+ Promise.all(promises).then((values) => {
261
+ for(ilig=0;ilig<values.length;ilig++){
262
+ let ligType = unique[ilig];
263
+ let ligandlines = values[ilig];
264
+ let molblock = dictToMolBlock(ligType,ligandlines);
265
+ let mol = RDKit.get_mol(molblock);
266
+ let mol2 = RDKit.get_mol(mol.remove_hs());
267
+ let smiles = mol2.get_smiles();
268
+ let mol3 = RDKit.get_mol(smiles);
269
+ svgResult[ligType] = mol3.get_svg();
270
+ }
271
+ postMessage(["result",svgResult]);
272
+ }).catch((error) => {
273
+ console.error(error);
274
+ for(ilig=0;ilig<unique.length;ilig++){
275
+ let ligType = unique[ilig];
276
+ svgResult[ligType] = "";
277
+ }
278
+ postMessage(["result",svgResult]);
279
+ });
280
+ }
281
+
282
+ }