Robert Elder commited on
Commit
a1eff75
·
1 Parent(s): 4f44d79

dealing with ceramics in QRF

Browse files
exposure3_module/exposure.py CHANGED
@@ -3,7 +3,7 @@ import numpy as np
3
  from flask import render_template, request
4
  from functions import SigFigs, Piringer, WilkeChang, SheetRelease, SheetRates, RatePlot
5
  from functions import Piecewise, PowerLaw
6
- from qrf_functions import QRF_Apply
7
  from . import blueprint
8
  from polymers import Polymers, Polymers3
9
  from ChemID import ResolveChemical
@@ -135,8 +135,10 @@ def exp_post():
135
 
136
  if use_qrf:
137
  #print('using qrf', file=sys.stderr)
138
- ## TODO ceramics
139
- diff,domain_extrap = QRF_Apply(density, polytg, smiles, quantiles=[0.03,0.5,0.97])
 
 
140
  diff = diff[2] # upper bound
141
  else:
142
  ## use categories
 
3
  from flask import render_template, request
4
  from functions import SigFigs, Piringer, WilkeChang, SheetRelease, SheetRates, RatePlot
5
  from functions import Piecewise, PowerLaw
6
+ from qrf_functions import QRF_Apply, QRF_Ceramic
7
  from . import blueprint
8
  from polymers import Polymers, Polymers3
9
  from ChemID import ResolveChemical
 
135
 
136
  if use_qrf:
137
  #print('using qrf', file=sys.stderr)
138
+ if ceramic:
139
+ diff,domain_extrap = QRF_Ceramic(density, polytg, quantiles=[0.03,0.5,0.97])
140
+ else:
141
+ diff,domain_extrap = QRF_Apply(density, polytg, smiles, quantiles=[0.03,0.5,0.97])
142
  diff = diff[2] # upper bound
143
  else:
144
  ## use categories
qrf_functions.py CHANGED
@@ -9,6 +9,31 @@ import mordred.descriptors
9
  import rdkit
10
  from rdkit import Chem
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  def QRF_Apply(density, polytg, smiles, quantiles=[0.03,0.5,0.97]):
13
  with open(f'qrf_model_bundle_37.pkl','rb') as f:
14
  reg, imp, scaler_X, sub_desc_list = pickle.load(f)
@@ -39,10 +64,10 @@ def QRF_Apply(density, polytg, smiles, quantiles=[0.03,0.5,0.97]):
39
  D_pred = D_pred[0]
40
  ## domain extrapolation check
41
  df_X = pd.read_excel('qrf_x.xlsx')
42
- X_train = imp.transform(df_X)
43
- X_train_scale = scaler_X.transform(X_train)
44
- dij = QRF_DomainExtrap(reg, X_train_scale, descs_scale)
45
- domain_extrap = dij > 0
46
  return D_pred, domain_extrap
47
 
48
  def QRF_DomainExtrap(estimator, X_train, X_test, D=0.0, return_features=False):
 
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'qrf_model_bundle_37.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')
17
+ X_all = imp.transform(df_X)
18
+ X_all_scale = scaler_X.transform(X_all)
19
+ ## use "worst-case" solute values
20
+ tmpq = np.array([0.95]*len(sub_desc_list))
21
+ tmpq[df_X.corrwith(df_y['LogD'])>0] = 0.05 # positive correlations (increase in variable increases D) use low values of variable, negative correlations use high values of variable
22
+ tmpv = [np.nanquantile(X_all_scale[:,i], q) for i,q in enumerate(tmpq)] # "worst-case" values of scaled descriptors
23
+ tmps = [polytg if n == 'Polymer_Tg' else (density if n == 'Polymer_Density' else 0) for i,n in enumerate(sub_desc_list)]
24
+ tmps = scaler_X.transform([tmps])[0] # scaled values of polymer descriptors
25
+ tmpv = [tmps[i] if n == 'Polymer_Tg' else (tmps[i] if n == 'Polymer_Density' else tmpv[i]) for i,n in enumerate(sub_desc_list)] # merge scaled polymer descriptors with worst-case scaled solute descriptors
26
+ LogD_pred = reg.predict([tmpv], quantiles=quantiles)
27
+ D_pred = 10**LogD_pred
28
+ if len(D_pred.shape)>1:
29
+ # return 1D array regardless of quantiles setting
30
+ D_pred = D_pred[0]
31
+ ## domain extrapolation check
32
+ dij = QRF_DomainExtrap(reg, X_all_scale, np.array([tmpv]))
33
+ domain_extrap = dij[0] > 0
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'qrf_model_bundle_37.pkl','rb') as f:
39
  reg, imp, scaler_X, sub_desc_list = pickle.load(f)
 
