dev-ruby/rack: add 3.1.9
[gentoo/gentoo.git] / sci-chemistry / gromacs / gromacs-2025.0_beta.ebuild
blobb3605cdfa525eef600921c3849a75574e00ee5cc
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="main" || 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         # since 2025 x86-32 support was dropped
30         KEYWORDS="~amd64 -arm ~arm64 ~riscv -x86 ~amd64-linux -x86-linux ~x64-macos"
33 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"
35 DESCRIPTION="The ultimate molecular dynamics simulation package"
36 HOMEPAGE="https://www.gromacs.org/"
38 # see COPYING for details
39 # https://repo.or.cz/w/gromacs.git/blob/HEAD:/COPYING
40 #        base,    vmd plugins, fftpack from numpy,  blas/lapck from netlib,        memtestG80 library,  mpi_thread lib
41 LICENSE="LGPL-2.1 UoI-NCSA !mkl? ( !fftw? ( BSD ) !blas? ( BSD ) !lapack? ( BSD ) ) cuda? ( LGPL-3 ) threads? ( BSD )"
42 SLOT="0/${PV}"
43 IUSE="blas clang clang-cuda cuda  +custom-cflags +doc build-manual double-precision +fftw +gmxapi +gmxapi-legacy +hwloc lapack mkl mpi nnpot +offensive opencl openmp +python +single-precision test +threads +tng ${ACCE_IUSE}"
45 CDEPEND="
46         blas? ( virtual/blas )
47         cuda? ( >=dev-util/nvidia-cuda-toolkit-11:=[profiler] )
48         opencl? ( virtual/opencl )
49         openmp? (
50                 sys-devel/gcc[openmp]
51                 llvm-core/clang-runtime[openmp]
52         )
53         fftw? ( sci-libs/fftw:3.0= )
54         hwloc? ( sys-apps/hwloc:= )
55         lapack? ( virtual/lapack )
56         mkl? ( sci-libs/mkl )
57         mpi? ( virtual/mpi[cxx] )
58         nnpot? ( sci-libs/caffe2[cuda=,opencl=] )
59         sci-libs/lmfit:=
60         >=dev-cpp/muParser-2.3:=
61         ${PYTHON_DEPS}
62         "
63 BDEPEND="${CDEPEND}
64         virtual/pkgconfig
65         clang? ( >=llvm-core/clang-6:* )
66         doc? (
67                 $(python_gen_cond_dep '
68                         dev-python/sphinx[${PYTHON_USEDEP}]
69                         dev-python/sphinx-copybutton[${PYTHON_USEDEP}]
70                         dev-python/sphinx-inline-tabs[${PYTHON_USEDEP}]
71                         dev-python/sphinx-argparse[${PYTHON_USEDEP}]
72                         dev-python/sphinxcontrib-autoprogram[${PYTHON_USEDEP}]
73                 ')
74         )
75         build-manual? (
76                 app-text/doxygen
77                 $(python_gen_cond_dep '
78                         dev-python/sphinx[${PYTHON_USEDEP}]
79                         dev-python/sphinx-copybutton[${PYTHON_USEDEP}]
80                         dev-python/sphinx-inline-tabs[${PYTHON_USEDEP}]
81                         dev-python/sphinx-argparse[${PYTHON_USEDEP}]
82                         dev-python/sphinxcontrib-autoprogram[${PYTHON_USEDEP}]
83                 ')
84                 media-gfx/mscgen
85                 media-gfx/graphviz
86                 dev-texlive/texlive-latex
87                 dev-texlive/texlive-latexextra
88                 media-gfx/imagemagick
89         )"
90 RDEPEND="${CDEPEND}"
92 REQUIRED_USE="
93         || ( single-precision double-precision )
94         doc? ( !build-manual )
95         cuda? ( single-precision )
96         opencl? ( single-precision )
97         cuda? ( !opencl )
98         clang-cuda? ( clang cuda )
99         mkl? ( !blas !fftw !lapack )
100         ${PYTHON_REQUIRED_USE}"
102 DOCS=( AUTHORS README )
104 RESTRICT="!test? ( test )"
106 PATCHES=(
107         "${FILESDIR}/${PN}-gcc-15.patch"
108         "${FILESDIR}/${PN}-2025.0-beta-fix-man-build.patch"
111 if [[ ${PV} != *9999 ]]; then
112         S="${WORKDIR}/${PN}-${PV/_/-}"
115 pkg_pretend() {
116         [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp
119 pkg_setup() {
120         [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp
121         python-single-r1_pkg_setup
124 src_unpack() {
125         if [[ ${PV} != *9999 ]]; then
126                 default
127         else
128                 git-r3_src_unpack
129                 if use test; then
130                         EGIT_REPO_URI="https://gitlab.com/gromacs/gromacs-regressiontests.git" \
131                         EGIT_BRANCH="${EGIT_BRANCH}" \
132                         EGIT_CHECKOUT_DIR="${WORKDIR}/regressiontests"\
133                                 git-r3_src_unpack
134                 fi
135         fi
138 src_prepare() {
139         #notes/todos
140         # -on apple: there is framework support
142         xdg_environment_reset #591952
144         # we can use clang as default
145         if use clang && ! tc-is-clang ; then
146                 export CC=${CHOST}-clang
147                 export CXX=${CHOST}-clang++
148         else
149                 tc-export CXX CC
150         fi
151         # clang-cuda need to filter mfpmath
152         if use clang-cuda ; then
153                 filter-mfpmath sse
154                 filter-mfpmath i386
155         fi
157         cmake_src_prepare
159         use cuda && cuda_src_prepare
161         GMX_DIRS=""
162         use single-precision && GMX_DIRS+=" float"
163         use double-precision && GMX_DIRS+=" double"
165         if use test; then
166                 for x in ${GMX_DIRS}; do
167                         mkdir -p "${WORKDIR}/${P}_${x}" || die
168                         cp -al "${WORKDIR}/regressiontests"* "${WORKDIR}/${P}_${x}/tests" || die
169                 done
170         fi
172         DOC_CONTENTS="Gromacs can use sci-chemistry/vmd to read additional file formats"
173         if use build-manual; then
174                 # try to create policy for imagemagik
175                 mkdir -p "${HOME}"/.config/ImageMagick
176                 cat >> "${HOME}"/.config/ImageMagick/policy.xml <<- EOF
177                 <?xml version="1.0" encoding="UTF-8"?>
178                 <!DOCTYPE policymap [
179                 <!ELEMENT policymap (policy)+>
180                 !ATTLIST policymap xmlns CDATA #FIXED ''>
181                 <!ELEMENT policy EMPTY>
182                 <!ATTLIST policy xmlns CDATA #FIXED '' domain NMTOKEN #REQUIRED
183                         name NMTOKEN #IMPLIED pattern CDATA #IMPLIED rights NMTOKEN #IMPLIED
184                         stealth NMTOKEN #IMPLIED value CDATA #IMPLIED>
185                 ]>
186                 <policymap>
187                         <policy domain="coder" rights="read | write" pattern="PS" />
188                         <policy domain="coder" rights="read | write" pattern="PS2" />
189                         <policy domain="coder" rights="read | write" pattern="PS3" />
190                         <policy domain="coder" rights="read | write" pattern="EPS" />
191                         <policy domain="coder" rights="read | write" pattern="PDF" />
192                         <policy domain="coder" rights="read | write" pattern="XPS" />
193                 </policymap>
194                 EOF
195         fi
198 src_configure() {
199         local mycmakeargs_pre=( ) extra fft_opts=( )
200         local acce="AUTO"
201         local nnpot="OFF"
203         if use nnpot; then
204                 nnpot="TORCH"
205         fi
207         if use custom-cflags; then
208                 #go from slowest to fastest acceleration
209                 acce="None"
210                 if (use amd64 || use x86); then
211                         use cpu_flags_x86_sse2 && acce="SSE2"
212                         use cpu_flags_x86_sse4_1 && acce="SSE4.1"
213                         use cpu_flags_x86_fma4 && acce="AVX_128_FMA"
214                         use cpu_flags_x86_avx && acce="AVX_256"
215                         use cpu_flags_x86_avx2 && acce="AVX2_256"
216                         use cpu_flags_x86_avx512f && acce="AVX_512"
217                 elif (use arm); then
218                         use cpu_flags_arm_neon && acce="ARM_NEON"
219                 elif (use arm64); then
220                         use cpu_flags_arm_neon && acce="ARM_NEON_ASIMD"
221                 fi
222         else
223                 strip-flags
224         fi
226         #to create man pages, build tree binaries are executed (bug #398437)
227         [[ ${CHOST} = *-darwin* ]] && \
228                 extra+=" -DCMAKE_BUILD_WITH_INSTALL_RPATH=OFF"
230         if use fftw; then
231                 fft_opts=( -DGMX_FFT_LIBRARY=fftw3 )
232         elif use mkl; then
233                 local bits=$(get_libdir)
234                 fft_opts=( -DGMX_FFT_LIBRARY=mkl
235                         -DMKL_INCLUDE_DIR="$(echo /opt/intel/*/mkl/include)"
236                         -DMKL_LIBRARIES="$(echo /opt/intel/*/mkl/lib/*${bits/lib}/libmkl_rt.so)"
237                 )
238         else
239                 fft_opts=( -DGMX_FFT_LIBRARY=fftpack )
240         fi
242         mycmakeargs_pre+=(
243                 "${fft_opts[@]}"
244                 "${lmfit_opts[@]}"
245                 -DGMX_USE_LMFIT=EXTERNAL
246                 -DGMX_USE_MUPARSER=EXTERNAL
247                 -DGMX_EXTERNAL_BLAS=$(usex blas)
248                 -DGMX_EXTERNAL_LAPACK=$(usex lapack)
249                 -DGMX_OPENMP=$(usex openmp)
250                 -DGMX_COOL_QUOTES=$(usex offensive)
251                 -DGMX_USE_TNG=$(usex tng)
252                 -DGMX_BUILD_MANUAL=$(usex build-manual)
253                 -DGMX_USE_HDF5=off
254                 -DGMX_HWLOC=$(usex hwloc)
255                 -DGMX_DEFAULT_SUFFIX=off
256                 -DGMX_BUILD_HELP=$(usex doc)
257                 -DGMX_SIMD="$acce"
258                 -DGMX_NNPOT="$nnpot"
259                 -DGMX_VMD_PLUGIN_PATH="${EPREFIX}/usr/$(get_libdir)/vmd/plugins/*/molfile/"
260                 -DBUILD_TESTING=$(usex test)
261                 -DGMX_BUILD_UNITTESTS=$(usex test)
262                 -DPYTHON_EXECUTABLE="${EPREFIX}/usr/bin/${EPYTHON}"
263                 ${extra}
264         )
266         for x in ${GMX_DIRS}; do
267                 einfo "Configuring for ${x} precision"
268                 local suffix=""
269                 #if we build single and double - double is suffixed
270                 use double-precision && use single-precision && \
271                         [[ ${x} = "double" ]] && suffix="_d"
272                 local p
273                 [[ ${x} = "double" ]] && p="-DGMX_DOUBLE=ON" || p="-DGMX_DOUBLE=OFF"
274                 local gpu=( "-DGMX_GPU=OFF" )
275                 [[ ${x} = "float" ]] && use cuda && gpu=( "-DGMX_GPU=CUDA" )
276                 [[ ${x} = "float" ]] && use clang-cuda && gpu=( "-DGMX_GPU=CUDA" "-DGMX_CLANG_CUDA=ON" )
277                 use opencl && gpu=( "-DGMX_GPU=OPENCL" )
278                 local mycmakeargs=(
279                         ${mycmakeargs_pre[@]} ${p}
280                         -DGMX_MPI=$(usex mpi)
281                         -DGMX_THREAD_MPI=$(usex threads)
282                         -DGMXAPI=$(usex gmxapi)
283                         -DGMX_INSTALL_LEGACY_API=$(usex gmxapi-legacy)
284                         "${gpu[@]}"
285                         "$(use test && echo -DREGRESSIONTEST_PATH="${WORKDIR}/${P}_${x}/tests")"
286                         -DGMX_BINARY_SUFFIX="${suffix}"
287                         -DGMX_LIBS_SUFFIX="${suffix}"
288                         -DGMX_PYTHON_PACKAGE=$(usex python)
289                 )
290                 BUILD_DIR="${WORKDIR}/${P}_${x}" cmake_src_configure
291                 [[ ${CHOST} != *-darwin* ]] || \
292                   sed -i '/SET(CMAKE_INSTALL_NAME_DIR/s/^/#/' "${WORKDIR}/${P}_${x}/gentoo_rules.cmake" || die
293         done
296 src_compile() {
297         for x in ${GMX_DIRS}; do
298                 einfo "Compiling for ${x} precision"
299                 BUILD_DIR="${WORKDIR}/${P}_${x}"\
300                         cmake_src_compile
301                 BUILD_DIR="${WORKDIR}/${P}_${x}"\
302                         cmake_src_compile man
303                 if use python; then
304                         BUILD_DIR="${WORKDIR}/${P}_${x}"\
305                                 cmake_src_compile       python_packaging/all
306                         BUILD_DIR="${WORKDIR}/${P}" \
307                                 distutils-r1_src_compile
308                 fi
309                 # not 100% necessary for rel ebuilds as available from website
310                 if use build-manual; then
311                         BUILD_DIR="${WORKDIR}/${P}_${x}"\
312                                 cmake_src_compile manual
313                 fi
314         done
317 src_test() {
318         for x in ${GMX_DIRS}; do
319                 BUILD_DIR="${WORKDIR}/${P}_${x}"\
320                         cmake_src_compile check
321         done
324 src_install() {
325         for x in ${GMX_DIRS}; do
326                 BUILD_DIR="${WORKDIR}/${P}_${x}" \
327                         cmake_src_install
328                 if use python; then
329                         BUILD_DIR="${WORKDIR}/${P}_${x}" \
330                                 cmake_src_install       python_packaging/install
331                 fi
332                 if use build-manual; then
333                         newdoc "${WORKDIR}/${P}_${x}"/docs/manual/gromacs.pdf "${PN}-manual-${PV}.pdf"
334                 fi
336                 if use doc; then
337                         if [[ ${PV} != *9999* ]]; then
338                                 newdoc "${DISTDIR}/manual-${PV/_/-}.pdf" "${PN}-manual-${PV}.pdf"
339                         fi
340                 fi
341         done
343         if use tng; then
344                 insinto /usr/include/tng
345                 doins src/external/tng_io/include/tng/*h
346         fi
347         # drop unneeded stuff
348         rm "${ED}"/usr/bin/GMXRC* || die
349         for x in "${ED}"/usr/bin/gmx-completion-*.bash ; do
350                 local n=${x##*/gmx-completion-}
351                 n="${n%.bash}"
352                 cat "${ED}"/usr/bin/gmx-completion.bash "$x" > "${T}/${n}" || die
353                 newbashcomp "${T}"/"${n}" "${n}"
354         done
355         rm "${ED}"/usr/bin/gmx-completion*.bash || die
356         readme.gentoo_create_doc
359 pkg_postinst() {
360         einfo
361         einfo  "Please read and cite gromacs related papers from list:"
362         einfo  "https://www.gromacs.org/articles.html"
363         einfo
364         readme.gentoo_print_elog