NeLy-EPFL / NeuroMechFly

A neuromechanical model of adult Drosophila melanogaster.
https://nely-epfl.github.io/NeuroMechFly/
Apache License 2.0
44 stars 1 forks source link
drosophila-melanogaster evolutionary-algorithms gait-optimization locomotion published-article pybullet simulation

NeuroMechFly

License Version

IMPORTANT INFORMATION: This website contains documentation for legacy code related to Lobato-Rios et al, Nature Methods, 2022. NeuroMechFly has since been updated, and this repository is no longer actively maintained. For most up-to-date information, please visit neuromechfly.org.

NeuroMechFly is a data-driven computational simulation of adult Drosophila melanogaster designed to synthesize rapidly growing experimental datasets and to test theories of neuromechanical behavioral control. For the technical background and details, please refer to our paper.

If you use NeuroMechFly in your research, you can cite us:

@article{LobatoRios2022,
  doi = {10.1038/s41592-022-01466-7},
  url = {https://doi.org/10.1038/s41592-022-01466-7},
  year = {2022},
  month = May,
  publisher = {Springer Science and Business Media {LLC}},
  volume = {19},
  number = {5},
  pages = {620--627},
  author = {Victor Lobato-Rios and Shravan Tata Ramalingasetty and Pembe Gizem \"{O}zdil and Jonathan Arreguit and Auke Jan Ijspeert and Pavan Ramdya},
  title = {{NeuroMechFly},  a neuromechanical model of adult Drosophila melanogaster},
  journal = {Nature Methods}
}

A Gym environment of NeuroMechFly is under development here.

Content

Starting

Reproducing the experiments

Note: before running the following scripts, please be sure to activate the virtual environment (see the installation guide)

NeuroMechFly is run in PyBullet. In the Graphical User Interface, you can use the following keyboard and mouse combinations to control the camera's viewpoint:

1. Kinematic replay

Run the following commands on the terminal to reproduce the kinematic replay experiments:

Furthermore, for both commands above, you can add the flag -fly # to run the simulation with other walking behaviors, # can be 1, 2, or 3 (default is 1). The flag --show_collisions will colored in green the segments in collision. Finally, the flag --record will save a video from the simulation in the folder scripts/kinematic_replay/simulation_results. The video will be recorded at 0.2x real-time (refer to the environment tutorial to learn how to change this value).

NOTE: At the end of each simulation run, a folder called kinematicreplay_ containing the physical quantities (joint angles, torques etc.) will be created under the scripts/kinematic_replay/simulation_results folder.

NOTE: Flags --show_collisions and --record will slow down your simulation.

NOTE: To obtain new pose estimates from the DeepFly3D Database, please refer to DeepFly3D repository. After running the pose estimator on the recordings, you can follow the instructions for computing joint angles to control NeuroMechFly here.


2. Gait optimization

Run the following commands on the terminal to reproduce the locomotor gait optimization experiments:

NOTE: At the end of each simulation run, a folder named according to the chosen optimization run will be created under the scripts/neuromuscular_optimization folder which contains the network parameters and physical quantities.

NOTE: Optimization results will be stored under scripts/neuromuscular_optimization/optimization_results inside a folder named according to the chosen optimization run.

NOTE: To formulate new objective functions and penalties, please refer to the neural controller tutorial.


3. Sensitivity Analysis

Customizing NeuroMechFly

Each module in NeuroMechFly can be modified to create a customized simulation. Here are some tutorials explaining how to do this:


Miscellaneous

1. Central Pattern Generator Controller


2. Blender Model


3. Reproducing the Figures

path_data = '~/NeuroMechFly/scripts/kinematic_replay/simulation_results/'

Selecting a behavior (walking or grooming)

behavior = 'walking'

Selecting a fly

fly_number = 1

Selecting the right front leg for plotting (other options are LF, RM, LM, LH, or RH)

leg = 'LF' # 'RF' for grooming

Reading angles from a file

angles_path = os.path.join(str(Path.home()),f'NeuroMechFly/data/joint_tracking/{behavior}/fly{fly_number}/df3d/') file_path = glob.glob(f'{angles_path}/joint_angles*.pkl')[0] with open(file_path, 'rb') as f: angles = pickle.load(f)

Defining time limits for a plot (in seconds)

start_time = 3.0 # 0.5 for grooming stop_time = 5.0 # 2.5 for grooming

plotting.plot_data(path_data, leg, sim_data=behavior, angles=angles, plot_angles_intraleg=True, plot_torques=True, plot_grf=True, plot_collisions=True, collisions_across=True, begin=start_time, end=stop_time)


- To reproduce gait/collision diagrams from Figs. 4 and 5, first, run the script *run_kinematic_replay* or *run_kinematic_replay_ground*, and then use:
```python
from NeuroMechFly.utils import plotting

path_data = '~/NeuroMechFly/scripts/kinematic_replay/simulation_results/<name-of-the-results-folder>'

# Selecting walking behavior
behavior = 'walking'

# Defining time limits for the plot (seconds)
start_time = 3.0 # 0.5 for grooming
stop_time = 5.0 # 2.5 for grooming

plotting.plot_collision_diagram(path_data,
                        behavior,
                        begin=start_time,
                        end=stop_time)

e.g. type: fastest, tradeoff, most_stable, or the individual, number: generation number

path_data = '~/NeuroMechFly/scripts/neuromuscular_optimization/simulation_lastrun/gen/sol_'

Selecting the joint of interest (Coxa-Trochanter/Femur)

link = 'Femur'

Defining time limits for the plot (in seconds)

start_time = 1.0 stop_time = 1.5

plotting.plot_network_activity( results_path=path_data, link=link, beg=start_time, end=stop_time )


---
**4. The CT-scan Data**

File containing the raw X-ray microtomography data could be downloaded [here](https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/PEOVAV).

---

## License
[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)

---
## README for the GitHub Pages Branch
This branch is simply a cache for the website served from https://nely-epfl.github.io/NeuroMechFly/,
and is  not intended to be viewed on github.com.