summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/gaussian-src/package.py
blob: 5cd0cf9e27e661aee1cf1372e485d16799b3c1fc (plain) (blame)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import glob
import os

import llnl.util.tty as tty

from spack.package import *


class GaussianSrc(Package):
    """Gaussian is a computer program for computational chemistry.

    This Spack package builds Gaussian from source.

    Needs post-install steps to make it run!
    See package installation log for details."""

    homepage = "http://www.gaussian.com/"
    manual_download = True

    maintainers("dev-zero")

    version("16-C.01", sha256="c9eb73a9df5ca8705fcf2d7ce2d5f9aceb05ae663689f54c0a581c9d4d44fffb")

    depends_on("tcsh", type="build")

    # All compilers except for pgi are in conflict:
    requires("%pgi", msg="Gaussian can only be built with the PGI compiler")

    patch("16-C.01-replace-deprecated-pgf77-with-pgfortran.patch", when="@16-C.01")
    patch("16-C.01-fix-building-c-code-with-pgcc.patch", when="@16-C.01")
    patch("16-C.01-fix-shebangs.patch", when="@16-C.01")

    @property
    def g_name(self):
        return "g{0}".format(self.version.up_to(1))

    @property
    def g_root(self):
        return self.prefix.join(self.g_name)

    def url_for_version(self, version):
        return "file://{0}/g{1}.tgz".format(os.getcwd(), version)

    def install(self, spec, prefix):
        # Spacks strips the single dir inside the tarball, but Gaussian
        # needs it -> move them back
        files = os.listdir()
        mkdirp(self.g_name)
        for f in files:
            os.rename(f, join_path(self.g_name, f))

        opts = ["all"]
        #  if spec.satisfies('+cuda'):
        #      opts += [spec.variants['cuda_family'].value]

        with working_dir(self.g_name):
            # can only build with tcsh
            tcsh = which("tcsh")
            tcsh(
                "-c",
                "source ${0}root/{0}/bsd/{0}.login ;"
                "./bsd/bld{0} {1}".format(self.g_name, " ".join(opts)),
            )

            install_tree("./bsd", self.g_root.bsd)
            install_tree("./basis", self.g_root.basis)
            install_tree("./doc", self.g_root.doc)

            for exe in glob.glob("*.exe"):
                install(exe, self.g_root)

            exes = [
                self.g_name,
                "gauopt",
                "gauoptl",
                "ghelp",
                "newzmat",
                "testrt",
                "cubegen",
                "cubman",
                "c8616",
                "ham506",
                "rwfdump",
                "freqchk",
                "freqmem",
                "formchk",
                "demofc",
                "chkchk",
                "solname",
                "gautraj",
                "copychk",
                "pluck",
                "rdmat",
                "wrmat",
                "unfchk",
                "gdrgen",
                "trajgen",
                "mm",
                "grate",
            ]
            for exe in exes:
                install(exe, self.g_root)

    @run_after("install")
    def caveats(self):
        perm_script = "spack_perms_fix.sh"
        perm_script_path = join_path(self.spec.prefix, perm_script)
        with open(perm_script_path, "w") as f:
            env = spack.tengine.make_environment(dirs=self.package_dir)
            t = env.get_template(perm_script + ".j2")
            f.write(t.render({"prefix": self.g_root}))
        chmod = which("chmod")
        chmod("0555", perm_script_path)

        tty.warn(
            """
For a working Gaussian installation, all executable files can only be accessible by
the owner and the group but not the world.

We've installed a script that will make the necessary changes;
read through it and then execute it:

    {0}

If you have to give others access, please customize the group membership of the package
files as documented here:

    https://spack.readthedocs.io/en/latest/build_settings.html#package-permissions""".format(
                perm_script_path
            )
        )

    def setup_build_environment(self, env):
        env.set("{0}root".format(self.g_name), self.stage.source_path)

    def setup_run_environment(self, env):
        # defaults taken from G16's g16.profile
        env.set("GAUSS_LFLAGS2", "--LindaOptions -s 10000000")
        env.set("_DSM_BARRIER", "SHM")
        env.set("PGI_TERM", "trace,abort")

        env.set("{0}root".format(self.g_name), self.prefix)

        env.prepend_path("GAUSS_EXEDIR", self.g_root)
        env.prepend_path("GAUSS_EXEDIR", self.g_root.bsd)

        env.prepend_path("PATH", self.g_root)
        env.prepend_path("PATH", self.g_root.bsd)

        env.set("GAUSS_LEXEDIR", self.g_root.join("linda-exe"))
        env.set("GAUSS_ARCHDIR", self.g_root.arch)
        env.set("GAUSS_BSDDIR", self.g_root.bsd)
        env.set("G{0}BASIS".format(self.version.up_to(1)), self.g_root.basis)

        env.prepend_path("LD_LIBRARY_PATH", self.g_root)
        env.prepend_path("LD_LIBRARY_PATH", self.g_root.bsd)