Skip to content

Commit e4d20bf

Browse files
Added the python_sscha Installation Guide.
1 parent b2c9e4a commit e4d20bf

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

python-sscha Installation Guide.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# python-sscha Installation Guide
2+
3+
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.
4+
5+
## Recommended Installation: Conda / Mamba
6+
7+
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.
8+
9+
### Step 1: Create and Activate the Environment
10+
11+
1. Install Conda/Mamba. If you don't have it, we recommend installing *micromamba*.
12+
13+
2. 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*.
14+
15+
```bash
16+
micromamba create -n sscha python=3.12 gfortran libblas lapack openmpi openmpi-mpicc pkg-config pip numpy scipy spglib=2.2 cellconstructor matplotlib ase
17+
```
18+
19+
* Python Version: We use Python 3.12. Newer versions are not yet supported due to a dependency constraint from *spglib <= 2.2*.
20+
21+
* pkg-config: This package is essential. Meson requires it to correctly detect the BLAS and LAPACK libraries provided by Conda.
22+
23+
3. Activate the environment. You must activate the environment before proceeding.
24+
25+
```bash
26+
micromamba activate sscha
27+
```
28+
29+
### Step 2: Clone the Repository (if not done)
30+
31+
If you don't have the source code locally, clone it from the repository.
32+
33+
```bash
34+
git clone https://github.com/SSCHAcode/python-sscha.git
35+
cd python-sscha
36+
```
37+
38+
### Step 3: Install python-sscha
39+
40+
With the environment active, install the package using *pip*. *pip* will automatically use Meson to compile and install the project.
41+
42+
```bash
43+
pip install .
44+
```
45+
46+
The installation is now complete! You can verify it by running the tests or importing the modules in Python.
47+
48+
## Advanced Installation: Manual Configuration
49+
50+
This section is for users who cannot use Conda or need to configure the build with specific compilers or options.
51+
52+
### Prerequisites
53+
54+
* A C and Fortran compiler.
55+
56+
* Python 3.12 and pip.
57+
58+
* Ninja and Meson: *pip install meson ninja*.
59+
60+
* System libraries for BLAS, LAPACK, and MPI.
61+
62+
* All Python dependencies, including CellConstructor, must be installed in your environment.
63+
64+
### Method 1: Using Environment Variables
65+
66+
You can specify compilers by setting the *CC* (C compiler) and *FC* (Fortran compiler) environment variables before running *pip*.
67+
68+
```bash
69+
# Example using compilers from a specific toolchain
70+
export CC=/usr/local/bin/gcc-11
71+
export FC=/usr/local/bin/gfortran-11
72+
73+
# Install the project
74+
pip install .
75+
```
76+
77+
### Method 2: Using a Meson Cross File
78+
79+
For a reproducible setup, define your compilers in a file (e.g., *native-toolchain.ini*).
80+
81+
Example *native-toolchain.ini*:
82+
83+
```bash
84+
[binaries]
85+
c = '/path/to/my/custom/gcc'
86+
fortran = '/path/to/my/custom/gfortran'
87+
```
88+
89+
Then, install by passing this file to Meson via *pip*:
90+
91+
```bash
92+
pip install . --config-settings=meson-args="--native-file=native-toolchain.ini"
93+
```
94+
95+
## Build Options
96+
97+
You can pass options to Meson to customize the build.
98+
99+
* Create a debug build:
100+
101+
```bash
102+
pip install . --config-settings=meson-args="-Dbuildtype=debug"
103+
```
104+
105+
* Enable Intel MKL (requires MKL to be installed and findable by your system):
106+
107+
```bash
108+
pip install . --config-settings=meson-args="-Duse_mkl=true"
109+
```
110+
111+
* Combine multiple options:
112+
113+
```bash
114+
pip install . --config-settings=meson-args="-Dbuildtype=debug,-Duse_mkl=true"
115+
```
116+
117+
## Reconfiguring a Build
118+
119+
If you need to change build options, it is best to perform a clean installation.
120+
121+
```bash
122+
# 1. Uninstall the package
123+
pip uninstall python-sscha
124+
125+
# 2. (Optional but recommended) Remove the build directory
126+
rm -rf build/
127+
128+
# 3. Reinstall with the new options
129+
pip install . --config-settings=meson-args="-Dnew_option=value"
130+
```

0 commit comments

Comments
 (0)