summary refs log tree commit diff
path: root/pkgs/applications/science/chemistry/openmolcas/default.nix
blob: 33c77c063bf915cdecddbbe4225be64b63771344 (plain) (blame)
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
147
148
149
150
151
152
153
154
155
156
157
158
159
{ lib
, stdenv
, fetchFromGitLab
, fetchFromGitHub
, cmake
, gfortran
, perl
, blas-ilp64
, hdf5-cpp
, python3
, texliveMinimal
, armadillo
, libxc
, makeWrapper
, gsl
, boost175
, autoPatchelfHook
  # Note that the CASPT2 module is broken with MPI
  # See https://gitlab.com/Molcas/OpenMolcas/-/issues/169
, enableMpi ? false
, mpi
, globalarrays
}:

assert blas-ilp64.isILP64;
assert lib.elem blas-ilp64.passthru.implementation [ "openblas" "mkl" ];

let
  python = python3.withPackages (ps: with ps; [ six pyparsing numpy h5py ]);
  qcmaquisSrc = fetchFromGitHub {
    owner = "qcscine";
    repo = "qcmaquis";
    rev = "release-3.1.1"; # Must match tag in cmake/custom/qcmaquis.cmake
    hash = "sha256-diLDWj/Om6EHrVp+Hd24jsN6R9vV2vRl0y9gqyRWhkI=";
  };
  nevtp2Src = fetchFromGitHub {
    owner = "qcscine";
    repo = "nevpt2";
    rev = "e1484fd"; # Must match tag in cmake/custom/nevpt2.cmake
    hash = "sha256-Vl+FhwhJBbD/7U2CwsYE9BClSQYLJ8DKXV9EXxQUmz0=";
  };

in
stdenv.mkDerivation {
  pname = "openmolcas";
  version = "23.10";

  src = fetchFromGitLab {
    owner = "Molcas";
    repo = "OpenMolcas";
    # The tag keeps moving, fix a hash instead
    rev = "c74317e68572d1da82fdce4210b005c2c1b1de53"; # 2023-09-25
    hash = "sha256-wBrASZ6YFsWsu/TreEZ6Q+VxNQwCwMpyPC8AOqmNxos=";
  };

  patches = [
    # Required to handle openblas multiple outputs
    ./openblasPath.patch

    # Required for a local QCMaquis build
    ./qcmaquis.patch
  ];

  postPatch = ''
    # Using env fails in the sandbox
    substituteInPlace Tools/pymolcas/export.py --replace \
      "/usr/bin/env','python3" "python3"

    # Pointing CMake to local QCMaquis and NEVPT2 archives
    substituteInPlace cmake/custom/qcmaquis.cmake \
      --subst-var-by "qcmaquis_src_url" "file://${qcmaquisSrc}"

    substituteInPlace cmake/custom/nevpt2.cmake \
      --subst-var-by "nevpt2_src_url" "file://${nevtp2Src}"
  '';

  nativeBuildInputs = [
    perl
    gfortran
    cmake
    texliveMinimal
    makeWrapper
    autoPatchelfHook
  ];

  buildInputs = [
    blas-ilp64.passthru.provider
    hdf5-cpp
    python
    armadillo
    libxc
    gsl.dev
    boost175
  ] ++ lib.optionals enableMpi [
    mpi
    globalarrays
  ];

  passthru = lib.optionalAttrs enableMpi { inherit mpi; };

  cmakeFlags = [
    "-DOPENMP=ON"
    "-DLINALG=OpenBLAS"
    "-DTOOLS=ON"
    "-DHDF5=ON"
    "-DFDE=ON"
    "-DEXTERNAL_LIBXC=${lib.getDev libxc}"
    "-DDMRG=ON"
    "-DNEVPT2=ON"
    "-DCMAKE_SKIP_BUILD_RPATH=ON"
  ] ++ lib.optionals (blas-ilp64.passthru.implementation == "openblas") [
    "-DOPENBLASROOT=${blas-ilp64.passthru.provider.dev}"
    "-DLINALG=OpenBLAS"
  ] ++ lib.optionals (blas-ilp64.passthru.implementation == "mkl") [
    "-DMKLROOT=${blas-ilp64.passthru.provider}"
    "-DLINALG=MKL"
  ] ++ lib.optionals enableMpi [
    "-DGA=ON"
    "-DMPI=ON"
  ];

  preConfigure = lib.optionalString enableMpi ''
    export GAROOT=${globalarrays};
  '';

  postConfigure = ''
    # The Makefile will install pymolcas during the build grrr.
    mkdir -p $out/bin
    export PATH=$PATH:$out/bin
  '';

  postInstall = ''
    mv $out/pymolcas $out/bin
    find $out/Tools -type f -exec mv \{} $out/bin \;
    rm -r $out/Tools
  '';

  # DMRG executables contain references to /build, however, they are properly
  # removed by autopatchelf
  noAuditTmpdir = true;

  postFixup = ''
    # Wrong store path in shebang (no Python pkgs), force re-patching
    sed -i "1s:/.*:/usr/bin/env python:" $out/bin/pymolcas
    patchShebangs $out/bin

    wrapProgram $out/bin/pymolcas --set MOLCAS $out
  '';

  meta = with lib; {
    description = "Advanced quantum chemistry software package";
    homepage = "https://gitlab.com/Molcas/OpenMolcas";
    maintainers = [ maintainers.markuskowa ];
    license = with licenses; [ lgpl21Only bsd3 ];
    platforms = [ "x86_64-linux" ];
    mainProgram = "pymolcas";
  };
}