A machine learning project that uses evolutionary algorithms to train neural networks for automated molecular docking procedures. The system supports progressive environment complexity, comprehensive trajectory storage, and advanced analysis capabilities.
- Evolutionary Algorithms: Train neural networks using bio-inspired optimization
- Progressive Environments: Start simple and increase complexity for better learning
- Trajectory Database: Store millions of trajectories with full reproducibility
- Multi-processing Support: Concurrent simulations with safe database access
- Visualization Tools: Plot results with matplotlib and render in Blender
- 3D Rendering: High-quality trajectory visualization in Blender
- Species Tracking: Identify and analyze evolutionary species
- Comprehensive Analysis: Performance metrics, generation statistics, and more
The project is structured for modularity and reusability:
src/bioinspired/
βββ algorithm/ # Evolutionary algorithms
βββ data/ # Database models and management
βββ docking/ # Docking simulation logic
βββ visualization/ # Plotting and rendering tools
- Python 3.8+
- Docker & Docker Compose
- Git
-
Clone the repository:
git clone <your-repo-url> cd BioInspired
-
Run the setup script (creates virtual environment and sets up everything):
python setup.py
This will:
- Create a virtual environment in
venv/ - Install Python dependencies in the virtual environment
- Start PostgreSQL database
- Initialize database tables
- Run example usage
- Create a virtual environment in
-
Activate the virtual environment (for future work):
# Windows PowerShell .\activate.ps1 # Or manually .\venv\Scripts\Activate.ps1 # Unix/Linux/Mac source activate.sh # Or manually source venv/bin/activate
If you prefer manual setup:
-
Create and activate virtual environment:
python -m venv venv .\venv\Scripts\Activate.ps1 # Windows # source venv/bin/activate # Unix/Linux/Mac
-
Install dependencies:
pip install -r requirements.txt -
Start the database:
docker-compose up -d
-
Initialize database tables:
python init_db.py
-
Run the example:
python example_usage.py
The system uses PostgreSQL with the following main entities:
- Environment: Simulation environments with increasing complexity
- Algorithm: Algorithm runs with hyperparameters and settings
- Individual: Candidate solutions with fitness scores
- Trajectory: Large numerical trajectory data (stored as files)
- Annotation: Analysis results and metadata
from bioinspired.data import DatabaseManager
import numpy as np
# Initialize database manager
db = DatabaseManager()
# Create an environment
env = db.create_environment(
name="Basic Docking Environment",
description="Simple environment for initial training",
parameters={"complexity_level": 1}
)
# Create algorithm run
algorithm = db.create_algorithm(
environment_id=env.id,
population_id="experiment_001",
seed=42,
hyperparameters={
"population_size": 100,
"num_generations": 50
}
)
# Create individual with trajectory
individual = db.create_individual(
algorithm_id=algorithm.id,
generation=0,
fitness=0.85,
species="species_A"
)
# Save trajectory data
trajectory_data = np.random.rand(1000, 3) # 1000 steps, 3D
trajectory = db.save_trajectory_data(
individual_id=individual.id,
trajectory_data=trajectory_data
)# Get best individuals
best = db.get_best_individuals(algorithm.id, limit=10)
# Get generation statistics
stats = db.get_generation_stats(algorithm.id)
# Load trajectory data
trajectory_obj, data = db.load_trajectory_data(trajectory.id)Edit .env file:
DATABASE_URL=postgresql://bioinspired_user:bioinspired_pass@localhost:5432/bioinspired
DEBUG=True
LOG_LEVEL=INFOThe docker-compose.yml sets up PostgreSQL with persistent storage. Modify ports or credentials as needed.
The project now includes a separate blender_bio package for 3D visualization:
src/
βββ bioinspired/ # Core evolutionary algorithm package
β βββ algorithm/ # Evolutionary algorithms
β βββ data/ # Database and trajectory management
β βββ docking/ # Docking simulation
β βββ visualization/ # Basic matplotlib plotting
βββ blender_bio/ # Advanced 3D rendering with Blender
βββ core/ # Scene setup and materials
βββ trajectory/ # Trajectory rendering and animation
βββ molecules/ # Molecular visualization (future)
βββ exporters/ # Video/image export utilities (future)
βββ standalone/ # Standalone rendering scripts
The Blender package can be used in two ways:
- From Python (subprocess): Use
blender_rendering_example.py - Within Blender: Run scripts directly in Blender's Python console
# Render a trajectory from outside Blender
from blender_rendering_example import render_trajectory_with_blender
render_trajectory_with_blender(trajectory_id=1)
# Or use the interactive script
python blender_rendering_example.py# Render from command line with Blender
blender --background --python src/blender_bio/standalone/render_trajectory.py -- --trajectory_id 1 --output_path ./renders/- Create algorithm modules in
src/bioinspired/algorithm/ - Use the
DatabaseManagerto store results - Follow the existing patterns for reproducibility
- Create visualization modules in
src/bioinspired/visualization/ - Use matplotlib for plotting, Blender for 3D rendering
- Query data using the database interface
# Run tests (once you add them)
python -m pytest tests/
# Check database connectivity
python init_db.py- Large Datasets: Trajectory data is stored in compressed NumPy files
- Concurrent Access: PostgreSQL handles multiple processes safely
- Indexing: Database tables are optimized for common queries
- Memory Usage: Only load trajectory data when needed
This project uses a custom license that allows modification but not incorporation into other programs, and requires attribution. See LICENSE for details.
Custom Non-Commercial, No-Derivative License with Attribution.
- β Modification allowed
- β Commercial use prohibited
- β Incorporation into other programs prohibited
- β Attribution required
# Check if database is running
docker-compose ps
# Restart database
docker-compose restart
# Check logs
docker-compose logs postgres# Install in development mode
pip install -e .- Trajectory files are automatically excluded from git
- Use
.gitignorepatterns to exclude large datasets - Consider using Git LFS for sharing large files