summaryrefslogtreecommitdiffstats
path: root/pkgs/applications/science/chemistry/quantum-espresso/default.nix
blob: 2156c1d2696915e77dfbda68bd95df1038c27104 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
{ lib
, stdenv
, fetchFromGitLab
, fetchFromGitHub
, git
, cmake
, gfortran
, pkg-config
, fftw
, blas
, lapack
, scalapack
, wannier90
, hdf5
, libmbd
, libxc
, enableMpi ? true
, mpi
}:

assert ! blas.isILP64;
assert ! lapack.isILP64;

let
  # "rev"s must exactly match the git submodule commits in the QE repo
  gitSubmodules = {
    devxlib = fetchFromGitLab {
      group = "max-centre";
      owner = "components";
      repo = "devicexlib";
      rev = "a6b89ef77b1ceda48e967921f1f5488d2df9226d";
      hash = "sha256-p3fRplVG4YSN6ILNlOwf+aSEhpTJPXqiS1+wnzWVA2U=";
    };

    pw2qmcpack = fetchFromGitHub {
      owner = "QMCPACK";
      repo = "pw2qmcpack";
      rev = "f72ab25fa4ea755c1b4b230ae8074b47d5509c70";
      hash = "sha256-K1Z90xexsUvk4SdEb8FGryRal0GAFoLz3j1h/RT2nYw=";
    };
  };

in
stdenv.mkDerivation rec {
  version = "7.2";
  pname = "quantum-espresso";

  src = fetchFromGitLab {
    owner = "QEF";
    repo = "q-e";
    rev = "qe-${version}";
    hash = "sha256-0q0QWX4BVjVHjcbKOBpjbBADuL+2S5LAALyrxmjVs4c=";
  };

  # add git submodules manually and fix pkg-config file
  prePatch = ''
    chmod -R +rwx external/

    substituteInPlace external/devxlib.cmake \
      --replace "qe_git_submodule_update(external/devxlib)" ""
    substituteInPlace external/CMakeLists.txt \
      --replace "qe_git_submodule_update(external/pw2qmcpack)" "" \
      --replace "qe_git_submodule_update(external/d3q)" "" \
      --replace "qe_git_submodule_update(external/qe-gipaw)" ""

    ${builtins.toString (builtins.attrValues
      (builtins.mapAttrs
        (name: val: ''
          cp -r ${val}/* external/${name}/.
          chmod -R +rwx external/${name}
        '')
        gitSubmodules
      )
    )}

    substituteInPlace cmake/quantum_espresso.pc.in \
      --replace 'libdir="''${prefix}/@CMAKE_INSTALL_LIBDIR@"' 'libdir="@CMAKE_INSTALL_FULL_LIBDIR@"'
  '';

  passthru = { inherit mpi; };

  nativeBuildInputs = [
    cmake
    gfortran
    git
    pkg-config
  ];

  buildInputs = [
    fftw
    blas
    lapack
    wannier90
    libmbd
    libxc
    hdf5
  ] ++ lib.optional enableMpi scalapack;

  propagatedBuildInputs = lib.optional enableMpi mpi;
  propagatedUserEnvPkgs = lib.optional enableMpi mpi;

  cmakeFlags = [
    "-DBUILD_SHARED_LIBS=ON"
    "-DWANNIER90_ROOT=${wannier90}"
    "-DMBD_ROOT=${libmbd}"
    "-DQE_ENABLE_OPENMP=ON"
    "-DQE_ENABLE_LIBXC=ON"
    "-DQE_ENABLE_HDF5=ON"
    "-DQE_ENABLE_PLUGINS=pw2qmcpack"
  ] ++ lib.optionals enableMpi [
    "-DQE_ENABLE_MPI=ON"
    "-DQE_ENABLE_MPI_MODULE=ON"
    "-DQE_ENABLE_SCALAPACK=ON"
  ];

  meta = with lib; {
    description = "Electronic-structure calculations and materials modeling at the nanoscale";
    longDescription = ''
      Quantum ESPRESSO is an integrated suite of Open-Source computer codes for
      electronic-structure calculations and materials modeling at the
      nanoscale. It is based on density-functional theory, plane waves, and
      pseudopotentials.
    '';
    homepage = "https://www.quantum-espresso.org/";
    license = licenses.gpl2;
    platforms = [ "x86_64-linux" "x86_64-darwin" ];
    maintainers = [ maintainers.costrouc ];
  };
}