summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/neuron/package.py
blob: e789f90b8ab06a19ff812f420ea2f00fd8fc81b4 (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
# 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)

from spack.package import *


class Neuron(CMakePackage):
    """NEURON is a simulation environment for single and networks of neurons.

    NEURON is a simulation environment for modeling individual and networks of
    neurons. NEURON models individual neurons via the use of sections that are
    automatically subdivided into individual compartments, instead of
    requiring the user to manually create compartments.
    """

    homepage = "https://www.neuron.yale.edu/"
    url = "https://neuron.yale.edu/ftp/neuron/versions/v7.7/nrn-7.7.tar.gz"
    git = "https://github.com/neuronsimulator/nrn"
    maintainers("pramodk", "nrnhines", "iomaganaris", "alexsavulescu")

    license("BSD-3-Clause")

    version("develop", branch="master", submodules="True")
    version(
        "8.0.0", tag="8.0.0", commit="429d11ef34b1d860b3ddbfffc9f7960acb399b0c", submodules="True"
    )
    version(
        "7.8.2", tag="7.8.2", commit="09b151ecb2b3984335c265932dc6ba3e4fcb318e", submodules="True"
    )
    version(
        "7.8.1", tag="7.8.1", commit="47cd8c85aa3fde5dbb7319facd6f475438235d7d", submodules="True"
    )

    variant("coreneuron", default=False, description="Enable CoreNEURON as submodule")
    variant("cross-compile", default=False, description="Build for cross-compile environment")
    variant("interviews", default=False, description="Enable GUI with INTERVIEWS")
    variant("legacy-unit", default=False, description="Enable legacy units")
    variant("mpi", default=True, description="Enable MPI parallelism")
    variant("python", default=True, description="Enable python")
    variant("rx3d", default=False, description="Enable cython translated 3-d rxd")
    variant("tests", default=False, description="Enable unit tests")
    variant("caliper", default=False, description="Add LLNL/Caliper support")

    depends_on("bison", type="build")
    depends_on("flex", type="build")
    depends_on("py-cython", when="+rx3d", type="build")

    depends_on("gettext")
    depends_on("mpi", when="+mpi")
    depends_on("ncurses")
    depends_on("python@2.7:", when="+python")
    depends_on("py-pytest", when="+python+tests")
    depends_on("py-mpi4py", when="+mpi+python+tests")
    depends_on("readline")
    depends_on("caliper", when="+caliper")
    depends_on("py-numpy", type="run")

    conflicts("+rx3d", when="~python")

    patch("patch-v782-git-cmake-avx512.patch", when="@7.8.2")

    def cmake_args(self):
        spec = self.spec

        def cmake_options(spec_options):
            value = "TRUE" if spec_options in spec else "FALSE"
            cmake_name = spec_options[1:].upper().replace("-", "_")
            return "-DNRN_ENABLE_" + cmake_name + ":BOOL=" + value

        args = [
            cmake_options(variant)
            for variant in [
                "+coreneuron",
                "+interviews",
                "+mpi",
                "+python",
                "+rx3d",
                "+coreneuron",
                "+tests",
            ]
        ]
        args.append("-DNRN_ENABLE_BINARY_SPECIAL=ON")

        if "~mpi" in spec and "+coreneuron" in spec:
            args.append("-DCORENRN_ENABLE_MPI=OFF")

        if "+python" in spec:
            args.append("-DPYTHON_EXECUTABLE:FILEPATH=" + spec["python"].command.path)

        if spec.variants["build_type"].value == "Debug":
            args.append("-DCMAKE_C_FLAGS=-g -O0")
            args.append("-DCMAKE_CXX_FLAGS=-g -O0")
            args.append("-DCMAKE_BUILD_TYPE=Custom")

        if "+legacy-unit" in spec:
            args.append("-DNRN_DYNAMIC_UNITS_USE_LEGACY=ON")

        if "+caliper" in spec:
            args.append("-DCORENRN_CALIPER_PROFILING=ON")

        return args

    @run_after("install")
    def filter_compilers(self):
        """run after install to avoid spack compiler wrappers
        getting embded into nrnivmodl script"""

        spec = self.spec

        if "cray" in spec.architecture:
            cc_compiler = "cc"
            cxx_compiler = "CC"
        elif spec.satisfies("+mpi"):
            cc_compiler = spec["mpi"].mpicc
            cxx_compiler = spec["mpi"].mpicxx
        else:
            cc_compiler = self.compiler.cc
            cxx_compiler = self.compiler.cxx

        kwargs = {"backup": False, "string": True}
        nrnmech_makefile = join_path(self.prefix, "./bin/nrnmech_makefile")

        # assign_operator is changed to fix wheel support
        if self.spec.satisfies("@:7"):
            assign_operator = "?="
        else:
            assign_operator = "="

        filter_file(
            "CC {0} {1}".format(assign_operator, env["CC"]),
            "CC = {0}".format(cc_compiler),
            nrnmech_makefile,
            **kwargs,
        )
        filter_file(
            "CXX {0} {1}".format(assign_operator, env["CXX"]),
            "CXX = {0}".format(cxx_compiler),
            nrnmech_makefile,
            **kwargs,
        )

        if spec.satisfies("+coreneuron"):
            corenrn_makefile = join_path(self.prefix, "share/coreneuron/nrnivmodl_core_makefile")
            filter_file(env["CXX"], cxx_compiler, corenrn_makefile, **kwargs)

    def setup_run_environment(self, env):
        env.prepend_path("PATH", join_path(self.prefix, "bin"))
        env.prepend_path("LD_LIBRARY_PATH", join_path(self.prefix, "lib"))
        if self.spec.satisfies("+python"):
            env.prepend_path("PYTHONPATH", self.spec.prefix.lib.python)