# 16. Related Codes¶

Here we summarize some codes used in stellar dynamics that are similar to NEMO. We only list codes that are (publically) available. SPH/hydro codes are currently not included. See also ASCL to find more codes.

First we start off with some expanded examples on a few specific codes that have a tighter connection to NEMO:

## 16.1. AMUSE¶

AMUSE (Astrophysical Multipurpose Software Environment) originates some ideas
from its predecessors: ACS, StarLab and NEMO, but uses the python language.
Another feature of AMUSE is that
python is also the *glue* shell between legacy codes that can orchestrate
simulations taking components from different codes, whereas in NEMO legacy codes
have a NEMO CLI interface, at best.

For seasoned AMUSE users, here we highlight some differences between the two, and give some examples how to achieve the same task in NEMO and AMUSE.

### 16.1.1. Differences¶

**Shell**: NEMO uses a Unix shell, AMUSE uses python (ipython, jupyter, …).**Community Code**: Both packages maintain a tight connection to legacy software and community codes. You can find them in**$AMUSE/src/amuse/community**and**$NEMO/usr**resp., though the latter has some supporting script in**$NEMO/src/scripts/mknemo.d****Units**: NEMO uses dimensionless values, and units are implied. Most programs actually use virial units (a.k.a N-body units, or Henon units) where G=1, but there are a few programs (e.g. galaxy, nbodyX) that use other units. The units(1NEMO) tries to help you converting. AMUSE (optionally?) attaches units to numbers , using a python trick, e.g.

```
from amuse.units import units
mass = 1.0 | units.MSun
```

**astropy** users might be a bit baffled, since this looks very different. But

```
m1 = mass.as_astropy_quantity()
```

will look more familiar. In pure **astropy** it might look as follows:

```
from astropy import units as u
m = 1.0 * u.solMass
m2 = m.to(u.kg).value
```

### 16.1.2. Examples: Creating a Plummer sphere¶

Here we create a Plummer sphere, in virial units, in NEMO, and display an X-VX projection on the sky in a shell session:

```
source /opt/nemo/nemo_start.sh
mkplummer p100 100
snapplot p100 xvar=x yvar=vx
```

or in the style of using pipes this can be a one liner

```
mkplummer - 100 | snapplot - xvar=x yvar=vx
```

And in AMUSE the following python session can do something similar:

Todo

figure out the right py-gnuplot

```
from amuse.units import units
from amuse.units import nbody_system
from amuse.ic.plummer import new_plummer_sphere
convert_nbody = nbody_system.nbody_to_si(100.0 | units.MSun, 1 | units.parsec)
plummer = new_plummer_sphere(1000, convert_nbody)
plotter = Gnuplot.Gnuplot()
plotter.splot(plummer.position.value_in(units.parsec))
```

The AMUSE manual has some NEMO I/O examples.

### 16.1.3. Installation¶

AMUSE can usually be installed *easily* as follows:

```
pip install amuse
```

but this can take a while as it finds the right dependencies and needs to compile massive amounts of code. Some of these can easily fail if you don’t have the correct prerequisites (e.g. MPI).

A potentially faster way is to first install the AMUSE frame work and then the selected module(s):

```
pip install amuse-framework
pip install amuse-seba amuse-brutus
```

There are many more details in the AMUSE installation manual.

## 16.2. Martini¶

There is an expanded example in https://teuben.github.io/nemo/examples/eagle.html,
and some supporting notes are in `$NEMO/usr/martini`

.

It can also be installed with

```
pip install astromartini
```

## 16.3. ClusterTools¶

This python package can also read NEMO (gyrfalcON) files. Installation can be done as follows:

```
cd $NEMO/local
git clone https://github.com/webbjj/clustertools
pip install -e clustertools
```

For a few packages, we have a few existing examples in the `$NEMO/usr`

tree
(e.g. amuse, martini, unsio and uns_projects)

## 16.4. ZENO¶

ZENO is Josh Barnes’ version of an earlier version of NEMO that he continues to develop. We also keep a zeno manual page highlighting some differences.

Warning

Adding ZENO to NEMO will result in some programs that have duplicated names.

### 16.4.1. Installation¶

For the benefit of NEMO users, ZENO can usually be installed as follows:

