git-nomad: 0.7.1 -> 0.8.0 (#365279)
[NixPkgs.git] / pkgs / applications / science / chemistry / nwchem / default.nix
blobcc80ad3c67ec078f80678dbc1d976d2d4ff4a8a8
2   lib,
3   stdenv,
4   fetchFromGitHub,
5   fetchurl,
6   mpiCheckPhaseHook,
7   which,
8   openssh,
9   gcc,
10   gfortran,
11   perl,
12   mpi,
13   blas,
14   lapack,
15   python3,
16   tcsh,
17   automake,
18   autoconf,
19   libtool,
20   makeWrapper,
23 assert blas.isILP64 == lapack.isILP64;
25 let
26   versionGA = "5.8.2"; # Fixed by nwchem
28   gaSrc = fetchFromGitHub {
29     owner = "GlobalArrays";
30     repo = "ga";
31     rev = "v${versionGA}";
32     hash = "sha256-2ffQIg9topqKX7ygnWaa/UunL9d0Lj9qr9xucsjLuoY=";
33   };
35   dftd3Src = fetchurl {
36     url = "https://www.chemie.uni-bonn.de/grimme/software/dft-d3/dftd3.tgz";
37     hash = "sha256-2Xz5dY9hqoH9hUJUSPv0pujOB8EukjZzmDGjrzKID1k=";
38   };
40   versionLibxc = "6.1.0";
41   libxcSrc = fetchurl {
42     url = "https://gitlab.com/libxc/libxc/-/archive/${versionLibxc}/libxc-${versionLibxc}.tar.gz";
43     hash = "sha256-9ZN0X6R+v7ndxGeqr9wvoSdfDXJQxpLOl2E4mpDdjq8=";
44   };
46   plumedSrc = fetchFromGitHub {
47     owner = "edoapra";
48     repo = "plumed2";
49     rev = "88f06db71173e7893713a582e5ada7193e8ae1c9";
50     hash = "sha256-p5XNxHcE/QkJ5WdQH/xPp2EyrqCNjA/w/e1R2fkwYts=";
51   };
54 stdenv.mkDerivation rec {
55   pname = "nwchem";
56   version = "7.2.3";
58   src = fetchFromGitHub {
59     owner = "nwchemgit";
60     repo = "nwchem";
61     rev = "v${version}-release";
62     hash = "sha256-2qc4kLb/WmUJuJGonIyS7pgCfyt8yXdcpDAKU0RMY58=";
63   };
65   nativeBuildInputs = [
66     perl
67     automake
68     autoconf
69     libtool
70     makeWrapper
71     gfortran
72     which
73   ];
74   buildInputs = [
75     tcsh
76     openssh
77     blas
78     lapack
79     python3
80   ];
81   propagatedBuildInputs = [ mpi ];
82   propagatedUserEnvPkgs = [ mpi ];
84   postUnpack = ''
85     # These run 'configure' in source tree and
86     # require a writable directory
87     cp -r ${gaSrc}/ source/src/tools/ga-${versionGA}
88     chmod -R u+w source/src/tools/ga-${versionGA}
90     cp -r ${plumedSrc} source/src/libext/plumed/plumed2
91     chmod -R u+w source/src/libext/plumed/plumed2
93     # Provide tarball in expected location
94     ln -s ${dftd3Src} source/src/nwpw/nwpwlib/nwpwxc/dftd3.tgz
95     ln -s ${libxcSrc} source/src/libext/libxc/libxc-${versionLibxc}.tar.gz
96   '';
98   postPatch = ''
99     find -type f -executable -exec sed -i "s:/bin/csh:${tcsh}/bin/tcsh:" \{} \;
100     find -type f -name "GNUmakefile" -exec sed -i "s:/usr/bin/gcc:${gcc}/bin/gcc:" \{} \;
101     find -type f -name "GNUmakefile" -exec sed -i "s:/bin/rm:rm:" \{} \;
102     find -type f -executable -exec sed -i "s:/bin/rm:rm:" \{} \;
103     find -type f -name "makelib.h" -exec sed -i "s:/bin/rm:rm:" \{} \;
105     # Overwrite script, skipping the download
106     echo -e '#!/bin/sh\n cd ga-${versionGA};autoreconf -ivf' > src/tools/get-tools-github
108     # /usr/bin/env bash fails in sandbox/Makefile setting
109     substituteInPlace src/config/makefile.h --replace '/usr/bin/env bash' "${stdenv.shell}"
111     patchShebangs ./
112   '';
114   # There is no configure script. Instead the build is controlled via
115   # environment variables passed to the Makefile
116   configurePhase = ''
117     runHook preConfigure
119     # config parameters
120     export NWCHEM_TARGET="LINUX64"
122     export ARMCI_NETWORK="MPI-PR"
123     export USE_MPI="y"
124     export USE_MPIF="y"
126     export NWCHEM_MODULES="all python"
128     export USE_PYTHONCONFIG="y"
129     export USE_PYTHON64="n"
130     export PYTHONLIBTYPE="so"
131     export PYTHONHOME="${python3}"
132     export PYTHONVERSION=${lib.versions.majorMinor python3.version}
134     export BLASOPT="-L${blas}/lib -lblas"
135     export LAPACK_LIB="-L${lapack}/lib -llapack"
136     export BLAS_SIZE=${if blas.isILP64 then "8" else "4"}
138     # extra TCE related options
139     export MRCC_METHODS="y"
140     export EACCSD="y"
141     export IPCCSD="y"
143     export CCSDTQ="y"
145     export NWCHEM_TOP="$(pwd)"
147     runHook postConfigure
148   '';
150   enableParallelBuilding = true;
152   preBuild = ''
153     ln -s ${gaSrc} src/tools/ga-${versionGA}.tar.gz
154     cd src
155     make nwchem_config
156     ${lib.optionalString (!blas.isILP64) "make 64_to_32"}
157   '';
159   postBuild = ''
160     cd $NWCHEM_TOP/src/util
161     make version
162     make
163     cd $NWCHEM_TOP/src
164     make link
165   '';
167   installPhase = ''
168     runHook preInstall
170     mkdir -p $out/bin $out/share/nwchem
172     cp $NWCHEM_TOP/bin/LINUX64/nwchem $out/bin/nwchem
173     cp -r $NWCHEM_TOP/src/data $out/share/nwchem/
174     cp -r $NWCHEM_TOP/src/basis/libraries $out/share/nwchem/data
175     cp -r $NWCHEM_TOP/src/nwpw/libraryps $out/share/nwchem/data
177     wrapProgram $out/bin/nwchem \
178       --set-default NWCHEM_BASIS_LIBRARY $out/share/nwchem/data/libraries/
180     cat > $out/share/nwchem/nwchemrc << EOF
181     nwchem_basis_library $out/share/nwchem/data/libraries/
182     nwchem_nwpw_library $out/share/nwchem//data/libraryps/
183     ffield amber
184     amber_1 $out/share/nwchem/data/amber_s/
185     amber_2 $out/share/nwchem/data/amber_q/
186     amber_3 $out/share/nwchem/data/amber_x/
187     amber_4 $out/share/nwchem/data/amber_u/
188     spce    $out/share/nwchem/data/solvents/spce.rst
189     charmm_s $out/share/nwchem/data/charmm_s/
190     charmm_x $out/share/nwchem/data/charmm_x/
191     EOF
193     runHook postInstall
194   '';
196   doCheck = false;
198   doInstallCheck = true;
199   nativeInstallCheckInputs = [ mpiCheckPhaseHook ];
200   installCheckPhase = ''
201     runHook preInstallCheck
203     # run a simple water test
204     mpirun -np 2 $out/bin/nwchem $NWCHEM_TOP/QA/tests/h2o/h2o.nw > h2o.out
205     grep "Total SCF energy" h2o.out  | grep 76.010538
207     runHook postInstallCheck
208   '';
210   passthru = { inherit mpi; };
212   meta = with lib; {
213     description = "Open Source High-Performance Computational Chemistry";
214     mainProgram = "nwchem";
215     platforms = [
216       "x86_64-linux"
217       "aarch64-linux"
218     ];
219     maintainers = with maintainers; [
220       sheepforce
221       markuskowa
222     ];
223     homepage = "https://nwchemgit.github.io";
224     license = licenses.ecl20;
225   };