David Saylor commited on
Commit ·
55b7cf1
1
Parent(s): c11b4ec
cleaning up a bit
Browse files
ChemID.py
CHANGED
|
@@ -17,13 +17,15 @@ from rdkit.Chem import Descriptors,Descriptors3D, Draw
|
|
| 17 |
def ResolveChemical(chemName, IDtype):
|
| 18 |
|
| 19 |
if IDtype == 'CAS':
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
mol = Chem.MolFromSmiles(smiles)
|
| 22 |
Mw = Descriptors.MolWt(mol)
|
| 23 |
im = ImageFromSmiles(smiles)
|
| 24 |
im64 = Imageto64(im)
|
| 25 |
|
| 26 |
-
return (
|
| 27 |
|
| 28 |
#Generates an image of the molecule represented by the SMILES code given.
|
| 29 |
#Returns None if the image cannot be generated. From https://github.com/ronaldo-prata/flask-test/blob/master/functions.py
|
|
@@ -43,14 +45,8 @@ def ImageFromSmiles(smiles):
|
|
| 43 |
|
| 44 |
def wTrim(img):
|
| 45 |
bbox = ImageOps.invert(img).getbbox()
|
| 46 |
-
|
| 47 |
crop = (bbox[0], bbox[1], bbox[2], bbox[3])
|
| 48 |
-
|
| 49 |
-
# crop = (300, 300, 700, 700)
|
| 50 |
-
# elif (bbox[2]-bbox[0] > bbox[3]-bbox[1]):
|
| 51 |
-
# crop = (bbox[0], bbox[0], bbox[2], bbox[2])
|
| 52 |
-
# else:
|
| 53 |
-
# crop = (bbox[1], bbox[1], bbox[3], bbox[3])
|
| 54 |
return img.crop(crop)
|
| 55 |
|
| 56 |
#Converts a PIL image into its base64 representation.
|
|
@@ -102,6 +98,39 @@ def cas2smiles(cas):
|
|
| 102 |
smiles = None
|
| 103 |
return smiles
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
# function to convert chemical entity string to iupac name
|
| 106 |
def string2name(string):
|
| 107 |
name = None
|
|
|
|
| 17 |
def ResolveChemical(chemName, IDtype):
|
| 18 |
|
| 19 |
if IDtype == 'CAS':
|
| 20 |
+
cas = chemName
|
| 21 |
+
smiles = cas2smiles(cas)
|
| 22 |
+
name = cas2name(cas)
|
| 23 |
mol = Chem.MolFromSmiles(smiles)
|
| 24 |
Mw = Descriptors.MolWt(mol)
|
| 25 |
im = ImageFromSmiles(smiles)
|
| 26 |
im64 = Imageto64(im)
|
| 27 |
|
| 28 |
+
return (name, cas, smiles, Mw, im64)
|
| 29 |
|
| 30 |
#Generates an image of the molecule represented by the SMILES code given.
|
| 31 |
#Returns None if the image cannot be generated. From https://github.com/ronaldo-prata/flask-test/blob/master/functions.py
|
|
|
|
| 45 |
|
| 46 |
def wTrim(img):
|
| 47 |
bbox = ImageOps.invert(img).getbbox()
|
|
|
|
| 48 |
crop = (bbox[0], bbox[1], bbox[2], bbox[3])
|
| 49 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
return img.crop(crop)
|
| 51 |
|
| 52 |
#Converts a PIL image into its base64 representation.
|
|
|
|
| 98 |
smiles = None
|
| 99 |
return smiles
|
| 100 |
|
| 101 |
+
# function to convert cas to name
|
| 102 |
+
def cas2name(cas):
|
| 103 |
+
name = None
|
| 104 |
+
#if not is_cas(cas):
|
| 105 |
+
# name = 'INVALID CAS'
|
| 106 |
+
# first try chemicals package
|
| 107 |
+
if not name:
|
| 108 |
+
try:
|
| 109 |
+
cm = chemicals.search_chemical(cas)
|
| 110 |
+
name = cm.common_name
|
| 111 |
+
except:
|
| 112 |
+
name = None
|
| 113 |
+
# then try cirpy
|
| 114 |
+
if not name:
|
| 115 |
+
try:
|
| 116 |
+
name = cirpy.resolve(cas, 'iupac_name')
|
| 117 |
+
except:
|
| 118 |
+
name = None
|
| 119 |
+
if type(name) is list:
|
| 120 |
+
name = name[0]
|
| 121 |
+
# next try pubchem for compounds
|
| 122 |
+
if not name:
|
| 123 |
+
try:
|
| 124 |
+
compounds = pcp.get_compounds(cas, namespace='name')
|
| 125 |
+
c = compounds[0]
|
| 126 |
+
name = c.iupac_name
|
| 127 |
+
if not name:
|
| 128 |
+
# have seen empty iupac_name before, try synonyms if this happens
|
| 129 |
+
name = c.synonyms[0]
|
| 130 |
+
except:
|
| 131 |
+
name = None
|
| 132 |
+
return name
|
| 133 |
+
|
| 134 |
# function to convert chemical entity string to iupac name
|
| 135 |
def string2name(string):
|
| 136 |
name = None
|
exposure_module/exposure.py
CHANGED
|
@@ -21,7 +21,7 @@ def exp_post():
|
|
| 21 |
chemName = request.form["chemName"]
|
| 22 |
IDtype = request.form["IDtype"]
|
| 23 |
|
| 24 |
-
|
| 25 |
|
| 26 |
amount = float(request.form["amount"])
|
| 27 |
mass = float(request.form["mass"])
|
|
@@ -67,4 +67,4 @@ def exp_post():
|
|
| 67 |
|
| 68 |
return render_template('exposure_report.html', polymers=polymers, pIndex=pIndex, release=release,
|
| 69 |
assume=assume, area=area, vol=vol, amount=amount, diff=diff, time=time, exposure=exposure, TTC=TTC,
|
| 70 |
-
MOS=MOS, chemName=chemName, image=pngImageB64String, MW=MW, smiles=smiles, molImage=molImage)
|
|
|
|
| 21 |
chemName = request.form["chemName"]
|
| 22 |
IDtype = request.form["IDtype"]
|
| 23 |
|
| 24 |
+
iupac, cas, smiles, MW, molImage = ResolveChemical(chemName, IDtype)
|
| 25 |
|
| 26 |
amount = float(request.form["amount"])
|
| 27 |
mass = float(request.form["mass"])
|
|
|
|
| 67 |
|
| 68 |
return render_template('exposure_report.html', polymers=polymers, pIndex=pIndex, release=release,
|
| 69 |
assume=assume, area=area, vol=vol, amount=amount, diff=diff, time=time, exposure=exposure, TTC=TTC,
|
| 70 |
+
MOS=MOS, chemName=chemName, image=pngImageB64String, MW=MW, iupac=iupac, cas=cas, smiles=smiles, molImage=molImage)
|
exposure_module/templates/exposure_index.html
CHANGED
|
@@ -36,14 +36,13 @@ For details on how to use CHRIS, please click the information icons next to each
|
|
| 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">
|
|
@@ -78,8 +77,8 @@ Matrix: <select name="polymer">
|
|
| 78 |
<option value="{{polymer}}">{{polymer}}</option>
|
| 79 |
{% endfor %}
|
| 80 |
</select> <br>
|
| 81 |
-
Mass (g): <input name="mass" id="mass" step="any" value="1.0" min="0.000001" type="number"> <br>
|
| 82 |
-
Density (g/cm<sup>3</sup>): <input name="density" id="density" step="any" value="1.0" min="0.01" type="number">
|
| 83 |
|
| 84 |
<!-- Modal -->
|
| 85 |
<div id="PolymerModal" class="modal fade" role="dialog">
|
|
@@ -108,13 +107,13 @@ Density (g/cm<sup>3</sup>): <input name="density" id="density" step="any" value=
|
|
| 108 |
|
| 109 |
<h3> Device characteristics <button type=button class="Info_btn" data-toggle="modal" data-target="#DeviceModal">ⓘ</button> </h3>
|
| 110 |
Exposed surface area (cm<sup>2</sup>):
|
| 111 |
-
<input name="area" id="area" step="any" value="5.0" min="0.001" type="number"><br>
|
| 112 |
Exposure type:
|
| 113 |
<input type="radio" name="exposure" id="long-term" value="long-term" onclick="javascript:exposureCheck();" checked > long-term
|
| 114 |
<input type="radio" name="exposure" id="prolonged" value="prolonged" onclick="javascript:exposureCheck();" > prolonged
|
| 115 |
<input type="radio" name="exposure" id="limited" value="limited" onclick="javascript:exposureCheck();" > limited
|
| 116 |
<span id="limitedtime" style="visibility:hidden">
|
| 117 |
-
⇒ Exposure time (h): <input name="exptime" id="time" step="any" min="0.001" max="24" value="24" type="number" ><br>
|
| 118 |
</span>
|
| 119 |
|
| 120 |
<!-- Modal -->
|
|
|
|
| 36 |
|
| 37 |
Identifier type: <select name="IDtype">
|
| 38 |
<option value="CAS" selected>CAS</option>
|
|
|
|
| 39 |
<option value="SMILES" >SMILES</option>
|
| 40 |
<option value="common" >Common name</option>
|
| 41 |
</select> <br>
|
| 42 |
|
| 43 |
Identifier: <input name="chemName" id="chemName" type="text" value="" required><br>
|
| 44 |
|
| 45 |
+
Amount (mg): <input name="amount" id="amount" value="1.0" step="any" min="0.000001" type="number" required> <br>
|
| 46 |
|
| 47 |
<!-- Modal -->
|
| 48 |
<div id="LeachModal" class="modal fade" role="dialog">
|
|
|
|
| 77 |
<option value="{{polymer}}">{{polymer}}</option>
|
| 78 |
{% endfor %}
|
| 79 |
</select> <br>
|
| 80 |
+
Mass (g): <input name="mass" id="mass" step="any" value="1.0" min="0.000001" type="number" required> <br>
|
| 81 |
+
Density (g/cm<sup>3</sup>): <input name="density" id="density" step="any" value="1.0" min="0.01" type="number" required>
|
| 82 |
|
| 83 |
<!-- Modal -->
|
| 84 |
<div id="PolymerModal" class="modal fade" role="dialog">
|
|
|
|
| 107 |
|
| 108 |
<h3> Device characteristics <button type=button class="Info_btn" data-toggle="modal" data-target="#DeviceModal">ⓘ</button> </h3>
|
| 109 |
Exposed surface area (cm<sup>2</sup>):
|
| 110 |
+
<input name="area" id="area" step="any" value="5.0" min="0.001" type="number" required><br>
|
| 111 |
Exposure type:
|
| 112 |
<input type="radio" name="exposure" id="long-term" value="long-term" onclick="javascript:exposureCheck();" checked > long-term
|
| 113 |
<input type="radio" name="exposure" id="prolonged" value="prolonged" onclick="javascript:exposureCheck();" > prolonged
|
| 114 |
<input type="radio" name="exposure" id="limited" value="limited" onclick="javascript:exposureCheck();" > limited
|
| 115 |
<span id="limitedtime" style="visibility:hidden">
|
| 116 |
+
⇒ Exposure time (h): <input name="exptime" id="time" step="any" min="0.001" max="24" value="24" type="number" required><br>
|
| 117 |
</span>
|
| 118 |
|
| 119 |
<!-- Modal -->
|
exposure_module/templates/exposure_report.html
CHANGED
|
@@ -50,9 +50,10 @@
|
|
| 50 |
<div class="container">
|
| 51 |
<div class="row">
|
| 52 |
<div class="column">
|
| 53 |
-
Name
|
| 54 |
-
|
| 55 |
-
|
|
|
|
| 56 |
</div>
|
| 57 |
<div class="column">
|
| 58 |
<img src="{{molImage}}"/>
|
|
|
|
| 50 |
<div class="container">
|
| 51 |
<div class="row">
|
| 52 |
<div class="column">
|
| 53 |
+
IUPAC Name :: {{iupac}} <br> <br>
|
| 54 |
+
CAS :: {{cas}} <br> <br>
|
| 55 |
+
Molecular weight :: {{MW}} <br> <br>
|
| 56 |
+
SMILES :: {{smiles}}
|
| 57 |
</div>
|
| 58 |
<div class="column">
|
| 59 |
<img src="{{molImage}}"/>
|