```
cd $NEMO/usr/zeno
make zeno
```

This will currently download two repos: zeno_jeb and zeno_pjt. Pick one by using a symlink to become the official one for the install:

```
ln -s zeno_pjt zeno
source zeno_start.sh
cd zeno
make -f Zeno
```

Now various ZENO commands are available:

```
ls $ZENOPATH/bin
```

## 16.5. STARLAB¶

### 16.5.1. Installation¶

For the benefit of NEMO users, STARLAB can usually be installed as follows:

```
mknemo starlab
```

### 16.5.2. Examples¶

These examples were taken from http://www.sns.ias.edu/~starlab/examples/, but an up-to-date list may be found in the file EXAMPLES in the Starlab distribution. If installed within NEMO, this should be in $NEMO/local/starlab/EXAMPLES.

For details on a specific program, type

```
program --help
```

Create a linked list of 100 equal-mass nodes of unit total mass

```
makenode -n 100 -m 1
```

Create a system of 100 nodes with a Salpeter mass spectrum with masses in the range 0.5 to 10

```
makenode -n 100 | makemass -f 1 -x -2.35 -l 0.5 -u 10
```

Create a system of 100 nodes with a mass spectrum and evolve the stars without dynamics

```
makenode -n 100 | makemass -f 1 -x -2.35 -l 0.5 -u 10 \
| ...(to come)...
```

Create a 500-particle Plummer model, with numbered stars, scaled to standard dynamical units

```
makeplummer -n 500 -i
```

Create a 500-particle W0 = 5 King model, with numbered stars, unscaled

```
makeking -n 500 -w 5 -i -u
```

Create a 500-particle W0 = 5 King model with a Miller-Scalo mass spectrum between 0.1 and 20 solar masses, then rescale to unit total mass, total energy -0.25, and virial ratio 0.5 and display the results graphically

```
makeking -n 500 -w 5 -i -u \
| makemass -F Miller_Scalo -l 0.1 -u 20 \
| scale -m 1 -e -0.25 -q 0.5 \
| xstarplot -l 5 -P .5
```

Create a 500-particle W0 = 5 King model with a Miller-Scalo mass spectrum between 0.1 and 20 solar masses, add in a 10 percent 1-10 kT binary population, then rescale to unit total mass, total energy (top-level nodes) -0.25, and virial ratio (top-level nodes) 0.5, and finally verify the results by analyzing the final snapshot

```
makeking -n 500 -w 5 -i -u \
| makemass -f 2 -l 0.1 -u 20 \
| makesecondary -f 0.1 -l 0.25 \
| scale -m 1 -e -0.25 -q 0.5 \
| makebinary -l 1 -u 10 \
| sys_stats -n
```

Evolve this model without stellar evolution for 100 dynamical times, with log output every dynamical time and snapshot output every 10 dynamical times, with a self-consistent tidal field, removing escapers when they are more than two Jacobi radii from the cluster center

```
makeking -n 500 -w 5 -i -u \
| makemass -f 2 -l 0.1 -u 20 \
| makesecondary -f 0.1 -l 0.25 \
| makebinary -l 1 -u 10 \
| scale -m 1 -e -0.25 -q 0.5 \
| kira -t 100 -d 1 -D 10 -Q -G 2
```

Create a King model with a power-law mass spectrum and a binary population, then evolve it with stellar and binary evolution

```
makeking -n 500 -w 5 -i -u \
| makemass -f 1 -x -2.0 -l 0.1 -u 20 \
| makesecondary -f 0.1 -l 0.1 \
| add_star -Q 0.5 -R 5 \
| scale -M 1 -E -0.25 -Q 0.5 \
| makebinary -f 1 -l 1 -u 1000 -o 2 \
| kira -t 100 -d 1 -D 10 -f 0.3 \
-n 10 -q 0.5 -Q -G 2 -B
```

Perform a series of 100 3-body scattering experiments involving an equal-mass circular binary and a double-mass incomer, with impact parameter equal to the binary semimajor axis, relative velocity at infinity half that needed for zero total energy, and all other parameters chosen randomly, and display the results as a movie

```
scatter3 -m 0.5 -e 0 -M 1 -r 1 -v 0.5 \
-n 100 -C 5 -D 0.1 \
| xstarplot -l 4
```

