File size: 5,354 Bytes
24fbee3
820bf6e
a26b7e6
ac3f130
a26b7e6
ac3f130
005ad92
a26b7e6
24fbee3
54a82d6
 
 
ac3f130
 
24fbee3
f685541
 
 
 
 
 
 
27cf697
a87b16d
820bf6e
24fbee3
 
 
 
ac3f130
820bf6e
24fbee3
 
005ad92
 
 
 
a87b16d
f685541
7438734
a87b16d
54a82d6
f685541
521c75f
487a9d5
54a82d6
487a9d5
005ad92
f685541
 
 
 
54a82d6
 
f685541
 
 
 
54a82d6
 
 
f685541
 
 
54a82d6
 
 
552d4cb
 
f242067
552d4cb
 
 
 
f685541
552d4cb
 
 
7fe9b1a
552d4cb
54a82d6
 
f242067
 
54a82d6
f242067
54a82d6
 
f685541
54a82d6
d47d8f8
24fbee3
 
 
 
 
 
 
 
 
 
 
 
 
68128db
24fbee3
 
 
 
 
ac3f130
 
 
24fbee3
ac3f130
 
820bf6e
ac3f130
820bf6e
 
24fbee3
 
 
ac3f130
 
 
24fbee3
820bf6e
 
 
 
24fbee3
f685541
24fbee3
a87b16d
f242067
3b7f36c
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
import numpy as np
from flask import render_template, request
#from functions import *
from functions import SigFigs, Piringer, WilkeChang, SheetRelease, SheetRates, RatePlot

from polymers import Polymers
from ChemID import ResolveChemical
from . import blueprint

import rdkit
from rdkit.Chem import AllChem as Chem

# load polymer data including Ap values
polymers, Ap = Polymers()

# get additional physical properties, options are: logp, rho, mp
#get_properties = [] # don't get any; this breaks ceramics logic
#get_properties = ['logp','rho','mp'] # get all three
get_properties = ['mp'] # only get mp
# show additional physical properties
show_properties = False
# output additional info for physical properties
debug = False

# load the index page for the exposure module
@blueprint.route('/exposure', methods=['GET'])
def exposure():
    return render_template('exposure_index.html', polymers=polymers)


# build the report page for the exposure module
@blueprint.route('/exposure', methods=['POST'])
def exp_post():

    chemName = request.form["chemName"]
    IDtype = request.form["IDtype"]

    if debug:
        iupac, cas, smiles, MW, LogP, LogP_origin, rho, rho_origin, mp, mp_origin, molImage, error = ResolveChemical(chemName, IDtype, debug=debug, get_properties=['logp','rho','mp'])
        LogP_origin, rho_origin, mp_origin = f' ({LogP_origin})', f' ({rho_origin})', f' ({mp_origin})', 
    else:
        LogP_origin, rho_origin, mp_origin = '','',''
        iupac, cas, smiles, MW, LogP, rho, mp, molImage, error = ResolveChemical(chemName, IDtype, get_properties=get_properties)

    if error > 0:
        # TODO output more useful info
        return render_template('chemError.html')

    #MW = SigFigs(MW, 6)
    if 'logp' not in get_properties:
        LogP = 'Not searched'
    elif LogP is np.nan or LogP is None:
        LogP = 'Not found'
    else:
        LogP = SigFigs(LogP, 4)
    if 'rho' not in get_properties:
        rho = 'Not searched'
    elif rho is np.nan or rho is None:
        rho = 'Not found'
    else:
        rho = SigFigs(rho, 4)
    if 'mp' not in get_properties:
        mp = 'Not searched'
    elif mp is np.nan or mp is None:
        mp = 'Not found'

    # metals/ceramics logic
    mol = Chem.MolFromSmiles(smiles)
    natoms = mol.GetNumAtoms()
    ceramic = False
    if natoms == 1 and smiles != '[C]':

        # only one atom, except for carbon -> assumed metal
        # return render_template('chemError.html')
        return render_template('metalError.html', show_properties=show_properties, chemName=chemName, MW=MW, LogP=LogP, rho=rho, mp=mp, iupac=iupac,
                               cas=cas, smiles=smiles, molImage=molImage,
                               LogP_origin=LogP_origin, rho_origin=rho_origin, mp_origin=mp_origin)
    else:
        if (type(mp) is float or type(mp) is int) and mp > 1000.:

            # more than one atom, or carbon -> assumed ceramic
            # TODO say something about what we're doing on report? (e.g. 'detected ceramic, setting MW = 1100')
            # I added something to address this, edit as needed
            # We can perhaps increase the mp limit to 1000 C, just in case
            MW = 1100.
            ceramic = True

    if MW < 100.:
        return render_template('MwError.html', show_properties=show_properties, chemName=chemName, MW=MW, LogP=LogP, rho=rho, mp=mp, iupac=iupac, cas=cas, smiles=smiles, molImage=molImage, 
                               LogP_origin=LogP_origin, rho_origin=rho_origin, mp_origin=mp_origin)

    amount = float(request.form["amount"])
    mass = float(request.form["mass"])
    density = float(request.form["density"])
    vol = mass / density
    polymer = request.form["polymer"]
    pIndex = (np.where(polymers == polymer)[0])[0]
    area = float(request.form["area"])
    exposure = request.form["exposure"]

    if exposure != "limited":
        time = 24.
    else:
        time = float(request.form["exptime"])

    if exposure != "long-term":
        TTC = 0.12
    else:
        TTC = 0.0015

    assume = np.array((request.form.get("assume1") is not None, request.form.get("assume2") is not None,
                      request.form.get("assume3") is not None, request.form.get("assume4") is not None,
                      request.form.get("assume5") is not None))

    if not np.isnan(Ap[pIndex]):
        diff = Piringer(MW, Ap[pIndex])
    else:
        diff = WilkeChang(MW)

    release = SheetRelease(amount, vol, area, time, diff)

    MOS = TTC / release

    release = SigFigs(release, 2)
    MOS = SigFigs(MOS, 2)
    diff = SigFigs(diff, 2)

    # Generate the rate plot using matplotlib
    tarray = np.arange(1., 31., 1.)
    rates = SheetRates(amount, vol, area, tarray, diff)
    pngImageB64String = RatePlot(tarray, rates)

    return render_template('exposure_report.html', show_properties=show_properties, polymers=polymers, pIndex=pIndex, release=release,
                           assume=assume, area=area, vol=vol, amount=amount, diff=diff, time=time, exposure=exposure, TTC=TTC,
                           MOS=MOS, chemName=chemName, image=pngImageB64String, MW=MW, LogP=LogP, rho=rho, mp=mp, iupac=iupac, cas=cas, smiles=smiles, molImage=molImage,
                           LogP_origin=LogP_origin, rho_origin=rho_origin, mp_origin=mp_origin, ceramic=ceramic)