1{
2 buildPythonPackage,
3 lib,
4 fetchFromGitLab,
5 writeTextFile,
6 fetchurl,
7 blas,
8 lapack,
9 mpi,
10 fftw,
11 scalapack,
12 libxc,
13 libvdwxc,
14 which,
15 ase,
16 numpy,
17 scipy,
18 pyyaml,
19 inetutils,
20}:
21
22assert lib.asserts.assertMsg (!blas.isILP64) "A 32 bit integer implementation of BLAS is required.";
23
24assert lib.asserts.assertMsg (
25 !lapack.isILP64
26) "A 32 bit integer implementation of LAPACK is required.";
27
28let
29 gpawConfig = writeTextFile {
30 name = "siteconfig.py";
31 text = ''
32 # Compiler
33 compiler = 'gcc'
34 mpicompiler = '${lib.getDev mpi}/bin/mpicc'
35 mpilinker = '${lib.getDev mpi}/bin/mpicc'
36
37 # BLAS
38 libraries += ['blas']
39 library_dirs += ['${lib.getLib blas}/lib']
40
41 # FFTW
42 fftw = True
43 if fftw:
44 libraries += ['fftw3']
45
46 scalapack = True
47 if scalapack:
48 libraries += ['scalapack']
49
50 # LibXC
51 libxc = True
52 if libxc:
53 xc = '${libxc}/'
54 include_dirs += ['${lib.getDev libxc}/include']
55 library_dirs += ['${lib.getLib libxc}/lib']
56 if 'xc' not in libraries:
57 libraries.append('xc')
58
59 # LibVDWXC
60 libvdwxc = True
61 if libvdwxc:
62 vdwxc = '${libvdwxc}/'
63 library_dirs += ['${lib.getLib libvdwxc}/lib']
64 include_dirs += ['${lib.getDev libvdwxc}/include']
65 libraries += ['vdwxc']
66 '';
67 };
68
69 setupVersion = "24.11.0";
70 pawDataSets = fetchurl {
71 url = "https://wiki.fysik.dtu.dk/gpaw-files/gpaw-setups-${setupVersion}.tar.gz";
72 hash = "sha256-lkyBzCj3+RpGhtPTGCxOvaMO+wnT+Wt/lerjFGSZwRA=";
73 };
74in
75buildPythonPackage rec {
76 pname = "gpaw";
77 version = "25.1.0";
78 format = "setuptools";
79
80 src = fetchFromGitLab {
81 owner = "gpaw";
82 repo = "gpaw";
83 rev = version;
84 hash = "sha256-tdS383qT6hBr5hOqjoFS36nRSS2vdVkUR7sExwjWhng=";
85 };
86
87 # `inetutils` is required because importing `gpaw`, as part of
88 # pythonImportsCheck, tries to execute its binary, which in turn tries to
89 # execute `rsh` as a side-effect.
90 nativeBuildInputs = [
91 which
92 inetutils
93 ];
94
95 buildInputs = [
96 blas
97 scalapack
98 libxc
99 libvdwxc
100 fftw
101 ];
102
103 propagatedBuildInputs = [
104 ase
105 scipy
106 numpy
107 (lib.getBin mpi)
108 pyyaml
109 ];
110
111 patches = [ ./SetupPath.patch ];
112
113 postPatch = ''
114 substituteInPlace gpaw/__init__.py \
115 --subst-var-by gpawSetupPath "$out/share/gpaw/gpaw-setups-${setupVersion}"
116 '';
117
118 preConfigure = ''
119 unset CC
120 cp ${gpawConfig} siteconfig.py
121 '';
122
123 postInstall = ''
124 currDir=$(pwd)
125 mkdir -p $out/share/gpaw && cd $out/share/gpaw
126 cp ${pawDataSets} gpaw-setups.tar.gz
127 tar -xvf $out/share/gpaw/gpaw-setups.tar.gz
128 rm gpaw-setups.tar.gz
129 cd $currDir
130 '';
131
132 doCheck = false; # Requires MPI runtime to work in the sandbox
133 pythonImportsCheck = [ "gpaw" ];
134
135 passthru = {
136 inherit mpi;
137 };
138
139 meta = with lib; {
140 description = "Density functional theory and beyond within the projector-augmented wave method";
141 homepage = "https://wiki.fysik.dtu.dk/gpaw/index.html";
142 license = licenses.gpl3Only;
143 platforms = platforms.unix;
144 maintainers = [ maintainers.sheepforce ];
145 };
146}