Compute cross-sections for interactions between a circular binary with component masses 0.75 and 0.25 and an incoming star of mass 1 and velocity at infinity 0.1, all stars having radius 0.05 binary semimajor axes

```
sigma3 -d 100 -m 0.25 -e 0 -M 1 -v 0.1 \
-x 0.05 -y 0.05 -z 0.05
```

Create a scattering configuration involving a head-on collision between a circular binary and a stable hierarchical triple, and verify the result

```
makescat -M 1.5 -r 0 -v 1 -t -a 1 -e 0 \
-p -a 1 -e 0 -p1 -a 0.1 -e 0 \
| flatten | make_tree -D 1 | pretty_print_tree
```

Create a scattering configuration involving a head-on collision between a circular binary and a stable hierarchical triple, and integrate it forward in time

```
scatter -i "-M 1.5 -r 0 -v 1 -t -a 1 -e 0 \
-p -a 1 -e 0 -p1 -a 0.1 -e 0" \
-t 100 -d 1 -v
```

## 16.6. REBOUND¶

Note

REBOUND Documentation on https://rebound.readthedocs.io

REBOUND is an N-body integrator, i.e. a software package that can integrate the motion of particles under the influence of gravity. The particles can represent stars, planets, moons, ring or dust particles. REBOUND is very flexible and can be customized to accurately and efficiently solve many problems in astrophysics.

REBOUND is primarely a library, with a mature API, but tools will need to be written (typically in C/C++) to create science applications. A python interface is also available.

NEMO has current 4 example programs that are linked with the REBOUND library:

program |
description |
---|---|

reb2s |
convert a REBOUND SimulationArchive to a NEMO SnapShot |

s2reb |
convert a NEMO SnapShot to a REBOUND SimulationArchive |

reb_integrate |
integrate a system and produce a REBOUND SimulationArchive |

reb_viewer |
view a REBOUND SimulationArchive |

### 16.6.1. Example¶

With these tools a typical N-body simulation starting from a NEMO snapshot can be done as follows:

```
mkplummer - 128 seed=128 | s2reb - p128.in
reb_integrate p128.in p128.bin tstop=100 dt=1/32 dtout=1 eps=0.05 integrator=leapfrog
reb_viewer p128.bin
reb2s p128.bin - | snapplot - nxy=3,3
```

### 16.6.2. Install¶

Installation can be done via `mknemo rebound`

, but the manual steps are as follows:

```
cd $NEMO/usr/hannorein
make install
cd nemo
make install
```

This will copy the library and header file into the $NEMO tree for each of compile path management.

## 16.7. GALPY¶

With some examples we show how things done in **galpy** can be done in **NEMO**

### 16.7.1. Rotation Curves¶

The following code example shows how to initialize a Miyamoto-Nagai disk potential and plot its rotation curve

galpy prefers a normalization, which definese the value of the rotation curve at radius = 1

```
from galpy.potential import MiyamotoNagaiPotential
#
mp= MiyamotoNagaiPotential(a=0.5,b=0.0375,normalize=1.)
mp.plotRotcurve(Rrange=[0.01,10.],grid=1001)
```

NEMO normally defines the mass as the first non-pattern speed parameter that normalizes the rotation curve

```
rotcurves miyamoto 0,1,0.5,0.0375 radii=0.01:10:0.01
```

and an example of a combined potential

```
from galpy.potential import NFWPotential, HernquistPotential
#
mp= MiyamotoNagaiPotential(a=0.5,b=0.0375,normalize=.6)
np= NFWPotential(a=4.5,normalize=.35)
hp= HernquistPotential(a=0.6/8,normalize=0.05)
from galpy.potential import plotRotcurve
plotRotcurve(hp+mp+np,Rrange=[0.01,10.],grid=1001,yrange=[0.,1.2])
#
mp.plotRotcurve(Rrange=[0.01,10.],grid=1001,overplot=True)
hp.plotRotcurve(Rrange=[0.01,10.],grid=1001,overplot=True)
np.plotRotcurve(Rrange=[0.01,10.],grid=1001,overplot=True)
```

galpy’s rescale option is more complicated in NEMO. However, since speed scales with sqrt(mass), we can at least use the sqrt of galpy’s normalization, and at least get the relative weights correct.

