Robert Elder commited on
Commit ·
aae0aac
1
Parent(s): e33154d
fixing quantity module errors
Browse files- color3_module/templates/color3_index.html +3 -1
- exposure3_module/templates/exposure3_index.html +3 -1
- qrf_functions.py +4 -4
- qrf_train.py +1 -1
- quantity_functions.py +29 -23
- quantity_module/quantity.py +19 -9
- quantity_module/templates/quantity_index.html +3 -1
- quantity_module/templates/quantity_report.html +2 -2
color3_module/templates/color3_index.html
CHANGED
|
@@ -24,7 +24,9 @@
|
|
| 24 |
|
| 25 |
<p> For details on how to use the CHRIS color additive module, please click the information icons next to each section header and read the
|
| 26 |
<a href="{{url_for('.static', filename='COU.html')}}"> Context of Use (CoU)</a>, which includes limitations of use. Answers to frequently asked questions can be
|
| 27 |
-
found <a href="{{url_for('.static', filename='FAQ.html')}}"> here</a>. For a history of updates, please see the <a href="{{url_for('.static', filename='Changelog.html')}}"> changelog</a>.
|
|
|
|
|
|
|
| 28 |
|
| 29 |
<body>
|
| 30 |
|
|
|
|
| 24 |
|
| 25 |
<p> For details on how to use the CHRIS color additive module, please click the information icons next to each section header and read the
|
| 26 |
<a href="{{url_for('.static', filename='COU.html')}}"> Context of Use (CoU)</a>, which includes limitations of use. Answers to frequently asked questions can be
|
| 27 |
+
found <a href="{{url_for('.static', filename='FAQ.html')}}"> here</a>. For a history of updates, please see the <a href="{{url_for('.static', filename='Changelog.html')}}"> changelog</a>.
|
| 28 |
+
<!--For reference and disclaimer information, please see the <a href="{{url_for('.static', filename='RST.html')}}"> RST information</a> page.-->
|
| 29 |
+
</p>
|
| 30 |
|
| 31 |
<body>
|
| 32 |
|
exposure3_module/templates/exposure3_index.html
CHANGED
|
@@ -26,7 +26,9 @@
|
|
| 26 |
|
| 27 |
<p> For details on how to use the CHRIS bulk chemical module, please click the information icons next to each section header and read the
|
| 28 |
<a href="{{url_for('.static', filename='exposure_COU.html')}}"> context of use (COU)</a>, which includes limitations of use.
|
| 29 |
-
For a history of updates, please see the <a href="{{url_for('.static', filename='Changelog.html')}}"> changelog</a>.
|
|
|
|
|
|
|
| 30 |
|
| 31 |
<body>
|
| 32 |
|
|
|
|
| 26 |
|
| 27 |
<p> For details on how to use the CHRIS bulk chemical module, please click the information icons next to each section header and read the
|
| 28 |
<a href="{{url_for('.static', filename='exposure_COU.html')}}"> context of use (COU)</a>, which includes limitations of use.
|
| 29 |
+
For a history of updates, please see the <a href="{{url_for('.static', filename='Changelog.html')}}"> changelog</a>.
|
| 30 |
+
<!--For reference and disclaimer information, please see the <a href="{{url_for('.static', filename='RST.html')}}"> RST information</a> page.-->
|
| 31 |
+
</p>
|
| 32 |
|
| 33 |
<body>
|
| 34 |
|
qrf_functions.py
CHANGED
|
@@ -9,8 +9,8 @@ import mordred.descriptors
|
|
| 9 |
import rdkit
|
| 10 |
from rdkit import Chem
|
| 11 |
|
| 12 |
-
def QRF_Ceramic(density, polytg, quantiles=[0.03,0.5,0.97]):
|
| 13 |
-
with open(f'
|
| 14 |
reg, imp, scaler_X, sub_desc_list = pickle.load(f)
|
| 15 |
df_X = pd.read_excel('qrf_x.xlsx')
|
| 16 |
df_y = pd.read_excel('qrf_y.xlsx')
|
|
@@ -34,8 +34,8 @@ def QRF_Ceramic(density, polytg, quantiles=[0.03,0.5,0.97]):
|
|
| 34 |
return D_pred, domain_extrap
|
| 35 |
|
| 36 |
|
| 37 |
-
def QRF_Apply(density, polytg, smiles, quantiles=[0.03,0.5,0.97]):
|
| 38 |
-
with open(f'
|
| 39 |
reg, imp, scaler_X, sub_desc_list = pickle.load(f)
|
| 40 |
# get list of descriptors to calculate
|
| 41 |
solute_desc_list = sub_desc_list.copy()
|
|
|
|
| 9 |
import rdkit
|
| 10 |
from rdkit import Chem
|
| 11 |
|
| 12 |
+
def QRF_Ceramic(density, polytg, quantiles=[0.03,0.5,0.97], T=37):
|
| 13 |
+
with open(f'qrf_model_bundle_{int(T)}.pkl','rb') as f:
|
| 14 |
reg, imp, scaler_X, sub_desc_list = pickle.load(f)
|
| 15 |
df_X = pd.read_excel('qrf_x.xlsx')
|
| 16 |
df_y = pd.read_excel('qrf_y.xlsx')
|
|
|
|
| 34 |
return D_pred, domain_extrap
|
| 35 |
|
| 36 |
|
| 37 |
+
def QRF_Apply(density, polytg, smiles, quantiles=[0.03,0.5,0.97], T=37):
|
| 38 |
+
with open(f'qrf_model_bundle_{int(T)}.pkl','rb') as f:
|
| 39 |
reg, imp, scaler_X, sub_desc_list = pickle.load(f)
|
| 40 |
# get list of descriptors to calculate
|
| 41 |
solute_desc_list = sub_desc_list.copy()
|
qrf_train.py
CHANGED
|
@@ -5,7 +5,7 @@ import sklearn
|
|
| 5 |
import sklearn.impute
|
| 6 |
from quantile_forest import RandomForestQuantileRegressor
|
| 7 |
|
| 8 |
-
T_target =
|
| 9 |
T_cut = 5
|
| 10 |
qhiv, qlov = 0.97, 0.03
|
| 11 |
state = 12345
|
|
|
|
| 5 |
import sklearn.impute
|
| 6 |
from quantile_forest import RandomForestQuantileRegressor
|
| 7 |
|
| 8 |
+
T_target = 50
|
| 9 |
T_cut = 5
|
| 10 |
qhiv, qlov = 0.97, 0.03
|
| 11 |
state = 12345
|
quantity_functions.py
CHANGED
|
@@ -200,7 +200,7 @@ def get_c_dist(T,Tg,MW):
|
|
| 200 |
cs = cs[cs>0]
|
| 201 |
return cs
|
| 202 |
|
| 203 |
-
def get_D_dists(w,T,Polymer_Tg,Solvent_Name,Solvent_MW,Solute_MW,CHRIS_category,rng,N=100000,return_DCs=False):
|
| 204 |
"""
|
| 205 |
D_dist_noswell, D_dist_swell, (c, Ds, DWCs, DCs) = get_D_dists(Swelling_wtfrac,T,Polymer_Tg,Solvent_Name,Solvent_MW,Solute_MW,CHRIS_category,return_DCs=True,N=N)
|
| 206 |
"""
|
|
@@ -230,33 +230,39 @@ def get_D_dists(w,T,Polymer_Tg,Solvent_Name,Solvent_MW,Solute_MW,CHRIS_category,
|
|
| 230 |
lnD_D0 = c*w/(1+(c-1)*w) * np.log(DWCs/Ds)
|
| 231 |
## distribution of D_CHRIS
|
| 232 |
if not use_new:
|
| 233 |
-
if
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
A_list = params[1:]
|
| 239 |
-
D_list = [Piringer(Solute_MW, Ai, T) for Ai in A_list]
|
| 240 |
-
else:
|
| 241 |
-
Ball = params[1]
|
| 242 |
-
A_list = params[2:]
|
| 243 |
-
D_list = np.exp([PowerLaw(Solute_MW, Ai, Ball) for Ai in A_list])
|
| 244 |
-
else:
|
| 245 |
-
if Solute_MW > 50:
|
| 246 |
-
subkey = f'{CHRIS_category}_hi'
|
| 247 |
-
else:
|
| 248 |
-
subkey = f'{CHRIS_category}_lo'
|
| 249 |
-
allparams = [param_dists[Ti][subkey] for Ti in param_dists if T+T_cut_new >= int(Ti)+273.15 >= T-T_cut_new]
|
| 250 |
-
#allparams = [param_dists[Ti][subkey] for Ti in param_dists if T+T_cut_new > int(Ti)+273.15 > T-T_cut_new]
|
| 251 |
-
D_list = []
|
| 252 |
-
for params in allparams:
|
| 253 |
if params[0] == 'pir':
|
| 254 |
A_list = params[1:]
|
| 255 |
-
D_list
|
| 256 |
else:
|
| 257 |
Ball = params[1]
|
| 258 |
A_list = params[2:]
|
| 259 |
-
D_list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
D_dist_noswell = rng.choice(D_list, N)
|
| 261 |
D_dist_swell = np.exp(np.log(D_dist_noswell)+lnD_D0)
|
| 262 |
if return_DCs:
|
|
|
|
| 200 |
cs = cs[cs>0]
|
| 201 |
return cs
|
| 202 |
|
| 203 |
+
def get_D_dists(w,T,Polymer_Tg,Solvent_Name,Solvent_MW,Solute_MW,CHRIS_category,rng,N=100000,return_DCs=False,input_Ds=None):
|
| 204 |
"""
|
| 205 |
D_dist_noswell, D_dist_swell, (c, Ds, DWCs, DCs) = get_D_dists(Swelling_wtfrac,T,Polymer_Tg,Solvent_Name,Solvent_MW,Solute_MW,CHRIS_category,return_DCs=True,N=N)
|
| 206 |
"""
|
|
|
|
| 230 |
lnD_D0 = c*w/(1+(c-1)*w) * np.log(DWCs/Ds)
|
| 231 |
## distribution of D_CHRIS
|
| 232 |
if not use_new:
|
| 233 |
+
if input_Ds is None:
|
| 234 |
+
if Solute_MW > 50:
|
| 235 |
+
params = param_dists[T-273.15][f'{CHRIS_category}_hi']
|
| 236 |
+
else:
|
| 237 |
+
params = param_dists[T-273.15][f'{CHRIS_category}_lo']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
if params[0] == 'pir':
|
| 239 |
A_list = params[1:]
|
| 240 |
+
D_list = [Piringer(Solute_MW, Ai, T) for Ai in A_list]
|
| 241 |
else:
|
| 242 |
Ball = params[1]
|
| 243 |
A_list = params[2:]
|
| 244 |
+
D_list = np.exp([PowerLaw(Solute_MW, Ai, Ball) for Ai in A_list])
|
| 245 |
+
else:
|
| 246 |
+
D_list = input_Ds
|
| 247 |
+
else:
|
| 248 |
+
if input_Ds is None:
|
| 249 |
+
if Solute_MW > 50:
|
| 250 |
+
subkey = f'{CHRIS_category}_hi'
|
| 251 |
+
else:
|
| 252 |
+
subkey = f'{CHRIS_category}_lo'
|
| 253 |
+
allparams = [param_dists[Ti][subkey] for Ti in param_dists if T+T_cut_new >= int(Ti)+273.15 >= T-T_cut_new]
|
| 254 |
+
#allparams = [param_dists[Ti][subkey] for Ti in param_dists if T+T_cut_new > int(Ti)+273.15 > T-T_cut_new]
|
| 255 |
+
D_list = []
|
| 256 |
+
for params in allparams:
|
| 257 |
+
if params[0] == 'pir':
|
| 258 |
+
A_list = params[1:]
|
| 259 |
+
D_list += [Piringer(Solute_MW, Ai, T) for Ai in A_list]
|
| 260 |
+
else:
|
| 261 |
+
Ball = params[1]
|
| 262 |
+
A_list = params[2:]
|
| 263 |
+
D_list += list(np.exp([PowerLaw(Solute_MW, Ai, Ball) for Ai in A_list]))
|
| 264 |
+
else:
|
| 265 |
+
D_list = input_Ds
|
| 266 |
D_dist_noswell = rng.choice(D_list, N)
|
| 267 |
D_dist_swell = np.exp(np.log(D_dist_noswell)+lnD_D0)
|
| 268 |
if return_DCs:
|
quantity_module/quantity.py
CHANGED
|
@@ -36,6 +36,7 @@ def exp_post():
|
|
| 36 |
|
| 37 |
Polymer_Tg = float(request.form['Polymer_Tg']) ## NOTE Tg is provided in C
|
| 38 |
T = float(request.form['T'])
|
|
|
|
| 39 |
|
| 40 |
if T<Polymer_Tg:
|
| 41 |
return render_template('quantity_temperatureError.html')
|
|
@@ -107,23 +108,32 @@ def exp_post():
|
|
| 107 |
if polymer == 'Other polymer':
|
| 108 |
use_qrf = True
|
| 109 |
|
| 110 |
-
|
| 111 |
-
if use_qrf and False:
|
| 112 |
method = 'qrf'
|
|
|
|
| 113 |
if is_ceramic:
|
| 114 |
-
diff,domain_extrap = QRF_Ceramic(PolymerDensity, Polymer_Tg, quantiles=
|
| 115 |
else:
|
| 116 |
-
diff,domain_extrap = QRF_Apply(PolymerDensity, Polymer_Tg, smiles, quantiles=
|
| 117 |
-
diff = diff[2] # upper bound
|
| 118 |
if domain_extrap:
|
| 119 |
# outside training domain, default to Wilke-Chang
|
| 120 |
-
diff = Piecewise(MW, params[None])
|
|
|
|
|
|
|
| 121 |
method = 'qrf/wc'
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
else:
|
| 123 |
## use categories
|
| 124 |
-
## TODO what is the correct worst-case for a generic polymer? G2?
|
| 125 |
CHRIS_category = categories[pIndex]
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
D_dist_noswell, D_dist_swell = get_D_dists(Swelling_wtfrac, T+273.15, Polymer_Tg+273.15, SolventName, SolventMW, SoluteMW, CHRIS_category, rng, return_DCs=False, N=N_sample)
|
| 128 |
M0_pred = get_M_dist(D_dist_swell, M_expt, PolymerVolume, SurfaceArea, SolventVolume, ExtractionTime*3600, K_expt=K_expt)
|
| 129 |
if 0:
|
|
@@ -133,7 +143,7 @@ def exp_post():
|
|
| 133 |
print('M_expt, PolymerVolume, SurfaceArea, SolventVolume, ExtractionTime*3600, K_expt')
|
| 134 |
print(M_expt, PolymerVolume, SurfaceArea, SolventVolume, ExtractionTime*3600, K_expt)
|
| 135 |
print(np.nanquantile(M0_pred, [0.05,0.5,0.95]))
|
| 136 |
-
if
|
| 137 |
method = 'category'
|
| 138 |
else:
|
| 139 |
method = 'wc'
|
|
|
|
| 36 |
|
| 37 |
Polymer_Tg = float(request.form['Polymer_Tg']) ## NOTE Tg is provided in C
|
| 38 |
T = float(request.form['T'])
|
| 39 |
+
rng = np.random.Generator(np.random.PCG64(seed=12345))
|
| 40 |
|
| 41 |
if T<Polymer_Tg:
|
| 42 |
return render_template('quantity_temperatureError.html')
|
|
|
|
| 108 |
if polymer == 'Other polymer':
|
| 109 |
use_qrf = True
|
| 110 |
|
| 111 |
+
if use_qrf:
|
|
|
|
| 112 |
method = 'qrf'
|
| 113 |
+
quantiles = list(np.linspace(0,1,101))
|
| 114 |
if is_ceramic:
|
| 115 |
+
diff,domain_extrap = QRF_Ceramic(PolymerDensity, Polymer_Tg, quantiles=quantiles, T=T)
|
| 116 |
else:
|
| 117 |
+
diff,domain_extrap = QRF_Apply(PolymerDensity, Polymer_Tg, smiles, quantiles=quantiles, T=T)
|
| 118 |
+
#diff = diff[2] # upper bound
|
| 119 |
if domain_extrap:
|
| 120 |
# outside training domain, default to Wilke-Chang
|
| 121 |
+
#diff = Piecewise(MW, params[None])
|
| 122 |
+
D_dist_noswell, D_dist_swell = get_D_dists(Swelling_wtfrac, T+273.15, Polymer_Tg+273.15, SolventName, SolventMW, SoluteMW, 'G2', rng, return_DCs=False, N=N_sample)
|
| 123 |
+
M0_pred = get_M_dist(D_dist_swell, M_expt, PolymerVolume, SurfaceArea, SolventVolume, ExtractionTime*3600, K_expt=K_expt)
|
| 124 |
method = 'qrf/wc'
|
| 125 |
+
else:
|
| 126 |
+
## TODO implement total quantity prediction with QRF
|
| 127 |
+
D_dist_noswell, D_dist_swell = get_D_dists(Swelling_wtfrac, T+273.15, Polymer_Tg+273.15, SolventName, SolventMW, SoluteMW, 'G2', rng, return_DCs=False, N=N_sample, input_Ds=diff)
|
| 128 |
+
M0_pred = get_M_dist(D_dist_swell, M_expt, PolymerVolume, SurfaceArea, SolventVolume, ExtractionTime*3600, K_expt=K_expt)
|
| 129 |
else:
|
| 130 |
## use categories
|
|
|
|
| 131 |
CHRIS_category = categories[pIndex]
|
| 132 |
+
CHRIS_flag = None
|
| 133 |
+
if CHRIS_category is None:
|
| 134 |
+
## worst-case for a generic polymer --> G2
|
| 135 |
+
CHRIS_flag = 'wc'
|
| 136 |
+
CHRIS_category = 'G2'
|
| 137 |
D_dist_noswell, D_dist_swell = get_D_dists(Swelling_wtfrac, T+273.15, Polymer_Tg+273.15, SolventName, SolventMW, SoluteMW, CHRIS_category, rng, return_DCs=False, N=N_sample)
|
| 138 |
M0_pred = get_M_dist(D_dist_swell, M_expt, PolymerVolume, SurfaceArea, SolventVolume, ExtractionTime*3600, K_expt=K_expt)
|
| 139 |
if 0:
|
|
|
|
| 143 |
print('M_expt, PolymerVolume, SurfaceArea, SolventVolume, ExtractionTime*3600, K_expt')
|
| 144 |
print(M_expt, PolymerVolume, SurfaceArea, SolventVolume, ExtractionTime*3600, K_expt)
|
| 145 |
print(np.nanquantile(M0_pred, [0.05,0.5,0.95]))
|
| 146 |
+
if CHRIS_flag is None:
|
| 147 |
method = 'category'
|
| 148 |
else:
|
| 149 |
method = 'wc'
|
quantity_module/templates/quantity_index.html
CHANGED
|
@@ -29,7 +29,9 @@
|
|
| 29 |
|
| 30 |
<p> For details on how to use the CHRIS total quantity module, please click the information icons next to each section header and read the
|
| 31 |
<a href="{{url_for('.static', filename='exposure_COU.html')}}"> context of use (COU)</a>, which includes limitations of use.
|
| 32 |
-
For a history of updates, please see the <a href="{{url_for('.static', filename='Changelog.html')}}"> changelog</a>. <
|
|
|
|
|
|
|
| 33 |
|
| 34 |
<body>
|
| 35 |
|
|
|
|
| 29 |
|
| 30 |
<p> For details on how to use the CHRIS total quantity module, please click the information icons next to each section header and read the
|
| 31 |
<a href="{{url_for('.static', filename='exposure_COU.html')}}"> context of use (COU)</a>, which includes limitations of use.
|
| 32 |
+
For a history of updates, please see the <a href="{{url_for('.static', filename='Changelog.html')}}"> changelog</a>. <!--For reference and disclaimer information,
|
| 33 |
+
please see the <a href="{{url_for('.static', filename='RST.html')}}"> RST information</a> page.-->
|
| 34 |
+
</p>
|
| 35 |
|
| 36 |
<body>
|
| 37 |
|
quantity_module/templates/quantity_report.html
CHANGED
|
@@ -77,11 +77,11 @@
|
|
| 77 |
{% if methods[0]=="category" %}
|
| 78 |
<u> Modeling extraction from {{polymers[pIndex]}} estimates the total quantity = {{M0}} {{units}}. </u>
|
| 79 |
{% elif methods[0]=="wc" %}
|
| 80 |
-
<u> Modeling extraction from the polymer (with worst-case diffusion in
|
| 81 |
{% elif methods[0]=="qrf" %}
|
| 82 |
<u> Modeling extraction from the polymer (with density = {{methods[2]}} g/cm<sup>3</sup> and T<sub>g</sub> = {{methods[1]}} °C) estimates the total quantity = {{M0}} {{units}}. </u>
|
| 83 |
{% elif methods[0]=="qrf/wc" %}
|
| 84 |
-
<u> Modeling extraction from the polymer (with worst-case diffusion in
|
| 85 |
{% endif %}
|
| 86 |
<p>
|
| 87 |
|
|
|
|
| 77 |
{% if methods[0]=="category" %}
|
| 78 |
<u> Modeling extraction from {{polymers[pIndex]}} estimates the total quantity = {{M0}} {{units}}. </u>
|
| 79 |
{% elif methods[0]=="wc" %}
|
| 80 |
+
<u> Modeling extraction from the polymer (with worst-case diffusion in a glassy polymer assumed) estimates the total quantity = {{M0}} {{units}}. </u>
|
| 81 |
{% elif methods[0]=="qrf" %}
|
| 82 |
<u> Modeling extraction from the polymer (with density = {{methods[2]}} g/cm<sup>3</sup> and T<sub>g</sub> = {{methods[1]}} °C) estimates the total quantity = {{M0}} {{units}}. </u>
|
| 83 |
{% elif methods[0]=="qrf/wc" %}
|
| 84 |
+
<u> Modeling extraction from the polymer (with worst-case diffusion in a glassy polymer assumed because this system is outside the model training domain) estimates the total quantity = {{M0}} {{units}}. </u>
|
| 85 |
{% endif %}
|
| 86 |
<p>
|
| 87 |
|