WebGL Visualization Widget (iPython)

REBOUND, but it currently misses a few features such as rendering spheres and support for periodic boundary conditions.

Using the widget makes setting up a simulation very interactive. One can spot many mistakes in the setup process of a simulation by visually inspecting the particles.

The widget is using the ipywidgets package which needs to be installed and enabled. More information on this can be found in the ipywidgets documentation at https://ipywidgets.readthedocs.io/en/latest/user_install.html. You also need a browser and a graphics card that supports WebGL.

Let us start this demo by setting up an empty simulation and calling the getWidget() function on the simulation object. This will create a new widget, attach it to the simulation and return it to the user.

import rebound
sim = rebound.Simulation()
sim.getWidget()

Next up, lets add some particles to the simulation. The widget updates automatically when a particle gets added or removed.

sim.add(m=1) # add a star
for i in range(10):
    sim.add(m=1e-3,a=0.4+0.1*i,inc=0.03*i,omega=5.*i) # Jupiter mass planets on close orbits
sim.move_to_com() # Move to the centre of mass frame

Drag the widget with your mouse or touchpad to look at the simulation from different angles. Keep the shift key pressed while you drag to zoom in or out.

Next, we will try to integrate the orbits forward in time. Because the planets are very massive and on close to each other, the system will go unstable very quickly. By default REBOUND is using the IAS15 integrator which can resolve close encounter. During each close encounter the instantaneous orbits of the planets show in the widget will change rapidly.

sim.integrate(500)

The widget can be configured with various options. For more details on those options, have a look at the documentation.

One thing we can do is change the size of the widget and turn off the plotting of instantaneous orbits. The latter is useful if one is integrating a hierarchical system, for example a binary star or moons around planets.

sim.getWidget(size=(400,200),orbits=False)

One can also preset the scale and the orientation of the view, which can be useful for constructing multple widgets at the same time that allows us to view the system from different angles.

widget_1 = sim.getWidget(orientation=(0,0,0,1),scale=2)
widget_2 = sim.getWidget(orientation=(0,1,0,1),scale=2,size=(50,200))
widget_3 = sim.getWidget(orientation=(1,0,0,1),scale=2,size=(200,50))
from ipywidgets import HBox, VBox
VBox((widget_3,HBox((widget_1, widget_2))))

In case you’re wondering, the orientation parameter above expects the x, y, z, and w components of a quaternion. If we now integrate the system a little further, all widgets will be updated at the same time, giving you an instantaneous idea of the three dimensional evolution of the system.

sim.integrate(800)

This widget is a relatively new addition to REBOUND. If you notice any bugs or have requests for new features, please open an issue on github.