```
rotcurves name1=miyamoto pars1="0,sqrt(0.6),0.5,0.0375" \
name2=hernquist pars2="0,sqrt(0.06),0.6/8" \
name3=nfw pars3="0,1,1" \
radii=0.05:10:0.05
```

### 16.7.2. Orbit integration¶

```
from galpy.potential import MiyamotoNagaiPotential
from galpy.orbit import Orbit
#
mp= MiyamotoNagaiPotential(a=0.5,b=0.0375,amp=1.,normalize=1.)
o= Orbit([1.,0.1,1.1,0.,0.1])
#
import numpy
ts= numpy.linspace(0,100,10000)
o.integrate(ts,mp,method='odeint')
#
o.plot()
```

```
# [R,vR,vT,z,vz] - not implemented
mkorbit r=1. vr=0.1 vt=1.1 z=0 vz=0.1 potname=miyamoto potpars=0,1,0.5,0.0375
orbint
orbplot
```

### 16.7.3. Surface of Section¶

https://galaxiesbook.org/chapters/III-02.-Orbits-in-Triaxial-Mass-Distributions.html

```
from galpy.potential import LogarithmicHaloPotential
from galpy.orbit import Orbit
ts= numpy.linspace(0.,30,601)
lp= LogarithmicHaloPotential(normalize=True,b=0.9,core=0.2)
o= Orbit([0.1,0.,lp.vcirc(0.1,phi=0.),0.])
o.integrate(ts,lp)
o.animate(staticPlot=True); # remove the ; to display the animation
```

```
mkorbit x=0.1 y=0 z=0 vx=0 vy=0 potname=log potpars=0,1,0.2,0.9
phi = v^2/2 log(x^2 + y^2/b^2 + a^2)
v^2/2 = m/a
```

## 16.8. Yt¶

yt is a community-developed analysis and visualization toolkit for volumetric data, and handles SnapShot type data.

Warning

using yt will require python3.

More to come. There is a notebook in prep.

## 16.9. List of Related Codes¶

Todo

this list needs to be annotated and spiced up with links.

- ACS¶
*The Art of Computational Science - How to build a computational lab.*In C++ and ruby. With ideas from NEMO and StarLab. | http://www.artcompsci.org/- agama¶
*Action-based galaxy modeling framework*. Also usable via`$NEMO/usr/agama`

. | http://ascl.net/1805.008- AMIGA¶
*Adaptive Mesh Investigations of Galaxy Assembly*. | http://ascl.net/1007.006- AMUSE¶
*Astrophysical Multipurpose Software Environment*. Also usable via`$NEMO/usr/amuse`

. | http://ascl.net/1107.007- arepo¶
*Cosmological magnetohydrodynamical moving-mesh simulation code*. | http://ascl.net/1909.010- bhint¶
High-precision integrator for stellar systems | https://ascl.net/1206.005

- bonsai¶
N-body GPU tree-code, in AMUSE. | http://ascl.net/1212.001

- brutus¶
See also AMUSE

- Catena¶
Ensemble of stars orbit integration | https://ascl.net/1206.008

- CGS¶
Collisionless Galactic Simulator. Also usable via NEMO with the runCGS interface. | http://ascl.net/1904.003

- ChaNGa¶
Charm N-body GrAvity solver | http://ascl.net/1105.005

- clustertools¶
A Python package with tools for analysing star clusters. | https://github.com/webbjj/clustertools

- DICE¶
Disk Initial Conditions Environment | https://ascl.net/1607.002

- Fewbody¶
Numerical toolkit for simulating small-N gravitational dynamics | http://ascl.net/1208.011

- fractal¶
*A parallel high resolution Poisson solver for an arbitrary distribution of particles*. | https://github.com/jensvvillumsen/Fractal- gadgetX¶
*A Code for Cosmological Simulations of Structure Formation*. Several versions available, X=1,2,3,4. gadget2 also available via`$NEMO/usr/gadget`

. | http://ascl.net/0003.001- Gala¶
*Galactic astronomy and gravitational dynamics*. | http://ascl.net/1302.011- galaxy¶
*N-body simulation software for isolated, collisionless stellar systems*. The older version still usable via NEMO with the**rungalaxy**interface. | http://ascl.net/1904.002- galpy¶
Galactic dynamics package (python) - also support NEMO’s potential format | http://ascl.net/1411.008

