/
cp2k.rb
101 lines (87 loc) 路 4 KB
/
cp2k.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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/v2024.1/cp2k-2024.1.tar.bz2"
sha256 "a7abf149a278dfd5283dc592a2c4ae803b37d040df25d62a5e35af5c4557668f"
license "GPL-2.0-or-later"
livecheck do
url :stable
strategy :github_latest
end
bottle do
rebuild 1
sha256 arm64_sonoma: "fc9760f1c03934d4b87c768b02195129e13babc78a174059ff4987b204dd0d98"
sha256 arm64_ventura: "384e8884db6ec442a2fa0e57fcd3d44ea6004c516969b6dd82930d4c56b90ace"
sha256 arm64_monterey: "612fc3597eb8a74da99da978cbb97e8e67a4a33fd75c419a671782ab974663cd"
sha256 sonoma: "65df5da13054e5c7e4023eaec235f0d16dbf339f1a5826150fa90e93798e9560"
sha256 ventura: "a75d0ceac451e6ef213300f2f0179bdec7b0b889a3555f9fc70dcc47aeb1aee0"
sha256 monterey: "d0fbe428294198e0eeaa64778c9ba08db0cd18cdd8b67e9bfacb1a5fe32102ea"
sha256 x86_64_linux: "a2bd232db7d2a02767c8630db162127abbfc9b4467111d9b04ffb58dcee7d9c1"
end
depends_on "cmake" => :build
depends_on "pkg-config" => :build
depends_on "fftw"
depends_on "gcc" # for gfortran
depends_on "libxc"
depends_on "open-mpi"
depends_on "openblas"
depends_on "scalapack"
uses_from_macos "python" => :build
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", "--enable-fortran", "--with-pic", *std_configure_args(prefix: libexec)
system "make"
ENV.deparallelize { system "make", "install" }
ENV.prepend_path "PKG_CONFIG_PATH", libexec/"lib/pkgconfig"
end
# TODO: Remove dbcsr build along with corresponding CMAKE_PREFIX_PATH
# and add -DCP2K_BUILD_DBCSR=ON once `cp2k` build supports this option.
system "cmake", "-S", "exts/dbcsr", "-B", "build_psmp/dbcsr",
"-DWITH_EXAMPLES=OFF",
*std_cmake_args(install_prefix: libexec)
system "cmake", "--build", "build_psmp/dbcsr"
system "cmake", "--install", "build_psmp/dbcsr"
# Need to build another copy for non-MPI variant.
system "cmake", "-S", "exts/dbcsr", "-B", "build_ssmp/dbcsr",
"-DUSE_MPI=OFF",
"-DWITH_EXAMPLES=OFF",
*std_cmake_args(install_prefix: buildpath/"dbcsr")
system "cmake", "--build", "build_ssmp/dbcsr"
system "cmake", "--install", "build_ssmp/dbcsr"
# Avoid trying to access /proc/self/statm on macOS
ENV.append "FFLAGS", "-D__NO_STATM_ACCESS" if OS.mac?
# Set -lstdc++ to allow gfortran to link libint
cp2k_cmake_args = %w[
-DCMAKE_SHARED_LINKER_FLAGS=-lstdc++
-DCP2K_BLAS_VENDOR=OpenBLAS
-DCP2K_USE_LIBINT2=ON
-DCP2K_USE_LIBXC=ON
] + std_cmake_args
system "cmake", "-S", ".", "-B", "build_psmp/cp2k",
"-DCMAKE_INSTALL_RPATH=#{rpath}",
"-DCMAKE_PREFIX_PATH=#{libexec}",
*cp2k_cmake_args
system "cmake", "--build", "build_psmp/cp2k"
system "cmake", "--install", "build_psmp/cp2k"
# Only build the main executable for non-MPI variant as libs conflict.
# Can consider shipping MPI and non-MPI variants as separate formulae
# or removing one variant depending on usage.
system "cmake", "-S", ".", "-B", "build_ssmp/cp2k",
"-DBUILD_SHARED_LIBS=OFF",
"-DCMAKE_PREFIX_PATH=#{buildpath}/dbcsr;#{libexec}",
"-DCP2K_USE_MPI=OFF",
*cp2k_cmake_args
system "cmake", "--build", "build_ssmp/cp2k", "--target", "cp2k-bin"
bin.install Dir["build_ssmp/cp2k/bin/*.ssmp"]
(pkgshare/"tests").install "tests/Fist/water.inp"
end
test do
system bin/"cp2k.ssmp", pkgshare/"tests/water.inp"
system "mpirun", bin/"cp2k.psmp", pkgshare/"tests/water.inp"
end
end