-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
65 lines (56 loc) · 1.47 KB
/
app.py
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
from flask import Flask, request, render_template
from molprops import MolProps, MolPlots
app = Flask(__name__)
h = '''
<!DOCTYPE html>
<head><title>Molecular Properties</title></head>
<body>
<style>
body { font-family: Arial }
table { border-collapse: collapse; }
th, td { border: 1px solid; }
</style>
<p>Enter SMILES, one per line:</p>
<form method="post">
<textarea name="smiles" rows="10" cols="60"></textarea>
<br>
<input type="submit" value="get properties">
<p></p>
</form>
'''
hp = '''
<!DOCTYPE html>
<head><title>Molecular Properties - Plots</title></head>
<body>
<style>
body { font-family: Arial }
table { border-collapse: collapse; }
th, td { border: 1px solid; }
</style>
<p>Enter group labels beginning with #, followed by SMILES, one per line. For example,</p>
<pre style="background-color: #f4f4f4" cols="80">
# straight-chain alkanes
CCC
CCCCC
# alcohols
CCO
CC(C)CO
</pre>
<form method="post">
<textarea name="smiles" rows=10 style="width: 100%;"></textarea>
<br>
<input type="submit" value="get properties">
<p></p>
</form>
'''
f = '</body></html>'
def isPost():
return request.method == 'POST'
@app.route('/', methods=['GET', 'POST'])
def home():
return h + (MolProps(request.form.get('smiles')) if isPost() else '') + f
@app.route('/plots', methods=['GET', 'POST'])
def plots():
return hp + (MolPlots(request.form.get('smiles')) if isPost() else '') + f
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=80)