dmsaylor commited on
Commit
555e72d
·
1 Parent(s): 394672a

Updated with working version, i.e. it doesn't throw errors

Browse files
color2_module/colors.py CHANGED
@@ -1,9 +1,21 @@
1
  from flask import Flask, render_template, request
2
  import numpy as np
3
- from functions import SigFigs, Piringer, WilkeChang, SheetRelease
4
  from functions import Piecewise, PowerLaw
5
  from . import blueprint
6
  from polymers import Polymers, Polymers2
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  # flag for testing new polymer categories
9
  use_new = True
@@ -16,20 +28,20 @@ else:
16
 
17
  # Named color additives, TI values, and Mw
18
  nCA = 14
19
- caData = np.zeros((nCA,), dtype=[('name', 'a75'), ('TI', 'd'), ('MW', 'd')])
20
- caData[0] = ('Titanium dioxide (CAS#:13463-67-7)', 1.0, 1100.)
21
- caData[1] = ('Carbon black (CAS#:1333-86-4)', 2.0, 1100.)
22
- caData[2] = ('Pigment brown 24 (CAS#:68186-90-3)', 0.5, 1100.)
23
- caData[3] = ('Zinc Oxide (CAS#:1314-13-2)', 0.05, 1100.)
24
- caData[4] = ('Pigment Red 101 (CAS#: 1309-37-1)', 1.0, 1100.)
25
- caData[5] = ('Solvent violet 13 (CAS#:81-48-1)', 0.0013, 319.4)
26
- caData[6] = ('Manganese phthalocyanine (CAS#:14325-24-7)', 0.15, 567.5)
27
- caData[7] = ('Pigment blue 15 (CAS#:147-14-8)', 0.15, 576.1)
28
- caData[8] = ('Phthalocyanine green (CAS#:1326-53-6)', 0.15, 1092.8)
29
- caData[9] = ('Ultramarine blue (CAS#:57445-37-5)', 3.3, 1100.)
30
- caData[10] = ('Pigment Yellow 138 (CAS#:30125-47-4)', 1.0, 693.96)
31
- caData[11] = ('Other color additive', 1.0, 1100.0)
32
- caData[12] = ('Other color additive associated compound', 1.0, 1100.0)
33
 
34
  CAs = np.zeros(nCA, dtype='object')
35
  caMW = np.zeros(nCA, dtype='object')
@@ -49,6 +61,7 @@ def colors():
49
 
50
  @blueprint.route('/color2', methods=['POST'])
51
  def app_post():
 
52
  amount = float(request.form["amount"])
53
  mass = float(request.form["mass"])
54
  density = float(request.form["density"])
@@ -62,31 +75,50 @@ def app_post():
62
 
63
  TI = caData[caIndex][1]
64
  impurity = 1.
65
- MW = 1100.
66
  isCA = True
67
  chemName = ''
68
 
69
- if caIndex < 11:
70
- MW = caData[caIndex][2]
71
- chemName = '*' + caData[caIndex][0].decode('UTF-8') + '*'
72
  impurity = float(request.form["impurity"]) * amount * 1e-2
73
- if caIndex == 11:
74
- MW = caData[caIndex][2]
75
- chemName = request.form["chemName"] if "chemName" in request.form else "CHEMICAL NAME NOT PROVIDED"
76
- chemName = '*' + chemName + '*'
77
  impurity = float(request.form["impurity"]) * amount * 1e-2
78
  if caIndex == 12:
79
- MW = float(request.form["MW"])
80
- chemName = request.form["chemName"] if "chemName" in request.form else "CHEMICAL NAME NOT PROVIDED"
81
- chemName = '*' + chemName + '*'
82
- impurity = float(request.form["impurity"]) * amount * 1e-2
83
- if caIndex == 13:
84
  isCA = False
85
- MW = float(request.form["MW"])
86
- chemName = request.form["chemName"] if "chemName" in request.form else "CHEMICAL NAME NOT PROVIDED"
87
- chemName = '*' + chemName + '*'
88
- impurity = float(request.form["impurity"]) * amount * 1e-2
89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  if exposure != "limited":
91
  time = 24.
92
  else:
@@ -124,9 +156,13 @@ def app_post():
124
  iMOS = SigFigs(iMOS, 2)
125
  impurity = SigFigs(impurity, 2)
126
 
