summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/gpaw/default.nix
blob: a4b4a4d6e60c8e6704b7b81d8ef0369709fced7e (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
{
  buildPythonPackage,
  lib,
  fetchFromGitLab,
  writeTextFile,
  fetchurl,
  blas,
  lapack,
  mpi,
  fftw,
  scalapack,
  libxc,
  libvdwxc,
  which,
  ase,
  numpy,
  scipy,
  pyyaml,
  inetutils,
}:

assert lib.asserts.assertMsg (!blas.isILP64) "A 32 bit integer implementation of BLAS is required.";

assert lib.asserts.assertMsg (
  !lapack.isILP64
) "A 32 bit integer implementation of LAPACK is required.";

let
  gpawConfig = writeTextFile {
    name = "siteconfig.py";
    text = ''
      # Compiler
      compiler = 'gcc'
      mpicompiler = '${lib.getDev mpi}/bin/mpicc'
      mpilinker = '${lib.getDev mpi}/bin/mpicc'

      # BLAS
      libraries += ['blas']
      library_dirs += ['${lib.getLib blas}/lib']

      # FFTW
      fftw = True
      if fftw:
        libraries += ['fftw3']

      scalapack = True
      if scalapack:
        libraries += ['scalapack']

      # LibXC
      libxc = True
      if libxc:
        xc = '${libxc}/'
        include_dirs += ['${lib.getDev libxc}/include']
        library_dirs += ['${lib.getLib libxc}/lib']
        if 'xc' not in libraries:
          libraries.append('xc')

      # LibVDWXC
      libvdwxc = True
      if libvdwxc:
        vdwxc = '${libvdwxc}/'
        library_dirs += ['${lib.getLib libvdwxc}/lib']
        include_dirs += ['${lib.getDev libvdwxc}/include']
        libraries += ['vdwxc']
    '';
  };

  setupVersion = "24.11.0";
  pawDataSets = fetchurl {
    url = "https://wiki.fysik.dtu.dk/gpaw-files/gpaw-setups-${setupVersion}.tar.gz";
    hash = "sha256-lkyBzCj3+RpGhtPTGCxOvaMO+wnT+Wt/lerjFGSZwRA=";
  };
in
buildPythonPackage rec {
  pname = "gpaw";
  version = "25.1.0";
  format = "setuptools";

  src = fetchFromGitLab {
    owner = "gpaw";
    repo = "gpaw";
    rev = version;
    hash = "sha256-tdS383qT6hBr5hOqjoFS36nRSS2vdVkUR7sExwjWhng=";
  };

  # `inetutils` is required because importing `gpaw`, as part of
  # pythonImportsCheck, tries to execute its binary, which in turn tries to
  # execute `rsh` as a side-effect.
  nativeBuildInputs = [
    which
    inetutils
  ];

  buildInputs = [
    blas
    scalapack
    libxc
    libvdwxc
    fftw
  ];

  propagatedBuildInputs = [
    ase
    scipy
    numpy
    (lib.getBin mpi)
    pyyaml
  ];

  patches = [ ./SetupPath.patch ];

  postPatch = ''
    substituteInPlace gpaw/__init__.py \
      --subst-var-by gpawSetupPath "$out/share/gpaw/gpaw-setups-${setupVersion}"
  '';

  preConfigure = ''
    unset CC
    cp ${gpawConfig} siteconfig.py
  '';

  postInstall = ''
    currDir=$(pwd)
    mkdir -p $out/share/gpaw && cd $out/share/gpaw
    cp ${pawDataSets} gpaw-setups.tar.gz
    tar -xvf $out/share/gpaw/gpaw-setups.tar.gz
    rm gpaw-setups.tar.gz
    cd $currDir
  '';

  doCheck = false; # Requires MPI runtime to work in the sandbox
  pythonImportsCheck = [ "gpaw" ];

  passthru = {
    inherit mpi;
  };

  meta = {
    description = "Density functional theory and beyond within the projector-augmented wave method";
    homepage = "https://wiki.fysik.dtu.dk/gpaw/index.html";
    license = lib.licenses.gpl3Only;
    platforms = lib.platforms.unix;
    maintainers = [ lib.maintainers.sheepforce ];
  };
}