-
Notifications
You must be signed in to change notification settings - Fork 0
/
bt_flask.py
50 lines (42 loc) · 1.18 KB
/
bt_flask.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
from flask import Flask, request, jsonify
import os
import logging
from bt_cli import BTCLI
app = Flask(__name__)
app.config.update(
DEBUG=True
)
# PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
# os.environ.update({
# 'PROJECT_ROOT': PROJECT_ROOT
# })
logging.basicConfig(level=logging.DEBUG)
###################
# FLASK ENDPOINTS #
###################
@app.route("/bt")
def test_page():
pass
@app.route("/bt/test")
def test_bt():
return jsonify({"status": "bt_flask up and running."})
@app.route("/bt/rest")
def rest_endpoints():
pass
@app.route("/bt/rest/run", methods=["POST"])
def run_bt():
"""
Runs bt_cli.py module for biotransformation predictions.
"""
post_dict = request.get_json()
smiles = post_dict["smiles"]
react_lib = post_dict["prop"]
gen_limit = post_dict["gen_limit"]
try:
bt_results = BTCLI().run_bt_routine(smiles, react_lib, gen_limit) # bt_cli expecting list of smiles
return jsonify({"status": True, "data": bt_results})
except Exception as e:
logging.warning("biotransformer exception: {}".format(e))
return jsonify({"status": False, "data": {"error": "error generating products"}})
if __name__ == "__main__":
app.run(debug=True, port=5002)