To build critic2, you will need:
A relatively modern Fortran compiler.
A C compiler.
The make program.
Optionally, a few additional libraries.
These tools may already be available on your machine but, if they are
not, they can be typically installed using a software package
rpm, etc. on Linux; homebrew on macOS).
Build Using cmake
Using cmake is the recommended installation procedure. Change to the critic2 root directory and make a subdirectory for the compilation:
mkdir build cd build
There are a number of
compilation options that can be passed to cmake, the most relevant of
-DCMAKE_INSTALL_PREFIX=prefix, which sets the installation
directory. You can tweak this and other compilation options using one
of the multiple cmake interfaces, like ccmake (use
ccmake .. from
build directory). To compile a static version of critic2, use:
cmake .. -DBUILD_STATIC=ON
This version can be copied to a different computer (with the same architecture), even if it does not have the compiler libraries. To compile a version with debug flags,
cmake .. -DCMAKE_BUILD_TYPE=Debug
This version gives more informative errors when the program crashes.
To build the program, do:
You can use
make -j n to use
n cores for the compilation. Running
make creates the
critic2 binary in
Build Using configure/make
If you downloaded the code from the git repository, you will need to run:
Prepare for compilation by doing:
configure --help for information about the different
compilation options. The
--prefix option to
configure sets the
installation path. More details about
configure can be found in the
INSTALL file included in the distribution. Once critic2 is configured,
compile the program using:
This should create the critic2 executable inside the
Installing and Setting up the Environment
Critic2 can be installed to the
prefix directory by doing:
However, the binary can be used directly from the source directory by
CRITIC_HOME environment. It must point to the root
directory of the distribution:
This variable is necessary for critic2 to find the atomic densities,
the cif dictionary, and other files. These files should be in
Critic2 is parallelized with OpenMP for shared-memory architectures
(unless disabled during compilation). You change the number of
parallel threads by setting the
variable. Note that the parallelization flags for compilers other than
ifort and gfortran may not be correct.
Which Compilers Work?
Critic2 uses some features from the more modern Fortran standards, which may not be available in some (most) compilers. In consequence, not all compilers may be able to generate the binary and, even if they do, it may be broken. Two versions of critic2 are distributed. The development version, corresponding to the master branch of the repository, and the stable version, in the stable branch. Only patches addressing serious bugs will be introduced in the stable version; all new development happens in the development version. The stable version is compilable with all versions of gfortran starting at 4.9. All intel fortran compiler versions from 2011 onwards also compile the stable code.
The development version can be compiled with gfortran-6 and later and with intel fortran 2019 and later. All other compilers tested have issues, and fail to produce a working binary. This is the list of compilers tested:
- gfortran 4.8: critic2 cannot be compiled because allocatable components in user-defined types are not supported in this and older versions.
- gfortran 4.9 through 5.4 (and possibly older and newer gfortran-5):
the code compiles correctly but there are errors allocating and
deallocating the global field array (
sy%f) and other complex user-defined types. The program is usable, but problems will arise if more than one crystal structure or more than 10 scalar fields are loaded.
- gfortran 6.x and above: no errors.
- ifort, all versions from 12.1 up to 18.0.3: catastrophic internal compiler errors of unknown origin.
- ifort, version 2019.0.3.199: it compiles but inexplicable segmentation faults with nonsensical tracebacks are thrown when using YT or BADER and when loading and unloading fields.
- ifort, version 2019.0.5.281: if aggressive optimization is used (
-O3flags), the compiler may freeze while compiling
- Portland Group Fortran compiler (pgfortran), version 17.3. There are two important compiler problems: i) passing subroutines and functions whose interface includes multidimensional arrays as arguments or function results does not work, and ii) internal compiler error when compiling meshmod.f90.
In summary: Only recent versions of gfortran and ifort are guaranteed to work with the development version. If you cannot use gfortran 6 or newer or ifort 2019 or newer, download the stable version. I do not think this is because of errors in the critic2 code (though if you find that it is, please let me know). If you paid for a recent version of your compiler and it throws an internal compiler error while trying to build critic2, you may want to consider submitting a bug report to the compiler developers.
If a recent compiler is not available, an alternative is to compile the program elsewhere with the static linking option:
LDFLAGS='-static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive' ./configure ...
provided the machine has the same architecture. (The part between the -Wl is there to prevent statically-linked gfortran executables from segfaulting.) You can choose the compiler by changing the FC and F77 flags before configure:
FC=gfortran F77=gfortran ./configure ...
CMAKE_Fortran_COMPILER options serve the same
purpose in a cmake build.
When critic2 is built using cmake, it is possible to link against the readline library. This library enables shell-like features for critic2’s command line interface such as keyboard shortcuts, history, and autocompletion.
Libxc is a library that implements
exchange-correlation energies and potentials for many semilocal
functionals (LDA, GGA and meta-GGA). In critic2, it is used to
calculate exchange and correlation energy densities via de
arithmetic expressions (see below).
To compile critic2 with libxc support, you must pass the location of
the library via
/opt/libxc/ is the directory that was the target for the libxc
installation (i.e. you used
--prefix=/opt/libxc when you configured
the libxc library). The code in critic2 is not compatible with
versions of libxc older than 4.1.
The libxc library is used in critic2 to create new scalar fields from
the exchange and correlation energy density definitions in the library
using a density, gradient, or kinetic energy density already available
to critic2 as a scalar field. For instance, if
contains the electron density in the urea crystal, then:
CRYSTAL urea.rho.cube LOAD urea.rho.cube LOAD AS "xc($1,1)+xc($1,9)"
defines a scalar field (number 2,
$2) as the LDA
exchange-correlation density. In the output, the cell integral of
the second field:
Cell integral (grid SUM) = -23.30215685
is the LDA exchange-correlation energy in this system. GGA and
meta-GGA exchange-correlation energy densities can be constructed in a
similar way, but they require additional arguments to
Another example: if we have a molecular wavefunction for benzene in
benzene.wfx, we can build a field containing the PBE energy density
and then integrate the PBE exchange-correlation energy with:
MOLECULE benzene.wfx LOAD benzene.wfx MOLCALC "xc($1,$1:g,101)+xc($1,$1:g,130)"
In this case,
xc() takes two arguments: the density and the
:g field modifier is used to pass the gradient of the
first field as the second argument to
xc(). The MOLCALC keyword
performs a numerical integration in a molecular mesh.
See the manual for more information.
Libcint is a library for calculating molecular integrals between Gaussian-Type Orbitals (GTOs). In critic2, this library is used mostly for testing but some options to the MOLCALC keyword and some functions in arithmetic expressions require it. To compile critic2 with libcint support, do either of these two:
./configure --with-cint-shared=/opt/libcint/lib ./configure --with-cint-static=/opt/libcint/lib
/opt/libcint/lib is the location of the libcint static (
or shared (
.so) libraries prefix where libcint was installed. If
compiled with the shared option, the same path needs to be available
when critic2 is executed (for instance, through the
The libcint library is used with molecular wavefunctions that provide
the basis set information (at present, this is only for fields read
from a Gaussian fchk file, but more will be implemented). The
nheff() chemical functions use the molecular
integrals calculated by libcint, as well as the
keyword. See the
chemical functions and the
MOLCALC sections of the manual.