*/*: Clean PYTHON_COMPAT of obsolete impls
[gentoo.git] / sci-chemistry / gromacs / gromacs-2020.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 CMAKE_MAKEFILE_GENERATOR="ninja"
7
8 PYTHON_COMPAT=( python3_{6,7} )
9
10 DISTUTILS_SINGLE_IMPL=1
11
12 inherit bash-completion-r1 cmake-utils cuda distutils-r1 eutils multilib readme.gentoo-r1 toolchain-funcs xdg-utils
13
14 if [[ $PV = *9999* ]]; then
15         EGIT_REPO_URI="git://git.gromacs.org/gromacs.git
16                 https://gerrit.gromacs.org/gromacs.git
17                 https://github.com/gromacs/gromacs.git
18                 https://repo.or.cz/r/gromacs.git"
19         [[ $PV = 9999 ]] && EGIT_BRANCH="master" || EGIT_BRANCH="release-${PV:0:4}"
20         inherit git-r3
21 else
22         SRC_URI="ftp://ftp.gromacs.org/pub/${PN}/${PN}-${PV/_/-}.tar.gz
23                 test? ( http://gerrit.gromacs.org/download/regressiontests-${PV/_/-}.tar.gz )"
24         KEYWORDS="~amd64 ~arm ~x86 ~amd64-linux ~x86-linux ~x64-macos ~x86-macos"
25 fi
26
27 ACCE_IUSE="cpu_flags_x86_sse2 cpu_flags_x86_sse4_1 cpu_flags_x86_fma4 cpu_flags_x86_avx cpu_flags_x86_avx2"
28
29 DESCRIPTION="The ultimate molecular dynamics simulation package"
30 HOMEPAGE="http://www.gromacs.org/"
31
32 # see COPYING for details
33 # https://repo.or.cz/w/gromacs.git/blob/HEAD:/COPYING
34 #        base,    vmd plugins, fftpack from numpy,  blas/lapck from netlib,        memtestG80 library,  mpi_thread lib
35 LICENSE="LGPL-2.1 UoI-NCSA !mkl? ( !fftw? ( BSD ) !blas? ( BSD ) !lapack? ( BSD ) ) cuda? ( LGPL-3 ) threads? ( BSD )"
36 SLOT="0/${PV}"
37 IUSE="X blas cuda +doc -double-precision +fftw +gmxapi +gmxapi-legacy +hwloc lapack +lmfit mkl mpi +offensive opencl openmp +python +single-precision test +threads +tng ${ACCE_IUSE}"
38
39 CDEPEND="
40         X? (
41                 x11-libs/libX11
42                 x11-libs/libSM
43                 x11-libs/libICE
44                 )
45         blas? ( virtual/blas )
46         cuda? ( >=dev-util/nvidia-cuda-toolkit-6.5.14 )
47         opencl? ( virtual/opencl )
48         fftw? ( sci-libs/fftw:3.0 )
49         hwloc? ( sys-apps/hwloc )
50         lapack? ( virtual/lapack )
51         lmfit? ( sci-libs/lmfit )
52         mkl? ( sci-libs/mkl )
53         mpi? ( virtual/mpi )
54         ${PYTHON_DEPS}
55         !sci-chemistry/gmxapi
56         "
57 BDEPEND="${CDEPEND}
58         virtual/pkgconfig
59         doc? (
60                 app-doc/doxygen
61                 dev-python/sphinx[${PYTHON_USEDEP}]
62                 media-gfx/mscgen
63                 media-gfx/graphviz
64                 dev-texlive/texlive-latex
65                 dev-texlive/texlive-latexextra
66                 media-gfx/imagemagick
67         )"
68 RDEPEND="${CDEPEND}"
69
70 REQUIRED_USE="
71         || ( single-precision double-precision )
72         cuda? ( single-precision )
73         cuda? ( !opencl )
74         mkl? ( !blas !fftw !lapack )
75         ${PYTHON_REQUIRED_USE}"
76
77 DOCS=( AUTHORS README )
78
79 RESTRICT="!test? ( test )"
80
81 if [[ ${PV} != *9999 ]]; then
82         S="${WORKDIR}/${PN}-${PV/_/-}"
83 fi
84
85 PATCHES=( "${FILESDIR}/${PN}-2020_beta1-pytest.patch" )
86
87 pkg_pretend() {
88         [[ $(gcc-version) == "4.1" ]] && die "gcc 4.1 is not supported by gromacs"
89         use openmp && ! tc-has-openmp && \
90                 die "Please switch to an openmp compatible compiler"
91 }
92
93 pkg_setup() {
94         python-single-r1_pkg_setup
95 }
96
97 src_unpack() {
98         if [[ ${PV} != *9999 ]]; then
99                 default
100         else
101                 git-r3_src_unpack
102                 if use test; then
103                         EGIT_REPO_URI="git://git.gromacs.org/regressiontests.git" \
104                         EGIT_BRANCH="${EGIT_BRANCH}" \
105                         EGIT_CHECKOUT_DIR="${WORKDIR}/regressiontests"\
106                                 git-r3_src_unpack
107                 fi
108         fi
109 }
110
111 src_prepare() {
112         #notes/todos
113         # -on apple: there is framework support
114
115         xdg_environment_reset #591952
116
117         cmake-utils_src_prepare
118
119         use cuda && cuda_src_prepare
120
121         GMX_DIRS=""
122         use single-precision && GMX_DIRS+=" float"
123         use double-precision && GMX_DIRS+=" double"
124
125         if use test; then
126                 for x in ${GMX_DIRS}; do
127                         mkdir -p "${WORKDIR}/${P}_${x}" || die
128                         cp -al "${WORKDIR}/regressiontests"* "${WORKDIR}/${P}_${x}/tests" || die
129                 done
130         fi
131
132         DOC_CONTENTS="Gromacs can use sci-chemistry/vmd to read additional file formats"
133
134         # try to create policy for imagemagik
135         mkdir -p ${HOME}/.config/ImageMagick
136         cat >> ${HOME}/.config/ImageMagick/policy.xml <<- EOF
137         <?xml version="1.0" encoding="UTF-8"?>
138         <!DOCTYPE policymap [
139         <!ELEMENT policymap (policy)+>
140         !ATTLIST policymap xmlns CDATA #FIXED ''>
141         <!ELEMENT policy EMPTY>
142         <!ATTLIST policy xmlns CDATA #FIXED '' domain NMTOKEN #REQUIRED
143                         name NMTOKEN #IMPLIED pattern CDATA #IMPLIED rights NMTOKEN #IMPLIED
144                         stealth NMTOKEN #IMPLIED value CDATA #IMPLIED>
145         ]>
146         <policymap>
147                 <policy domain="coder" rights="read | write" pattern="PS" />
148                 <policy domain="coder" rights="read | write" pattern="PS2" />
149                 <policy domain="coder" rights="read | write" pattern="PS3" />
150                 <policy domain="coder" rights="read | write" pattern="EPS" />
151                 <policy domain="coder" rights="read | write" pattern="PDF" />
152                 <policy domain="coder" rights="read | write" pattern="XPS" />
153         </policymap>
154         EOF
155 }
156
157 src_configure() {
158         local mycmakeargs_pre=( ) extra fft_opts=( )
159
160         #go from slowest to fastest acceleration
161         local acce="None"
162         use cpu_flags_x86_sse2 && acce="SSE2"
163         use cpu_flags_x86_sse4_1 && acce="SSE4.1"
164         use cpu_flags_x86_fma4 && acce="AVX_128_FMA"
165         use cpu_flags_x86_avx && acce="AVX_256"
166         use cpu_flags_x86_avx2 && acce="AVX2_256"
167
168         #to create man pages, build tree binaries are executed (bug #398437)
169         [[ ${CHOST} = *-darwin* ]] && \
170                 extra+=" -DCMAKE_BUILD_WITH_INSTALL_RPATH=OFF"
171
172         if use fftw; then
173                 fft_opts=( -DGMX_FFT_LIBRARY=fftw3 )
174         elif use mkl && has_version "=sci-libs/mkl-10*"; then
175                 fft_opts=( -DGMX_FFT_LIBRARY=mkl
176                         -DMKL_INCLUDE_DIR="${MKLROOT}/include"
177                         -DMKL_LIBRARIES="$(echo /opt/intel/mkl/10.0.5.025/lib/*/libmkl.so);$(echo /opt/intel/mkl/10.0.5.025/lib/*/libiomp*.so)"
178                 )
179         elif use mkl; then
180                 local bits=$(get_libdir)
181                 fft_opts=( -DGMX_FFT_LIBRARY=mkl
182                         -DMKL_INCLUDE_DIR="$(echo /opt/intel/*/mkl/include)"
183                         -DMKL_LIBRARIES="$(echo /opt/intel/*/mkl/lib/*${bits/lib}/libmkl_rt.so)"
184                 )
185         else
186                 fft_opts=( -DGMX_FFT_LIBRARY=fftpack )
187         fi
188
189         if use lmfit; then
190                 local lmfit_opts=( -DGMX_USE_LMFIT=EXTERNAL )
191         else
192                 local lmfit_opts=( -DGMX_USE_LMFIT=INTERNAL )
193         fi
194
195         mycmakeargs_pre+=(
196                 "${fft_opts[@]}"
197                 "${lmfit_opts[@]}"
198                 -DGMX_X11=$(usex X)
199                 -DGMX_EXTERNAL_BLAS=$(usex blas)
200                 -DGMX_EXTERNAL_LAPACK=$(usex lapack)
201                 -DGMX_OPENMP=$(usex openmp)
202                 -DGMX_COOL_QUOTES=$(usex offensive)
203                 -DGMX_USE_TNG=$(usex tng)
204                 -DGMX_BUILD_MANUAL=$(usex doc)
205                 -DGMX_HWLOC=$(usex hwloc)
206                 -DGMX_DEFAULT_SUFFIX=off
207                 -DGMX_SIMD="$acce"
208                 -DGMX_VMD_PLUGIN_PATH="${EPREFIX}/usr/$(get_libdir)/vmd/plugins/*/molfile/"
209                 -DBUILD_TESTING=$(usex test)
210                 -DGMX_BUILD_UNITTESTS=$(usex test)
211                 -DPYTHON_EXECUTABLE="${EPREFIX}/usr/bin/${EPYTHON}"
212                 ${extra}
213         )
214
215         for x in ${GMX_DIRS}; do
216                 einfo "Configuring for ${x} precision"
217                 local suffix=""
218                 #if we build single and double - double is suffixed
219                 use double-precision && use single-precision && \
220                         [[ ${x} = "double" ]] && suffix="_d"
221                 local p
222                 [[ ${x} = "double" ]] && p="-DGMX_DOUBLE=ON" || p="-DGMX_DOUBLE=OFF"
223                 local cuda=( "-DGMX_GPU=OFF" )
224                 [[ ${x} = "float" ]] && use cuda && \
225                         cuda=( "-DGMX_GPU=ON" )
226                 local opencl=( "-DGMX_USE_OPENCL=OFF" )
227                 use opencl && opencl=( "-DGMX_USE_OPENCL=ON" ) cuda=( "-DGMX_GPU=ON" )
228                 mycmakeargs=(
229                         ${mycmakeargs_pre[@]} ${p}
230                         -DGMX_MPI=OFF
231                         -DGMX_THREAD_MPI=$(usex threads)
232                         -DGMXAPI=$(usex gmxapi)
233                         -DGMX_INSTALL_LEGACY_API=$(usex gmxapi-legacy)
234                         "${opencl[@]}"
235                         "${cuda[@]}"
236                         "$(use test && echo -DREGRESSIONTEST_PATH="${WORKDIR}/${P}_${x}/tests")"
237                         -DGMX_BINARY_SUFFIX="${suffix}"
238                         -DGMX_LIBS_SUFFIX="${suffix}"
239                         -DGMX_PYTHON_PACKAGE=$(usex python)
240                         )
241                 BUILD_DIR="${WORKDIR}/${P}_${x}" cmake-utils_src_configure
242                 [[ ${CHOST} != *-darwin* ]] || \
243                   sed -i '/SET(CMAKE_INSTALL_NAME_DIR/s/^/#/' "${WORKDIR}/${P}_${x}/gentoo_rules.cmake" || die
244                 use mpi || continue
245                 einfo "Configuring for ${x} precision with mpi"
246                 mycmakeargs=(
247                         ${mycmakeargs_pre[@]} ${p}
248                         -DGMX_THREAD_MPI=OFF
249                         -DGMX_MPI=ON
250                         -DGMX_OPENMM=OFF
251                         -DGMXAPI=OFF
252                         "${opencl[@]}"
253                         "${cuda[@]}"
254                         -DGMX_BUILD_MDRUN_ONLY=ON
255                         -DBUILD_SHARED_LIBS=OFF
256                         -DGMX_BUILD_MANUAL=OFF
257                         -DGMX_BINARY_SUFFIX="_mpi${suffix}"
258                         -DGMX_LIBS_SUFFIX="_mpi${suffix}"
259                         )
260                 BUILD_DIR="${WORKDIR}/${P}_${x}_mpi" CC="mpicc" cmake-utils_src_configure
261                 [[ ${CHOST} != *-darwin* ]] || \
262                   sed -i '/SET(CMAKE_INSTALL_NAME_DIR/s/^/#/' "${WORKDIR}/${P}_${x}_mpi/gentoo_rules.cmake" || die
263         done
264 }
265
266 src_compile() {
267         for x in ${GMX_DIRS}; do
268                 einfo "Compiling for ${x} precision"
269                 BUILD_DIR="${WORKDIR}/${P}_${x}"\
270                         cmake-utils_src_compile
271                 if use python; then
272                         BUILD_DIR="${WORKDIR}/${P}_${x}"\
273                                 cmake-utils_src_compile python_packaging/all
274                         BUILD_DIR="${WORKDIR}/${P}" \
275                                 distutils-r1_src_compile
276                 fi
277                 # not 100% necessary for rel ebuilds as available from website
278                 if use doc; then
279                         BUILD_DIR="${WORKDIR}/${P}_${x}"\
280                                 cmake-utils_src_compile manual
281                 fi
282                 use mpi || continue
283                 einfo "Compiling for ${x} precision with mpi"
284                 BUILD_DIR="${WORKDIR}/${P}_${x}_mpi"\
285                         cmake-utils_src_compile
286         done
287 }
288
289 src_test() {
290         for x in ${GMX_DIRS}; do
291                 BUILD_DIR="${WORKDIR}/${P}_${x}"\
292                         cmake-utils_src_make check
293         done
294 }
295
296 src_install() {
297         for x in ${GMX_DIRS}; do
298                 BUILD_DIR="${WORKDIR}/${P}_${x}" \
299                         cmake-utils_src_install
300                 if use python; then
301                         BUILD_DIR="${WORKDIR}/${P}_${x}" \
302                                 cmake-utils_src_install python_packaging/install
303                 fi
304                 if use doc; then
305                         newdoc "${WORKDIR}/${P}_${x}"/docs/manual/gromacs.pdf "${PN}-manual-${PV}.pdf"
306                 fi
307                 use mpi || continue
308                 BUILD_DIR="${WORKDIR}/${P}_${x}_mpi" \
309                         cmake-utils_src_install
310         done
311
312         if use tng; then
313                 insinto /usr/include/tng
314                 doins src/external/tng_io/include/tng/*h
315         fi
316         # drop unneeded stuff
317         rm "${ED}"/usr/bin/GMXRC* || die
318         for x in "${ED}"/usr/bin/gmx-completion-*.bash ; do
319                 local n=${x##*/gmx-completion-}
320                 n="${n%.bash}"
321                 cat "${ED}"/usr/bin/gmx-completion-gmx.bash "$x" > "${T}/${n}" || die
322                 newbashcomp "${T}"/"${n}" "${n}"
323         done
324         rm "${ED}"/usr/bin/gmx-completion*.bash || die
325         readme.gentoo_create_doc
326 }
327
328 pkg_postinst() {
329         einfo
330         einfo  "Please read and cite:"
331         einfo  "Gromacs 4, J. Chem. Theory Comput. 4, 435 (2008). "
332         einfo  "https://dx.doi.org/10.1021/ct700301q"
333         einfo
334         readme.gentoo_print_elog
335 }