File size: 3,590 Bytes
43e7ae4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# HITL Drug Discovery - Modular Architecture

## πŸ—οΈ Project Structure

```
HITL_Drug_Discovery/
β”œβ”€β”€ main.py                 # Main entry point
β”œβ”€β”€ app.py                  # Legacy monolithic app (backup)
β”œβ”€β”€ requirements.txt        # Dependencies
β”œβ”€β”€ README.md              # Original README
β”œβ”€β”€ README_MODULAR.md      # This file
└── src/                   # Modular source code
    β”œβ”€β”€ __init__.py
    β”œβ”€β”€ app.py             # Main application orchestrator
    β”œβ”€β”€ molecules/         # Molecular analysis and variations
    β”‚   β”œβ”€β”€ __init__.py
    β”‚   β”œβ”€β”€ analysis.py    # Molecular property calculations
    β”‚   └── variations.py  # Structure variation generation
    β”œβ”€β”€ ai/                # AI services
    β”‚   β”œβ”€β”€ __init__.py
    β”‚   └── services.py    # AI chat and structure generation
    β”œβ”€β”€ ui/                # UI components and handlers
    β”‚   β”œβ”€β”€ __init__.py
    β”‚   β”œβ”€β”€ components.py  # UI component definitions
    β”‚   └── handlers.py    # Event handlers and business logic
    └── config/            # Configuration and settings
        β”œβ”€β”€ __init__.py
        └── settings.py    # App configuration and constants
```

## πŸš€ Running the Application

### Option 1: Modular Version (Recommended)
```bash
python main.py
```

### Option 2: Legacy Monolithic Version
```bash
python app.py
```

## πŸ“ Module Descriptions

### `src/molecules/`
- **`analysis.py`**: Molecular property calculations, SMILES validation, drug-likeness assessment
- **`variations.py`**: Generation of multiple molecular structure visualizations

### `src/ai/`
- **`services.py`**: AI-powered chat responses and structure generation using OpenAI GPT-OSS-20B

### `src/ui/`
- **`components.py`**: Reusable UI component definitions for Gradio interface
- **`handlers.py`**: Event handlers, business logic, and state management

### `src/config/`
- **`settings.py`**: Application configuration, constants, and styling

### `src/app.py`
- **Main orchestrator**: Ties all modules together and creates the Gradio interface

## πŸ”§ Benefits of Modular Architecture

1. **Maintainability**: Each module has a single responsibility
2. **Testability**: Individual modules can be tested in isolation
3. **Scalability**: Easy to add new features without affecting existing code
4. **Readability**: Clear separation of concerns
5. **Reusability**: Components can be reused across different parts of the app
6. **Professional**: Industry-standard project structure

## πŸ§ͺ Key Features

- **Molecular Analysis**: SMILES validation, property calculations, drug-likeness assessment
- **Chemical Variations**: Multiple visualization styles and rendering options
- **AI Structure Generation**: AI-powered molecular structure suggestions
- **Interactive UI**: Clean, modern interface with real-time feedback
- **Bookmarking**: Save and manage favorite molecular structures

## πŸ”„ Migration from Monolithic

The original `app.py` (1082 lines) has been refactored into:
- **6 focused modules** with clear responsibilities
- **~200 lines per module** for better maintainability
- **Clean imports** and dependencies
- **Preserved functionality** with improved organization

## πŸš€ Future Enhancements

With the modular structure, it's now easy to:
- Add new molecular analysis algorithms
- Implement additional AI models
- Create new UI components
- Add database integration
- Implement user authentication
- Add API endpoints
- Create unit tests for each module