127
- return render_template('color2_report.html', polymers=polymers, pIndex=pIndex, caIndex=caIndex, release=release,
128
- assume=assume,
129
- area=area, vol=vol, amount=amount, diff=diff, time=time, exposure=exposure, TTC=TTC,
130
- isCA=isCA, TI=TI, MOS=MOS,
131
- chemName=chemName, impurity=impurity, iMOS=iMOS)
 
 
 
 
132
 
 
1
  from flask import Flask, render_template, request
2
  import numpy as np
3
+ from functions import SigFigs, Piringer, WilkeChang, SheetRelease, SheetRates, RatePlot
4
  from functions import Piecewise, PowerLaw
5
  from . import blueprint
6
  from polymers import Polymers, Polymers2
7
+ from ChemID import ResolveChemical
8
+ import rdkit
9
+ from rdkit.Chem import AllChem as Chem
10
+
11
+ # get additional physical properties, options are: logp, rho, mp
12
+ #get_properties = [] # don't get any; this breaks ceramics logic
13
+ #get_properties = ['logp','rho','mp'] # get all three
14
+ get_properties = ['mp'] # only get mp
15
+ # show additional physical properties
16
+ show_properties = False
17
+ # output additional info for physical properties
18
+ debug = False
19
 
20
  # flag for testing new polymer categories
21
  use_new = True
 
28
 
29
  # Named color additives, TI values, and Mw
30
  nCA = 14
31
+ caData = np.zeros((nCA,), dtype=[('name', 'a75'), ('TI', 'd'), ('MW', 'd'),('CAS', 'a75')])
32
+ caData[0] = ('Titanium dioxide (CAS#:13463-67-7)', 1.0, 1100., '13463-67-7')
33
+ caData[1] = ('Carbon black (CAS#:1333-86-4)', 2.0, 1100., '1333-86-4')
34
+ caData[2] = ('Pigment brown 24 (CAS#:68186-90-3)', 0.5, 1100., '68186-90-3')
35
+ caData[3] = ('Zinc Oxide (CAS#:1314-13-2)', 0.05, 1100., '1314-13-2')
36
+ caData[4] = ('Pigment Red 101 (CAS#: 1309-37-1)', 1.0, 1100., '1309-37-1')
37
+ caData[5] = ('Solvent violet 13 (CAS#:81-48-1)', 0.0013, 319.4, '81-48-1')
38
+ caData[6] = ('Manganese phthalocyanine (CAS#:14325-24-7)', 0.15, 567.5, '14325-24-7')
39
+ caData[7] = ('Pigment blue 15 (CAS#:147-14-8)', 0.15, 576.1, '147-14-8')
40
+ caData[8] = ('Phthalocyanine green (CAS#:1326-53-6)', 0.15, 1092.8, '1326-53-6')
41
+ caData[9] = ('Ultramarine blue (CAS#:57445-37-5)', 3.3, 1100., '57445-37-5')
42
+ caData[10] = ('Pigment Yellow 138 (CAS#:30125-47-4)', 1.0, 693.96, '30125-47-4')
43
+ caData[11] = ('Other color additive', 1.0, 1100.0, ' ')
44
+ caData[12] = ('Other color additive associated compound', 1.0, 1100.0, ' ')
45
 
46
  CAs = np.zeros(nCA, dtype='object')
47
  caMW = np.zeros(nCA, dtype='object')
 
61
 
62
  @blueprint.route('/color2', methods=['POST'])
63
  def app_post():
64
+
65
  amount = float(request.form["amount"])
66
  mass = float(request.form["mass"])
67
  density = float(request.form["density"])
 
75
 
76
  TI = caData[caIndex][1]
77
  impurity = 1.
 
78
  isCA = True
79
  chemName = ''
80
 
81
+ if caIndex <= 10:
82
+ IDtype = "CAS"
83
+ chemName = caData[caIndex][3].decode('UTF-8')
84
  impurity = float(request.form["impurity"]) * amount * 1e-2
85
+ if caIndex > 10:
86
+ chemName = request.form["chemName"]
87
+ IDtype = request.form["IDtype"]
 
88
  impurity = float(request.form["impurity"]) * amount * 1e-2
89
  if caIndex == 12:
 
 
 
 
 
90
  isCA = False
 
 
 
 
91
 
