Trương Gia Bảo commited on
Commit
03728c1
·
1 Parent(s): fe40bb4

Fix mol image bug

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -637,17 +637,19 @@ def Optimize_a_molecule():
637
  com_col = st.columns(3)
638
  com_col[1].markdown("<h4 style='text-align: center;'>Original</h4>",unsafe_allow_html=True)
639
  com_col[2].markdown("<h4 style='text-align: center;'>New</h4>",unsafe_allow_html=True)
 
 
640
  imgByteArr.seek(0)
641
- MolToImage(Chem.MolFromSmiles(st.session_state.canon_smiles),size=(200,200)).save(imgByteArr,format='PNG')
642
- old_mol = base64.b64encode(imgByteArr.getvalue()).decode()
643
  imgByteArr.seek(0)
644
- MolToImage(Chem.MolFromSmiles(st.session_state.new_smiles),size=(200,200)).save(imgByteArr,format='PNG')
645
- new_mol = base64.b64encode(imgByteArr.getvalue()).decode()
646
  com_col[1].markdown("<p style='text-align: center;'>"+
647
- f"<img src='data:image/png;base64,{old_mol}' class='img-fluid'>"+
648
  "</p>", unsafe_allow_html=True)
649
  com_col[2].markdown("<p style='text-align: center;'>"+
650
- f"<img src='data:image/png;base64,{new_mol}' class='img-fluid'>"+
651
  "</p>", unsafe_allow_html=True)
652
  old_mol_metrics = Metrics(st.session_state.canon_smiles).calculate_all()
653
  new_mol_metrics = Metrics(st.session_state.new_smiles).calculate_all()
@@ -706,7 +708,7 @@ def Optimize_a_molecule():
706
  drawer = rdMolDraw2D.MolDraw2DSVG(200,200)
707
  # drawer.drawOptions().fillHighlights = False
708
  matches = sum(patt, ())
709
- drawer.DrawMolecule(mol, highlightAtoms=matches)
710
  drawer.FinishDrawing()
711
  svg = drawer.GetDrawingText()
712
  imgByteArr.seek(0)
@@ -727,7 +729,7 @@ def Optimize_a_molecule():
727
  drawer = rdMolDraw2D.MolDraw2DSVG(200,200)
728
  # drawer.drawOptions().fillHighlights = False
729
  matches = sum(patt, ())
730
- drawer.DrawMolecule(mol, highlightAtoms=matches)
731
  drawer.FinishDrawing()
732
  svg = drawer.GetDrawingText()
733
  imgByteArr.seek(0)
 
637
  com_col = st.columns(3)
638
  com_col[1].markdown("<h4 style='text-align: center;'>Original</h4>",unsafe_allow_html=True)
639
  com_col[2].markdown("<h4 style='text-align: center;'>New</h4>",unsafe_allow_html=True)
640
+ old_mol = Chem.MolFromSmiles(st.session_state.canon_smiles)
641
+ new_mol = Chem.MolFromSmiles(st.session_state.new_smiles)
642
  imgByteArr.seek(0)
643
+ MolToImage(old_mol,size=(200,200)).save(imgByteArr,format='PNG')
644
+ old_mol_base64 = base64.b64encode(imgByteArr.getvalue()).decode()
645
  imgByteArr.seek(0)
646
+ MolToImage(new_mol,size=(200,200)).save(imgByteArr,format='PNG')
647
+ new_mol_base64 = base64.b64encode(imgByteArr.getvalue()).decode()
648
  com_col[1].markdown("<p style='text-align: center;'>"+
649
+ f"<img src='data:image/png;base64,{old_mol_base64}' class='img-fluid'>"+
650
  "</p>", unsafe_allow_html=True)
651
  com_col[2].markdown("<p style='text-align: center;'>"+
652
+ f"<img src='data:image/png;base64,{new_mol_base64}' class='img-fluid'>"+
653
  "</p>", unsafe_allow_html=True)
654
  old_mol_metrics = Metrics(st.session_state.canon_smiles).calculate_all()
655
  new_mol_metrics = Metrics(st.session_state.new_smiles).calculate_all()
 
708
  drawer = rdMolDraw2D.MolDraw2DSVG(200,200)
709
  # drawer.drawOptions().fillHighlights = False
710
  matches = sum(patt, ())
711
+ drawer.DrawMolecule(old_mol, highlightAtoms=matches)
712
  drawer.FinishDrawing()
713
  svg = drawer.GetDrawingText()
714
  imgByteArr.seek(0)
 
729
  drawer = rdMolDraw2D.MolDraw2DSVG(200,200)
730
  # drawer.drawOptions().fillHighlights = False
731
  matches = sum(patt, ())
732
+ drawer.DrawMolecule(new_mol, highlightAtoms=matches)
733
  drawer.FinishDrawing()
734
  svg = drawer.GetDrawingText()
735
  imgByteArr.seek(0)