64
  D_pred = D_pred[0]
65
  ## domain extrapolation check
66
  df_X = pd.read_excel('qrf_x.xlsx')
67
+ X_all = imp.transform(df_X)
68
+ X_all_scale = scaler_X.transform(X_all)
69
+ dij = QRF_DomainExtrap(reg, X_all_scale, descs_scale)
70
+ domain_extrap = dij[0] > 0
71
  return D_pred, domain_extrap
72
 
73
  def QRF_DomainExtrap(estimator, X_train, X_test, D=0.0, return_features=False):
templates/main.html CHANGED
@@ -62,14 +62,6 @@ This module can be used similarly to the color additive tool, but can be applied
62
  the total amount of the chemical is known, e.g. from a certificate of analysis.
63
  </p>
64
 
65
- &#x2022; <a href="/exposure3"> Bulk chemicals (excluding color additives) RST (v3) </a>
66
-
67
- <p>
68
- This module can be used similarly to the color additive tool, but can be applied to any non-color additive bulk additive or impurity (surface impurities / manufacturing
69
- residuals are excluded) that is present in a polymeric device component provided that the user can justify the chemical is a bulk species and that
70
- the total amount of the chemical is known, e.g. from a certificate of analysis. Updated to address additional polymers.
71
- </p>
72
-
73
  &#x2022; <a href="/efficiency"> Extraction efficiency </a>
74
 
75
  <p>
@@ -78,8 +70,16 @@ This module can be used to estimate the fraction of the total pool or solvent co
78
  extraction conditions depending on the endpoint of interest.
79
  </p>
80
 
81
- <!--
82
- <h2> Modules in development <button type=button class="Info_btn" data-toggle="modal" data-target="#DevModal">&#9432;</button> </h2>-->
 
 
 
 
 
 
 
 
83
 
84
  <!--<h2> Future modules <button type=button class="Info_btn" data-toggle="modal" data-target="#FutureModal">&#9432;</button> </h2>
85
 
 
62
  the total amount of the chemical is known, e.g. from a certificate of analysis.
63
  </p>
64
 
 
 
 
 
 
 
 
 
65
  &#x2022; <a href="/efficiency"> Extraction efficiency </a>
66
 
67
  <p>
 
70
  extraction conditions depending on the endpoint of interest.
71
  </p>
72
 
73
+
74
+ <h2> Modules in development <button type=button class="Info_btn" data-toggle="modal" data-target="#DevModal">&#9432;</button> </h2>
75
+
76
+ &#x2022; <a href="/exposure3"> Bulk chemicals (excluding color additives) (v3) </a>
77
+
78
+ <p>
79
+ This module can be used similarly to the color additive tool, but can be applied to any non-color additive bulk additive or impurity (surface impurities / manufacturing
80
+ residuals are excluded) that is present in a polymeric device component provided that the user can justify the chemical is a bulk species and that
81
+ the total amount of the chemical is known, e.g. from a certificate of analysis. Updated to address additional polymers.
82
+ </p>
83
 
84
  <!--<h2> Future modules <button type=button class="Info_btn" data-toggle="modal" data-target="#FutureModal">&#9432;</button> </h2>
85