92
+ print(chemName)
93
+ iupac, cas, smiles, MW, LogP, rho, mp, molImage, error = ResolveChemical(chemName, IDtype,
94
+ get_properties=get_properties)
95
+
96
+ if error > 0:
97
+ # TODO output more useful info
98
+ return render_template('chemError.html')
99
+
100
+ # metals/ceramics logic
101
+ mol = Chem.MolFromSmiles(smiles)
102
+ natoms = mol.GetNumAtoms()
103
+ ceramic = False
104
+ if natoms == 1 and smiles != '[C]':
105
+
106
+ # only one atom, except for carbon -> assumed metal
107
+ # return render_template('chemError.html')
108
+ return render_template('metalError.html', show_properties=show_properties, chemName=chemName, MW=MW,
109
+ LogP=LogP, rho=rho, mp=mp, iupac=iupac,
110
+ cas=cas, smiles=smiles, molImage=molImage,
111
+ LogP_origin=LogP_origin, rho_origin=rho_origin, mp_origin=mp_origin)
112
+ else:
113
+ if (type(mp) is float or type(mp) is int) and mp > 1000.:
114
+ # more than one atom, or carbon -> assumed ceramic
115
+ # TODO say something about what we're doing on report? (e.g. 'detected ceramic, setting MW = 1100')
116
+ # I added something to address this, edit as needed
117
+ # We can perhaps increase the mp limit to 1000 C, just in case
118
+ MW = 1100.
119
+ ceramic = True
120
+
121
+ # Exposure type
122
  if exposure != "limited":
123
  time = 24.
124
  else:
 
156
  iMOS = SigFigs(iMOS, 2)
157
  impurity = SigFigs(impurity, 2)
158
 
159
+ # Generate the rate plot using matplotlib
160
+ tarray = np.arange(1., 31., 1.)
161
+ rates = SheetRates(amount, vol, area, tarray, diff)
162
+ pngImageB64String = RatePlot(tarray, rates)
163
+
164
+ return render_template('color2_report.html', caIndex=caIndex, TI=TI, show_properties=show_properties, polymers=polymers, pIndex=pIndex, release=release,
165
+ assume=assume, area=area, vol=vol, amount=amount, diff=diff, time=time, exposure=exposure, TTC=TTC,
166
+ MOS=MOS, chemName=chemName, image=pngImageB64String, MW=MW, LogP=LogP, rho=rho, mp=mp, iupac=iupac, cas=cas, smiles=smiles, molImage=molImage,
167
+ ceramic=ceramic, impurity=impurity, iMOS=iMOS)
168
 
color2_module/templates/color2_index.html CHANGED
@@ -76,8 +76,10 @@ $(window).on('pageshow', function() { caCheck(); });
76
  <h4 class="modal-title">Color additive</h4>
77
  </div>
78
  <div class="modal-body">
79
- <p><em>Identity</em> - Select the color additive in the component being evaluated via the pull down list. If the color additive is not explicitly listed, please choose either "Other metal oxide color additive" or "Other non-metal oxide color additive" and enter the chemical name, including CAS # if known. If "Other non-metal oxide color additive" is selected, please enter the molecular weight of the color additive in grams per mole. If you are evaluating an additive associated with a color additive please select "Other color additive associated compound" and enter the chemical name and molecular weight. Note that CHRIS is limited to color additive associated substances with molecular weight up to 1100 g/mol. For compounds with molecular weight > 1100 g/mol, this value can be used for a conservative exposure estimate.
80
- <p><em>Molecular weight</em> - Enter the molecular weight of the substance in grams per mole.</p>
 
 
81
  <p><em>Amount</em> - Enter the total mass of the substance in the component being evaluated expressed in milligrams.</p>
82
  <p><em>Total impurity concentration</em> - If you have selected a color additive, please enter the combined concentration of all impurities associated with the color additive as a percentage (% mass/mass).</p>
83
  </div>
 
76
  <h4 class="modal-title">Color additive</h4>
77
  </div>
78
  <div class="modal-body">
79
+ <p><em>Identity</em> - Select the color additive in the component being evaluated via the pull down list.
80
+ If the color additive is not explicitly listed, please choose "Other color additive" and ...
81
+ If you are evaluating an additive associated with a color additive please select "Other color additive associated compound" and
82
+ enter the chemical name and molecular weight ...
83
  <p><em>Amount</em> - Enter the total mass of the substance in the component being evaluated expressed in milligrams.</p>
84
  <p><em>Total impurity concentration</em> - If you have selected a color additive, please enter the combined concentration of all impurities associated with the color additive as a percentage (% mass/mass).</p>
85
  </div>