- GalPot¶
Galaxy potential code | http://ascl.net/1611.006

- GANDALF¶
Graphical Astrophysics code for N-body Dynamics And Lagrangian Fluids | http://ascl.net/1602.015

- GENGA¶
Gravitational ENcounters with Gpu Acceleration | http://ascl.net/1812.014

- Glnemo2¶
Interactive Visualization 3D Program | http://ascl.net/1110.008

- gnuastro¶
GNU Astronomy Utilities | https://www.gnu.org/software/gnuastro/

- GraviDy¶
Gravitational Dynamics. Also usable via NEMO with the

**rungravidy**interface. | http://ascl.net/1902.004- gsf¶
galactic structure finder | http://ascl.net/1806.008

- gyrfalcON¶
Dehnen’s code. Included in NEMO | http://ascl.net/1402.031

- hermite¶
In AMUSE.

- HiGPUs¶
*Hermite’s N-body integrator running on Graphic Processing Units*. Part of AMUSE. | https://ascl.net/1207.002- HUAYNO¶
Hierarchically split-Up AstrophYsical N-body sOlver N-body code. Part of AMUSE. | http://ascl.net/2102.019

- Hydra¶
A Parallel Adaptive Grid Code | http://ascl.net/1103.010

- hnbody¶
also | http://ascl.net/1201.010

- ICICLE¶
Initial Conditions for Isolated CoLlisionless systems https://ascl.net/1703.012 | http://ascl.net/1703.012

- identikit¶
1: A Modeling Tool for Interacting Disk Galaxies. | https://ascl.net/1011.001 2: An Algorithm for Reconstructing Galactic Collisions. | https://ascl.net/1102.011

- InitialConditions¶
Website with a collection of programs for integrating the equations of motion for N objects, implemented in many languages, from Ada to Swift. | http://www.initialconditions.org/codes

- JSPAM¶
Interacting galaxies modeller | http://ascl.net/1511.002

- limepy¶
Lowered Isothermal Model Explorer in PYthon. | https://ascl.net/1710.023

- MARTINI¶
Mock spatially resolved spectral line observations of simulated galaxies Also usable via

`$NEMO/usr/martini`

, see example. | http://ascl.net/1911.005- mcluster¶
Make a plummer. Also usable via NEMO | http://ascl.net/1107.015

- McScatter¶
Three-Body Scattering with Stellar Evolution | http://ascl.net/1201.001

- mercury¶
*A software package for orbital dynamics*. In AMUSE. | http://ascl.net/1209.010- montage¶
An Astronomical Image Mosaicking Toolkit. | https://github.com/Caltech-IPAC/Montage

- MYRIAD¶
N-body code for simulations of star clusters | https://ascl.net/1203.009

- nbodyX¶
Where X=0,1,2,3,4,5,6,6++,7 Also usable via NEMO with the runbodyX interface. | http://ascl.net/1904.027

- nbody6tt¶
Tidal tensors in N-body simulations | http://ascl.net/1502.010

- nbodykit¶
Massively parallel, large-scale structure toolkit | http://ascl.net/1904.027

- nbody6xx¶
Alias for nbody6++ Also usable via NEMO | http://ascl.net/1502.010

- N-BodyShop¶
Simulation codes of astrophysical phenomenon with particle methods. (tipsy, changa, gasoline) | https://github.com/N-BodyShop

- nemesis¶
Another code to document. | http://ascl.net/1010.004

- NEMO¶
Stellar Dynamics Toolbox. Our current version is 4. | http://ascl.net/1010.051

- NIGO¶
Numerical Integrator of Galactic Orbits | https://ascl.net/1501.002

- N-MODY¶
A code for Collisionless N-body Simulations in Modified Newtonian Dynamics | http://ascl.net/1102.001

- octgrav¶
- partiview¶
Immersive 4D Interactive Visualization of Large-Scale Simulations | https://ascl.net/1010.073

- PENTACLE¶
Large-scale particle simulations code for planet formation | http://ascl.net/1811.019

- petar¶
Another code to document. | http://ascl.net/2007.005

- plumix¶
another | http://ascl.net/1206.007

