L-Galaxies, Munich Galaxy Formation Model

Running the Model

0. Credits & Copyright

The source code for the Munich model of galaxy formation and evolution, L-Galaxies, is published under the GNU General Public License. If you make use of the code in a scientific paper, please include the following line in the ackowledgments:


"This work used the 2015 public version of the Munich model of galaxy formation and evolution: L-Galaxies. The source code and a full description of the model are available at http://galformod.mpa-garching.mpg.de/public/LGalaxies/"


Different parts of the code were developed and published in works by different authors. The current version of the model was presented in Henriques et al. 2015 and additional references can be found in its supplementary material. Included in the public release are a new module for the detailed chemical enrichment, presented in Yates et al. 2013, and the possibility to use clustering as a constraint for MCMC, introduced in van Daalen et al. 2015. The sampling of large parameter spaces using MCMC was introduced in the model in Henriques et al. 2009.


Significant previous contributions to the current version of the model include: White & Rees 1978; White & Frenk 1991; Kauffmann, White & Guiderdoni 1993; Kauffmann, Nusser & Steinmetz 1996; Kauffmann et al. 1999; Springel et al. 2001, 2005; De Lucia et al. 2004; Croton et al. 2006; De Lucia & Blaizot 2007; Guo et al. 2011, 2013.; Henriques et al. 2013.

  1. Files needed to run the L-Galaxies galaxy formation model
  2. Download the source code for the model from the L-Galaxies GitHub Repository (Download ZIP button):

    Download the dark matter merger trees into ./MergerTrees/ contained in the source code folder (choose from: 1st line (only a few trees), 2nd line (all trees in the millennium) or 3rd line (all trees in the millennium in 5 separate files); the 4th is needed if you plan to run MCMC):

    Untar both files: "tar -xvf MR_MergerTrees.tar" or "tar -xvf MR_allMergerTrees.tar" and "tar -xvf MCMC_MergerTrees.tar". Two folders, MR and MCMC, should be created.

    Millennium 2 trees: MRII_Trees0_1 MRII_Trees2_39 MRII_Trees40_79 MRII_Trees80_199 MRII_Trees200_511

    Millennium 2 tree aux files: MRII_Trees_aux0_1 MRII_Trees_aux2_39 MRII_Trees_aux40_79 MRII_Trees_aux80_199 MRII_Trees_aux200_511

    Millennium 2 dbids files: MRII_MergerTrees_dbids.tar

    Millennium WMAP7 tree files: MR7_Trees_0_9 MR7_Trees_10_99 MR7_Trees_100_511

    Download the Stellar Population Synthesis tables, needed for photometry, into the root of the directory containing the source code:

    Untar the file: "tar -xvf SpecPhotTables.tar". A folder, SpecPhotTables, should be created.


    The source code for the model also contains various scripts to analyse its output. ./AuxCode/Python/ for Python and ./AuxCode/Idl/ for IDL (the python plots are done using the jupyter ipython notebook which is available as part of the anaconda package).

    In the scripts to analyse the model outputs, its predictions are compared to a number of observational datasets:

    These should be extracted in the corresponding Python or IDL directory.

  3. Compiling the code
  4. To compile the code simply run make on the command line. This will follow compiling instructions from 3 Makefiles:

    • Makefile: standard Makefile listing all the object files. Here you can switch between standard or MCMC mode (by choosing between My_Makefile_options or My_Makefile_options_MCMC). You will also need to choose a SYSTYPE. This variable links to library paths defined in Makefile_compilers. You can try to use one of the systems available, but you will likely have to create your own (SYSTYPE="MyMachine" might work for MACs).
    • My_Makefile_options (or My_Makefile_options_MCMC): lists the makefile options that you want to be compiled (Makefile_options lists all the available options and is not used).
    • Makefile_compilers: libraries for different systems are listed here. You can add your own by defining a new SYSTYPE.

    2.1 Installing gsl and openmpi libraries on a mac:

    By default, SYSTYPE = "MyMachine" in Makefile. Under "ifeq ($(SYSTYPE),"MyMachine")", in Makefile_compilers, the paths to the necessary libraries are specified. Installing these libraries on a mac is straightforward if you have Homebrew installed (a software to manage the installation of others). This is installed by default on new macs and you just need to follow these steps:

    • Install gsl: "brew install gsl"
    • In principle the gsl libraries will be installed in their default location. This is already specified in Makefile_compilers, under "ifeq ($(SYSTYPE),"MyMachine")", with the lines:
      GSL_INCL = -I/usr/local/include
      GSL_LIBS = -L/usr/local/lib

    • Install openmpi: "brew install open-mpi"
    • In principle the openmpi libraries will be installed in their default location. This is already specified in Makefile_compilers, under "ifeq ($(SYSTYPE),"MyMachine")", with the lines:
      GSL_INCL = -I/usr/local/Cellar/open-mpi/1.10.1/include
      GSL_LIBS = -L/usr/local/opt/libevent/lib -L/usr/local/Cellar/open-mpi/1.10.1/lib
      If the compilation misses the openmpi libraries, you can locate them using: "mpicc -showme".

  5. Running the code
  6. After the code has been compiled, an executable called L-Galaxies will be created. To run the code simply execute the file in the command line giving it an input.par file (see Input files below) as a runtime argument:

    ./L-Galaxies ./input/input_Henriques2015_MR_W1_PLANCK.par


    With this input file, as downloaded from the online repository, you will be running exactly the Henriques2015 version of L-Galaxies.


    The variables FirstFile and LastFile, in the input file, define the first and last dark matter merger tree files in which the galaxy formation model will be run. These correspond to sub-volumes of the dark matter simulation. As default, only file 5 is computed (a subvolume roughly representative of the full simulation) but you have files 0-9 in the download package (the full Millennium simulation ocrresponds to files 0-511).

    (later, to run the code in parallel, you might want to us thee bash scripts available in ./AuxCode/Run/, e.g. cosma.bash.)

    3.1 Check list for errors while reading the inputs:

    The first task done by the galaxy formation model is to read the inputs. If some inputs are missing or the specified paths are incorrect, you will get an error. Here is a check list on what to look for:

    • Parameter file not found: If at run time you write the wrong name for the input file after "./L-Galaxies" you will get the following error: "Parameter file ./input/input_Henriques15_MR_W1_PLANC.par not found". Followed by a line for each parameter supposed to be read from the input file saying that it is missing.
    • Zlist:: If the file with the list of dark matter redshifts is incorrectly specified you will get the following error:"code termination on task=0, function read_zlist(), file code/init.c, line 180: can't read output list in file './input/zlists/zlist_planck_MR1.txt'"
    • Output redshifts::If the file with the list of output redshifts is incorrectly specified you will get the following error: "code termination on task=0, function read_output_snaps(), file code/init.c, line 323: file `./input/desired_output_redshifts1.txt' not found"
    • Inconsistent NOUT:: If the value of OPT += -DNOUT=28 specified in My_Makefile_options is larger than the number of outputs defined in FileWithOutputRedshifts, you will get the following error: "code termination on task=0, function read_output_snaps(), file code/init.c, line 332: I/O error in file './input/desired_output_redshifts.txt"
    • SpecPhot folder::If the file with the containing the spectro and photometric tables is incorrectly specified specified you will get the following error: "code termination on task=0, function setup_LumTables_precomputed(), file code/model_spectro_photometric.c, line 61: file `./SpecPhotTables1//PhotTables/M05_Chabrier_Metallicity_list.dat' not found."
    • SpecPhotProperties:: If you specify the wrong PhotPrefix or SpecPhotIMF, or you combine them wrongly with the My_Makefile_options (M05, BC03 or CB07) you will get the following error:"code termination on task=0, function setup_LumTables_precomputed(), file code/model_spectro_photometric.c, line 103: file `./SpecPhotTables//PhotTables/PLANCK_M0_Chabrier_Phot_Table_MR_MagU_m0.0010.dat' not found."
    • SimulationDir::If you specify SimulationDir incorrectly, you will get the following error: "code termination on task=0, function load_all_auxdata(), file code/update_type_two.c, line 206: Can't open file `./MergerTrees/MR1//treedata/treeaux_063.5'"

    3.2 Input files for different models:

    If you are running the model for the first time jump to point 4 below. After you are familiar with running the Henriques2015 version of L-Galaxies you can try other versions by using a pre-defined selection of input files and MAKEFILE options. A number of input files for different models are available in /input/, with the following naming convection:

    input_"ModelName_Simulation"_"OriginalCosmology"_"TargetCosmology".par


    • ./input/input_Henriques15_MR_W1_PLANCK.par: input file for the Henriques2015a model for the Millennium Simulation.
    • ./input/input_Henriques15_MRII_W1_PLANCK.par: input file for the Henriques2015a model for the MillenniumII Simulation (requires OPT += -DMRII in My_Makefile_options).

    Inputs for previous versions of the model:


    • ./input/LegacyModels_inputs/input_Henriques13_MR_W1_W7.par: input file for the Henriques2013 model for the Millennium Simulation (requires OPT += -DHENRIQUES13 in My_Makefile_options).
    • ./input/LegacyModels_inputs/input_Henriques13_MRII_W1_W7.par: input file for the Henriques2015a model for the MillenniumII Simulation (requires OPT += -DHENRIQUES13 and OPT += -DMRII in My_Makefile_options).
    • ./input/LegacyModels_inputs/input_Guo13_MR_W1_W7.par: input file for the Guo2013 model for the Millennium Simulation (requires OPT += -DGuo13 in My_Makefile_options).
    • ./input/LegacyModels_inputs/input_Guo13_MRII_W1_W7.par: input file for the Guo2013 model for the MillenniumII Simulation (requires OPT += -DGuo13 and OPT += -DMRII in My_Makefile_options).
    • ./input/LegacyModels_inputs/input_Guo11_MR_W1_W1.par: input file for the Guo2011 model for the Millennium Simulation (requires OPT += -DGuo11 in My_Makefile_options).
    • ./input/LegacyModels_inputs/input_Guo11_MRII_W1_W1.par: input file for the Guo2011 model for the MillenniumII Simulation (requires OPT += -DGuo11 and OPT += -DMRII in My_Makefile_options).


    A range of files without a model name are available for new model development: ./input/input_MR_W1_PLANCK.par and ./input/input_MRII_W1_PLANCK.par (PLANCK year1 cosmology), ./input/input_MR_W1_W7.par and ./input/input_MRII_W1_W7.par (WMAP7 cosmology), ./input/input_MR_W1_W1.par and ./input/input_MRII_W1_W1.par (WMAP1 cosmology).

    Running different models will likely change the output structure. Always make sure you are trying to read the correct LGalaxies_struct in your plotting routines. If the new models have different cosmologies you will also need to adjust the Volume and Hubble_h used in plots.

  7. Analysing the Output
  8. After the galaxy formation model has finished, output galaxy catalogues will be created in the output directory (./output/ is the default). One file will be created for each of the dark matter simulation sub volumes (just file number 5 as default, 0-9 available in the download package, a total of 512 for the full Millennium simulation). In normal mode, one file will be created for each output snapshot (1 file per subvolume and 1 file per snapshot):

    SA_z56.42_0, SA_z56.42_1, ..., SA_z56.42_511
    ...
    SA_z0.05_0, SA_z0.05_1, ..., SA_z0.05_511
    SA_z0.03_0, SA_z0.03_1, ..., SA_z0.03_511
    SA_z0.00_0, SA_z0.00_1, ..., SA_z0.00_511


    If +OPT = -DGALAXYTREE, all snapshots, for a given sub-volume, will be in a single file:

    SA_galtree_0, SA_galtree_1, ..., SA_galtree_511


    Python and Idl scripts to read the model output and produce a few simple plots can be downloaded on the top of the page. Critically you will need to know the galaxy structure written into the output files. If you run make metadata, in the root directory, the output structue will be written into ./AuxCode/awk/idl/LGalaxy.pro. This will likely change if you change the Makefile options.