This guide provides step-by-step instructions to compile and install the sscha library. The project uses the Meson build system to compile C and Fortran extensions for Python.
The easiest and most reproducible way to install python-sscha is by using a Conda environment. We strongly recommend using micromamba or mamba as they are significantly faster. This method installs all the required compilers, libraries, and Python packages inside an isolated environment, avoiding the need to modify your base system.
-
Install Conda/Mamba. If you don't have it, we recommend installing micromamba.
-
Create the environment. Open your terminal and run the following command. It will create a new environment named sscha with all the necessary dependencies, including CellConstructor.
micromamba create -n sscha python=3.12 gfortran libblas lapack openmpi openmpi-mpicc pkg-config pip numpy scipy spglib=2.2 cellconstructor matplotlib ase-
Python Version: We use Python 3.12. Newer versions are not yet supported due to a dependency constraint from spglib <= 2.2.
-
pkg-config: This package is essential. Meson requires it to correctly detect the BLAS and LAPACK libraries provided by Conda.
- Activate the environment. You must activate the environment before proceeding.
micromamba activate sschaIf you don't have the source code locally, clone it from the repository.
git clone https://github.com/SSCHAcode/python-sscha.git
cd python-sschaWith the environment active, install the package using pip. pip will automatically use Meson to compile and install the project.
pip install .The installation is now complete! You can verify it by running the tests or importing the modules in Python.
This section is for users who cannot use Conda or need to configure the build with specific compilers or options.
-
A C and Fortran compiler.
-
Python 3.12 and pip.
-
Ninja and Meson: pip install meson ninja.
-
System libraries for BLAS, LAPACK, and MPI.
-
All Python dependencies, including CellConstructor, must be installed in your environment.
You can specify compilers by setting the CC (C compiler) and FC (Fortran compiler) environment variables before running pip.
# Example using compilers from a specific toolchain
export CC=/usr/local/bin/gcc-11
export FC=/usr/local/bin/gfortran-11
# Install the project
pip install .For a reproducible setup, define your compilers in a file (e.g., native-toolchain.ini).
Example native-toolchain.ini:
[binaries]
c = '/path/to/my/custom/gcc'
fortran = '/path/to/my/custom/gfortran'Then, install by passing this file to Meson via pip:
pip install . --config-settings=meson-args="--native-file=native-toolchain.ini"You can pass options to Meson to customize the build.
- Create a debug build:
pip install . --config-settings=meson-args="-Dbuildtype=debug"- Enable Intel MKL (requires MKL to be installed and findable by your system):
pip install . --config-settings=meson-args="-Duse_mkl=true"- Combine multiple options:
pip install . --config-settings=meson-args="-Dbuildtype=debug,-Duse_mkl=true"If you need to change build options, it is best to perform a clean installation.
# 1. Uninstall the package
pip uninstall python-sscha
# 2. (Optional but recommended) Remove the build directory
rm -rf build/
# 3. Reinstall with the new options
pip install . --config-settings=meson-args="-Dnew_option=value"