NanoSimLab provides a comprehensive Docker orchestration system that includes both a REST API backend and a responsive web GUI frontend. This setup allows you to run the entire application stack with a single command.
-
Clone and navigate to the repository:
git clone https://github.com/hkevin01/NanoSimLab.git cd NanoSimLab -
Start the complete application stack:
./run.sh up
-
Access the applications:
- Web GUI: http://localhost:3000
- API Documentation: http://localhost:8080/docs
- API Health Check: http://localhost:8080/status
- Docker (v20.10+)
- Docker Compose (v2.0+) or docker-compose (v1.29+)
- Bash shell (macOS/Linux)
The orchestration script automatically detects your Docker setup and uses the appropriate commands.
┌─────────────────┐ ┌─────────────────┐
│ Web GUI │ │ REST API │
│ (Port 3000) │◄───┤ (Port 8080) │
│ Static Files │ │ FastAPI │
│ + JavaScript │ │ + NanoSimLab │
└─────────────────┘ └─────────────────┘
│ │
└───────────────────────┘
Docker Network
- REST API Backend: FastAPI server exposing NanoSimLab functionality
- Web GUI Frontend: Responsive single-page application with real-time simulation monitoring
- Docker Orchestration: Comprehensive run.sh script managing the entire stack
The ./run.sh script provides a complete Docker orchestration interface:
./run.sh help # Show detailed usage information
./run.sh up # Start all services (auto-creates GUI if missing)
./run.sh down # Stop and remove all services
./run.sh restart # Restart all services
./run.sh status # Show service status and health./run.sh build # Build Docker images
./run.sh logs [service] # Show logs (default: api)
./run.sh shell [service] # Open shell in container
./run.sh exec "command" # Execute command in API container./run.sh gui:create # Create GUI scaffold if missing
./run.sh gui:create --force # Recreate GUI (overwrites existing)
./run.sh gui:open # Open GUI in default browser./run.sh ps # Show running containers
./run.sh clean # Remove containers and volumes
./run.sh prune # Clean entire Docker system (WARNING)Create a .env file to customize your setup:
# Copy the example configuration
cp .env.example .env
# Edit configuration
nano .envKey Configuration Options:
| Variable | Default | Description |
|---|---|---|
PORTS |
8080:8080 |
API port mapping |
GUI_PORT |
3000 |
GUI port |
API_URL |
http://localhost:8080 |
API URL for GUI |
DEV_MODE |
false |
Enable development features |
IMAGE_NAME |
nanosimlab-api:local |
Backend Docker image name |
GUI_IMAGE_NAME |
nanosimlab-gui:local |
Frontend Docker image name |
Enable development mode for hot reloading and debugging:
# Set in .env file
DEV_MODE=true
# Or set temporarily
DEV_MODE=true ./run.sh upDevelopment mode features:
- Source code hot reloading
- Additional development tools in containers
- Verbose logging
- Development server with auto-restart
The automatically generated GUI provides:
- Predefined simulation presets (small test, nanoparticles, charged particles)
- One-click simulation launching
- Interactive parameter adjustment
- Real-time form validation
- Support for Lennard-Jones and Yukawa potentials
- Real-time progress tracking
- Job status updates
- Background simulation execution
- Trajectory summaries
- Mean-squared displacement (MSD) analysis
- Radial distribution function (RDF) plots
- Downloadable results
- Mobile-friendly interface
- Modern, accessible UI components
- Real-time status indicators
The REST API provides programmatic access to NanoSimLab:
| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Health check |
GET |
/status |
Service status |
POST |
/simulate |
Start simulation |
GET |
/simulate/{job_id} |
Get job status |
GET |
/simulate/{job_id}/result |
Get results |
GET |
/jobs |
List all jobs |
DELETE |
/jobs/{job_id} |
Delete job |
POST |
/analyze |
Analyze uploaded trajectory |
GET |
/presets |
Get simulation presets |
- Swagger UI: http://localhost:8080/docs
- ReDoc: http://localhost:8080/redoc
# Start simulation
curl -X POST "http://localhost:8080/simulate" \
-H "Content-Type: application/json" \
-d '{
"n_particles": 100,
"box_size": 15.0,
"steps": 5000,
"potential": {
"type": "lj",
"epsilon": 1.0,
"sigma": 1.0
}
}'
# Response: {"job_id": "uuid", "status": "queued", ...}curl "http://localhost:8080/simulate/{job_id}"import requests
# Start simulation
response = requests.post("http://localhost:8080/simulate", json={
"n_particles": 200,
"box_size": 20.0,
"steps": 10000,
"potential": {"type": "lj", "epsilon": 1.0, "sigma": 1.0}
})
job_id = response.json()["job_id"]
# Poll for completion
import time
while True:
status = requests.get(f"http://localhost:8080/simulate/{job_id}").json()
if status["status"] == "completed":
break
time.sleep(2)
# Get results
results = requests.get(f"http://localhost:8080/simulate/{job_id}/result").json()1. Port Already in Use
# Check what's using the port
lsof -i :8080
# Or change the port
PORTS=8081:8080 ./run.sh up2. Docker Permission Issues
# Add user to docker group
sudo usermod -aG docker $USER
# Then logout and login again3. GUI Not Loading
# Check API connectivity
curl http://localhost:8080/status
# Recreate GUI
./run.sh gui:create --force
./run.sh restart4. Memory Issues
# Monitor container resources
docker stats
# Adjust container limits in docker-compose.ymlEnable verbose logging:
# Show detailed logs
./run.sh logs api
# Follow logs in real-time
./run.sh logs api | tail -f
# Check container health
docker inspect nanosimlab-api | grep Health -A 10# Complete reset
./run.sh clean
./run.sh prune # WARNING: removes all Docker data
./run.sh upAdjust container resources in docker-compose.yml:
services:
api:
deploy:
resources:
limits:
memory: 4G # Increase for large simulations
cpus: '2.0' # Use multiple coresRun multiple API instances:
# Scale API service
docker-compose up --scale api=3For GPU-accelerated simulations (future feature):
services:
api:
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]For production use:
-
Use environment-specific configuration:
cp .env.example .env.production # Edit production settings -
Enable HTTPS:
- Use a reverse proxy (nginx, traefik)
- Configure SSL certificates
- Update CORS settings
-
Use external databases:
- Redis for job queue
- PostgreSQL for persistent data
-
Monitor and log:
- Set up log aggregation
- Configure health monitoring
- Set resource alerts
When contributing Docker-related changes:
- Test with both
docker composeanddocker-compose - Ensure compatibility with both development and production modes
- Update documentation for any new environment variables
- Test the complete workflow with
./run.sh up
For more information, see the main README.md and CONTRIBUTING.md.