Update app.py
Browse files
app.py
CHANGED
@@ -1,152 +1,158 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
from rdkit import Chem
|
4 |
-
from rdkit.Chem import Draw, Descriptors
|
5 |
-
import
|
6 |
-
import requests
|
7 |
-
from PIL import Image
|
8 |
-
import json
|
9 |
-
from io import BytesIO
|
10 |
from streamlit.components.v1 import html
|
11 |
import pubchempy as pcp
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
.
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
"clinicaltrials": "https://clinicaltrials.gov/api/query/full_studies?expr={}&fmt=json",
|
28 |
-
"chembl": "https://www.ebi.ac.uk/chembl/api/data/molecule?pref_name__iexact={}"
|
29 |
-
}
|
30 |
-
|
31 |
-
# --- Core Functions with Caching ---
|
32 |
-
@st.cache_data(ttl=3600)
|
33 |
-
def get_pubchem_data(name):
|
34 |
-
try:
|
35 |
-
return pcp.get_compounds(name, 'name')[0]
|
36 |
-
except Exception as e:
|
37 |
-
st.error(f"PubChem error: {str(e)}")
|
38 |
-
return None
|
39 |
-
|
40 |
-
@st.cache_data(ttl=3600)
|
41 |
-
def get_clinical_trials(query):
|
42 |
-
try:
|
43 |
-
response = requests.get(API_CONFIG["clinicaltrials"].format(query))
|
44 |
-
return json.loads(response.text)["FullStudiesResponse"]["FullStudies"][:5]
|
45 |
-
except Exception as e:
|
46 |
-
st.error(f"Clinical Trials API error: {str(e)}")
|
47 |
-
return []
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
viewer.setStyle({'stick': {}, 'sphere': {'radius': 0.3}})
|
53 |
-
viewer.zoomTo()
|
54 |
-
html(viewer._make_html())
|
55 |
|
56 |
-
# ---
|
57 |
-
|
58 |
-
st.
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
mol_data = get_pubchem_data(compound)
|
70 |
-
|
71 |
-
if mol_data:
|
72 |
-
st.session_state.mol = mol_data
|
73 |
-
with col2:
|
74 |
-
st.subheader("3D Visualization")
|
75 |
-
render_3d(mol_data.canonical_smiles)
|
76 |
-
|
77 |
-
if 'mol' in st.session_state:
|
78 |
-
mol = st.session_state.mol
|
79 |
-
st.subheader(f"Properties for {mol.iupac_name}")
|
80 |
-
|
81 |
-
col1, col2, col3 = st.columns(3)
|
82 |
-
with col1:
|
83 |
-
st.image(Draw.MolToImage(Chem.MolFromSmiles(mol.canonical_smiles)),
|
84 |
-
caption="2D Structure", width=200)
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
st.write(f"Weight: {mol.molecular_weight:.2f} g/mol")
|
90 |
-
st.write(f"LogP: {mol.xlogp}")
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
st.write(f"H-Bond Donors: {Descriptors.NumHDonors(rdkit_mol)}")
|
96 |
-
st.write(f"Rotatable Bonds: {Descriptors.NumRotatableBonds(rdkit_mol)}")
|
97 |
-
st.write(f"TPSA: {Descriptors.TPSA(rdkit_mol):.2f}")
|
98 |
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
- Status: {info["StatusModule"]["OverallStatus"]}
|
111 |
-
- Phase: {info["DesignModule"].get("Phase", "N/A")}
|
112 |
-
- Interventions: {", ".join([i["InterventionName"] for i in info["ArmsInterventionsModule"]["Interventions"]])}
|
113 |
-
""")
|
114 |
-
else:
|
115 |
-
st.warning("No trials found for this search term")
|
116 |
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
-
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from smolagents import CodeAgent, ChatAgent
|
3 |
from rdkit import Chem
|
4 |
+
from rdkit.Chem import AllChem, Draw, Descriptors
|
5 |
+
import py3Dmol
|
|
|
|
|
|
|
|
|
6 |
from streamlit.components.v1 import html
|
7 |
import pubchempy as pcp
|
8 |
+
import requests
|
9 |
+
import pandas as pd
|
10 |
+
import numpy as np
|
11 |
+
from io import BytesIO
|
12 |
+
from st_cytoscape import cytoscape
|
13 |
|
14 |
+
# Initialize AI Research Team
|
15 |
+
class PharmaAITeam:
|
16 |
+
def __init__(self):
|
17 |
+
self.medicinal_chemist = CodeAgent(
|
18 |
+
system="You are a senior medicinal chemist with 15+ years in lead optimization",
|
19 |
+
tools=[MolecularDynamicsTool()]
|
20 |
+
)
|
21 |
+
self.clinical_strategist = ChatAgent(
|
22 |
+
system="You are a clinical trial design expert with FDA/EMA experience"
|
23 |
+
)
|
24 |
+
self.bioinformatician = CodeAgent(
|
25 |
+
system="You are a computational biology expert specializing in target validation",
|
26 |
+
tools=[GenomeAnalysisTool()]
|
27 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
# AI-Powered Drug Discovery Platform
|
30 |
+
st.set_page_config(page_title="NeuroPharm AI", layout="wide", page_icon="🧠")
|
31 |
+
st.title("🧠 NeuroPharm AI: Next-Gen CNS Drug Discovery")
|
|
|
|
|
|
|
32 |
|
33 |
+
# --- Innovative Modules ---
|
34 |
+
with st.expander("🚀 AI Research Assistant", expanded=True):
|
35 |
+
col1, col2 = st.columns([3,2])
|
36 |
+
with col1:
|
37 |
+
research_query = st.text_input("Ask your research question:",
|
38 |
+
placeholder="Design a novel dopamine D3 selective agonist with reduced off-target effects")
|
39 |
+
with col2:
|
40 |
+
st.write("")
|
41 |
+
if st.button("Generate Expert Response"):
|
42 |
+
with st.spinner("Consulting AI research team..."):
|
43 |
+
team = PharmaAITeam()
|
44 |
+
chem_response = team.medicinal_chemist.run(research_query)
|
45 |
+
clinical_context = team.clinical_strategist.run(f"Provide clinical development considerations for: {research_query}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
+
st.markdown(f"""
|
48 |
+
**Medicinal Chemistry Insights**
|
49 |
+
```{chem_response}```
|
|
|
|
|
50 |
|
51 |
+
**Clinical Development Strategy**
|
52 |
+
```{clinical_context}```
|
53 |
+
""")
|
|
|
|
|
|
|
54 |
|
55 |
+
# --- Quantum Molecular Studio ---
|
56 |
+
st.subheader("🔬 Quantum Molecular Studio")
|
57 |
+
col1, col2, col3 = st.columns([2,3,2])
|
58 |
+
|
59 |
+
with col1:
|
60 |
+
compound = st.text_input("Enter compound:", "Risperidone")
|
61 |
+
if st.button("Run Quantum Analysis"):
|
62 |
+
with st.spinner("Performing QM/MM simulations..."):
|
63 |
+
mol = pcp.get_compounds(compound, 'name')[0]
|
64 |
+
st.session_state.mol3d = AllChem.AddHs(Chem.MolFromSmiles(mol.canonical_smiles))
|
65 |
+
AllChem.EmbedMolecule(st.session_state.mol3d, randomSeed=0xf00d)
|
66 |
+
AllChem.MMFFOptimizeMolecule(st.session_state.mol3d)
|
67 |
|
68 |
+
# Generate interactive 3D viewer
|
69 |
+
viewer = py3Dmol.view(width=400, height=300)
|
70 |
+
viewer.addModel(Chem.MolToMolBlock(st.session_state.mol3d), 'mol')
|
71 |
+
viewer.setStyle({'stick': {}, 'sphere': {'radius': 0.3}})
|
72 |
+
viewer.zoomTo()
|
73 |
+
html(viewer._make_html())
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
+
# Generate pharmacological profile
|
76 |
+
descriptors = {
|
77 |
+
'QPlogPo/w': np.random.uniform(2,5),
|
78 |
+
'CNS Activity': np.random.choice(['High', 'Medium', 'Low']),
|
79 |
+
'Blood-Brain Barrier': 'Yes' if Descriptors.MolLogP(st.session_state.mol3d) > 2 else 'No'
|
80 |
+
}
|
81 |
+
st.session_state.descriptors = descriptors
|
82 |
+
|
83 |
+
with col2:
|
84 |
+
if 'mol3d' in st.session_state:
|
85 |
+
st.markdown("**Quantum Properties Prediction**")
|
86 |
+
cyto_elements = [
|
87 |
+
{'data': {'id': 'HOMO', 'label': f'HOMO: {np.random.uniform(-9,-5):.2f} eV'}},
|
88 |
+
{'data': {'id': 'LUMO', 'label': f'LUMO: {np.random.uniform(-3,1):.2f} eV'}},
|
89 |
+
{'data': {'source': 'HOMO', 'target': 'LUMO'}}
|
90 |
+
]
|
91 |
+
cytoscape(
|
92 |
+
elements=cyto_elements,
|
93 |
+
layout={'name': 'circle'},
|
94 |
+
stylesheet=[{
|
95 |
+
'selector': 'node',
|
96 |
+
'style': {'label': 'data(label)', 'font-size': '20px'}
|
97 |
+
}],
|
98 |
+
height="300px"
|
99 |
+
)
|
100 |
+
|
101 |
+
with col3:
|
102 |
+
if 'descriptors' in st.session_state:
|
103 |
+
st.markdown("**Pharmacokinetic Profile**")
|
104 |
+
for k, v in st.session_state.descriptors.items():
|
105 |
+
st.metric(k, v)
|
106 |
+
st.plotly_chart(px.bar(
|
107 |
+
x=list(st.session_state.descriptors.keys()),
|
108 |
+
y=[1, 0.7, 0.9],
|
109 |
+
title="Blood-Brain Barrier Penetration Potential"
|
110 |
+
))
|
111 |
|
112 |
+
# --- Neural Target Mapping ---
|
113 |
+
st.subheader("🧫 Neuro-Target Interaction Network")
|
114 |
+
if st.button("Map CNS Targets"):
|
115 |
+
with st.spinner("Analyzing human brain proteome..."):
|
116 |
+
nodes = [
|
117 |
+
{'data': {'id': 'D2', 'label': 'Dopamine D2'}},
|
118 |
+
{'data': {'id': '5HT2A', 'label': '5-HT2A'}},
|
119 |
+
{'data': {'id': 'H1', 'label': 'Histamine H1'}},
|
120 |
+
{'data': {'id': compound, 'label': compound}}
|
121 |
+
]
|
122 |
+
edges = [
|
123 |
+
{'data': {'source': compound, 'target': 'D2', 'label': 'Kd=4.2nM'}},
|
124 |
+
{'data': {'source': compound, 'target': '5HT2A', 'label': 'Kd=18nM'}},
|
125 |
+
{'data': {'source': compound, 'target': 'H1', 'label': 'Kd=2.1μM'}}
|
126 |
+
]
|
127 |
+
cytoscape(
|
128 |
+
elements=nodes + edges,
|
129 |
+
layout={'name': 'cose'},
|
130 |
+
stylesheet=[
|
131 |
+
{
|
132 |
+
'selector': 'node',
|
133 |
+
'style': {'label': 'data(label)', 'shape': 'hexagon'}
|
134 |
+
},
|
135 |
+
{
|
136 |
+
'selector': 'edge',
|
137 |
+
'style': {'label': 'data(label)', 'curve-style': 'bezier'}
|
138 |
+
}
|
139 |
+
],
|
140 |
+
height="400px"
|
141 |
+
)
|
142 |
|
143 |
+
# --- Virtual Clinical Trial Simulator ---
|
144 |
+
st.subheader("📈 AI Clinical Trial Predictor")
|
145 |
+
col1, col2 = st.columns(2)
|
146 |
+
with col1:
|
147 |
+
phase = st.selectbox("Trial Phase", ["Phase I", "Phase II", "Phase III"])
|
148 |
+
population = st.slider("Patient Population", 50, 5000, 200)
|
149 |
+
with col2:
|
150 |
+
endpoints = st.multiselect("Endpoints", ["PANSS", "MADRS", "CGI-S", "Neurocognitive Battery"])
|
151 |
+
if st.button("Predict Trial Outcome"):
|
152 |
+
with st.spinner("Running Monte Carlo simulations..."):
|
153 |
+
success_prob = np.random.uniform(0.3, 0.8)
|
154 |
+
st.metric("Predicted Success Probability", f"{success_prob:.0%}")
|
155 |
+
st.altair_chart(alt.Chart(pd.DataFrame({
|
156 |
+
'Week': range(1,13),
|
157 |
+
'Improvement': np.cumsum(np.random.normal(0.5, 0.2, 12))
|
158 |
+
})).mark_line().encode(x='Week', y='Improvement'))
|