File size: 2,643 Bytes
c32f5ba
0e3e8c8
 
6e7f1b9
0e3e8c8
c32f5ba
0e3e8c8
ea4d4e1
0e3e8c8
 
 
 
 
 
 
 
 
 
 
 
 
 
ebff2fb
6501c66
6e7f1b9
ddbb91a
 
6e7f1b9
 
 
 
0e3e8c8
ebff2fb
c32f5ba
 
 
 
0e3e8c8
ebff2fb
ddbb91a
 
 
 
 
c32f5ba
 
 
 
ddbb91a
c32f5ba
0e3e8c8
6e7f1b9
ea4d4e1
6e7f1b9
c32f5ba
0e3e8c8
ea4d4e1
ebff2fb
0e3e8c8
ea4d4e1
c32f5ba
6e7f1b9
c32f5ba
 
 
0e3e8c8
ea4d4e1
0e3e8c8
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import gradio as gr
from rdkit import Chem
from rdkit.Chem import Descriptors
import pandas as pd
import io
import base64

# تحليل ADMET
def get_admet(smiles):
    mol = Chem.MolFromSmiles(smiles)
    if not mol:
        return pd.Series([None]*7, index=["MW", "LogP", "TPSA", "HBA", "HBD", "RotB", "Lipinski"])
    mw = Descriptors.MolWt(mol)
    logp = Descriptors.MolLogP(mol)
    tpsa = Descriptors.TPSA(mol)
    hba = Descriptors.NumHAcceptors(mol)
    hbd = Descriptors.NumHDonors(mol)
    rotb = Descriptors.NumRotatableBonds(mol)
    lipinski = "✅" if (mw <= 500 and logp <= 5 and hba <= 10 and hbd <= 5) else "❌"
    return pd.Series([mw, logp, tpsa, hba, hbd, rotb, lipinski],
                     index=["MW", "LogP", "TPSA", "HBA", "HBD", "RotB", "Lipinski"])

# المعالجة الرئيسية
def analyze_smiles(file):
    try:
        with open(file.name, "r", encoding="utf-8") as f:
            content = f.read()
        smiles_list = [line.strip() for line in content.splitlines() if line.strip()]
        df = pd.DataFrame({"SMILES": smiles_list})
        admet_df = df["SMILES"].apply(get_admet)
        final_df = pd.concat([df, admet_df], axis=1)

        # Excel file
        excel_buffer = io.BytesIO()
        final_df.to_excel(excel_buffer, index=False, engine="openpyxl")
        excel_data = excel_buffer.getvalue()
        excel_b64 = base64.b64encode(excel_data).decode()

        # Markdown table
        try:
            import tabulate  # Try to import it explicitly
            table_md = final_df.to_markdown(index=False)
        except ImportError:
            table_md = "❌ مكتبة 'tabulate' مطلوبة لعرض الجدول. استخدم: pip install tabulate"

        return (
            "✅ التحليل ناجح!",
            table_md,
            f'<a download="ADMET_Analysis.xlsx" href="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,{excel_b64}">⬇️ تحميل ملف Excel</a>'
        )

    except Exception as e:
        return f"❌ خطأ أثناء المعالجة: {str(e)}", "", ""

# واجهة Gradio
with gr.Blocks() as demo:
    gr.Markdown("## 🧪 تحليل ADMET من قائمة SMILES")

    with gr.Row():
        smiles_file = gr.File(label="📄 ارفع ملف .txt يحتوي على SMILES")
        run_btn = gr.Button("🚀 تحليل ADMET")

    status = gr.Textbox(label="📢 الحالة")
    table = gr.Textbox(label="📊 جدول النتائج (Markdown)", lines=12)
    download = gr.HTML()

    run_btn.click(fn=analyze_smiles, inputs=[smiles_file], outputs=[status, table, download])

demo.launch()