# fly_frain **Repository Path**: dxatar/fly_frain ## Basic Information - **Project Name**: fly_frain - **Description**: 基于果蝇大脑的运动可视化项目 - **Primary Language**: Unknown - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 4 - **Created**: 2026-09-19 - **Last Updated**: 2026-09-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # FlyBrain Simulation A computational neuroscience simulation of Drosophila melanogaster (fruit fly) behavior, featuring a spiking neural network connectome, physical embodiment, and real-time web visualization. ## Overview FlyBrain simulates the closed-loop interaction between a fly's neural activity and its physical behavior in a virtual environment. The system integrates: - **LIF Neural Network**: Leaky Integrate-and-Fire neuron model with configurable connectivity - **Connectome**: Hierarchical neural architecture (sensory → integration → motor) - **Behavioral State Machine**: Real-time behavior classification (foraging, quiescence, etc.) - **Physics Engine**: 2D body dynamics with environmental interaction - **Web Interface**: Live visualization and experimental manipulation ## Installation ```bash # Clone the repository git clone https://gitee.com/dxatar/fly_frain.git cd fly_frain # Install dependencies pip install -r requirements.txt ``` ## Quick Start ```bash python main.py --port 8765 ``` Then open `http://localhost:8765` in your browser. Use the web controls to: - Toggle free movement mode - Monitor neural activity and behavior state - Apply experimental manipulations ## Architecture ### Neural Subsystem | Module | Purpose | |--------|---------| | `connectome.py` | Neural topology and synaptic weights | | `brain_sim.py` | LIF network dynamics and integration | | `motor_decode.py` | Neural activity → motor commands | ### Behavioral Subsystem | Module | Purpose | |--------|---------| | `behavior.py` | Behavior classification from neural state | | `exploration.py` | Spontaneous drive and satiety dynamics | ### Physical Subsystem | Module | Purpose | |--------|---------| | `fly_physics.py` | Body dynamics and environmental interaction | | `manipulations.py` | Experimental manipulations (optogenetics, silencing) | ### Interface | Module | Purpose | |--------|---------| | `server.py` | HTTP API and websocket streaming | | `web/` | Browser-based visualization | ## Usage ### Command Line Options ```bash python main.py --port 8765 --speed 2.0 --headless 30 ``` | Parameter | Description | |-----------|-------------| | `--port` | Web server port (default: 8765) | | `--speed` | Simulation speed multiplier | | `--headless` | Run without visualization for N seconds | ### Programmatic API ```python from flybrain.connectome import Connectome from flybrain.brain_sim import LIFNetwork from flybrain.fly_physics import Environment # Load connectome con = Connectome.built_in() # Initialize network net = LIFNetwork(con) # Run simulation step I_ext = {n: 0.0 for n in con.keys()} rates = net.step(I_ext) ``` ## Experimental Manipulations The system supports real-time manipulation of neural subsets: - `ChR` - Channelrhodopsin excitation - `GtAC1` - ArchT inhibition - `sib` - Sibutramine manipulation Apply via web interface or API: ```python from flybrain.manipulations import ManipulationState state = ManipulationState() state.set("ChR", True) # Activate ChR-expressing neurons ``` ## Data Format ### Nodes CSV | Column | Description | |--------|-------------| | id | Unique neuron identifier | | layer | Processing layer (sensory/motor/etc.) | | type | Neuron type | ### Edges CSV | Column | Description | |--------|-------------| | src | Source neuron ID | | dst | Destination neuron ID | | weight | Synaptic strength | | delay | Transmission delay (ms) | ## Development ### Running Tests ```bash python -m pytest tests/ ``` ### Key Test Files | File | Purpose | |------|---------| | `tests/behavior.py` | Behavior classification validation | | `tests/manipulation.py` | Manipulation state tests | | `tests/tune*.py` | Parameter optimization scripts | ## File Structure ``` fly_frain/ ├── flybrain/ # Core simulation modules │ ├── __init__.py │ ├── behavior.py # Behavior classifier │ ├── brain_sim.py # LIF network │ ├── connectome.py # Neural connectivity │ ├── exploration.py # Drive/satiety │ ├── fly_physics.py # Body dynamics │ ├── manipulations.py # Experimental states │ ├── motor_decode.py # Motor decoder │ └── server.py # HTTP interface ├── web/ # Frontend assets ├── data/ # Example datasets ├── tests/ # Test suite ├── main.py # Entry point └── requirements.txt # Dependencies ``` ## License MIT License ## References - Fly connectome: [Janelia FlyEM](https://www.janelia.org/project-teams/flyem) - LIF neuron model: Abbott (1999) - Behavioral ethogram: [FlyPedia](https://flybrain.neurobio.arizona.edu)