1{
2 lib,
3 stdenv,
4 fetchFromGitLab,
5 fetchFromGitHub,
6 git,
7 cmake,
8 gfortran,
9 pkg-config,
10 fftw,
11 blas,
12 lapack,
13 scalapack,
14 wannier90,
15 hdf5,
16 libmbd,
17 libxc,
18 enableMpi ? true,
19 mpi,
20}:
21
22assert !blas.isILP64;
23assert !lapack.isILP64;
24
25let
26 # "rev"s must exactly match the git submodule commits in the QE repo
27 gitSubmodules = {
28 devxlib = fetchFromGitLab {
29 group = "max-centre";
30 owner = "components";
31 repo = "devicexlib";
32 rev = "a6b89ef77b1ceda48e967921f1f5488d2df9226d";
33 hash = "sha256-p3fRplVG4YSN6ILNlOwf+aSEhpTJPXqiS1+wnzWVA2U=";
34 };
35
36 pw2qmcpack = fetchFromGitHub {
37 owner = "QMCPACK";
38 repo = "pw2qmcpack";
39 rev = "f72ab25fa4ea755c1b4b230ae8074b47d5509c70";
40 hash = "sha256-K1Z90xexsUvk4SdEb8FGryRal0GAFoLz3j1h/RT2nYw=";
41 };
42 };
43
44in
45stdenv.mkDerivation rec {
46 version = "7.4.1";
47 pname = "quantum-espresso";
48
49 src = fetchFromGitLab {
50 owner = "QEF";
51 repo = "q-e";
52 rev = "qe-${version}";
53 hash = "sha256-o1CjIuJCTtIud4zeHROksK1Ub9RL/OB8GecAQOIGf1s=";
54 };
55
56 # add git submodules manually and fix pkg-config file
57 prePatch = ''
58 chmod -R +rwx external/
59
60 substituteInPlace external/devxlib.cmake \
61 --replace "qe_git_submodule_update(external/devxlib)" ""
62 substituteInPlace external/CMakeLists.txt \
63 --replace "qe_git_submodule_update(external/pw2qmcpack)" "" \
64 --replace "qe_git_submodule_update(external/d3q)" "" \
65 --replace "qe_git_submodule_update(external/qe-gipaw)" ""
66
67 ${builtins.toString (
68 builtins.attrValues (
69 builtins.mapAttrs (name: val: ''
70 cp -r ${val}/* external/${name}/.
71 chmod -R +rwx external/${name}
72 '') gitSubmodules
73 )
74 )}
75
76 substituteInPlace cmake/quantum_espresso.pc.in \
77 --replace 'libdir="''${prefix}/@CMAKE_INSTALL_LIBDIR@"' 'libdir="@CMAKE_INSTALL_FULL_LIBDIR@"'
78 '';
79
80 patches = [
81 # this patch reverts commit 5fb5a679, which enforced static library builds.
82 ./findLibxc.patch
83 ];
84
85 passthru = { inherit mpi; };
86
87 nativeBuildInputs = [
88 cmake
89 gfortran
90 git
91 pkg-config
92 ];
93
94 buildInputs = [
95 fftw
96 blas
97 lapack
98 wannier90
99 libmbd
100 libxc
101 hdf5
102 ]
103 ++ lib.optional enableMpi scalapack;
104
105 propagatedBuildInputs = lib.optional enableMpi mpi;
106 propagatedUserEnvPkgs = lib.optional enableMpi mpi;
107
108 cmakeFlags = [
109 "-DBUILD_SHARED_LIBS=ON"
110 "-DWANNIER90_ROOT=${wannier90}"
111 "-DMBD_ROOT=${libmbd}"
112 "-DQE_ENABLE_OPENMP=ON"
113 "-DQE_ENABLE_LIBXC=ON"
114 "-DQE_ENABLE_HDF5=ON"
115 "-DQE_ENABLE_PLUGINS=pw2qmcpack"
116 ]
117 ++ lib.optionals enableMpi [
118 "-DQE_ENABLE_MPI=ON"
119 "-DQE_ENABLE_MPI_MODULE=ON"
120 "-DQE_ENABLE_SCALAPACK=ON"
121 ];
122
123 meta = with lib; {
124 description = "Electronic-structure calculations and materials modeling at the nanoscale";
125 longDescription = ''
126 Quantum ESPRESSO is an integrated suite of Open-Source computer codes for
127 electronic-structure calculations and materials modeling at the
128 nanoscale. It is based on density-functional theory, plane waves, and
129 pseudopotentials.
130 '';
131 homepage = "https://www.quantum-espresso.org/";
132 license = licenses.gpl2;
133 platforms = [
134 "x86_64-linux"
135 "x86_64-darwin"
136 ];
137 maintainers = [ maintainers.costrouc ];
138 };
139}