dev-python/agate: Bump to 1.13.0
[gentoo/gentoo.git] / sci-chemistry / gromacs / gromacs-2025.9999.ebuild
blobbec110e3340c12d53f0f4d7be353d42607de245b
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 if [[ ${PV} != *9999 ]]; then
107         S="${WORKDIR}/${PN}-${PV/_/-}"
110 pkg_pretend() {
111         [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp
114 pkg_setup() {
115         [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp
116         python-single-r1_pkg_setup
119 src_unpack() {
120         if [[ ${PV} != *9999 ]]; then
121                 default
122         else
123                 git-r3_src_unpack
124                 if use test; then
125                         EGIT_REPO_URI="https://gitlab.com/gromacs/gromacs-regressiontests.git" \
126                         EGIT_BRANCH="${EGIT_BRANCH}" \
127                         EGIT_CHECKOUT_DIR="${WORKDIR}/regressiontests"\
128                                 git-r3_src_unpack
129                 fi
130         fi
133 src_prepare() {
134         #notes/todos
135         # -on apple: there is framework support
137         xdg_environment_reset #591952
139         # we can use clang as default
140         if use clang && ! tc-is-clang ; then
141                 export CC=${CHOST}-clang
142                 export CXX=${CHOST}-clang++
143         else
144                 tc-export CXX CC
145         fi
146         # clang-cuda need to filter mfpmath
147         if use clang-cuda ; then
148                 filter-mfpmath sse
149                 filter-mfpmath i386
150         fi
152         cmake_src_prepare
154         use cuda && cuda_src_prepare
156         GMX_DIRS=""
157         use single-precision && GMX_DIRS+=" float"
158         use double-precision && GMX_DIRS+=" double"
160         if use test; then
161                 for x in ${GMX_DIRS}; do
162                         mkdir -p "${WORKDIR}/${P}_${x}" || die
163                         cp -al "${WORKDIR}/regressiontests"* "${WORKDIR}/${P}_${x}/tests" || die
164                 done
165         fi
167         DOC_CONTENTS="Gromacs can use sci-chemistry/vmd to read additional file formats"
168         if use build-manual; then
169                 # try to create policy for imagemagik
170                 mkdir -p "${HOME}"/.config/ImageMagick
171                 cat >> "${HOME}"/.config/ImageMagick/policy.xml <<- EOF
172                 <?xml version="1.0" encoding="UTF-8"?>
173                 <!DOCTYPE policymap [
174                 <!ELEMENT policymap (policy)+>
175                 !ATTLIST policymap xmlns CDATA #FIXED ''>
176                 <!ELEMENT policy EMPTY>
177                 <!ATTLIST policy xmlns CDATA #FIXED '' domain NMTOKEN #REQUIRED
178                         name NMTOKEN #IMPLIED pattern CDATA #IMPLIED rights NMTOKEN #IMPLIED
179                         stealth NMTOKEN #IMPLIED value CDATA #IMPLIED>
180                 ]>
181                 <policymap>
182                         <policy domain="coder" rights="read | write" pattern="PS" />
183                         <policy domain="coder" rights="read | write" pattern="PS2" />
184                         <policy domain="coder" rights="read | write" pattern="PS3" />
185                         <policy domain="coder" rights="read | write" pattern="EPS" />
186                         <policy domain="coder" rights="read | write" pattern="PDF" />
187                         <policy domain="coder" rights="read | write" pattern="XPS" />
188                 </policymap>
189                 EOF
190         fi
193 src_configure() {
194         local mycmakeargs_pre=( ) extra fft_opts=( )
195         local acce="AUTO"
196         local nnpot="OFF"
198         if use nnpot; then
199                 nnpot="TORCH"
200         fi
202         if use custom-cflags; then
203                 #go from slowest to fastest acceleration
204                 acce="None"
205                 if (use amd64 || use x86); then
206                         use cpu_flags_x86_sse2 && acce="SSE2"
207                         use cpu_flags_x86_sse4_1 && acce="SSE4.1"
208                         use cpu_flags_x86_fma4 && acce="AVX_128_FMA"
209                         use cpu_flags_x86_avx && acce="AVX_256"
210                         use cpu_flags_x86_avx2 && acce="AVX2_256"
211                         use cpu_flags_x86_avx512f && acce="AVX_512"
212                 elif (use arm); then
213                         use cpu_flags_arm_neon && acce="ARM_NEON"
214                 elif (use arm64); then
215                         use cpu_flags_arm_neon && acce="ARM_NEON_ASIMD"
216                 fi
217         else
218                 strip-flags
219         fi
221         #to create man pages, build tree binaries are executed (bug #398437)
222         [[ ${CHOST} = *-darwin* ]] && \
223                 extra+=" -DCMAKE_BUILD_WITH_INSTALL_RPATH=OFF"
225         if use fftw; then
226                 fft_opts=( -DGMX_FFT_LIBRARY=fftw3 )
227         elif use mkl; then
228                 local bits=$(get_libdir)
229                 fft_opts=( -DGMX_FFT_LIBRARY=mkl
230                         -DMKL_INCLUDE_DIR="$(echo /opt/intel/*/mkl/include)"
231                         -DMKL_LIBRARIES="$(echo /opt/intel/*/mkl/lib/*${bits/lib}/libmkl_rt.so)"
232                 )
233         else
234                 fft_opts=( -DGMX_FFT_LIBRARY=fftpack )
235         fi
237         mycmakeargs_pre+=(
238                 "${fft_opts[@]}"
239                 "${lmfit_opts[@]}"
240                 -DGMX_USE_LMFIT=EXTERNAL
241                 -DGMX_USE_MUPARSER=EXTERNAL
242                 -DGMX_EXTERNAL_BLAS=$(usex blas)
243                 -DGMX_EXTERNAL_LAPACK=$(usex lapack)
244                 -DGMX_OPENMP=$(usex openmp)
245                 -DGMX_COOL_QUOTES=$(usex offensive)
246                 -DGMX_USE_TNG=$(usex tng)
247                 -DGMX_BUILD_MANUAL=$(usex build-manual)
248                 -DGMX_USE_HDF5=off
249                 -DGMX_HWLOC=$(usex hwloc)
250                 -DGMX_DEFAULT_SUFFIX=off
251                 -DGMX_BUILD_HELP=$(usex doc)
252                 -DGMX_SIMD="$acce"
253                 -DGMX_NNPOT="$nnpot"
254                 -DGMX_VMD_PLUGIN_PATH="${EPREFIX}/usr/$(get_libdir)/vmd/plugins/*/molfile/"
255                 -DBUILD_TESTING=$(usex test)
256                 -DGMX_BUILD_UNITTESTS=$(usex test)
257                 -DPYTHON_EXECUTABLE="${EPREFIX}/usr/bin/${EPYTHON}"
258                 ${extra}
259         )
261         for x in ${GMX_DIRS}; do
262                 einfo "Configuring for ${x} precision"
263                 local suffix=""
264                 #if we build single and double - double is suffixed
265                 use double-precision && use single-precision && \
266                         [[ ${x} = "double" ]] && suffix="_d"
267                 local p
268                 [[ ${x} = "double" ]] && p="-DGMX_DOUBLE=ON" || p="-DGMX_DOUBLE=OFF"
269                 local gpu=( "-DGMX_GPU=OFF" )
270                 [[ ${x} = "float" ]] && use cuda && gpu=( "-DGMX_GPU=CUDA" )
271                 [[ ${x} = "float" ]] && use clang-cuda && gpu=( "-DGMX_GPU=CUDA" "-DGMX_CLANG_CUDA=ON" )
272                 use opencl && gpu=( "-DGMX_GPU=OPENCL" )
273                 local mycmakeargs=(
274                         ${mycmakeargs_pre[@]} ${p}
275                         -DGMX_MPI=$(usex mpi)
276                         -DGMX_THREAD_MPI=$(usex threads)
277                         -DGMXAPI=$(usex gmxapi)
278                         -DGMX_INSTALL_LEGACY_API=$(usex gmxapi-legacy)
279                         "${gpu[@]}"
280                         "$(use test && echo -DREGRESSIONTEST_PATH="${WORKDIR}/${P}_${x}/tests")"
281                         -DGMX_BINARY_SUFFIX="${suffix}"
282                         -DGMX_LIBS_SUFFIX="${suffix}"
283                         -DGMX_PYTHON_PACKAGE=$(usex python)
284                 )
285                 BUILD_DIR="${WORKDIR}/${P}_${x}" cmake_src_configure
286                 [[ ${CHOST} != *-darwin* ]] || \
287                   sed -i '/SET(CMAKE_INSTALL_NAME_DIR/s/^/#/' "${WORKDIR}/${P}_${x}/gentoo_rules.cmake" || die
288         done
291 src_compile() {
292         for x in ${GMX_DIRS}; do
293                 einfo "Compiling for ${x} precision"
294                 BUILD_DIR="${WORKDIR}/${P}_${x}"\
295                         cmake_src_compile
296                 BUILD_DIR="${WORKDIR}/${P}_${x}"\
297                         cmake_src_compile man
298                 if use python; then
299                         BUILD_DIR="${WORKDIR}/${P}_${x}"\
300                                 cmake_src_compile       python_packaging/all
301                         BUILD_DIR="${WORKDIR}/${P}" \
302                                 distutils-r1_src_compile
303                 fi
304                 # not 100% necessary for rel ebuilds as available from website
305                 if use build-manual; then
306                         BUILD_DIR="${WORKDIR}/${P}_${x}"\
307                                 cmake_src_compile manual
308                 fi
309         done
312 src_test() {
313         for x in ${GMX_DIRS}; do
314                 BUILD_DIR="${WORKDIR}/${P}_${x}"\
315                         cmake_src_compile check
316         done
319 src_install() {
320         for x in ${GMX_DIRS}; do
321                 BUILD_DIR="${WORKDIR}/${P}_${x}" \
322                         cmake_src_install
323                 if use python; then
324                         BUILD_DIR="${WORKDIR}/${P}_${x}" \
325                                 cmake_src_install       python_packaging/install
326                 fi
327                 if use build-manual; then
328                         newdoc "${WORKDIR}/${P}_${x}"/docs/manual/gromacs.pdf "${PN}-manual-${PV}.pdf"
329                 fi
331                 if use doc; then
332                         if [[ ${PV} != *9999* ]]; then
333                                 newdoc "${DISTDIR}/manual-${PV/_/-}.pdf" "${PN}-manual-${PV}.pdf"
334                         fi
335                 fi
336         done
338         if use tng; then
339                 insinto /usr/include/tng
340                 doins src/external/tng_io/include/tng/*h
341         fi
342         # drop unneeded stuff
343         rm "${ED}"/usr/bin/GMXRC* || die
344         for x in "${ED}"/usr/bin/gmx-completion-*.bash ; do
345                 local n=${x##*/gmx-completion-}
346                 n="${n%.bash}"
347                 cat "${ED}"/usr/bin/gmx-completion.bash "$x" > "${T}/${n}" || die
348                 newbashcomp "${T}"/"${n}" "${n}"
349         done
350         rm "${ED}"/usr/bin/gmx-completion*.bash || die
351         readme.gentoo_create_doc
354 pkg_postinst() {
355         einfo
356         einfo  "Please read and cite gromacs related papers from list:"
357         einfo  "https://www.gromacs.org/articles.html"
358         einfo
359         readme.gentoo_print_elog