# -*- coding: utf-8 -*- """ Created on Sun Nov 3 08:48:11 2024 @author: BM109X32G-10GPU-02 """ import streamlit as st import pandas as pd import rdkit import streamlit_ketcher from streamlit_ketcher import st_ketcher import run import screen # Page setup st.set_page_config(page_title="BiBERTa", page_icon="🔋", layout="wide") st.title("🔋BiBERTa") st.subheader('',divider='rainbow') # Connect to the Google Sheet url1= r"https://docs.google.com/spreadsheets/d/1AKkZS04VF3osFT36aNHIb4iUbV8D1uNfsldcpHXogj0/gviz/tq?tqx=out:csv&sheet=dap" df1 = pd.read_csv(url1, dtype=str, encoding='utf-8') col1, col2 = st.columns(2) st.subheader("💗**The donor and acceptor database**") with col1: st.caption("🔍**Search papers or molecules**") text_search = st.text_input(label="_", value="",label_visibility="hidden" ) m1 = df1["Donor_Name"].str.contains(text_search) m2 = df1["reference"].str.contains(text_search) m3 = df1["Acceptor_Name"].str.contains(text_search) df_search = df1[m1 | m2|m3] with col2: st.subheader(" ") st.link_button(":black[📝**DATABASE**]", r"https://docs.google.com/spreadsheets/d/1AKkZS04VF3osFT36aNHIb4iUbV8D1uNfsldcpHXogj0") st.caption(':black[👆If you want to update the origin database, click the button.]') if text_search: st.write(df_search) st.download_button( "⬇️Download edited files as .csv", df_search.to_csv(), "df_search.csv", use_container_width=True) edited_df = st.data_editor(df1, num_rows="dynamic") st.download_button( "⬇️ Download edited files as .csv", edited_df.to_csv(), "edited_df.csv", use_container_width=True ) #st.subheader("👇 :red[***Select the type of active layer...***]") st.subheader("💗**Molecular editor**") col3, col4 = st.columns(2) with col3: option = st.selectbox( ' 👇Select the type of active layer materials to be edited...', ("🎈Donor", "🎈Acceptor"), placeholder="👇Select the type of active layer materials...", ) with col4: st.subheader(" ") st.markdown('👇An example of PM6 : Y6.') if st.button("🙋‍♂️**Example**"): option ="example" molecule = 'O=C(C(C=C(F)C(F)=C1)=C1C/2=C(C#N)/C#N)C2=C/C3=C(CCCCCCCCCCC)C(S4)=C(S3)C5=C4C6=C(N5CC(CC)CCCC)C7=C(C(SC8=C9SC(/C=C%10C(C(C=C(F)C(F)=C%11)=C%11C\%10=C(C#N)C#N)=O)=C8CCCCCCCCCCC)=C9N7CC(CC)CCCC)C%12=NSN=C6%12' do = 'CCCCC(CC)CC1=C(F)C=C(C2=C3C=C(C4=CC=C(C5=C6C(=O)C7=C(CC(CC)CCCC)SC(CC(CC)CCCC)=C7C(=O)C6=C(C6=CC=C(C)S6)S5)S4)SC3=C(C3=CC(F)=C(CC(CC)CCCC)S3)C3=C2SC(C)=C3)S1' if option =="🎈Acceptor": st.subheader("👨‍🔬**Input the SMILES of Acceptor Molecule**") molecule = st.text_input("👨‍🔬**Input the SMILES of Acceptor Molecule**", label_visibility="hidden" ) acceptor= st_ketcher(molecule ) st.subheader("💗**PCE prediction**") st.subheader(f"🏆**New SMILES of edited acceptor molecules**: {acceptor}") st.subheader(":black[**🧡Input the SMILES of Donor Molecule**]") donor= st.text_input(":black[**🧡Input the SMILES of Donor Molecule**]", label_visibility="hidden") if option =="🎈Donor": st.subheader("👨‍🔬**Input the SMILES of Donor Molecule**" ) do= st.text_input("👨‍🔬**Input the SMILES of Donor Molecule**" , label_visibility="hidden") donor = st_ketcher(do) st.subheader("💗**PCE prediction**") st.subheader(f"🏆**New SMILES of edited donor molecules**: {donor}") st.subheader(":black[**🧡Input the SMILES of Acceptor Molecule**]") acceptor = st.text_input(":black[**🧡Input the SMILES of Acceptor Molecule**]", label_visibility="hidden") if option =="example": st.subheader("👨‍🔬**Input the SMILES of Acceptor**") st.markdown(molecule) acceptor= st_ketcher(molecule ) st.subheader(f"🏆**New SMILES of edited acceptor molecules**: {acceptor}") st.subheader(":black[**🧡Input the SMILES of Donor**]") st.markdown(do) donor= do try: pce = run.smiles_aas_test( str(acceptor ), str(donor) ) st.subheader(f"⚡**PCE**: ``{pce}``") except: st.subheader(f"⚡**PCE**: None ") st.subheader(":black[**🧡 High-throughput screening for high-performance D/A pairs**]") col5, col6 = st.columns(2) with col5: uploaded_files = st.file_uploader("Choose a CSV file") st.write( "🎈upload a csv file containing ['donor' ] and ['acceptor']") with col6: url2= r"https://docs.google.com/spreadsheets/d/1jPfHM21IjksNn_80fdakS1ofDNIagwMXBWAjoZBr-YY/gviz/tq?tqx=out:csv" df2 = pd.read_csv(url2) st.markdown('👇The example of input files for high-throughput screening.') st.download_button( "⬇️ Download example files", df2.to_csv(), "example.csv" ) if st.button("📑PREDICT"): if uploaded_files is not None: text = st.markdown(":red[Predictions are being made... Please wait...]") st.progress(100, text=None) x = screen.smiles_aas_test(uploaded_files ) fx = pd.DataFrame(list(x)) st.markdown(":red[Prediction finished! ]") st.download_button( "⬇️Download the predicted files as .csv", fx.to_csv(), "predict results.csv", use_container_width=True) else: st.markdown(":red[Please upload the file first!]")