robert.elder commited on
Commit
abbdafd
·
1 Parent(s): 13c99e1

tweak to ceramics logic, added picture of pigment brown

Browse files
Files changed (1) hide show
  1. color2_module/colors.py +18 -13
color2_module/colors.py CHANGED
@@ -4,7 +4,7 @@ from functions import SigFigs, Piringer, WilkeChang, SheetRelease, SheetRates, R
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
 
@@ -20,6 +20,9 @@ debug = False
20
  # flag for testing new polymer categories
21
  use_new = True
22
 
 
 
 
23
  # load polymer data including Ap values
24
  if not use_new:
25
  polymers, Ap = Polymers()
@@ -99,7 +102,10 @@ def app_post():
99
  #IDtype = 'SMILES'
100
  #chemName = 'O=[Ti]=O.O=[Sb]O[Sb](=O)=O.O=[Cr]O[Cr]=O'
101
  #iupac, cas, smiles, MW, LogP, rho, mp, molImage, error = ResolveChemical(chemName, IDtype, get_properties=get_properties)
102
- iupac, cas, smiles, MW, LogP, rho, mp, molImage, error = None, chemName, 'O=[Ti]=O.O=[Sb]O[Sb](=O)=O.O=[Cr]O[Cr]=O', 1100, None, None, 1001, None, 0
 
 
 
103
  elif chemName == '14325-24-7':
104
  IDtype = 'SMILES'
105
  chemName = 'C1=CC=C2C(=C1)C3=NC4=NC(=NC5=C6C=CC=CC6=C([N-]5)N=C7C8=CC=CC=C8C(=N7)N=C2[N-]3)C9=CC=CC=C94.[Mn+2]'
@@ -111,8 +117,6 @@ def app_post():
111
  # iupac, cas, smiles, MW, LogP, rho, mp, molImage, error = ResolveChemical(chemName, IDtype, get_properties=get_properties)
112
  else:
113
  iupac, cas, smiles, MW, LogP, rho, mp, molImage, error = ResolveChemical(chemName, IDtype, get_properties=get_properties)
114
- ## XXX
115
- #print(iupac, cas, smiles, MW, LogP, rho, mp, error)
116
 
117
  if error > 0:
118
  # TODO output more useful info
@@ -120,22 +124,23 @@ def app_post():
120
 
121
  # metals/ceramics logic
122
  mol = Chem.MolFromSmiles(smiles)
123
- mol = Chem.AddHs(mol)
124
- natoms = mol.GetNumAtoms()
125
- metal_nums = [3,4,11,12,13] + list(range(19,31+1)) + list(range(37,50+1)) + list(range(55,84+1)) + list(range(87,114+1)) + [116]
126
  ceramic = False
127
- if all(a.GetAtomicNum() in metal_nums for a in mol.GetAtoms()):
 
 
 
 
 
128
  # if all atoms are metals -> this is a metal
129
- #if natoms == 1 and smiles != '[C]':
130
- # only one atom, except for carbon -> assumed metal
131
- # return render_template('chemError.html')
132
  return render_template('metalError.html', show_properties=show_properties, chemName=chemName, MW=MW,
133
  LogP=LogP, rho=rho, mp=mp, iupac=iupac,
134
  cas=cas, smiles=smiles, molImage=molImage)
135
  #LogP_origin=LogP_origin, rho_origin=rho_origin, mp_origin=mp_origin)
136
  else:
137
- if (type(mp) is float or type(mp) is int) and mp > 1000.:
138
- # if not a metal but melting point > 1000, assume ceramic
139
  MW = 1100.
140
  ceramic = True
141
 
 
4
  from functions import Piecewise, PowerLaw
5
  from . import blueprint
6
  from polymers import Polymers, Polymers2
7
+ from ChemID import ResolveChemical, ImageFromSmiles, Imageto64
8
  import rdkit
9
  from rdkit.Chem import AllChem as Chem
10
 
 
20
  # flag for testing new polymer categories
21
  use_new = True
22
 
23
+ ORGANIC_ATOM_SET = {5, 6, 7, 8, 9, 15, 16, 17, 35, 53}
24
+ METAL_ATOM_SET = set([3,4,11,12,13] + list(range(19,31+1)) + list(range(37,50+1)) + list(range(55,84+1)) + list(range(87,114+1)) + [116])
25
+
26
  # load polymer data including Ap values
27
  if not use_new:
28
  polymers, Ap = Polymers()
 
102
  #IDtype = 'SMILES'
103
  #chemName = 'O=[Ti]=O.O=[Sb]O[Sb](=O)=O.O=[Cr]O[Cr]=O'
104
  #iupac, cas, smiles, MW, LogP, rho, mp, molImage, error = ResolveChemical(chemName, IDtype, get_properties=get_properties)
105
+ iupac, cas, smiles, MW, LogP, rho, mp, molImage, error = None, chemName, 'O=[Ti]=O.O=[Sb]O[Sb]=O.O=[Cr]O[Cr]=O', 1100, None, None, 1001, None, 0
106
+ im = ImageFromSmiles(smiles)
107
+ im64 = Imageto64(im)
108
+ molImage = im64
109
  elif chemName == '14325-24-7':
110
  IDtype = 'SMILES'
111
  chemName = 'C1=CC=C2C(=C1)C3=NC4=NC(=NC5=C6C=CC=CC6=C([N-]5)N=C7C8=CC=CC=C8C(=N7)N=C2[N-]3)C9=CC=CC=C94.[Mn+2]'
 
117
  # iupac, cas, smiles, MW, LogP, rho, mp, molImage, error = ResolveChemical(chemName, IDtype, get_properties=get_properties)
118
  else:
119
  iupac, cas, smiles, MW, LogP, rho, mp, molImage, error = ResolveChemical(chemName, IDtype, get_properties=get_properties)
 
 
120
 
121
  if error > 0:
122
  # TODO output more useful info
 
124
 
125
  # metals/ceramics logic
126
  mol = Chem.MolFromSmiles(smiles)
127
+ #mol = Chem.AddHs(mol)
128
+ #natoms = mol.GetNumAtoms()
 
129
  ceramic = False
130
+ atom_num_list = [a.GetAtomicNum() for a in mol.GetAtoms()]
131
+ is_metal = set(atom_num_list) <= METAL_ATOM_SET
132
+ #is_metal = all(a.GetAtomicNum() in metal_nums for a in mol.GetAtoms())
133
+ #is_organic = set(atom_num_list) <= ORGANIC_ATOM_SET
134
+ num_CC_bonds = sum([1 if b.GetBeginAtom().GetAtomicNum() == 6 and b.GetEndAtom().GetAtomicNum() == 6 else 0 for b in mol.GetBonds()])
135
+ if is_metal:
136
  # if all atoms are metals -> this is a metal
 
 
 
137
  return render_template('metalError.html', show_properties=show_properties, chemName=chemName, MW=MW,
138
  LogP=LogP, rho=rho, mp=mp, iupac=iupac,
139
  cas=cas, smiles=smiles, molImage=molImage)
140
  #LogP_origin=LogP_origin, rho_origin=rho_origin, mp_origin=mp_origin)
141
  else:
142
+ if not num_CC_bonds and (type(mp) is float or type(mp) is int) and mp > 1000.:
143
+ # if not a metal and no carbon-carbon bonds but melting point > 1000, assume ceramic
144
  MW = 1100.
145
  ceramic = True
146