Spaces:
Build error
Build error
Upload 5 files
Browse files- Dockerfile +21 -11
- README.md +17 -0
- app.py +80 -0
- requirements.txt +2 -0
- sample_molecules.csv +7 -0
Dockerfile
CHANGED
|
@@ -1,20 +1,30 @@
|
|
| 1 |
-
FROM python:3.
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
|
|
|
|
| 5 |
RUN apt-get update && apt-get install -y \
|
| 6 |
build-essential \
|
| 7 |
-
|
|
|
|
| 8 |
git \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 19 |
|
| 20 |
-
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
# Install dependencies
|
| 4 |
RUN apt-get update && apt-get install -y \
|
| 5 |
build-essential \
|
| 6 |
+
python3-dev \
|
| 7 |
+
wget \
|
| 8 |
git \
|
| 9 |
+
ca-certificates \
|
| 10 |
+
libxrender1 \
|
| 11 |
+
libglib2.0-0 \
|
| 12 |
+
libsm6 \
|
| 13 |
+
libxext6 \
|
| 14 |
+
libssl-dev \
|
| 15 |
+
libffi-dev \
|
| 16 |
&& rm -rf /var/lib/apt/lists/*
|
| 17 |
|
| 18 |
+
# Install RDKit via conda
|
| 19 |
+
RUN pip install --upgrade pip
|
| 20 |
+
RUN pip install streamlit pandas
|
| 21 |
+
RUN pip install rdkit-pypi
|
| 22 |
|
| 23 |
+
# Copy app files
|
| 24 |
+
COPY app.py /app/app.py
|
| 25 |
+
COPY requirements.txt /app/requirements.txt
|
| 26 |
+
COPY sample_molecules.csv /app/sample_molecules.csv
|
| 27 |
|
| 28 |
+
WORKDIR /app
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]
|
README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AI Drug Designer (Hugging Face Space)
|
| 2 |
+
|
| 3 |
+
This is a Docker-based Streamlit app for de novo drug screening using RDKit.
|
| 4 |
+
|
| 5 |
+
## Features
|
| 6 |
+
|
| 7 |
+
- Upload SMILES molecules
|
| 8 |
+
- Compute QED, MW, logP, H-bond counts
|
| 9 |
+
- Validate with Lipinski Rule-of-5
|
| 10 |
+
- Simulate SA Score
|
| 11 |
+
- Visualize molecules with legends
|
| 12 |
+
|
| 13 |
+
## How to Use on Hugging Face
|
| 14 |
+
|
| 15 |
+
1. Create a new Space β Select **Docker** β Template: **Streamlit**
|
| 16 |
+
2. Upload these files
|
| 17 |
+
3. App will run on https://your-username.hf.space
|
app.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from rdkit import Chem
|
| 3 |
+
from rdkit.Chem import Descriptors, QED
|
| 4 |
+
from rdkit.Chem import Draw
|
| 5 |
+
import pandas as pd
|
| 6 |
+
import base64
|
| 7 |
+
from io import BytesIO
|
| 8 |
+
|
| 9 |
+
st.set_page_config(page_title="AI Drug Generator Demo", layout="wide")
|
| 10 |
+
st.title("π AI-Driven De Novo Drug Design - Molecule Screening Demo")
|
| 11 |
+
|
| 12 |
+
st.markdown("""
|
| 13 |
+
This app demonstrates a simplified AI-driven drug design platform.
|
| 14 |
+
- Upload a CSV of SMILES
|
| 15 |
+
- Compute QED, MW, logP, and Lipinski Rule
|
| 16 |
+
- Visualize molecules and export results
|
| 17 |
+
""")
|
| 18 |
+
|
| 19 |
+
def validate_smiles(smiles_list):
|
| 20 |
+
valid = []
|
| 21 |
+
mols = []
|
| 22 |
+
for smi in smiles_list:
|
| 23 |
+
mol = Chem.MolFromSmiles(smi)
|
| 24 |
+
if mol:
|
| 25 |
+
valid.append(smi)
|
| 26 |
+
mols.append(mol)
|
| 27 |
+
return valid, mols
|
| 28 |
+
|
| 29 |
+
def simulated_sa_score(mol):
|
| 30 |
+
return Descriptors.NumRotatableBonds(mol) + 2
|
| 31 |
+
|
| 32 |
+
def draw_molecule_grid(mols, legends):
|
| 33 |
+
return Draw.MolsToGridImage(mols, molsPerRow=4, legends=legends, subImgSize=(200,200))
|
| 34 |
+
|
| 35 |
+
uploaded_file = st.file_uploader("π Upload CSV with SMILES column", type=["csv"])
|
| 36 |
+
|
| 37 |
+
if uploaded_file:
|
| 38 |
+
df = pd.read_csv(uploaded_file)
|
| 39 |
+
smiles_column = st.selectbox("Select SMILES column", df.columns.tolist())
|
| 40 |
+
smiles_list = df[smiles_column].dropna().astype(str).tolist()
|
| 41 |
+
|
| 42 |
+
valid_smiles, mols = validate_smiles(smiles_list)
|
| 43 |
+
st.success(f"β
Found {len(valid_smiles)} valid molecules.")
|
| 44 |
+
|
| 45 |
+
results = []
|
| 46 |
+
for smi, mol in zip(valid_smiles, mols):
|
| 47 |
+
mw = Descriptors.MolWt(mol)
|
| 48 |
+
logp = Descriptors.MolLogP(mol)
|
| 49 |
+
hbd = Descriptors.NumHDonors(mol)
|
| 50 |
+
hba = Descriptors.NumHAcceptors(mol)
|
| 51 |
+
qed = QED.qed(mol)
|
| 52 |
+
sa_score = simulated_sa_score(mol)
|
| 53 |
+
lipinski = all([mw <= 500, logp <= 5, hbd <= 5, hba <= 10])
|
| 54 |
+
results.append({
|
| 55 |
+
"SMILES": smi,
|
| 56 |
+
"MW": round(mw, 2),
|
| 57 |
+
"logP": round(logp, 2),
|
| 58 |
+
"HBD": hbd,
|
| 59 |
+
"HBA": hba,
|
| 60 |
+
"QED": round(qed, 2),
|
| 61 |
+
"SA Score (simulated)": sa_score,
|
| 62 |
+
"Lipinski Pass": lipinski
|
| 63 |
+
})
|
| 64 |
+
|
| 65 |
+
result_df = pd.DataFrame(results)
|
| 66 |
+
st.subheader("π Molecule Properties Table")
|
| 67 |
+
st.dataframe(result_df)
|
| 68 |
+
|
| 69 |
+
st.subheader("π§ͺ Molecule Visualization")
|
| 70 |
+
legends = [f"QED={row['QED']}" for row in results[:8]]
|
| 71 |
+
grid_img = draw_molecule_grid(mols[:8], legends)
|
| 72 |
+
st.image(grid_img)
|
| 73 |
+
|
| 74 |
+
csv_buffer = BytesIO()
|
| 75 |
+
result_df.to_csv(csv_buffer, index=False)
|
| 76 |
+
b64 = base64.b64encode(csv_buffer.getvalue()).decode()
|
| 77 |
+
st.markdown(f"π₯ [Download Results CSV](data:file/csv;base64,{b64})", unsafe_allow_html=True)
|
| 78 |
+
|
| 79 |
+
else:
|
| 80 |
+
st.info("π Upload a CSV with SMILES to begin.")
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
pandas
|
sample_molecules.csv
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
smiles
|
| 2 |
+
CCO
|
| 3 |
+
CC(=O)OC1=CC=CC=C1C(=O)O
|
| 4 |
+
CC(C)CC1=CC=C(C=C1)C(C)C(=O)O
|
| 5 |
+
C1=CC=C(C=C1)C=O
|
| 6 |
+
C1CCC(CC1)CO
|
| 7 |
+
CC(C)C(C(=O)O)N
|