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