- pNbody¶
A python parallelized N-body reduction toolbox https://ascl.net/1302.004

- pycola¶
N-body COLA method code | http://ascl.net/1509.007

- pyfalcon¶
Python interface for gyrfalcON | https://github.com/GalacticDynamics-Oxford/pyfalcon

- pynbody¶
N-Body/SPH analysis for python. | http://ascl.net/1305.002

- QYMSYM¶
A GPU-accelerated hybrid symplectic integrator | https://ascl.net/1210.028

- RAMSES¶
A new N-body and hydrodynamical code | https://ascl.net/1011.007

- Raga¶
Monte Carlo simulations of gravitational dynamics of non-spherical stellar systems | http://ascl.net/1411.010

- rebound¶
Multi-purpose N-body code for collisional dynamics | https://ascl.net/1110.016 Also usable via NEMO

- SecularMultiple¶
Hierarchical multiple system secular evolution model | http://ascl.net/1909.003

- sidm-nbody¶
Monte Carlo N-body Simulation for Self-Interacting Dark Matter | http://ascl.net/1703.007

- slimplectic¶
Discrete non-conservative numerical integrator | http://ascl.net/1507.005

- smalln¶
- smile¶
orbits? | http://ascl.net/1308.001

- SpaceHub¶
High precision few-body and large scale N-body simulations | http://ascl.net/2104.025

- SpheCow¶
Galaxy and dark matter halo dynamical properties | http://ascl.net/2105.007

- Starlab¶
Also usable via NEMO | https://ascl.net/1010.076

- Swarm-NG¶
Parallel n-body Integrations | https://ascl.net/1208.012

- Torch¶
Coupled gas and N-body dynamics simulator | http://ascl.net/2003.014

- TPI¶
Test Particle Integrator | http://ascl.net/1909.004

- UNSIO¶
Universal Nbody Snapshot I/O - See examples.

- VINE¶
A numerical code for simulating astrophysical systems using particles | http://ascl.net/1010.058

- yt¶
A Multi-Code Analysis Toolkit for Astrophysical Simulation Data | https://ascl.net/1011.022

- ZENO¶
Barnes version that was derived from NEMO V1. | https://ascl.net/1102.027 Also usable via NEMO , but watch out for duplicate names of programs

A large number of these codes can also be found by searching on ASCL, for example: https://ascl.net/code/search/dynamics and https://ascl.net/code/search/hermite and https://ascl.net/code/search/orbit and https://ascl.net/code/search/nbody. The last time this list was cross-checked was … 16-jul-2021.

## 16.10. Python¶

Python support in NEMO itself is still rudimentary, though the common

```
cd $NEMO
pip3 install -e .
```

will add the `nemopy`

module to your python environment. Currently only
a simple getparam interface is available, to build NEMO style programs.

There are good import and export routines to other N-body formats, through which other toolkits can provide interesting ways to analyze NEMO data. We list a few

yt toolkit: https://yt-project.org/

nobodykit: https://nbodykit.readthedocs.io/en/latest

clustep, galstep: https://github.com/elvismello create initial conditions in gadget2 format. ($NEMO/usr/mello)

galanyl: https://hg.sr.ht/~ngoldbaum/galaxy_analysis pip install galanyl

unsio: pip install python-unsio python-unsiotools ($NEMO/usr/jcl)

agama: https://github.com/GalacticDynamics-Oxford/Agama - pip install agama ($NEMO/usr/agama)

pynbody: https://github.com/pynbody/pynbody

martini: https://github.com/kyleaoman/martini ($NEMO/usr/martini)

galpak: http://galpak3d.univ-lyon1.fr/index.html - pip install galpak

amuse: https://github.com/amusecode - pip install amuse-framework

SnapGadget: https://github.com/regmachado/SnapGadget

### 16.10.1. Examples¶

Todo

more needed here

3rd party modules. Good examples are with unsio.

qtrun is a GUI building app

NEMO style apps that use the python version of getparam. Examples are tabplot with matplotlib

## 16.11. Categories¶

Such a niche list of codes made me wonder what kind of meta-data we could use to categorize such dynamics codes, but then perhaps along the lines of the Unified Astronomy Thesaurus project.

dynamics - nbody, orbit, integrator, sph, hydro, analysis, integrator