awacke1 commited on
Commit
cfb3fe2
·
1 Parent(s): 1049d12

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -39
app.py CHANGED
@@ -21,29 +21,6 @@ def smi2conf(smiles):
21
  else:
22
  return None
23
 
24
- smi = 'COc3nc(OCc2ccc(C#N)c(c1ccc(C(=O)O)cc1)c2P(=O)(O)O)ccc3C[NH2+]CC(I)NC(=O)C(F)(Cl)Br'
25
- conf = smi2conf(smi)
26
- viewer = MolTo3DView(conf, size=(600, 300), style='sphere')
27
- viewer.show()
28
-
29
- compound_smiles = 'c1cc(C(=O)O)c(OC(=O)C)cc1'
30
- m = Chem.MolFromSmiles(compound_smiles)
31
- im=Draw.MolToImage(m)
32
- st.image(im)
33
-
34
-
35
- def MakeMolecule(name, ingredients):
36
- st.write(name)
37
- m = Chem.MolFromSmiles(ingredients)
38
- im=Draw.MolToImage(m)
39
- st.image(im)
40
-
41
- MakeMolecule("Ethanol", "CCO")
42
- MakeMolecule("Acetic acid", "CC(=O)O")
43
- MakeMolecule("Cyclohexane", "C1CCCCC1")
44
- MakeMolecule("Pyridine", "c1cnccc1")
45
-
46
-
47
  def MolTo3DView(mol, size=(300, 300), style="stick", surface=False, opacity=0.5):
48
  """Draw molecule in 3D
49
 
@@ -68,8 +45,49 @@ def MolTo3DView(mol, size=(300, 300), style="stick", surface=False, opacity=0.5)
68
  viewer.addSurface(py3Dmol.SAS, {'opacity': opacity})
69
  viewer.zoomTo()
70
  return viewer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
 
72
- viewer = Chem.MolTo3DView(conf, size=(600, 300), style='sphere')
73
  viewer.show()
74
 
75
  smis = [ 'COc3nc(OCc2ccc(C#N)c(c1ccc(C(=O)O)cc1)c2P(=O)(O)O)ccc3C[NH2+]CC(I)NC(=O)C(F)(Cl)Br',
@@ -80,10 +98,6 @@ smis = [ 'COc3nc(OCc2ccc(C#N)c(c1ccc(C(=O)O)cc1)c2P(=O)(O)O)ccc3C[NH2+]CC(I)NC(=
80
 
81
  confs = [smi2conf(s) for s in smis]
82
 
83
- def conf_viewer(idx):
84
- mol = confs[idx]
85
- return Chem.MolTo3DView(mol).show()
86
-
87
  interact(conf_viewer, idx=ipywidgets.IntSlider(min=0,max=len(class_0_list)-1, step=1))
88
 
89
 
@@ -97,7 +111,7 @@ confs = [smi2conf(s) for s in smis]
97
 
98
  def style_selector(idx, s):
99
  conf = confs[idx]
100
- return Chem.MolTo3DView(conf, style=s).show()
101
 
102
  interact(style_selector,
103
  idx=ipywidgets.IntSlider(min=0,max=len(class_0_list)-1, step=1),
@@ -107,14 +121,5 @@ interact(style_selector,
107
  description='Style:'))
108
 
109
 
110
-
111
- @interact
112
- def smi2viewer(smi='CC=O'):
113
- try:
114
- conf = smi2conf(smi)
115
- return Chem.MolTo3DView(conf).show()
116
- except:
117
- return None
118
-
119
-
120
 
 
21
  else:
22
  return None
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  def MolTo3DView(mol, size=(300, 300), style="stick", surface=False, opacity=0.5):
25
  """Draw molecule in 3D
26
 
 
45
  viewer.addSurface(py3Dmol.SAS, {'opacity': opacity})
46
  viewer.zoomTo()
47
  return viewer
48
+
49
+
50
+ def MakeMolecule(name, ingredients):
51
+ st.write(name)
52
+ m = Chem.MolFromSmiles(ingredients)
53
+ im=Draw.MolToImage(m)
54
+ st.image(im)
55
+
56
+
57
+ def conf_viewer(idx):
58
+ mol = confs[idx]
59
+ return MolTo3DView(mol).show()
60
+
61
+ @interact
62
+ def smi2viewer(smi='CC=O'):
63
+ try:
64
+ conf = smi2conf(smi)
65
+ return MolTo3DView(conf).show()
66
+ except:
67
+ return None
68
+
69
+
70
+
71
+ smi = 'COc3nc(OCc2ccc(C#N)c(c1ccc(C(=O)O)cc1)c2P(=O)(O)O)ccc3C[NH2+]CC(I)NC(=O)C(F)(Cl)Br'
72
+ conf = smi2conf(smi)
73
+ viewer = MolTo3DView(conf, size=(600, 300), style='sphere')
74
+ viewer.show()
75
+
76
+ compound_smiles = 'c1cc(C(=O)O)c(OC(=O)C)cc1'
77
+ m = Chem.MolFromSmiles(compound_smiles)
78
+ im=Draw.MolToImage(m)
79
+ st.image(im)
80
+
81
+
82
+
83
+ MakeMolecule("Ethanol", "CCO")
84
+ MakeMolecule("Acetic acid", "CC(=O)O")
85
+ MakeMolecule("Cyclohexane", "C1CCCCC1")
86
+ MakeMolecule("Pyridine", "c1cnccc1")
87
+
88
+
89
 
90
+ viewer = MolTo3DView(conf, size=(600, 300), style='sphere')
91
  viewer.show()
92
 
93
  smis = [ 'COc3nc(OCc2ccc(C#N)c(c1ccc(C(=O)O)cc1)c2P(=O)(O)O)ccc3C[NH2+]CC(I)NC(=O)C(F)(Cl)Br',
 
98
 
99
  confs = [smi2conf(s) for s in smis]
100
 
 
 
 
 
101
  interact(conf_viewer, idx=ipywidgets.IntSlider(min=0,max=len(class_0_list)-1, step=1))
102
 
103
 
 
111
 
112
  def style_selector(idx, s):
113
  conf = confs[idx]
114
+ return MolTo3DView(conf, style=s).show()
115
 
116
  interact(style_selector,
117
  idx=ipywidgets.IntSlider(min=0,max=len(class_0_list)-1, step=1),
 
121
  description='Style:'))
122
 
123
 
124
+
 
 
 
 
 
 
 
 
 
125