libokj commited on
Commit
6f11c42
·
1 Parent(s): 47572cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -29
app.py CHANGED
@@ -189,35 +189,36 @@ def rgb_to_hex(rgb):
189
 
190
 
191
  def mol_to_pharm3d(mol, mode='html'):
192
- if mol is None:
193
- return
194
- # AllChem.Compute2DCoords(mol)
195
- mol = Chem.AddHs(mol)
196
- params = AllChem.ETKDGv3()
197
- params.randomSeed = 0xf00d # for reproducibility
198
- AllChem.EmbedMolecule(mol, params)
199
-
200
- feats = FEAT_FACTORY.GetFeaturesForMol(mol)
201
-
202
- view = View3DmolCell(width=320, height=200)
203
- for feat in feats:
204
- pos = feat.GetPos()
205
- color = _featColors.get(feat.GetFamily(), (.5, .5, .5))
206
- view.addSphere({
207
- 'center': {'x': pos.x, 'y': pos.y, 'z': pos.z},
208
- 'radius': 0.5,
209
- 'color': rgb_to_hex(color)
210
- })
211
-
212
- mol_block = Chem.MolToMolBlock(mol)
213
- view.addModel(mol_block, 'sdf')
214
- view.setStyle({'stick': {}})
215
- view.zoomTo()
216
-
217
- if mode == 'html':
218
- return view.write_html()
219
- # case 'png':
220
- # return view.png()
 
221
 
222
 
223
  class HelpTip:
 
189
 
190
 
191
  def mol_to_pharm3d(mol, mode='html'):
192
+ try:
193
+ # AllChem.Compute2DCoords(mol)
194
+ mol = Chem.AddHs(mol)
195
+ params = AllChem.ETKDGv3()
196
+ params.randomSeed = 0xf00d # for reproducibility
197
+ AllChem.EmbedMolecule(mol, params)
198
+
199
+ feats = FEAT_FACTORY.GetFeaturesForMol(mol)
200
+
201
+ view = View3DmolCell(width=320, height=200)
202
+ for feat in feats:
203
+ pos = feat.GetPos()
204
+ color = _featColors.get(feat.GetFamily(), (.5, .5, .5))
205
+ view.addSphere({
206
+ 'center': {'x': pos.x, 'y': pos.y, 'z': pos.z},
207
+ 'radius': 0.5,
208
+ 'color': rgb_to_hex(color)
209
+ })
210
+
211
+ mol_block = Chem.MolToMolBlock(mol)
212
+ view.addModel(mol_block, 'sdf')
213
+ view.setStyle({'stick': {}})
214
+ view.zoomTo()
215
+
216
+ if mode == 'html':
217
+ return view.write_html()
218
+ # case 'png':
219
+ # return view.png()
220
+ except Exception:
221
+ return None
222
 
223
 
224
  class HelpTip: