-
Notifications
You must be signed in to change notification settings - Fork 6
/
water_stability_prediction.html
executable file
·969 lines (826 loc) · 49 KB
/
water_stability_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
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
<!-- 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/full/10.1021/jacs.4c05879">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>
<!-- Button for generating MOF cif file -->
<!-- <button class='btn btn-primary round_button selection_button' id='bb-redirect' type='button'
style='font-size:22px;'>Building block assembly</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 -->
<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 water stability of MOF -->
<button class='btn btn-primary round_button' id='predict_w' style='display:inline-block; width:49%; font-size:22px;' type='button'>2-class water stability</button> <!-- Button for predicting acid stability of MOF -->
<button class='btn btn-primary round_button' id='predict_a' style='display:inline-block; width:49%; font-size:22px;' type='button'>Acidic aqueous solution stability</button>
</div>
</div>
<p class='zebra' style='font-size:18px;text-align: center;'>The 2-class water stability model groups the four water stability classes U, LK, HK, and TS<br>into two classes: water-stable (HK+TS) and water-unstable (U+LK).<br>The acid model assumes a MOF is water-stable.</p>
</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='water_stability_prediction' style='font-size:22px;white-space: pre-wrap;'></div>
<div class='col-12' id='water_form'>
<form action='/process_feedback_water' class='col-10' enctype="multipart/form-data" id='water_stability_feedback' method="post" name="water_stability_feedback" style='font-size:22px;margin-left:15px'>
<input name="feedback_form_name" type="hidden" value="water_stability"> <input name="cif_file_name" type="hidden" value=""> <input name="structure" type="hidden" value=""> <i id='rate_water'>Rate this prediction: *</i> <input class="rating" data-size="md" id="water_rating" name="rating" required="" type="text">
<div class="input-group mt-2" style="">
<div class="input-group-prepend">
<span class="input-group-text" id="water_rating_email_desc">Email (.edu preferred) *</span>
</div><input aria-describedby="water_rating_email_desc" class="form-control" id="water_rating_email" name="email" required="" type="email">
</div><select class="form-control mt-2 mb-0" id="inputState_A" name="reason" required="">
<option value="">
Reason for rating... *
</option>
<option>
I've worked with this MOF before, the prediction is good
</option>
<option>
I've worked with this MOF before, the prediction is bad (elaborate in Comments field)
</option>
<option>
The literature contains counter examples of this prediction (provide DOI of papers with counterexamples in Comments field)
</option>
</select>
<div class="input-group mt-2" style="">
<div class="input-group-prepend">
<span class="input-group-text" id="water_rating_comments_desc">Comments</span>
</div><input aria-describedby="water_rating_comments_desc" class="form-control" id="water_rating_comments" name="comments" type="text">
</div>
<button class="btn btn-primary mt-2" id="submit_A" type="submit">Submit</button>
</form>
</div>
<div class='col-12' id='acid_stability_prediction' style='font-size:22px;white-space: pre-wrap;'></div>
<div class='col-12' id='acid_form'>
<form action='/process_feedback_water' class='col-10' enctype="multipart/form-data" id='acid_stability_feedback' method="post" name="acid_stability_feedback" style='font-size:22px;margin-left:15px'>
<input name="feedback_form_name" type="hidden" value="acid_stability"> <input name="cif_file_name" type="hidden" value=""> <input name="structure" type="hidden" value=""> <i id='rate_acid'>Rate this prediction: *</i> <input class="rating" data-size="md" id="acid_rating" name="rating" required="" type="text">
<div class="input-group mt-2" style="">
<div class="input-group-prepend">
<span class="input-group-text" id="acid_rating_email_desc">Email (.edu preferred) *</span>
</div><input aria-describedby="acid_rating_email_desc" class="form-control" id="acid_rating_email" name="email" required="" type="email">
</div><select class="form-control mt-2 mb-0" id="inputState_B" name="reason" required="">
<option value="">
Reason for rating... *
</option>
<option>
I've worked with this MOF before, the prediction is good
</option>
<option>
I've worked with this MOF before, the prediction is bad (elaborate in Comments field)
</option>
<option>
The literature contains counter examples of this prediction (provide DOI of papers with counterexamples in Comments field)
</option>
</select>
<div class="input-group mt-2" style="">
<div class="input-group-prepend">
<span class="input-group-text" id="acid_rating_comments_desc">Comments</span>
</div><input aria-describedby="acid_rating_comments_desc" class="form-control" id="acid_rating_comments" name="comments" type="text">
</div>
<button class="btn btn-primary mt-2" id="submit_B" type="submit">Submit</button>
</form>
</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;
water_pred_color = original_blue;
acid_pred_color = original_blue;
$(function () {
// Set up 3Dmol viewer
let element = $('#container-01');
let config = { backgroundColor: 'white' };
let component_viewer = $3Dmol.createViewer(element, config);
data = {};
// Reset zoom level.
$('#reset_zoom').click(function () {
component_viewer.zoomTo();
})
// 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 'bb'
if (action != 'example') {
document.getElementById('example_holder').value = null; // clears example cif
}
if (action != 'input') {
document.getElementById('file_input').value = null; // clearing any cifs loaded by the user
}
color_reset(); // resetting selection and prediction and visualize and component button colors
w_stability_field = document.getElementById('water_stability_prediction');
setColor(w_stability_field, 'transparent') // color background, transparent
a_stability_field = document.getElementById('acid_stability_prediction');
setColor(a_stability_field, 'transparent') // color background, transparent
// hiding sections
$('#predict_section').hide()
$('#status_section').hide()
$('#descriptor_section').hide()
$('#cif_hint').hide()
$('#water_form').hide()
$('#acid_form').hide()
// clearing previous predictions
$('#water_stability_prediction').text('');
$('#acid_stability_prediction').text('');
// Clearing everything in the Status messages and MOF predictions section of the website, and the holders.
$('#upload_status').text(''); // now nothing is uploaded
}
// Resets the colors of the selection and prediction and visualize and component buttons
function color_reset() {
load_color = original_blue;
upload_color = original_blue;
water_pred_color = original_blue;
acid_pred_color = original_blue;
descriptor_color = original_blue;
$('#example-redirect').css({ 'background-color': original_blue, 'border-color': original_blue })
$('#upload').css({ 'background-color': original_blue, 'border-color': original_blue })
$('#bb-redirect').css({ 'background-color': original_blue, 'border-color': original_blue })
$('#predict_w').css({ 'background-color': original_blue, 'border-color': original_blue })
$('#predict_a').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 water stability prediction when the "2-class water stability" button is clicked.
$('#predict_w').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.");
water_pred_color = failure_red;
$('#predict_w').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
return;
}
}
$('#water_stability_prediction').text('The 2-class water stability prediction is loading...');
water_pred_color = inprogress_yellow;
$('#predict_w').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
// myFile.text() is a promise
myFile.text().then(function (result) {
// result is the text of the loaded .cif file
myDict = { 'name': name, 'structure': result }
// The $ is jquery. The post stuff sends a command to the app.py code to execute the function that is routed to by /predict_water_stability
// 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_water_stability", JSON.stringify(myDict)).done(
function (response) {
if (response == 'OVERLOAD') {
alert('Server is receiving high traffic, please try again later')
water_pred_color = failure_red;
$('#predict_w').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
$('#water_stability_prediction').text('');
return; // Do not update water stability prediction if server is too busy.
}
if (response == 'FAILED') {
alert('Failed to featurize')
water_pred_color = failure_red;
$('#predict_w').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
$('#water_stability_prediction').text('');
return; // Do not update water stability prediction if prediction failed.
}
$('#water_form').show()
$('#water_form input[name=cif_file_name]').val(myDict['name']);
$('#water_form input[name=structure]').val(myDict['structure']); // Populate the feedback form with metadata
water_pred_color = success_green;
$('#predict_w').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']
// preparing the human-interpretable water stability prediction
if (prediction <= 0.2) {
verdict = 'Very confident the MOF is water-unstable.\n439/1,092 MOFs in WS24 are water-unstable.';
my_color = '#ffad97' // color background, light red
}
else if (prediction <= 0.4) {
verdict = 'Fairly confident the MOF is water-unstable.\n439/1,092 MOFs in WS24 are water-unstable.';
my_color = '#ffcd97' // light orange
}
else if (prediction <= 0.5) {
verdict = 'Uncertain, but predict the MOF is water-unstable.\n439/1,092 MOFs in WS24 are water-unstable.';
my_color = '#fffa97' // light yellow
}
else if (prediction <= 0.6) {
verdict = 'Uncertain, but predict the MOF has water-stable.\n653/1,092 MOFs in WS24 are water-stable.';
my_color = '#fffa97' // light yellow
}
else if (prediction <= 0.8) {
verdict = 'Fairly confident the MOF has water-stable.\n653/1,092 MOFs in WS24 are water-stable.';
my_color = '#e7ff97' // light lime
}
else {
verdict = 'Very confident the MOF has water-stable.\n653/1,092 MOFs in WS24 are water-stable.';
my_color = '#90ee90' // light green
}
$('#water_stability_prediction').text('The 2-class water stability prediction is: ' + prediction.toString() + '. ' + verdict);
stability_field = document.getElementById('water_stability_prediction');
setColor(stability_field, my_color) // color background based on the prediction
water_form = document.getElementById('water_form');
setColor(water_form, my_color)
})
.fail(function(xhr, textStatus, errorThrown) { // for timeout error; triggers after 1 minute
water_pred_color = failure_red;
$('#predict_w').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
$('#water_stability_prediction').text('');
alert(errorThrown.concat("; MOF may be too large for web-based analysis"))
})
})
});
function setColor(element, color) {
element.style.backgroundColor = color;
}
// Generate acidic aqueous solution stability prediction when the "Acidic aqueous solution stability" button is clicked.
$('#predict_a').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.");
acid_pred_color = failure_red;
$('#predict_a').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
return;
}
}
acid_pred_color = inprogress_yellow;
$('#predict_a').css({ 'background-color': inprogress_yellow, 'border-color': inprogress_yellow }); // setting button color to indicate in progress
$('#acid_stability_prediction').text('The acid stability 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
// myFile.text() is a promise
myFile.text().then(function (result) {
// result is the text of the loaded .cif file
myDict = { 'name': name, 'structure': result }
$.post("/predict_acid_stability", JSON.stringify(myDict)).done(
function (response) {
if (response == 'OVERLOAD') {
alert('Server is receiving high traffic, please try again later')
acid_pred_color = failure_red;
$('#predict_a').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
$('#acid_stability_prediction').text('')
return; // Do not update acid stability prediction if server is too busy.
}
if (response == 'FAILED') {
alert('Failed to featurize')
acid_pred_color = failure_red;
$('#predict_a').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
$('#acid_stability_prediction').text('')
return; // Do not update acid stability prediction if prediction failed.
}
$('#acid_form').show()
$('#acid_form input[name=cif_file_name]').val(myDict['name']);
$('#acid_form input[name=structure]').val(myDict['structure']); // Populate the feedback form with metadata
acid_pred_color = success_green;
$('#predict_a').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']
// preparing the human-interpretable acid stability prediction
if (prediction <= 0.2) {
verdict = 'Very confident the MOF is acid-unstable.\n565/653 water-stable MOFs in WS24 are acid-unstable.';
my_color = '#ffad97' // color background, light red
}
else if (prediction <= 0.4) {
verdict = 'Fairly confident the MOF is acid-unstable.\n565/653 water-stable MOFs in WS24 are acid-unstable.';
my_color = '#ffcd97' // light orange
}
else if (prediction <= 0.5) {
verdict = 'Uncertain, but predict the MOF is acid-unstable.\n565/653 water-stable MOFs in WS24 are acid-unstable.';
my_color = '#fffa97' // light yellow
}
else if (prediction <= 0.6) {
verdict = 'Uncertain, but predict the MOF is acid-stable.\n88/653 water-stable MOFs in WS24 are acid-stable.';
my_color = '#fffa97' // light yellow
}
else if (prediction <= 0.8) {
verdict = 'Fairly confident the MOF is acid-stable.\n88/653 water-stable MOFs in WS24 are acid-stable.';
my_color = '#e7ff97' // light lime
}
else {
verdict = 'Very confident the MOF is acid-stable.\n88/653 water-stable MOFs in WS24 are acid-stable.';
my_color = '#90ee90' // light green
}
$('#acid_stability_prediction').text('The acidic aqueous solution stability prediction is: ' + prediction.toString() + '. ' + verdict);
stability_field = document.getElementById('acid_stability_prediction');
setColor(stability_field, my_color) // color background based on the prediction
acid_form = document.getElementById('acid_form');
setColor(acid_form, my_color)
})
.fail(function(xhr, textStatus, errorThrown) { // for timeout error; triggers after 1 minute
acid_pred_color = failure_red;
$('#predict_a').css({ 'background-color': failure_red, 'border-color': failure_red }); // setting button color to indicate failure
$('#acid_stability_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_water", 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
}
// Functions for handling feedback
// When the "Submit" button is clicked for the water stability prediction feedback
$('#submit_A').click(function () {
// Returns an alert to the user indicating whether their feedback was accepted. Sends form data to backend if form is filled out well.
// First, ensures that the required fields are filled out. If not, returns, and no alerts are shown.
var rating = document.getElementById('water_rating').value;
var email = document.getElementById('water_rating_email').value;
var reason = document.getElementById('inputState_A').value;
if (rating && email && reason) {
var data = new FormData($('#water_stability_feedback')[0])
document.getElementById('water_stability_feedback').reset() // reset the form
// send form data to backend
var request = new XMLHttpRequest();
request.onreadystatechange = function() { return; } // Override the response behavior of the request
request.open("POST", 'process_feedback_water', true)
request.send(data)
alert('Thank you for your feedback!')
}
})
// When the "Submit" button is clicked for the acid stability prediction feedback
$('#submit_B').click(function () {
// Returns an alert to the user indicating whether their feedback was accepted. Sends form data to backend if form is filled out well.
// First, ensures that the required fields are filled out. If not, returns, and no alerts are shown.
var rating = document.getElementById('acid_rating').value;
var email = document.getElementById('acid_rating_email').value;
var reason = document.getElementById('inputState_B').value;
if (rating && email && reason) {
var data = new FormData($('#acid_stability_feedback')[0])
document.getElementById('acid_stability_feedback').reset() // reset the form
// send form data to backend
var request = new XMLHttpRequest();
request.onreadystatechange = function() { return; } // Override the response behavior of the request
request.open("POST", 'process_feedback_water', true)
request.send(data)
alert('Thank you for your feedback!')
}
})
// 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_linkers = response['my_linkers']
// my_sbus = response['my_sbus']
// my_nets = response['my_nets']
my_MOFs = response['my_MOFs']
// // Populating the linkers in the building block section
// document.getElementById('linkers_list').innerHTML = option_generator(my_linkers); // populating the linkers dropdown
// // Next, populating the nodes in the building block section.
// document.getElementById('sbus_list').innerHTML = option_generator(my_sbus); // populating the sbus dropdown
// // Populating the nets in the building block section
// document.getElementById('nets_list').innerHTML = option_generator(my_nets); // populating the nets dropdown
// 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
})
// 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()
// 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", water_pred_color);
$(this).css("border-color", water_pred_color);
});
$("#predict_t").hover(function () {
$(this).css("background-color", "#1D2B37");
$(this).css("border-color", "#1D2B37");
}, function () {
$(this).css("background-color", acid_pred_color);
$(this).css("border-color", acid_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>