-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.py
More file actions
196 lines (156 loc) · 7.14 KB
/
demo.py
File metadata and controls
196 lines (156 loc) · 7.14 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
"""
BBB GNN Prediction System - Complete Demo
Showcases all capabilities of the breakthrough system
"""
import sys
from predict_bbb import BBBGNNPredictor
def print_header(text):
"""Print formatted header"""
print("\n" + "="*70)
print(text.center(70))
print("="*70)
def print_subheader(text):
"""Print formatted subheader"""
print("\n" + "-"*70)
print(text)
print("-"*70)
def demo_single_prediction(predictor):
"""Demonstrate single molecule prediction"""
print_subheader("DEMO 1: Single Molecule Prediction")
smiles = 'CN1C=NC2=C1C(=O)N(C(=O)N2C)C'
compound_name = 'Caffeine'
print(f"\nPredicting BBB permeability for {compound_name}...")
print(f"SMILES: {smiles}\n")
result = predictor.predict(smiles, return_details=True)
if result['success']:
print(f"BBB Permeability Score: {result['bbb_score']:.3f}")
print(f"Category: {result['category']}")
print(f"Interpretation: {result['interpretation']}")
if 'molecular_descriptors' in result:
desc = result['molecular_descriptors']
print(f"\nMolecular Properties:")
print(f" MW: {desc['molecular_weight']:.1f} Da")
print(f" LogP: {desc['logp']:.2f}")
print(f" TPSA: {desc['tpsa']:.1f} A^2")
print(f" H-Donors: {desc['num_h_donors']}")
print(f" H-Acceptors: {desc['num_h_acceptors']}")
print(f" BBB Rule Compliant: {desc['bbb_rule_compliant']}")
if result.get('warnings'):
print(f"\nWarnings:")
for warning in result['warnings']:
print(f" - {warning}")
def demo_batch_prediction(predictor):
"""Demonstrate batch prediction"""
print_subheader("DEMO 2: Batch Prediction")
compounds = [
('COC(=O)C1C(CC2CC1N2C)c3cccc(c3)OC', 'Cocaine (CNS stimulant)'),
('CC(C)NCC(COc1ccccc1)O', 'Propranolol (beta blocker)'),
('C(C(=O)O)N', 'Glycine (amino acid)'),
('C(C(C(C(C(C=O)O)O)O)O)O', 'Glucose (sugar)'),
('c1ccccc1', 'Benzene (aromatic)'),
('CC(=O)Nc1ccc(cc1)O', 'Acetaminophen (pain reliever)'),
]
smiles_list = [s for s, _ in compounds]
print(f"\nPredicting BBB permeability for {len(compounds)} compounds...")
results = predictor.predict_batch(smiles_list)
print(f"\n{'Compound':<30} {'BBB Score':>10} {'Category':>10} {'BBB Rule':>12}")
print("-" * 70)
for (_, name), result in zip(compounds, results):
if result['success']:
compliant = result.get('bbb_rule_compliant', 'N/A')
compliant_str = 'Yes' if compliant else 'No' if compliant is not None else 'N/A'
print(f"{name:<30} {result['bbb_score']:>10.3f} {result['category']:>10} {compliant_str:>12}")
def demo_drug_screening(predictor):
"""Demonstrate drug candidate screening"""
print_subheader("DEMO 3: Virtual Drug Screening")
candidates = [
('CN1C2CCC1C(C(C2)OC(=O)c3ccccc3)C(=O)OC', 'Atropine'),
('CC(C)(C)NCC(COc1ccc(cc1)COCCOC(C)(C)C)O', 'Carvedilol analog'),
('COc1ccc2c(c1)c(c[nH]2)CCN', 'Serotonin derivative'),
('C1CC(C(C(C1)N)O)N', 'Streptamine'),
]
print(f"\nScreening {len(candidates)} drug candidates for BBB penetration...")
print("\nCandidate Classification:")
print(f"\n{'Compound':<25} {'BBB Score':>10} {'Prediction':>15} {'MW':>8} {'LogP':>7}")
print("-" * 70)
for smiles, name in candidates:
result = predictor.predict(smiles, return_details=True)
if result['success']:
desc = result.get('molecular_descriptors', {})
mw = desc.get('molecular_weight', 0)
logp = desc.get('logp', 0)
print(f"{name:<25} {result['bbb_score']:>10.3f} {result['category']:>15} {mw:>8.1f} {logp:>7.2f}")
print("\nInterpretation:")
print(" BBB+: Likely to cross blood-brain barrier (CNS active)")
print(" BBB-: Unlikely to cross (peripheral action)")
print(" BBB±: Moderate permeability (case-by-case)")
def demo_property_analysis(predictor):
"""Demonstrate molecular property analysis"""
print_subheader("DEMO 4: Molecular Property Analysis")
test_smiles = 'COC(=O)C1C(CC2CC1N2C)c3cccc(c3)OC' # Cocaine
compound_name = 'Cocaine'
print(f"\nDetailed analysis of {compound_name}...")
result = predictor.predict(test_smiles, return_details=True)
if result['success'] and 'molecular_descriptors' in result:
desc = result['molecular_descriptors']
print(f"\nMolecular Structure:")
print(f" SMILES: {test_smiles}")
print(f"\nPhysicochemical Properties:")
print(f" Molecular Weight: {desc['molecular_weight']:.2f} Da")
print(f" LogP (lipophilicity): {desc['logp']:.2f}")
print(f" TPSA: {desc['tpsa']:.2f} A^2")
print(f" Rotatable Bonds: {desc['num_rotatable_bonds']}")
print(f" Aromatic Rings: {desc['num_aromatic_rings']}")
print(f" Total Atoms: {desc['num_atoms']}")
print(f"\nHydrogen Bonding:")
print(f" H-bond Donors: {desc['num_h_donors']}")
print(f" H-bond Acceptors: {desc['num_h_acceptors']}")
print(f"\nDrug-likeness:")
print(f" Lipinski Violations: {desc['lipinski_violations']}/4")
print(f" BBB Rule Compliant: {desc['bbb_rule_compliant']}")
print(f"\nBBB Prediction:")
print(f" Permeability Score: {result['bbb_score']:.3f}")
print(f" Category: {result['category']}")
print(f" Clinical Relevance: CNS-active stimulant")
def main():
"""Run complete demonstration"""
print_header("BBB GNN PREDICTION SYSTEM - COMPLETE DEMO")
print("\nInitializing hybrid GAT+SAGE GNN predictor...")
try:
predictor = BBBGNNPredictor(model_path='models/best_model.pth')
except Exception as e:
print(f"Error loading model: {e}")
print("\nPlease ensure you have:")
print(" 1. Trained the model using: python train_gnn.py")
print(" 2. Model file exists at: models/best_model.pth")
sys.exit(1)
print("\nModel loaded successfully!")
print(f"Architecture: Hybrid GAT+GraphSAGE")
print(f"Parameters: 649,345")
print(f"Node features: 9 (atomic properties)")
# Run demonstrations
demo_single_prediction(predictor)
demo_batch_prediction(predictor)
demo_drug_screening(predictor)
demo_property_analysis(predictor)
print_header("DEMO COMPLETE")
print("\nSystem Capabilities:")
print(" - Single molecule prediction")
print(" - Batch processing")
print(" - Drug candidate screening")
print(" - Molecular property analysis")
print(" - BBB rule compliance checking")
print(" - Real-time SMILES to prediction")
print("\nModel Performance:")
print(" - Validation MAE: 0.0967")
print(" - Validation RMSE: 0.1334")
print(" - Dataset: 42 curated compounds")
print("\nFor more information:")
print(" - README.md: System documentation")
print(" - RESULTS.md: Detailed performance metrics")
print(" - predict_bbb.py: Prediction API")
print(" - train_gnn.py: Training pipeline")
print("\nThank you for using BBB GNN Prediction System!")
print("=" * 70)
if __name__ == "__main__":
main()