Scripting
To produce custom simulations or behaviors not possible using the Simbrain GUI, you can either create scripts.
All scripts are currently beanshell scripts (there is nothing to prevent other scripting languages, but none have been implemented yet). See http://www.beanshell.org/docs.html
The best way to get a feel for scripting is to have a look at a few
scripts. Try opening a few in the scriptmenu directory, and
also running them, to see how to do things. Try modifying
them in simple ways (e.g. modifying the paramters at the top) and
re-running them. An example is sample-barchart.bsh.
All public objects in the Simbrain code can be accessed via these scripts. In most cases, the scripts by default have access to two variables:
workspace: the underlying model of all components in simbrain
desktop: the graphical object which displays a workspace.
Often you will provide some code get access to an object and themodify those objects.
The syntax for these scripts is java (with some modifications).
In each case some base object is made available that you can modify
using java commands. The best way to learn how to write these scripts
is probably to just look (and modify) existing scripts.
You can interact with scripts in different ways.
From Menus
One way to use a script is to edit it directly with a text
editor (Eclipse and other editors can have java syntax coloring
enabled), and then to invoke the script from the Simbrain
Gui. In most cases there are
The {Simbrain}/script directory and its subdirectories contains
beanshell scripts. You are encouraged to add your own
scripts. This is your entry point for customizing Simbrain.
Network: Scripts in ./network automatically appear in the "scripts" menu of Simbrain network components Use this directory to create custom actions that can be applied to a current network (e.g., methods of adding neurons, modifying neurons or synapses, etc.) The two objects available here are "network" and "networkPanel." These give access to the current org.simbrain.network.interfaces.Rootnetwork and its gui representation via an org.simbrain.network.gui.NetworkPanel.
Console: scripts in ./console are available from the Simbrain console (from which command line arguments can be issued) or terminal components. The objects available here are the same as with scriptmenu.
In the Console
Beanshell commands can also be invoked in real-time from the command line, which is available in special console windows or in a tab of the command window at the bottom of the simbrain desktop.
The console can be useful to quickly test or debug Simbrain. For a
sense of some things you can do in the console enter "help(); or
"tips();".
The console is similar to a UNIX or DOS terminal window. You can navigate around the file system using commands like "cd();"
To run a script from the console, using the source command, e.g. source("sparseNetwork.bsh");
Problems in Beanshell
Can't use 2d arrays
Can't use generics.
Editing Beanshell Scripts
In Eclipse, to get the syntax coloring, try Prefs > Editors > File associations > add .bsh > java editor
Example
Here is an example of a simpel script to create a few neurons conneted by a synapse. Again, have a look
import org.simbrain.network.NetworkComponent;
import org.simbrain.network.connections.*;
import org.simbrain.network.interfaces.*;
import org.simbrain.network.layouts.*;
import org.simbrain.network.networks.*;
import org.simbrain.network.neurons.*;
import org.simbrain.network.synapses.*;
import org.simbrain.workspace.*;
{
NetworkComponent networkComponent = new NetworkComponent("Test Network");
workspace.addWorkspaceComponent(networkComponent);
RootNetwork network = networkComponent.getRootNetwork();
Neuron neuron1 = new Neuron(network, "SpikingThresholdNeuron");
neuron1.setLocation(2,2);
network.addNeuron(neuron1);
Neuron neuron2 = new Neuron(network, "SpikingThresholdNeuron");
neuron2.setLocation(50,2);
network.addNeuron(neuron2);
network.addSynapse(new ClampedSynapse(neuron1, neuron2));
// Make sure the neurons lay out correct
desktop.getDesktopComponent(networkComponent).postAddInit();
}