Running NONMEM

NONMEM runs can be invoked using the command line/shell script nmfe (NONMEM Front End). The script is appended with release version, e.g. nmfe75 for NONMEM v7.5. The basic use requires two arguments, model file and report file:

1
2
  nmfe75.bat model.ctl model.res # Windows
  nmfe75 model.ctl model.res # Linux/Unix

The run will output status, information, and messages on screen, to re-direct/save them, one may use

1
2
  nmfe75 model.ctl model.res >stdout.txt
  nmfe75 mycontrol.ctl myresults.res -background>console.txt

Some common additional options are listed below.

  • -rundir. The user may enter a run directory that is different from the directory in which the script is launched:

    1
    
      -rundir=c:\my_favorite_dir

    One must have all user dependent input files, control stream file, msf files, and data files, are available in that run directory.

  • -nmexec. The user may also enter an alternative name for the constructed executable. For example,

    1
    
      -nmexec=nonmem2

    specifies an alternative executable name nonmem2, than the default nonmem.exe (windows) or nonmem (Linux).

  • -xmloff stops the XML output file from being created.
  • -flushtime=x requests file updating (flushing) to occur not more than every x seconds. For example,

    1
    
      -xmloff -flushtime=10.0

    may increase the simulation speed. File flushes for the MSF system are not affected, and continue to be updated every PRINT iterations during estimation. The default setting of flushtime is 1 second, suitable for most problems, but you can change this as needed (fractional seconds are also allowed). If you prefer file updates occurring as frequently as possible, you can set flushtime to 0.0, but this could cause considerable slowing of execution for small problems and data sets.

  • Beginning in NM73, an additional feature of the execution script file is that the path to the fortran compiler system and MPI system that is appropriate for NONMEM may be retrieved from a script file that could have the following environment variables defined:

    1
    2
    3
    4
    
      compilerpath
      mpibinpath
      mpilibpath
      mpilibname

    Comments in these files are provided for instructions about each of these environment variables. These paths will be temporarily added to the front of the PATH environment variable, so that the appropriate compiler or MPI system is called to service NONMEM. In the past, conflicts with other installed fortran compilers from other applications would prevent the appropriate compiler from being used for the NONMEM system. This location file method allows NONMEM to be forced to look in a particular location.

  • -locfile specifies the location file (nmloc.bat or nmloc by convention. See util/nmlocoriginal.* as templates). For example

    1
    
      nmfe75 myfile.ctl myfile.res -locfile=nmloc.bat

    If –locfile is not specified, the nmfe7x script looks in the present working directory for nmloc.bat (windows) or nmloc (linux). If this file is not found, it looks in the top directory of the NONMEM installed directory. Thus, the file nmloc.bat (Windows) or nmloc (Linux) in the top nonmem installed directory serves as the default location file, and may be modified, or used as a template and placed in the working directory or specified in the –locfile option on the command line. If a particular environment variable in the above list is not found or is not defined, then nmfe7x will behave as in earlier versions, and rely on the presently existing PATH for finding the compiler and MPI system. The nmfe7x script will display a statement as to what path it will use.

The following applies to the experimental library release. See NONMEM Installation Guide for traditional installation instructions.

Use precompiled library

As an experimental alternative, NONMEM is available as a precompiled library. One can download the library according to the OS and use the cmake and ninja build tools to build models. Currently this approach is available for GNU compilers.

Toolchain

Windows

The easiest way to set up toolchain on Windows is through MSYS2 and MinGW.

  1. Follow https://www.mingw-w64.org/getting-started/msys2/ to install MSYS2 and C/C++ compiler.
  2. Open MSYS2 MinGW64 command line and install the Fortran compiler

    1
    
      pacman -S mingw-w64-x86_64-gcc-fortran
  3. Install cmake and ninja-build

    1
    2
    
      pacman -S mingw-w64-x86_64-cmake
      pacman -S mingw-w64-x86_64-ninja

Linux

NONMEM has been tested on Ubuntu distribution. To install GNU compiler toolchain, do the following in shell.

1
2
3
4
5
  sudo apt update
  sudo apt install gcc
  sudo apt install gfortran
  sudo apt install cmake
  sudo apt install ninja-build

MacOS

NONMEM has been tested on MacOS with Apple silicon. To install GNU compilers, one can either use Xcode (assume Xcode installed)

1
  xcode-select --install

or homebrew

1
  brew install gcc

To install build toolchain, in terminal do

1
2
  brew install cmake
  brew install ninja

Build and run

  1. Create a build directory at, say "/path/to/build",

    1
    
      mkdir /path/to/build && cd /path/to/build
  2. To build a NONMEM model at /path/to/model/model-name.ctl, in the build directory, do

    1
    2
    3
    
      cmake ../nonmem -B. -GNinja -Dmodel=/path/to/model/model-name.ctl
      cmake --build . -j4
      cmake --install .

    The three commands above perform configuration, build, and installation, respectively. One can use additional cmake options to customize build. For example, assume multiple versions of compilers are present in the system, and one would like to use a certain version, say gfortran-15, as the Fortran compiler. One can do

    1
    
      cmake ../nonmem -B. -GNinja -Dmodel=/path/to/model/model-name.ctl -DCMAKE_Fortran_COMPILER=gfortran-15

    In the build command -j4 requests four parallel processes during building. One may adjust the number according to available hardware. After the last command, an executible with the same name ("model-name.exe" in the above example) of the model is created at the path /path/to/model/.

  3. To run the model, do

    1
    2
    
      cd /path/to/model/
      model-name.exe model-name.ctl output -licfile=/path/to/license/nonmem.lic

    Additional NONMEM executible options apply.