David Saylor commited on
Commit ·
c0c5fff
1
Parent(s): 5679508
new branch with chem id functionality started
Browse files- CHRIS.py +1 -1
- ChemID.py +59 -0
- exposure_module/exposure.py +10 -3
- exposure_module/templates/exposure_index.html +30 -25
- exposure_module/templates/exposure_report.html +7 -2
- functions.py +2 -1
CHRIS.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
from flask import Flask, render_template
|
| 2 |
|
| 3 |
app = Flask(__name__)
|
| 4 |
-
app.debug =
|
| 5 |
|
| 6 |
from color_module import blueprint
|
| 7 |
app.register_blueprint(blueprint)
|
|
|
|
| 1 |
from flask import Flask, render_template
|
| 2 |
|
| 3 |
app = Flask(__name__)
|
| 4 |
+
app.debug = True
|
| 5 |
|
| 6 |
from color_module import blueprint
|
| 7 |
app.register_blueprint(blueprint)
|
ChemID.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys,os,glob,re,string
|
| 2 |
+
import nltk
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import numpy as np
|
| 5 |
+
import pubchempy as pcp
|
| 6 |
+
import cirpy
|
| 7 |
+
import chemicals
|
| 8 |
+
|
| 9 |
+
import rdkit
|
| 10 |
+
from rdkit.Chem import AllChem as Chem
|
| 11 |
+
from rdkit.Chem import Descriptors,Descriptors3D
|
| 12 |
+
|
| 13 |
+
def ResolveChemical(chemName, IDtype):
|
| 14 |
+
|
| 15 |
+
if IDtype == 'CAS':
|
| 16 |
+
smiles = cas2smiles(chemName)
|
| 17 |
+
mol = Chem.MolFromSmiles(smiles)
|
| 18 |
+
Mw = Descriptors.MolWt(mol)
|
| 19 |
+
|
| 20 |
+
return (smiles, Mw, mol)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# function to convert CAS to SMILES
|
| 24 |
+
def cas2smiles(cas):
|
| 25 |
+
smiles = None
|
| 26 |
+
# first try chemicals package
|
| 27 |
+
try:
|
| 28 |
+
cm = chemicals.search_chemical(cas)
|
| 29 |
+
smiles = cm.smiles
|
| 30 |
+
except:
|
| 31 |
+
smiles = None
|
| 32 |
+
# then try pubchem for compounds
|
| 33 |
+
if not smiles:
|
| 34 |
+
try:
|
| 35 |
+
compounds = pcp.get_compounds(cas, namespace='name')
|
| 36 |
+
c = compounds[0]
|
| 37 |
+
smiles = c.isomeric_smiles
|
| 38 |
+
except:
|
| 39 |
+
smiles = None
|
| 40 |
+
# next try cirpy
|
| 41 |
+
if not smiles:
|
| 42 |
+
try:
|
| 43 |
+
smiles = cirpy.resolve(cas, 'smiles')
|
| 44 |
+
except:
|
| 45 |
+
smiles = None
|
| 46 |
+
if type(smiles) is list:
|
| 47 |
+
smiles = smiles[0]
|
| 48 |
+
# finally try it as a pubchem substance
|
| 49 |
+
if not smiles:
|
| 50 |
+
try:
|
| 51 |
+
compounds = pcp.get_substances(cas, namespace='name')
|
| 52 |
+
# sometimes there are multiple substances, and multiple synonyms per substance
|
| 53 |
+
allsyns = [syn for c in compounds for syn in c.isomeric_smiles if cas not in syn]
|
| 54 |
+
# choose the most common synonym
|
| 55 |
+
fd = nltk.FreqDist(allsyns)
|
| 56 |
+
smiles = fd.most_common(1)[0][0]
|
| 57 |
+
except:
|
| 58 |
+
smiles = None
|
| 59 |
+
return smiles
|
exposure_module/exposure.py
CHANGED
|
@@ -3,6 +3,7 @@ from flask import render_template, request
|
|
| 3 |
from functions import SigFigs, Piringer, WilkeChang, SheetRelease, SheetRates, RatePlot
|
| 4 |
from . import blueprint
|
| 5 |
from polymers import Polymers
|
|
|
|
| 6 |
|
| 7 |
# load polymer data including Ap values
|
| 8 |
polymers, Ap = Polymers()
|
|
@@ -16,6 +17,13 @@ def exposure():
|
|
| 16 |
# build the report page for the exposure module
|
| 17 |
@blueprint.route('/exposure', methods=['POST'])
|
| 18 |
def exp_post():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
amount = float(request.form["amount"])
|
| 20 |
mass = float(request.form["mass"])
|
| 21 |
density = float(request.form["density"])
|
|
@@ -24,8 +32,6 @@ def exp_post():
|
|
| 24 |
pIndex = (np.where(polymers == polymer)[0])[0]
|
| 25 |
area = float(request.form["area"])
|
| 26 |
exposure = request.form["exposure"]
|
| 27 |
-
MW = float(request.form["MW"])
|
| 28 |
-
chemName = '*' + request.form["chemName"] + '*'
|
| 29 |
|
| 30 |
if exposure != "limited":
|
| 31 |
time = 24.
|
|
@@ -53,6 +59,7 @@ def exp_post():
|
|
| 53 |
release = SigFigs(release, 2)
|
| 54 |
MOS = SigFigs(MOS, 2)
|
| 55 |
diff = SigFigs(diff, 2)
|
|
|
|
| 56 |
|
| 57 |
# Generate the rate plot using matplotlib
|
| 58 |
tarray = np.arange(1., 31., 1.)
|
|
@@ -61,4 +68,4 @@ def exp_post():
|
|
| 61 |
|
| 62 |
return render_template('exposure_report.html', polymers=polymers, pIndex=pIndex, release=release,
|
| 63 |
assume=assume, area=area, vol=vol, amount=amount, diff=diff, time=time, exposure=exposure, TTC=TTC,
|
| 64 |
-
MOS=MOS, chemName=chemName, image=pngImageB64String)
|
|
|
|
| 3 |
from functions import SigFigs, Piringer, WilkeChang, SheetRelease, SheetRates, RatePlot
|
| 4 |
from . import blueprint
|
| 5 |
from polymers import Polymers
|
| 6 |
+
from ChemID import ResolveChemical
|
| 7 |
|
| 8 |
# load polymer data including Ap values
|
| 9 |
polymers, Ap = Polymers()
|
|
|
|
| 17 |
# build the report page for the exposure module
|
| 18 |
@blueprint.route('/exposure', methods=['POST'])
|
| 19 |
def exp_post():
|
| 20 |
+
|
| 21 |
+
chemName = request.form["chemName"]
|
| 22 |
+
IDtype = request.form["IDtype"]
|
| 23 |
+
|
| 24 |
+
smiles, MW, mol = ResolveChemical(chemName, IDtype)
|
| 25 |
+
print(smiles,MW)
|
| 26 |
+
|
| 27 |
amount = float(request.form["amount"])
|
| 28 |
mass = float(request.form["mass"])
|
| 29 |
density = float(request.form["density"])
|
|
|
|
| 32 |
pIndex = (np.where(polymers == polymer)[0])[0]
|
| 33 |
area = float(request.form["area"])
|
| 34 |
exposure = request.form["exposure"]
|
|
|
|
|
|
|
| 35 |
|
| 36 |
if exposure != "limited":
|
| 37 |
time = 24.
|
|
|
|
| 59 |
release = SigFigs(release, 2)
|
| 60 |
MOS = SigFigs(MOS, 2)
|
| 61 |
diff = SigFigs(diff, 2)
|
| 62 |
+
MW = SigFigs(MW, 6)
|
| 63 |
|
| 64 |
# Generate the rate plot using matplotlib
|
| 65 |
tarray = np.arange(1., 31., 1.)
|
|
|
|
| 68 |
|
| 69 |
return render_template('exposure_report.html', polymers=polymers, pIndex=pIndex, release=release,
|
| 70 |
assume=assume, area=area, vol=vol, amount=amount, diff=diff, time=time, exposure=exposure, TTC=TTC,
|
| 71 |
+
MOS=MOS, chemName=chemName, image=pngImageB64String, MW=MW, smiles=smiles)
|
exposure_module/templates/exposure_index.html
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
-
|
| 5 |
-
|
| 6 |
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
|
| 7 |
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
|
| 8 |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.min.js" integrity="sha384-VHvPCCyXqtD5DqJeNxl2dtTyhF78xXNXdkwX1CZeRusQfRKp+tA7hAShOK/B/fQ2" crossorigin="anonymous"></script>
|
|
@@ -34,35 +34,40 @@ For details on how to use CHRIS, please click the information icons next to each
|
|
| 34 |
|
| 35 |
<h3> Bulk chemical <button type="button" class="Info_btn" data-toggle="modal" data-target="#LeachModal" >ⓘ</button> </h3>
|
| 36 |
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
|
| 41 |
-
Amount (mg): <input name="amount" id="amount" value="1.0" step="any" min="0.000001" type="number"> <br>
|
| 42 |
|
| 43 |
-
<!-- Modal -->
|
| 44 |
-
<div id="LeachModal" class="modal fade" role="dialog">
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
| 61 |
</div>
|
| 62 |
-
</div>
|
| 63 |
|
|
|
|
| 64 |
</div>
|
| 65 |
-
</div>
|
| 66 |
|
| 67 |
<!-- Polymer matrix input section -->
|
| 68 |
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<title>CHRIS</title>
|
| 6 |
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
|
| 7 |
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
|
| 8 |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.min.js" integrity="sha384-VHvPCCyXqtD5DqJeNxl2dtTyhF78xXNXdkwX1CZeRusQfRKp+tA7hAShOK/B/fQ2" crossorigin="anonymous"></script>
|
|
|
|
| 34 |
|
| 35 |
<h3> Bulk chemical <button type="button" class="Info_btn" data-toggle="modal" data-target="#LeachModal" >ⓘ</button> </h3>
|
| 36 |
|
| 37 |
+
Identifier type: <select name="IDtype">
|
| 38 |
+
<option value="CAS" selected>CAS</option>
|
| 39 |
+
<option value="IUPAC" >IUPAC</option>
|
| 40 |
+
<option value="SMILES" >SMILES</option>
|
| 41 |
+
<option value="common" >Common name</option>
|
| 42 |
+
</select> <br>
|
| 43 |
|
| 44 |
+
Identifier: <input name="chemName" id="chemName" type="text" value="" required><br>
|
| 45 |
|
| 46 |
+
Amount (mg): <input name="amount" id="amount" value="1.0" step="any" min="0.000001" type="number"> <br>
|
| 47 |
|
| 48 |
+
<!-- Modal -->
|
| 49 |
+
<div id="LeachModal" class="modal fade" role="dialog">
|
| 50 |
+
<div class="modal-dialog">
|
| 51 |
+
|
| 52 |
+
<!-- Modal content-->
|
| 53 |
+
<div class="modal-content">
|
| 54 |
+
<div class="modal-header">
|
| 55 |
+
<h4 class="modal-title">Bulk chemical</h4>
|
| 56 |
+
</div>
|
| 57 |
+
<div class="modal-body">
|
| 58 |
+
<p><em>Identity</em> - Please enter the chemical name, including CAS # if known. Note that CHRIS is limited to substances
|
| 59 |
+
with molecular weight between 100 and 1100 g/mol. For compounds with molecular weight > 1100 g/mol, this value
|
| 60 |
+
can be used for a conservative exposure estimate.
|
| 61 |
+
<p><em>Molecular weight</em> - Enter the molecular weight of the substance in grams per mole.</p>
|
| 62 |
+
<p><em>Amount</em> - Enter the total mass of the substance in the component being evaluated expressed in milligrams.</p>
|
| 63 |
+
</div>
|
| 64 |
+
<div class="modal-footer">
|
| 65 |
+
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
| 66 |
+
</div>
|
| 67 |
</div>
|
|
|
|
| 68 |
|
| 69 |
+
</div>
|
| 70 |
</div>
|
|
|
|
| 71 |
|
| 72 |
<!-- Polymer matrix input section -->
|
| 73 |
|
exposure_module/templates/exposure_report.html
CHANGED
|
@@ -23,10 +23,15 @@
|
|
| 23 |
<script> document.write(new Date().toLocaleDateString()); </script>.
|
| 24 |
</p>
|
| 25 |
|
| 26 |
-
<h2>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
<p>
|
| 29 |
-
<u> Diffusion calculation for
|
| 30 |
<p>
|
| 31 |
|
| 32 |
<p>
|
|
|
|
| 23 |
<script> document.write(new Date().toLocaleDateString()); </script>.
|
| 24 |
</p>
|
| 25 |
|
| 26 |
+
<h2> Compound </h2>
|
| 27 |
+
|
| 28 |
+
Molecular weight = {{MW}} <br>
|
| 29 |
+
SMILES = {{smiles}} <br>
|
| 30 |
+
|
| 31 |
+
<h2> Exposure </h2>
|
| 32 |
|
| 33 |
<p>
|
| 34 |
+
<u> Diffusion calculation for leaching from {{polymers[pIndex]}} estimates the worst case single day exposure = {{release}} mg. </u>
|
| 35 |
<p>
|
| 36 |
|
| 37 |
<p>
|
functions.py
CHANGED
|
@@ -12,7 +12,8 @@ def SigFigs(number, n):
|
|
| 12 |
return round(number, n - int(math.floor(math.log10(math.fabs(number)))) - 1)
|
| 13 |
|
| 14 |
def Piringer(Mw, Ap):
|
| 15 |
-
|
|
|
|
| 16 |
return 1e4 * np.exp(Ap - 0.1351 * Mw ** (2. / 3.) + 0.003 * Mw - 10454. / 310.)
|
| 17 |
|
| 18 |
def WilkeChang(Mw):
|
|
|
|
| 12 |
return round(number, n - int(math.floor(math.log10(math.fabs(number)))) - 1)
|
| 13 |
|
| 14 |
def Piringer(Mw, Ap):
|
| 15 |
+
if Mw > 1100.:
|
| 16 |
+
Mw = 1100.
|
| 17 |
return 1e4 * np.exp(Ap - 0.1351 * Mw ** (2. / 3.) + 0.003 * Mw - 10454. / 310.)
|
| 18 |
|
| 19 |
def WilkeChang(Mw):
|