-
Notifications
You must be signed in to change notification settings - Fork 6
/
C2_uptake_prediction.html
executable file
·830 lines (703 loc) · 39.3 KB
/
C2_uptake_prediction.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
<!-- Import NGL, webGavrog, and Bootstrap libraries-->
<!DOCTYPE html>
<html>
<head>
<script src="libraries/jquery-3.4.1.min.js">
</script>
<script src="libraries/ngl.js" type="text/javascript">
</script>
<script src="libraries/webGavrog/runtime.js" type="text/javascript">
</script>
<script src="libraries/webGavrog/vendors.js" type="text/javascript">
</script>
<script src="libraries/webGavrog/main.js" type="text/javascript">
</script>
<script src="libraries/3Dmol-min.js">
</script>
<script src="libraries/bootstrap.min.js">
</script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-2.3.1.min.js">
</script><!-- Import CSS -->
<link href="libraries/bootstrap.min.css" rel="stylesheet">
<link href="libraries/bootstrap_custom.min.css" rel="stylesheet"><!-- Imports related to star rating -->
<link href="https://cdn.jsdelivr.net/gh/kartik-v/[email protected]/css/star-rating.min.css" media="all" rel="stylesheet" type="text/css">
<script src="https://cdn.jsdelivr.net/gh/kartik-v/[email protected]/js/star-rating.min.js" type="text/javascript">
</script>
<link href="https://cdn.jsdelivr.net/gh/kartik-v/[email protected]/themes/krajee-svg/theme.css" media="all" rel="stylesheet" type="text/css">
<script src="https://cdn.jsdelivr.net/gh/kartik-v/[email protected]/themes/krajee-svg/theme.js">
</script><!-- Custom CSS code is placed within the <style> tag: -->
<style>
.btn {
margin-top: 3px;
}
.mol-container {
/* For component visualization */
height: 400px;
position: relative;
}
.form-control {
margin-bottom: 0.1cm;
}
.round_button {
border-radius: 25px;
font-size: 16px;
font-weight: bold;
min-width: 130px;
}
.selection_button {
display: inline-block;
width: 33%;
}
.link {
/* hyperlinks are blue */
color: #279AF1;
}
.dropdown-item {
font-size: 18px;
}
#viewportwrapper {
/* For MOF visualization */
grid-area: viz;
}
#header_background {
background-image: url('banner_light');
background-position: center; /* Keeps the banner centered even when window is shrunken */
background-size: cover; /* Makes the banner the appropriate size */
}
body {
/* The font to be used everywhere */
font-family: Arial, Helvetica, sans-serif;
color: black;
font-size: 16px;
}
.perm {
background: none;
border: none;
}
.pill-custom {
border-radius: 0px 0px 0px 0px !important;
border: 0px;
color: black !important;
background-color: white !important;
padding-left: 0px;
padding-right: 0px;
}
.pill-custom.active {
background-color: #f7f7f7 !important;
border-bottom: 5px solid black !important;
}
.pill-custom:hover {
color: #18bc9c !important;
}
</style><!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-7B1L0P0FXV">
</script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-7B1L0P0FXV');
</script><!-- End of Google Analytics stuff -->
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>MOFSimplify</title>
</head>
<body>
<!-- The following code creates a navbar. Each navbar item is in a list entry of class "nav-item". -->
<div class="navbar navbar-expand-lg fixed-top navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand" href="../" style='font-size: 30px; padding-right: 30px;'>MOFSimplify</a> <button aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation" class="navbar-toggler" data-target="#navbarResponsive" data-toggle="collapse" type='button'><span class="navbar-toggler-icon"><!-- Toggle navbar --></span></button>
<div class="collapse navbar-collapse" id="navbarResponsive" style='font-size: 20px;'>
<ul class="navbar-nav">
<li class="nav-item dropdown" style='padding-right: 30px;'>
<a aria-expanded="false" aria-haspopup="true" class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" id="navbarDropdownMenuLink" role="button">Property prediction</a>
<div aria-labelledby="navbarDropdownMenuLink" class="dropdown-menu">
<a class="dropdown-item" href="../">Solvent/Thermal</a>
<a class="dropdown-item" href="water_stability_prediction.html">Water/Acid</a>
<a class="dropdown-item" href="C2_uptake_prediction.html">C2 uptake</a>
</div>
</li>
<li class="nav-item" style='padding-right: 30px;'>
<a class="nav-link" href="stable_MOFs.html">Stable MOFs</a>
</li>
<li class="nav-item" style='padding-right: 30px;'>
<a class="nav-link" href="how_to_cite.html">How to Cite</a>
</li>
<li class="nav-item dropdown" style='padding-right: 30px;'>
<a aria-expanded="false" aria-haspopup="true" class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" id="navbarDropdownMenuLink">Code</a>
<div aria-labelledby="navbarDropdownMenuLink" class="dropdown-menu">
<a class="dropdown-item" href="https://github.com/hjkgrp/MOFSimplify">Source Code</a> <a class="dropdown-item" href="https://github.com/hjkgrp/molSimplify/tree/master/molSimplify/Informatics/MOF">MOF Code</a>
</div>
</li>
</ul>
</div><button class='btn btn-primary round_button' id='dark_mode' style='font-size:22px; width:20%;' type='button'>Dark mode</button>
</div>
</div>
<div class="container">
<div class="page-header" id="banner" style='padding-bottom:10px;'>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12" id='header_background'>
<!-- Title -->
<span style='position:relative;'><!-- The zebra class changes color depending if Dark mode is toggled on or not. --></span>
<p class='zebra' style="font-size: 27px; width:100%; text-align:center; font-style: italic; color: #2B3E50; margin-top: 6cm;"><span style='position:relative;'>The <a class="link" href="http://hjkgrp.mit.edu/">Kulik Group</a> at MIT<br>
Powered by <a class="link" href="https://molsimplify.readthedocs.io/en/latest/">molSimplify</a></span></p>
</div>
</div>
<div class="container" id="pills-main">
<div style='text-align:center; margin-top: 20px; margin-bottom: 20px;'>
<b class='zebra' style='font-size:26px;'>Associated paper available <a href="https://pubs.acs.org/doi/10.1021/acsami.4c14131">here</a><br></b>
</div>
<b class='zebra' style='font-size:22px;'>1) Select a MOF (metal-organic framework) for analysis</b>
<!-- Create a section containing buttons -->
<div class='col-lg-12'>
<div style='width:100%; text-align:center; margin-top:0.25cm;'>
<!-- Button for queuing up the example MOF cif file -->
<button class='btn btn-primary round_button selection_button' id='example-redirect' style='font-size:22px; width:40%; margin-right:40px;' type='button'>Example MOF</button>
<!-- Button for uploading MOF cif file -->
<button class='btn btn-primary round_button selection_button' id='upload' style='font-size:22px; width:40%' type='button'>Custom (upload cif file)</button>
<p class='zebra' id='cif_hint' style='display:inline-block; width:100%; font-size: 22px; margin-bottom: 0.25cm;'>Uploaded cif file must have P1 symmetry (all atom positions explicitly indicated) and be disorder free and without floating solvent</p>
<p class='zebra' id='permission_line' style='font-size:22px;'>May MOFSimplify store information on your MOFs? <button class='perm' id='perm_yes' style='color: green;'>Yes.</button> <button class='perm' id='perm_no' style='color: red;'>No.</button></p>
<!--   is a space gap -->
</div>
</div>
<div id='predict_section' style='margin-top: 1cm;'>
<b class='zebra' style='font-size:22px;'>2) Predict properties of the selected MOF</b> <!-- Create a section containing buttons -->
<div class='col-lg-12'>
<div style='width:100%; text-align:center; margin-top:0.25cm;'>
<!-- Button for predicting ethane uptake of MOF -->
<button class='btn btn-primary round_button' id='predict_ethane' style='display:inline-block; width:49%; font-size:22px;' type='button'>Ethane uptake</button> <!-- Button for predicting ethylene uptake of MOF -->
<button class='btn btn-primary round_button' id='predict_ethylene' style='display:inline-block; width:49%; font-size:22px;' type='button'>Ethylene uptake</button>
</div>
</div>
<!-- temperature input -->
<div class = 'row' style='margin-top: 0.25cm;'>
<div class='col-lg-4'>
<div class='zebra' style='font-size:22px;'>
Temperature (K)
</div>
</div>
<div class='col-lg-8'>
<input type="text" id="temperature_input" style='font-size: 22px; width:100%' class='form-control' placeholder="293">
</div>
</div>
<!-- pressure input -->
<div class = 'row' style='margin-top: 0.25cm;'>
<div class='col-lg-4'>
<div class='zebra' style='font-size:22px;'>
Pressure (kPa)
</div>
</div>
<div class='col-lg-8'>
<input type="text" id="pressure_input" style='font-size: 22px; width:100%' class='form-control' placeholder="100">
</div>
</div>
</div>
<div id='descriptor_section' style='margin-top: 1cm;'>
<b class='zebra' style='font-size:22px;'>3) Download descriptors of the selected MOF</b> <!-- Create a section containing buttons -->
<div class='col-lg-12'>
<div style='width:100%; text-align:center; margin-top:0.25cm;'>
<!-- Button for downloading descriptors of MOF -->
<button class='btn btn-primary round_button' id='download_descriptors' style='display:inline-block; width:49%; font-size:22px;' type='button'>Download descriptors</button>
</div>
</div>
</div><!-- Section where the MOF predictions are placed once predictions are made. Also displays which MOF is currently queued up and ready for analysis. -->
<div class='row' id='status_section' style='margin-top: 1cm;border-left:5px solid gray;border-color:#2c3e50;padding-left:5px;background-color:#f7f7f7;'>
<b style='font-size:22px;'>Status messages and MOF predictions</b>
<div class='col-12' id='upload_status' style='font-size:22px;'></div>
<div class='col-12' id='ethane_uptake_prediction' style='font-size:22px;white-space: pre-wrap;'></div>
<div class='col-12' id='ethylene_uptake_prediction' style='font-size:22px;white-space: pre-wrap;'></div>
</div>
</div><!-- The example MOF selection section of the website -->
<div class='zebra' id="pills-example" style='font-size: 20px;'>
Choose the default MOF HKUST-1 or any CoRE MOF. <!-- Selection box for the example MOF -->
<div class='zebra' style="padding-top: 30px; font-size: 22px;">
Example MOF options <input autocomplete="off" class='form-control locksMetrics' id="MOF_option" list='MOFs_list' onmousedown="value = '';" style='font-size: 22px;'>
</div><!-- Example MOFs -->
<datalist id='MOFs_list' style='font-size: 22px;'>
<!-- Defined near the end of the Javascript section below -->
</datalist>
<div style='width:100%; text-align:center; margin-top:0.5cm;'>
<button class='btn btn-primary round_button' id='select_example' style='display:inline-block; width:49%; font-size: 22px;' type='button'>Select example MOF</button>
</div>
</div>
</div>
</div>
<div class="navbar navbar-expand-lg relative navbar-dark bg-primary" style="margin-top: 50px; font-size: 24px;">
<div class="container">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link disabled">Site developed and maintained by the Kulik Group at MIT<br>
Contact: [email protected]</a>
</li>
</ul>
</div>
</div><!-- For cif file upload -->
<form>
<input id="file_input" name="file_input" style="display:none" type="file"> <!-- This will never display anything. Just used to store a MOF cif file if the button "Custom (upload cif file)" is used. -->
<!-- For example MOF file -->
</form>
<p id="example_holder"></p><!-- This will never display anything. Just used to store a MOF cif file if the button "Example MOF" is used. -->
<!-- Beginning of JavaScript section -->
<script>
// tags for changing the selection button colors, depending on if an operation is successfully completed or not
failure_red = '#A33B20';
success_green = '#18bc9c';
inprogress_yellow = '#F7B801'
original_blue = '#2c3e50';
load_color = original_blue;
upload_color = original_blue;
ethane_pred_color = original_blue;
ethylene_pred_color = original_blue;
$(function () {
// Reset certain fields when a new MOF is uploaded (either the example MOF or a user-specified MOF) or generated with building blocks.
function renew(action) { // something else was already called reset, so we're calling this renew
// action will be either 'example', 'input', or 'temp_pressure_text_entry'
if (action != 'example' && action != 'temp_pressure_text_entry') {
document.getElementById('example_holder').value = null; // clears example cif
}
if (action != 'input' && action != 'temp_pressure_text_entry') {
document.getElementById('file_input').value = null; // clearing any cifs loaded by the user
}
color_reset(action); // resetting selection and prediction and visualize and component button colors
// hiding sections
if (action != 'temp_pressure_text_entry') {
$('#predict_section').hide()
$('#status_section').hide()
$('#cif_hint').hide()
// Clearing everything in the Status messages and MOF predictions section of the website, and the holders.
$('#upload_status').text(''); // now nothing is uploaded
}
$('#descriptor_section').hide()
// clearing previous predictions
$('#ethane_uptake_prediction').text('');
$('#ethylene_uptake_prediction').text('');
}
// Resets the colors of the selection and prediction and visualize and component buttons
function color_reset(action) {
if (action != 'temp_pressure_text_entry') {
load_color = original_blue;
upload_color = original_blue;
$('#example-redirect').css({ 'background-color': original_blue, 'border-color': original_blue })
$('#upload').css({ 'background-color': original_blue, 'border-color': original_blue })
}
ethane_pred_color = original_blue;
ethylene_pred_color = original_blue;
descriptor_color = original_blue;
$('#predict_ethane').css({ 'background-color': original_blue, 'border-color': original_blue })
$('#predict_ethylene').css({ 'background-color': original_blue, 'border-color': original_blue })
$('#download_descriptors').css({ 'background-color': original_blue, 'border-color': original_blue })
}
// Used for ensuring that only .cif files are uploaded.
function getExtension(filename) {
var parts = filename.split('.');
return parts[parts.length - 1];
}
// Used for ensuring that only .cif files are uploaded.
function isCif(filename) {
var ext = getExtension(filename);
return ext == 'cif';
}
// Upload MOF cif file.
$('#upload').on('click', function () { // button triggers upload
$('#file_input').trigger('click'); // OS file selection
});
// This function triggers once the user uploads a file.
$("#file_input").change(function () {
renew('input');
// Check if uploaded file is a .cif.
if (!isCif(this.value)) { // if the uploaded file is not a cif
this.value = null; // clear the non-cif file
upload_color = failure_red;
$('#upload').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
alert("Must be a cif file.");
return; // if not a cif, doesn't continue
}
let myFile = document.getElementById('file_input').files[0]; // the uploaded file
$('#upload_status').text('Selected MOF (uploaded): ' + myFile.name);
upload_color = success_green;
$('#upload').css({ 'background-color': success_green, 'border-color': success_green }); // setting button color to indicate success
$('#predict_section').show()
$('#status_section').show()
$('#cif_hint').show()
});
// Code that updates the file upload text in any input form (i.e. change "Upload file..." to "file.pdf")
$('input[type="file"]').change(function(e){
var fileName = e.target.files[0].name;
$(e.target).siblings('.custom-file-label').html(fileName);
});
// Generate ethane uptake prediction when the "Ethane uptake" button is clicked.
$('#predict_ethane').click(function () {
// check if a cif is uploaded
let myFile = document.getElementById('file_input').files[0]; // the uploaded file
let myFile2 = document.getElementById('example_holder').value; // the example MOF, if Load example MOF has been used
// If neither the example MOF has been loaded, nor has the user uploaded nor generated a MOF, then an alert is raised and the function exits.
if (myFile == undefined) {
myFile = myFile2;
if (myFile2 == undefined) {
alert("Must select a MOF for analysis first.");
ethane_pred_color = failure_red;
$('#predict_ethane').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
return;
}
}
$('#ethane_uptake_prediction').text('The ethane uptake prediction is loading...');
ethane_pred_color = inprogress_yellow;
$('#predict_ethane').css({ 'background-color': inprogress_yellow, 'border-color': inprogress_yellow }); // setting button color to indicate in progress
// getting the name of the selected MOF
var name = document.getElementById('upload_status').innerHTML;
name = name.split(' ');
name = name.slice(-1)[0]; // getting the last element of the array
temperature = $('#temperature_input').val()
pressure = $('#pressure_input').val()
if (isNaN(temperature) || isNaN(pressure) || !temperature || !pressure) { // ! to check for empty values
alert("Temperature and pressure must be numbers.")
ethylene_pred_color = failure_red;
$('#predict_ethane').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
return;
}
if (temperature < 0 || pressure < 0) {
alert("Temperature and pressure must be non-negative.")
ethylene_pred_color = failure_red;
$('#predict_ethane').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
return;
}
// myFile.text() is a promise
myFile.text().then(function (result) {
// result is the text of the loaded .cif file
myDict = { 'name': name, 'structure': result , 'T': temperature , 'P': pressure }
// The $ is jquery. The post stuff sends a command to the app.py code to execute the function that is routed to by /predict_ethane_uptake
// It is a post request rather than a get request because information is sent to the backend (in a get request no information is sent)
$.post("/predict_ethane_uptake", JSON.stringify(myDict)).done(
function (response) {
if (response == 'OVERLOAD') {
alert('Server is receiving high traffic, please try again later')
ethane_pred_color = failure_red;
$('#predict_ethane').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
$('#ethane_uptake_prediction').text('');
return; // Do not update ethane uptake prediction if server is too busy.
}
if (response == 'FAILED') {
alert('Failed to featurize')
ethane_pred_color = failure_red;
$('#predict_ethane').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
$('#ethane_uptake_prediction').text('');
return; // Do not update ethane uptake prediction if prediction failed.
}
ethane_pred_color = success_green;
$('#predict_ethane').css({ 'background-color': success_green, 'border-color': success_green }); // setting button color to indicate success
$('#descriptor_section').show() // show section where can download descriptors
var prediction = response['prediction']
$('#ethane_uptake_prediction').text('The ethane uptake prediction is: ' + prediction.toString() + ' mmol/g.');
stability_field = document.getElementById('ethane_uptake_prediction');
})
.fail(function(xhr, textStatus, errorThrown) { // for timeout error; triggers after 1 minute
ethane_pred_color = failure_red;
$('#predict_ethane').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
$('#ethane_uptake_prediction').text('');
alert(errorThrown.concat("; MOF may be too large for web-based analysis"))
})
})
});
function setColor(element, color) {
element.style.backgroundColor = color;
}
// Generate ethylene uptake prediction when the "Ethylene uptake" button is clicked.
$('#predict_ethylene').click(function () {
// check if a cif is uploaded
let myFile = document.getElementById('file_input').files[0]; // the uploaded file
let myFile2 = document.getElementById('example_holder').value; // the example MOF, if Load example MOF has been used
// If neither the example MOF has been loaded, nor has the user uploaded nor generated a MOF, then an alert is raised and the function exits.
if (myFile == undefined) {
myFile = myFile2;
if (myFile2 == undefined) {
alert("Must select a MOF for analysis first.");
ethylene_pred_color = failure_red;
$('#predict_ethylene').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
return;
}
}
ethylene_pred_color = inprogress_yellow;
$('#predict_ethylene').css({ 'background-color': inprogress_yellow, 'border-color': inprogress_yellow }); // setting button color to indicate in progress
$('#ethylene_uptake_prediction').text('The ethylene uptake prediction is loading...'); // display prediction result
// getting the name of the selected MOF
var name = document.getElementById('upload_status').innerHTML;
name = name.split(' ');
name = name.slice(-1)[0]; // getting the last element of the array
temperature = $('#temperature_input').val()
pressure = $('#pressure_input').val()
if (isNaN(temperature) || isNaN(pressure) || !temperature || !pressure) { // ! to check for empty values
alert("Temperature and pressure must be numbers.")
ethylene_pred_color = failure_red;
$('#predict_ethylene').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
return;
}
if (temperature < 0 || pressure < 0) {
alert("Temperature and pressure must be non-negative.")
ethylene_pred_color = failure_red;
$('#predict_ethylene').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
return;
}
// myFile.text() is a promise
myFile.text().then(function (result) {
// result is the text of the loaded .cif file
myDict = { 'name': name, 'structure': result , 'T': temperature , 'P': pressure }
$.post("/predict_ethylene_uptake", JSON.stringify(myDict)).done(
function (response) {
if (response == 'OVERLOAD') {
alert('Server is receiving high traffic, please try again later')
ethylene_pred_color = failure_red;
$('#predict_ethylene').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
$('#ethylene_uptake_prediction').text('')
return; // Do not update ethylene uptake prediction if server is too busy.
}
if (response == 'FAILED') {
alert('Failed to featurize')
ethylene_pred_color = failure_red;
$('#predict_ethylene').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
$('#ethylene_uptake_prediction').text('')
return; // Do not update ethylene uptake prediction if prediction failed.
}
ethylene_pred_color = success_green;
$('#predict_ethylene').css({ 'background-color': success_green, 'border-color': success_green }); // setting button color to indicate success
$('#descriptor_section').show() // show section where can download descriptors
var prediction = response['prediction']
$('#ethylene_uptake_prediction').text('The ethylene uptake prediction is: ' + prediction.toString() + ' mmol/g.');
stability_field = document.getElementById('ethylene_uptake_prediction');
})
.fail(function(xhr, textStatus, errorThrown) { // for timeout error; triggers after 1 minute
ethylene_pred_color = failure_red;
$('#predict_ethylene').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
$('#ethylene_uptake_prediction').text('')
alert(errorThrown.concat("; MOF may be too large for web-based analysis")) // errorThrown will likely look like "Gateway Time-out"
})
})
});
// Load an example MOF when the "Select example MOF" button is clicked.
$('#select_example').click(function () {
my_MOF = $('#MOF_option').val() // Check which MOF is selected in the Example MOF options dropdown.
if (my_MOF === '') {
alert("Must choose a MOF first.");
return;
}
if (my_MOF === 'HKUST-1 (default)') {
default_loader()
}
else { // have a CSD MOF
csd_loader(my_MOF)
}
section_hider('#pills-main')
})
function default_loader() {
fetch('mof_examples/HKUST1.cif').then(response => { // grabbing the example MOF from local host
if (!response.ok) { // catching 404 and other issues
load_color = failure_red;
$('#example-redirect').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
throw Error(response.statusText);
}
return response.blob();
}).then(function (blob) {
renew('example'); // note: I call renew here rather than at the beginning of the load function in order to prevent NGL.Stage from throwing a hissy fit
var myFile = new File([blob], "example.cif", { type: "", lastModified: Date.now() }) // making a cif file
document.getElementById('example_holder').value = myFile; // setting the value of example_holder
$('#upload_status').text('Selected MOF: HKUST-1'); // indicating that the example MOF has been uploaded
load_color = success_green;
$('#example-redirect').css({ 'background-color': success_green, 'border-color': success_green }); // setting button color to indicate success
$('#predict_section').show() // show the prediction button section
$('#status_section').show() // show the status section
alert('Example MOF loaded!')
}).catch(error => {
renew('example');
load_color = failure_red;
$('#example-redirect').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
$('#upload_status').text('Failed to upload example MOF');
console.error('There has been a problem with your fetch operation:', error);
})
};
function csd_loader(my_MOF) {
// my_MOF is the six letter refcode, plus stuff like _clean
fetch('CoRE2019/' + my_MOF + '.cif').then(response => { // grabbing the example MOF from local host
if (!response.ok) { // catching 404 and other issues
load_color = failure_red;
$('#example-redirect').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
throw Error(response.statusText);
}
return response.blob();
}).then(function (blob) {
renew('example'); // note: I call renew here rather than at the beginning of the load function in order to prevent NGL.Stage from throwing a hissy fit
var myFile = new File([blob], "example.cif", { type: "", lastModified: Date.now() }) // making a cif file
document.getElementById('example_holder').value = myFile; // setting the value of example_holder
$('#upload_status').text('Selected MOF: ' + my_MOF); // indicating that the example MOF has been uploaded
load_color = success_green;
$('#example-redirect').css({ 'background-color': success_green, 'border-color': success_green }); // setting button color to indicate success
$('#predict_section').show() // show the prediction button section
$('#status_section').show() // show the status section
alert('Example MOF loaded!')
}).catch(error => {
renew('example');
load_color = failure_red;
$('#example-redirect').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
$('#upload_status').text('Failed to upload example MOF');
console.error('There has been a problem with your fetch operation:', error);
})
}
// This function is used for downloading information
// filename is the name of the file to be downloaded. text is the contents of the file.
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
// When the "Download descriptors" button is clicked, download the descriptors for the selected MOF
$('#download_descriptors').click(function () {
name = get_selected_MOF(false) // don't want the .cif extension
// Grab the contents of the descriptor csv
$.post("/get_descriptors_C2", JSON.stringify(name)).done(
function (response) {
descriptor_color = success_green;
$('#download_descriptors').css({ 'background-color': success_green, 'border-color': success_green }); // setting button color to indicate success
download(name + '_descriptors.csv', response)
})
})
// Form check for file extensions
upload_extensions = ['pdf', 'jpg', 'png', 'tiff'] // ['jpg', 'jpeg', 'png', 'pdf', 'tiff', 'tif', 'eps'] // acceptable file types
// This function returns the name of the selected MOF
// If extension is true, keep the .cif at the end; else don't
function get_selected_MOF(extension = true) {
var name = document.getElementById('upload_status').innerHTML; // getting the name of the selected MOF
name = name.split(' ');
name = name.slice(-1)[0]; // getting the last element of the array
if (!extension) {
if (name.substring(name.length - 4) == '.cif') { // getting rid of the .cif part
name = name.substring(0, name.length - 4)
}
}
return name
}
// When the "Dark mode" button is clicked:
black = '#000000'
white = '#FFFFFF'
$('#dark_mode').click(function () { // change background and button text depending on button state
button_text = document.getElementById('dark_mode').textContent
if (button_text == 'Dark mode') { // make background dark and text white
$('body').css("background-color", black);
document.getElementById('dark_mode').textContent = 'Light mode';
$('.zebra').css('color', white)
$('#header_background').css('background-image', 'url(\'banner_dark\')')
}
else { // Button says Light mode; make background white and text black
$('body').css("background-color", white);
document.getElementById('dark_mode').textContent = 'Dark mode';
$('.zebra').css('color', black)
$('#header_background').css('background-image', 'url(\'banner_light\')')
}
})
// The code below that has a lot of hide and show operations is the tab functionality that allows the user to switch tabs.
// For example, when the Visualization tab is clicked, all website displays that don't have to do with visualization are hidden, and visualization functionality is shown
// Helper function for the code below. Hides the appropriate sections when a button is clicked.
function section_hider(current_section) {
// hide everything but current_section
sections = ['#pills-main', '#pills-example']
$(current_section).show()
for (var i = 0; i < sections.length; i++) {
if (sections[i] != current_section) {
$(sections[i]).hide()
}
}
}
$('#example-redirect').click(function () {
section_hider('#pills-example')
$('#MOF_option').val('HKUST-1 (default)') // setting the default value
})
// option_generator is a helper function for populating dropdowns on the website
var option_generator = function(my_list) {
var options = ''
for (var i = 0; i < my_list.length; i++) {
options += '<option value="' + my_list[i] + '" />';
}
return options
}
$.get("/list_getter").done(
function (response) {
// Purpose of this is to get lists for the code below
my_MOFs = response['my_MOFs']
// In addition, populating the CSD MOF options for the Example MOF loading
document.getElementById('MOFs_list').innerHTML = option_generator(my_MOFs); // populating the MOFs dropdown
})
$('#temperature_input').change(function() {
renew('temp_pressure_text_entry')
})
$('#pressure_input').change(function() {
renew('temp_pressure_text_entry')
})
// On startup, hide certain sections
$('#pills-comp').hide()
$('#pills-example').hide()
$('#pills-data').hide()
$('#predict_section').hide()
$('#descriptor_section').hide()
$('#status_section').hide()
$('#cif_hint').hide()
// Also setting some default values
$('#temperature_input').val('293')
$('#pressure_input').val('100')
// functions to handle the selection and prediction and visualize and component button color change upon mouse hover
// since we change the selection and prediction and visualize and component button colors and lose the default hover color change
$("#example-redirect").hover(function () {
$(this).css("background-color", "#1D2B37"); // #1D2B37 is the dark blue that is the default hover color for the buttons
$(this).css("border-color", "#1D2B37");
}, function () {
$(this).css("background-color", load_color);
$(this).css("border-color", load_color);
});
$("#upload").hover(function () {
$(this).css("background-color", "#1D2B37");
$(this).css("border-color", "#1D2B37");
}, function () {
$(this).css("background-color", upload_color);
$(this).css("border-color", upload_color);
});
$("#predict_s").hover(function () {
$(this).css("background-color", "#1D2B37");
$(this).css("border-color", "#1D2B37");
}, function () {
$(this).css("background-color", ethane_pred_color);
$(this).css("border-color", ethane_pred_color);
});
$("#predict_t").hover(function () {
$(this).css("background-color", "#1D2B37");
$(this).css("border-color", "#1D2B37");
}, function () {
$(this).css("background-color", ethylene_pred_color);
$(this).css("border-color", ethylene_pred_color);
});
$("#download_descriptors").hover(function () {
$(this).css("background-color", "#1D2B37");
$(this).css("border-color", "#1D2B37");
}, function () {
$(this).css("background-color", descriptor_color);
$(this).css("border-color", descriptor_color);
});
$(".link").hover(function () { // for hyperlinks
$(this).css("color", '#18bc9c');
}, function () {
$(this).css("color", '#279AF1');
});
// When the "Yes" button is clicked for storage permission line
$("#perm_yes").click(function () {
$('#permission_line').hide()
$.post("/permission", JSON.stringify(true)).done(function (response) {
})
})
// When the "No" button is clicked for storage permission line
$("#perm_no").click(function () {
$('#permission_line').hide()
$.post("/permission", JSON.stringify(false)).done(function (response) {
})
})
});
</script> <!-- End of Javascript section -->
</body>
</html>