2021-07-09 08:38:10 +00:00
|
|
|
{ lib, stdenv, fetchFromGitHub, python3, gfortran, blas, lapack
|
|
|
|
, fftw, libint, libvori, libxc, mpi, gsl, scalapack, openssh, makeWrapper
|
2023-03-16 13:30:15 +00:00
|
|
|
, libxsmm, spglib, which, pkg-config, plumed, zlib
|
2021-12-10 19:56:21 +00:00
|
|
|
, enableElpa ? false
|
|
|
|
, elpa
|
2021-07-09 08:38:10 +00:00
|
|
|
} :
|
|
|
|
|
|
|
|
let
|
|
|
|
cp2kVersion = "psmp";
|
|
|
|
arch = "Linux-x86-64-gfortran";
|
|
|
|
|
|
|
|
in stdenv.mkDerivation rec {
|
|
|
|
pname = "cp2k";
|
2023-01-14 20:34:50 +00:00
|
|
|
version = "2023.1";
|
2021-07-09 08:38:10 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "cp2k";
|
|
|
|
repo = "cp2k";
|
|
|
|
rev = "v${version}";
|
2023-01-14 20:34:50 +00:00
|
|
|
hash = "sha256-SG5Gz0cDiSfbSZ8m4K+eARMLU4iMk/xK3esN5yt05RE=";
|
2021-07-09 08:38:10 +00:00
|
|
|
fetchSubmodules = true;
|
|
|
|
};
|
|
|
|
|
2021-12-02 16:22:41 +00:00
|
|
|
nativeBuildInputs = [ python3 which openssh makeWrapper pkg-config ];
|
2021-07-09 08:38:10 +00:00
|
|
|
buildInputs = [
|
|
|
|
gfortran
|
|
|
|
fftw
|
|
|
|
gsl
|
|
|
|
libint
|
|
|
|
libvori
|
|
|
|
libxc
|
|
|
|
libxsmm
|
|
|
|
spglib
|
|
|
|
scalapack
|
|
|
|
blas
|
|
|
|
lapack
|
2023-03-16 13:30:15 +00:00
|
|
|
plumed
|
|
|
|
zlib
|
2021-12-10 19:56:21 +00:00
|
|
|
] ++ lib.optional enableElpa elpa;
|
2021-07-09 08:38:10 +00:00
|
|
|
|
|
|
|
propagatedBuildInputs = [ mpi ];
|
|
|
|
propagatedUserEnvPkgs = [ mpi ];
|
|
|
|
|
|
|
|
makeFlags = [
|
|
|
|
"ARCH=${arch}"
|
|
|
|
"VERSION=${cp2kVersion}"
|
|
|
|
];
|
|
|
|
|
|
|
|
doCheck = true;
|
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
patchShebangs tools exts/dbcsr/tools/build_utils exts/dbcsr/.cp2k
|
2022-01-10 12:54:46 +00:00
|
|
|
substituteInPlace exts/build_dbcsr/Makefile \
|
|
|
|
--replace '/usr/bin/env python3' '${python3}/bin/python' \
|
|
|
|
--replace 'SHELL = /bin/sh' 'SHELL = bash'
|
2021-07-09 08:38:10 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
configurePhase = ''
|
|
|
|
cat > arch/${arch}.${cp2kVersion} << EOF
|
|
|
|
CC = mpicc
|
|
|
|
CPP =
|
|
|
|
FC = mpif90
|
|
|
|
LD = mpif90
|
|
|
|
AR = ar -r
|
|
|
|
DFLAGS = -D__FFTW3 -D__LIBXC -D__LIBINT -D__parallel -D__SCALAPACK \
|
|
|
|
-D__MPI_VERSION=3 -D__F2008 -D__LIBXSMM -D__SPGLIB \
|
2023-03-16 13:30:15 +00:00
|
|
|
-D__MAX_CONTR=4 -D__LIBVORI ${lib.optionalString enableElpa "-D__ELPA"} \
|
|
|
|
-D__PLUMED2
|
2021-07-09 08:38:10 +00:00
|
|
|
CFLAGS = -fopenmp
|
|
|
|
FCFLAGS = \$(DFLAGS) -O2 -ffree-form -ffree-line-length-none \
|
|
|
|
-ftree-vectorize -funroll-loops -msse2 \
|
|
|
|
-std=f2008 \
|
|
|
|
-fopenmp -ftree-vectorize -funroll-loops \
|
|
|
|
-I${libxc}/include -I${libxsmm}/include \
|
2021-12-10 19:56:21 +00:00
|
|
|
-I${libint}/include ${lib.optionalString enableElpa "$(pkg-config --variable=fcflags elpa)"}
|
2021-07-09 08:38:10 +00:00
|
|
|
LIBS = -lfftw3 -lfftw3_threads \
|
|
|
|
-lscalapack -lblas -llapack \
|
|
|
|
-lxcf03 -lxc -lxsmmf -lxsmm -lsymspg \
|
|
|
|
-lint2 -lstdc++ -lvori \
|
|
|
|
-lgomp -lpthread -lm \
|
2023-03-16 13:30:15 +00:00
|
|
|
-fopenmp ${lib.optionalString enableElpa "$(pkg-config --libs elpa)"} \
|
|
|
|
-lz -ldl -lstdc++ ${lib.optionalString (mpi.pname == "openmpi") "$(mpicxx --showme:link)"} \
|
|
|
|
-lplumed
|
2021-07-09 08:38:10 +00:00
|
|
|
LDFLAGS = \$(FCFLAGS) \$(LIBS)
|
2023-03-16 13:30:15 +00:00
|
|
|
include ${plumed}/lib/plumed/src/lib/Plumed.inc
|
2021-07-09 08:38:10 +00:00
|
|
|
EOF
|
|
|
|
'';
|
|
|
|
|
|
|
|
checkPhase = ''
|
|
|
|
export OMP_NUM_THREADS=1
|
|
|
|
|
|
|
|
export HYDRA_IFACE=lo # Fix to make mpich run in a sandbox
|
|
|
|
export OMPI_MCA_rmaps_base_oversubscribe=1
|
|
|
|
export CP2K_DATA_DIR=data
|
|
|
|
|
|
|
|
mpirun -np 2 exe/${arch}/libcp2k_unittest.${cp2kVersion}
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin $out/share/cp2k
|
|
|
|
|
|
|
|
cp exe/${arch}/* $out/bin
|
|
|
|
|
|
|
|
for i in cp2k cp2k_shell graph; do
|
|
|
|
wrapProgram $out/bin/$i.${cp2kVersion} \
|
|
|
|
--set-default CP2K_DATA_DIR $out/share/cp2k
|
|
|
|
done
|
|
|
|
|
|
|
|
wrapProgram $out/bin/cp2k.popt \
|
|
|
|
--set-default CP2K_DATA_DIR $out/share/cp2k \
|
|
|
|
--set OMP_NUM_THREADS 1
|
|
|
|
|
|
|
|
cp -r data/* $out/share/cp2k
|
|
|
|
'';
|
|
|
|
|
|
|
|
passthru = { inherit mpi; };
|
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
description = "Quantum chemistry and solid state physics program";
|
|
|
|
homepage = "https://www.cp2k.org";
|
|
|
|
license = licenses.gpl2Plus;
|
|
|
|
maintainers = [ maintainers.sheepforce ];
|
|
|
|
platforms = [ "x86_64-linux" ];
|
|
|
|
};
|
|
|
|
}
|