dev-python/agate: Bump to 1.13.0
[gentoo/gentoo.git] / sci-chemistry / gromacs / gromacs-2024.3.ebuild
blobcc4c9393b1407457aafb7aca174c1bd2c50f0738
1 # Copyright 1999-2024 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 EAPI=8
6 CMAKE_MAKEFILE_GENERATOR="ninja"
8 PYTHON_COMPAT=( python3_{10..12} )
10 DISTUTILS_OPTIONAL=1
11 DISTUTILS_USE_PEP517=no
12 DISTUTILS_SINGLE_IMPL=1
14 inherit bash-completion-r1 cmake cuda distutils-r1 flag-o-matic readme.gentoo-r1 toolchain-funcs xdg-utils
16 if [[ ${PV} = *9999* ]]; then
17         EGIT_REPO_URI="
18                 https://gitlab.com/gromacs/gromacs.git
19                 https://github.com/gromacs/gromacs.git
20                 "
21         [[ ${PV} = 9999 ]] && EGIT_BRANCH="master" || EGIT_BRANCH="release-${PV:0:4}"
22         inherit git-r3
23 else
24         SRC_URI="
25                 https://ftp.gromacs.org/gromacs/${PN}-${PV/_/-}.tar.gz
26                 doc? ( https://ftp.gromacs.org/manual/manual-${PV/_/-}.pdf )
27                 test? ( https://ftp.gromacs.org/regressiontests/regressiontests-${PV/_/-}.tar.gz )"
28         # since 2022 arm support was dropped (but not arm64)
29         KEYWORDS="amd64 -arm arm64 ~riscv -x86 ~amd64-linux -x86-linux ~x64-macos"
32 ACCE_IUSE="cpu_flags_x86_sse2 cpu_flags_x86_sse4_1 cpu_flags_x86_fma4 cpu_flags_x86_avx cpu_flags_x86_avx2 cpu_flags_x86_avx512f cpu_flags_arm_neon"
34 DESCRIPTION="The ultimate molecular dynamics simulation package"
35 HOMEPAGE="https://www.gromacs.org/"
37 # see COPYING for details
38 # https://repo.or.cz/w/gromacs.git/blob/HEAD:/COPYING
39 #        base,    vmd plugins, fftpack from numpy,  blas/lapck from netlib,        memtestG80 library,  mpi_thread lib
40 LICENSE="LGPL-2.1 UoI-NCSA !mkl? ( !fftw? ( BSD ) !blas? ( BSD ) !lapack? ( BSD ) ) cuda? ( LGPL-3 ) threads? ( BSD )"
41 SLOT="0/${PV}"
42 IUSE="blas clang clang-cuda cuda  +custom-cflags +doc build-manual double-precision +fftw +gmxapi +gmxapi-legacy +hwloc lapack mkl mpi +offensive opencl openmp +python +single-precision test +threads +tng ${ACCE_IUSE}"
44 CDEPEND="
45         blas? ( virtual/blas )
46         cuda? ( >=dev-util/nvidia-cuda-toolkit-11:=[profiler] )
47         opencl? ( virtual/opencl )
48         openmp? (
49                 sys-devel/gcc[openmp]
50                 llvm-core/clang-runtime[openmp]
51         )
52         fftw? ( sci-libs/fftw:3.0= )
53         hwloc? ( sys-apps/hwloc:= )
54         lapack? ( virtual/lapack )
55         mkl? ( sci-libs/mkl )
56         mpi? ( virtual/mpi[cxx] )
57         sci-libs/lmfit:=
58         >=dev-cpp/muParser-2.3:=
59         ${PYTHON_DEPS}
60         "
61 BDEPEND="${CDEPEND}
62         virtual/pkgconfig
63         clang? ( >=llvm-core/clang-6:* )
64         build-manual? (
65                 app-text/doxygen
66                 $(python_gen_cond_dep '
67                         dev-python/sphinx[${PYTHON_USEDEP}]
68                         dev-python/sphinx-copybutton[${PYTHON_USEDEP}]
69                         dev-python/sphinx-inline-tabs[${PYTHON_USEDEP}]
70                         dev-python/sphinx-argparse[${PYTHON_USEDEP}]
71                         dev-python/sphinxcontrib-autoprogram[${PYTHON_USEDEP}]
72                 ')
73                 media-gfx/mscgen
74                 media-gfx/graphviz
75                 dev-texlive/texlive-latex
76                 dev-texlive/texlive-latexextra
77                 media-gfx/imagemagick
78         )"
79 RDEPEND="${CDEPEND}"
81 REQUIRED_USE="
82         || ( single-precision double-precision )
83         doc? ( !build-manual )
84         cuda? ( single-precision )
85         opencl? ( single-precision )
86         cuda? ( !opencl )
87         clang-cuda? ( clang cuda )
88         mkl? ( !blas !fftw !lapack )
89         ${PYTHON_REQUIRED_USE}"
91 DOCS=( AUTHORS README )
93 RESTRICT="!test? ( test )"
95 PATCHES=( "${FILESDIR}/${PN}-gcc-15.patch" )
97 if [[ ${PV} != *9999 ]]; then
98         S="${WORKDIR}/${PN}-${PV/_/-}"
101 pkg_pretend() {
102         [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp
105 pkg_setup() {
106         [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp
107         python-single-r1_pkg_setup
110 src_unpack() {
111         if [[ ${PV} != *9999 ]]; then
112                 default
113         else
114                 git-r3_src_unpack
115                 if use test; then
116                         EGIT_REPO_URI="https://gitlab.com/gromacs/gromacs-regressiontests.git" \
117                         EGIT_BRANCH="${EGIT_BRANCH}" \
118                         EGIT_CHECKOUT_DIR="${WORKDIR}/regressiontests"\
119                                 git-r3_src_unpack
120                 fi
121         fi
124 src_prepare() {
125         #notes/todos
126         # -on apple: there is framework support
128         xdg_environment_reset #591952
130         # we can use clang as default
131         if use clang && ! tc-is-clang ; then
132                 export CC=${CHOST}-clang
133                 export CXX=${CHOST}-clang++
134         else
135                 tc-export CXX CC
136         fi
137         # clang-cuda need to filter mfpmath
138         if use clang-cuda ; then
139                 filter-mfpmath sse
140                 filter-mfpmath i386
141         fi
143         cmake_src_prepare
145         use cuda && cuda_src_prepare
147         GMX_DIRS=""
148         use single-precision && GMX_DIRS+=" float"
149         use double-precision && GMX_DIRS+=" double"
151         if use test; then
152                 for x in ${GMX_DIRS}; do
153                         mkdir -p "${WORKDIR}/${P}_${x}" || die
154                         cp -al "${WORKDIR}/regressiontests"* "${WORKDIR}/${P}_${x}/tests" || die
155                 done
156         fi
158         DOC_CONTENTS="Gromacs can use sci-chemistry/vmd to read additional file formats"
159         if use build-manual; then
160                 # try to create policy for imagemagik
161                 mkdir -p "${HOME}"/.config/ImageMagick
162                 cat >> "${HOME}"/.config/ImageMagick/policy.xml <<- EOF
163                 <?xml version="1.0" encoding="UTF-8"?>
164                 <!DOCTYPE policymap [
165                 <!ELEMENT policymap (policy)+>
166                 !ATTLIST policymap xmlns CDATA #FIXED ''>
167                 <!ELEMENT policy EMPTY>
168                 <!ATTLIST policy xmlns CDATA #FIXED '' domain NMTOKEN #REQUIRED
169                         name NMTOKEN #IMPLIED pattern CDATA #IMPLIED rights NMTOKEN #IMPLIED
170                         stealth NMTOKEN #IMPLIED value CDATA #IMPLIED>
171                 ]>
172                 <policymap>
173                         <policy domain="coder" rights="read | write" pattern="PS" />
174                         <policy domain="coder" rights="read | write" pattern="PS2" />
175                         <policy domain="coder" rights="read | write" pattern="PS3" />
176                         <policy domain="coder" rights="read | write" pattern="EPS" />
177                         <policy domain="coder" rights="read | write" pattern="PDF" />
178                         <policy domain="coder" rights="read | write" pattern="XPS" />
179                 </policymap>
180                 EOF
181         fi
184 src_configure() {
185         local mycmakeargs_pre=( ) extra fft_opts=( )
186         local acce="AUTO"
188         if use custom-cflags; then
189                 #go from slowest to fastest acceleration
190                 acce="None"
191                 if (use amd64 || use x86); then
192                         use cpu_flags_x86_sse2 && acce="SSE2"
193                         use cpu_flags_x86_sse4_1 && acce="SSE4.1"
194                         use cpu_flags_x86_fma4 && acce="AVX_128_FMA"
195                         use cpu_flags_x86_avx && acce="AVX_256"
196                         use cpu_flags_x86_avx2 && acce="AVX2_256"
197                         use cpu_flags_x86_avx512f && acce="AVX_512"
198                 elif (use arm); then
199                         use cpu_flags_arm_neon && acce="ARM_NEON"
200                 elif (use arm64); then
201                         use cpu_flags_arm_neon && acce="ARM_NEON_ASIMD"
202                 fi
203         else
204                 strip-flags
205         fi
207         #to create man pages, build tree binaries are executed (bug #398437)
208         [[ ${CHOST} = *-darwin* ]] && \
209                 extra+=" -DCMAKE_BUILD_WITH_INSTALL_RPATH=OFF"
211         if use fftw; then
212                 fft_opts=( -DGMX_FFT_LIBRARY=fftw3 )
213         elif use mkl; then
214                 local bits=$(get_libdir)
215                 fft_opts=( -DGMX_FFT_LIBRARY=mkl
216                         -DMKL_INCLUDE_DIR="$(echo /opt/intel/*/mkl/include)"
217                         -DMKL_LIBRARIES="$(echo /opt/intel/*/mkl/lib/*${bits/lib}/libmkl_rt.so)"
218                 )
219         else
220                 fft_opts=( -DGMX_FFT_LIBRARY=fftpack )
221         fi
223         mycmakeargs_pre+=(
224                 "${fft_opts[@]}"
225                 "${lmfit_opts[@]}"
226                 -DGMX_USE_LMFIT=EXTERNAL
227                 -DGMX_USE_MUPARSER=EXTERNAL
228                 -DGMX_EXTERNAL_BLAS=$(usex blas)
229                 -DGMX_EXTERNAL_LAPACK=$(usex lapack)
230                 -DGMX_OPENMP=$(usex openmp)
231                 -DGMX_COOL_QUOTES=$(usex offensive)
232                 -DGMX_USE_TNG=$(usex tng)
233                 -DGMX_BUILD_MANUAL=$(usex build-manual)
234                 -DGMX_HWLOC=$(usex hwloc)
235                 -DGMX_DEFAULT_SUFFIX=off
236                 -DGMX_SIMD="$acce"
237                 -DGMX_VMD_PLUGIN_PATH="${EPREFIX}/usr/$(get_libdir)/vmd/plugins/*/molfile/"
238                 -DBUILD_TESTING=$(usex test)
239                 -DGMX_BUILD_UNITTESTS=$(usex test)
240                 -DPYTHON_EXECUTABLE="${EPREFIX}/usr/bin/${EPYTHON}"
241                 ${extra}
242         )
244         for x in ${GMX_DIRS}; do
245                 einfo "Configuring for ${x} precision"
246                 local suffix=""
247                 #if we build single and double - double is suffixed
248                 use double-precision && use single-precision && \
249                         [[ ${x} = "double" ]] && suffix="_d"
250                 local p
251                 [[ ${x} = "double" ]] && p="-DGMX_DOUBLE=ON" || p="-DGMX_DOUBLE=OFF"
252                 local gpu=( "-DGMX_GPU=OFF" )
253                 [[ ${x} = "float" ]] && use cuda && gpu=( "-DGMX_GPU=CUDA" )
254                 [[ ${x} = "float" ]] && use clang-cuda && gpu=( "-DGMX_GPU=CUDA" "-DGMX_CLANG_CUDA=ON" )
255                 use opencl && gpu=( "-DGMX_GPU=OPENCL" )
256                 local mycmakeargs=(
257                         ${mycmakeargs_pre[@]} ${p}
258                         -DGMX_MPI=$(usex mpi)
259                         -DGMX_THREAD_MPI=$(usex threads)
260                         -DGMXAPI=$(usex gmxapi)
261                         -DGMX_INSTALL_LEGACY_API=$(usex gmxapi-legacy)
262                         "${gpu[@]}"
263                         "$(use test && echo -DREGRESSIONTEST_PATH="${WORKDIR}/${P}_${x}/tests")"
264                         -DGMX_BINARY_SUFFIX="${suffix}"
265                         -DGMX_LIBS_SUFFIX="${suffix}"
266                         -DGMX_PYTHON_PACKAGE=$(usex python)
267                 )
268                 BUILD_DIR="${WORKDIR}/${P}_${x}" cmake_src_configure
269                 [[ ${CHOST} != *-darwin* ]] || \
270                   sed -i '/SET(CMAKE_INSTALL_NAME_DIR/s/^/#/' "${WORKDIR}/${P}_${x}/gentoo_rules.cmake" || die
271         done
274 src_compile() {
275         for x in ${GMX_DIRS}; do
276                 einfo "Compiling for ${x} precision"
277                 BUILD_DIR="${WORKDIR}/${P}_${x}"\
278                         cmake_src_compile
279                 if use python; then
280                         BUILD_DIR="${WORKDIR}/${P}_${x}"\
281                                 cmake_src_compile       python_packaging/all
282                         BUILD_DIR="${WORKDIR}/${P}" \
283                                 distutils-r1_src_compile
284                 fi
285                 # not 100% necessary for rel ebuilds as available from website
286                 if use build-manual; then
287                         BUILD_DIR="${WORKDIR}/${P}_${x}"\
288                                 cmake_src_compile manual
289                 fi
290         done
293 src_test() {
294         for x in ${GMX_DIRS}; do
295                 BUILD_DIR="${WORKDIR}/${P}_${x}"\
296                         cmake_src_compile check
297         done
300 src_install() {
301         for x in ${GMX_DIRS}; do
302                 BUILD_DIR="${WORKDIR}/${P}_${x}" \
303                         cmake_src_install
304                 if use python; then
305                         BUILD_DIR="${WORKDIR}/${P}_${x}" \
306                                 cmake_src_install       python_packaging/install
307                 fi
308                 if use build-manual; then
309                         newdoc "${WORKDIR}/${P}_${x}"/docs/manual/gromacs.pdf "${PN}-manual-${PV}.pdf"
310                 fi
312                 if use doc; then
313                         if [[ ${PV} != *9999* ]]; then
314                                 newdoc "${DISTDIR}/manual-${PV/_/-}.pdf" "${PN}-manual-${PV}.pdf"
315                         fi
316                 fi
317         done
319         if use tng; then
320                 insinto /usr/include/tng
321                 doins src/external/tng_io/include/tng/*h
322         fi
323         # drop unneeded stuff
324         rm "${ED}"/usr/bin/GMXRC* || die
325         for x in "${ED}"/usr/bin/gmx-completion-*.bash ; do
326                 local n=${x##*/gmx-completion-}
327                 n="${n%.bash}"
328                 cat "${ED}"/usr/bin/gmx-completion.bash "$x" > "${T}/${n}" || die
329                 newbashcomp "${T}"/"${n}" "${n}"
330         done
331         rm "${ED}"/usr/bin/gmx-completion*.bash || die
332         readme.gentoo_create_doc
335 pkg_postinst() {
336         einfo
337         einfo  "Please read and cite gromacs related papers from list:"
338         einfo  "https://www.gromacs.org/articles.html"
339         einfo
340         readme.gentoo_print_elog