homebrew-core/Formula/cp2k.rb

134 lines
4.5 KiB
Ruby

class Cp2k < Formula
desc "Quantum chemistry and solid state physics software package"
homepage "https://www.cp2k.org/"
url "https://github.com/cp2k/cp2k/releases/download/v2022.1/cp2k-2022.1.tar.bz2"
sha256 "2c34f1a7972973c62d471cd35856f444f11ab22f2ff930f6ead20f3454fd228b"
license "GPL-2.0-or-later"
bottle do
sha256 cellar: :any, arm64_monterey: "cbaae31d66f9a00cad5e779b5626a3f36c6b3eee68d70e6f8538d4aadd2e4bac"
sha256 cellar: :any, arm64_big_sur: "2db2338f594f4189f47be7d71c9ba565293bc50b2e49316f9a1bbf4d27dabc05"
sha256 cellar: :any, monterey: "1b017ee636c197baa03be6cab743caddf1f8ac1ea44718a2473e7d963a306f8c"
sha256 cellar: :any, big_sur: "9663b89ff6c4d6f50574896387223d723953a3f38ca037dc6bd1e703444b414c"
sha256 cellar: :any, catalina: "c0194a21b6e589e27f510ad523c33390f2f7612e463f59a606726dee90fa666c"
sha256 x86_64_linux: "09374682881963e91b8afae795e85229dca3928cc07d7be989c95d7e922a9d71"
end
depends_on "python@3.10" => :build
depends_on "fftw"
depends_on "gcc" # for gfortran
depends_on "libxc"
depends_on "open-mpi"
depends_on "scalapack"
on_linux do
depends_on "openblas"
end
fails_with :clang # needs OpenMP support
resource "libint" do
url "https://github.com/cp2k/libint-cp2k/releases/download/v2.6.0/libint-v2.6.0-cp2k-lmax-5.tgz"
sha256 "1cd72206afddb232bcf2179c6229fbf6e42e4ba8440e701e6aa57ff1e871e9db"
end
def install
resource("libint").stage do
system "./configure", "--prefix=#{libexec}", "--enable-fortran"
system "make"
ENV.deparallelize { system "make", "install" }
end
arch = "local"
if OS.mac?
arch = "Darwin-gfortran"
# libint needs `-lstdc++` (https://github.com/cp2k/cp2k/blob/master/INSTALL.md)
# Can remove if added upstream to Darwin-gfortran.psmp and Darwin-gfortran.ssmp
libs = %W[
-L#{Formula["fftw"].opt_lib}
-lfftw3
-lstdc++
]
ENV["LIBXC_INCLUDE_DIR"] = Formula["libxc"].opt_include
ENV["LIBXC_LIB_DIR"] = Formula["libxc"].opt_lib
ENV["LIBINT_INCLUDE_DIR"] = libexec/"include"
ENV["LIBINT_LIB_DIR"] = libexec/"lib"
# CP2K configuration is done through editing of arch files
inreplace Dir["arch/Darwin-gfortran.*"].each do |s|
s.gsub!(/DFLAGS *=/, "DFLAGS = -D__FFTW3")
s.gsub!(/FCFLAGS *=/, "FCFLAGS = -I#{Formula["fftw"].opt_include}")
s.gsub!(/LIBS *=/, "LIBS = #{libs.join(" ")}")
end
# MPI versions link to scalapack
inreplace Dir["arch/Darwin-gfortran.p*"],
/LIBS *=/, "LIBS = -L#{Formula["scalapack"].opt_lib}"
# OpenMP versions link to specific fftw3 library
inreplace Dir["arch/Darwin-gfortran.*smp"],
"-lfftw3", "-lfftw3 -lfftw3_threads"
else
args = %W[
-j #{ENV.make_jobs}
--mpi-mode=openmpi
--math-mode=openblas
--with-gcc=system
--with-intel=no
--with-cmake=no
--with-openmpi=#{Formula["open-mpi"].opt_prefix}
--with-mpich=no
--with-intelmpi=no
--with-libxc=#{Formula["libxc"].opt_prefix}
--with-libint=#{libexec}
--with-fftw=#{Formula["fftw"].opt_prefix}
--with-acml=no
--with-mkl=no
--with-openblas=#{Formula["openblas"].opt_prefix}
--with-scalapack=#{Formula["scalapack"].opt_prefix}
--with-libxsmm=no
--with-elpa=no
--with-ptscotch=no
--with-superlu=no
--with-pexsi=no
--with-quip=no
--with-plumed=no
--with-sirius=no
--with-gsl=no
--with-libvdwxc=no
--with-spglib=no
--with-hdf5=no
--with-spfft=no
--with-spla=no
--with-cosma=no
--with-libvori=no
]
args << "--generic" if build.bottle?
cd "tools/toolchain" do
# Need OpenBLAS source to get proc arch info in scripts/get_openblas_arch.sh
Formula["openblas"].stable.stage Pathname.pwd/"build/OpenBLAS"
system "./install_cp2k_toolchain.sh", *args
(buildpath/"arch").install (Pathname.pwd/"install/arch").children
end
end
# Now we build
%w[ssmp psmp].each do |exe|
system "make", "ARCH=#{arch}", "VERSION=#{exe}"
bin.install "exe/#{arch}/cp2k.#{exe}"
bin.install "exe/#{arch}/cp2k_shell.#{exe}"
end
(pkgshare/"tests").install "tests/Fist/water512.inp"
end
test do
system bin/"cp2k.ssmp", pkgshare/"tests/water512.inp"
system "mpirun", bin/"cp2k.psmp", pkgshare/"tests/water512.inp"
end
end