diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..95ec042d --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,37 @@ +name: Build and Test + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: 3.9 + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y libblas-dev liblapack-dev gfortran pkg-config + + - name: Install Python dependencies + run: | + pip install meson ninja meson-python numpy scipy ase pytest + + - name: Setup build directory + run: meson setup builddir + + - name: Compile + run: meson compile -C builddir + + +# - name: Install package +# run: meson install -C builddir + +# - name: Run tests +# run: meson test -C builddir diff --git a/.github/workflows/pythonapp.yml b/.github/workflows/pythonapp.yml index 5d97c021..53521a4f 100644 --- a/.github/workflows/pythonapp.yml +++ b/.github/workflows/pythonapp.yml @@ -36,7 +36,8 @@ jobs: sudo apt-get install gfortran libblas-dev liblapack-dev - name: Install the package run: | - python setup.py install --user + # python setup.py install --user + pip install . - name: Test with pytest run: | pip install pytest diff --git a/CModules/wrapper3.c b/CModules/wrapper3.c index 16bfeea3..266511c4 100644 --- a/CModules/wrapper3.c +++ b/CModules/wrapper3.c @@ -45,13 +45,15 @@ static PyObject * gram_schmidt(PyObject* self, PyObject* args) { int NewDim; PyObject * npy_vectors; - + // Get the path dir if (!PyArg_ParseTuple(args, "Oii", &npy_vectors, &N_vectors, &N_dim)) return NULL; // Get the C pointers to the data of the numpy ndarray - vectors = (double*) PyArray_DATA(npy_vectors); + //vectors = (double*) PyArray_DATA(npy_vectors); + // Fix for new version of numpy and python + vectors = (double*) PyArray_DATA((PyArrayObject*) npy_vectors); NewDim = GramSchmidt(vectors, N_dim, N_vectors); diff --git a/CellConstructor Installation Guide.md b/CellConstructor Installation Guide.md new file mode 100644 index 00000000..f9f9bd3f --- /dev/null +++ b/CellConstructor Installation Guide.md @@ -0,0 +1,126 @@ +# CellConstructor Installation Guide + +This guide provides step-by-step instructions to compile and install the CellConstructor library. The project uses the Meson build system to compile C and Fortran extensions for Python. + +## Recommended Installation: Conda / Mamba + +The easiest and most reproducible way to install CellConstructor 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. + +### Step 1: Create and Activate the Environment + +1. Install Conda/Mamba. If you don't have it, we recommend installing micromamba. + +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. + +```bash +micromamba create -n sscha python=3.12 gfortran libblas lapack openmpi openmpi-mpicc pkg-config pip numpy scipy spglib=2.2 +``` + +* 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. + +3. Activate the environment. You must activate the environment before proceeding. + +```bash +micromamba activate sscha +``` + +### Step 2: Clone the Repository (if not done) + +If you don't have the source code locally, clone it from the repository. + +```bash +git clone https://github.com/SSCHAcode/CellConstructo +cd CellConstructor +``` + +### Step 3: Install CellConstructor + +With the environment active, install the package using *pip*. *pip* will automatically use Meson to compile and install the project. + +```bash +pip install . +``` + +The installation is now complete! You can verify it by running the tests or importing the modules in Python. + +## Advanced Installation: Manual Configuration + +This section is for users who cannot use Conda or need to configure the build with specific compilers or options. + +### Prerequisites + +* A C and Fortran compiler. + +* Python 3.12 and pip. + +* Ninja and Meson: *pip install meson ninja*. + +* System libraries for BLAS, LAPACK, and MPI. + +### Method 1: Using Environment Variables + +You can specify compilers by setting the *CC* (C compiler) and *FC* (Fortran compiler) environment variables before running *pip*. + +```bash +# 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 . +``` + +### Method 2: Using a Meson Cross File + +For a reproducible setup, define your compilers in a file (e.g., native-toolchain.ini). +Example *native-toolchain.ini*: + +```bash +[binaries] +c = '/path/to/my/custom/gcc' +fortran = '/path/to/my/custom/gfortran' +``` + +Then, install by passing this file to Meson via pip: + +```bash +pip install . --config-settings=meson-args="--native-file=native-toolchain.ini" +``` + +### Build Options +You can pass options to Meson to customize the build. + +* Create a debug build: + +```bash +pip install . --config-settings=meson-args="-Dbuildtype=debug" +``` + +* Enable Intel MKL (requires MKL to be installed and findable by your system): + +```bash +pip install . --config-settings=meson-args="-Duse_mkl=true" +``` + +* Combine multiple options: + +```bash +pip install . --config-settings=meson-args="-Dbuildtype=debug,-Duse_mkl=true" +``` + +#### Reconfiguring a Build + +If you need to change build options, it is best to perform a clean installation. + +```bash +# 1. Uninstall the package +pip uninstall CellConstructor + +# 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" +``` diff --git a/README.md b/README.md index e5e7910c..f48cfc86 100644 --- a/README.md +++ b/README.md @@ -29,20 +29,20 @@ To correnctly install and use the package, you need to have 5. A fortran compiler 6. Lapack -The fortran compiler is required to compile the fortran libraries +The fortran compiler is required to compile the fortran libraries from Quantum ESPRESSO. -Suggested, but not required, is the installation of ASE and spglib. -The presence of a valid ASE installation will enable some more features, -like the possibility to load structures by any ASE supported file format, +Suggested, but not required, is the installation of ASE and spglib. +The presence of a valid ASE installation will enable some more features, +like the possibility to load structures by any ASE supported file format, or the possibility to export the structures into a valid ASE Atoms class. -This library is able to compute symmetries from the structure, -and inside the symmetry module there is a convertor to let CellConstructure -dealing with symmetries extracted with spglib. +This library is able to compute symmetries from the structure, +and inside the symmetry module there is a convertor to let CellConstructure +dealing with symmetries extracted with spglib. However, for a more carefull symmetry analisys, we suggest the use of external tools like ISOTROPY. This package can generate ISOTROPY input files for more advanced symmetry detection. -Please, note that some fortran libraries are needed to be compiled, therefore the Python header files should be localized by the compiling process. +Please, note that some fortran libraries are needed to be compiled, therefore the Python header files should be localized by the compiling process. This requires the python distutils and developing tools to be properly installed. On ubuntu this can be achieved by running: ```bash @@ -100,15 +100,15 @@ conda install clangxx_osx-64 NOTE: If you want to install the package into a system python distribution, the -installation commands should be executed as a superuser. -Otherwise, append the --user flag to either the setup.py or the pip installation. +installation commands should be executed as a superuser. +Otherwise, append the --user flag to either the setup.py or the pip installation. In this way no administrator privileges is required, but the installation will be effective only for the current user. Note that some python distribution, like anaconda, does not need the superuser, as it has an installation path inside the HOME directory. You can install also using the intel compiler. In this case, you must edit the setup.py script so that: - remove the lapack and blas as extra library for the SCHAModules extension. -- add a new flag: 'extra_link_args = ["-mkl"]' to the extension. +- add a new flag: 'extra_link_args = ["-mkl"]' to the extension. Remember to specify the intel compiler both to the compilation and for the running: CC="icc" @@ -118,7 +118,7 @@ otherwise the C module will give an error when loaded reguarding some "_fast_mem ## GO! -To test if the installation runned properly, run the examples reported +To test if the installation runned properly, run the examples reported in the test directory. The python code in these tests should be almost self explaining and introduce you to the potentiality of this library. @@ -142,3 +142,84 @@ For example, if you want the html version run: make html ``` inside the UserGuide directory. It will generate a build directory that contains the html version of the full documentation. + +## Installation using 'Meson' + +### Compiling with Meson + +To compile and install CellConstructor with Meson, follow these typical steps: + +### 1. Change to the Source Directory + +First, open a terminal and navigate to the root directory of the project source code. This is where the `meson.build` file is located. + +```bash +cd /path/to/source/root/cellconstructor +``` + + +### 2. Configure the Build Directory + +Create and configure a build directory by running: + +```bash +meson setup builddir +``` + +or if you are in a conda env (the best option for a local installation): +```bash +meson setup builddir --prefix=$CONDA_PREFIX +``` + +if you want to use Intel MKL: +```bash +setup builddir -Duse_mkl=true +``` + +This command sets up a separate build directory (`builddir`) where all compiled files and build artifacts will be placed, keeping the source directory clean. After this, change into the build directory: + +```bash +cd builddir +``` + + +### 3. Compile the Project + +Once inside the build directory, compile the project using: + +```bash +meson compile +``` + +This will compile the source code according to the configuration from the previous step. + +### 4. Run Tests (Optional) + +The project includes tests, you need to install pytest to work. You can run them with: + +```bash +meson test +``` + +This step helps verify that the build works correctly. + +### 5. Install the Project (Optional) + +To install the compiled binaries, libraries, and other files system-wide (or to a custom location), run: + + +```bash +meson install +``` + +or + +```bash +sudo meson install +``` + +You may need superuser privileges (hence `sudo`) to install to system directories. + +*** + +Following these steps will help you successfully compile, test, and install SSCHA with Meson as their build system. diff --git a/cellconstructor/Phonons.py b/cellconstructor/Phonons.py index 33f6921e..5eec5110 100644 --- a/cellconstructor/Phonons.py +++ b/cellconstructor/Phonons.py @@ -2875,7 +2875,7 @@ def InterpolateMesh(self, mesh_dim, lo_to_splitting = False): INTERPOLATE THE DYNAMICAL MATRIX IN A FINER Q MESH ================================================== - This method employs the Tensor2 interpolateion functions + This method employs the Tensor2 interpolation functions from the ForceTensor module to perform the interpolation. Parameters diff --git a/cellconstructor/Spectral.py b/cellconstructor/Spectral.py index 488daeae..991afdf9 100644 --- a/cellconstructor/Spectral.py +++ b/cellconstructor/Spectral.py @@ -241,10 +241,11 @@ def get_static_correction_interpolated(dyn, tensor3, T, new_supercell, k_grid): dynq = get_static_correction(dyn, tensor3, k_grid, q_tot, T) # Add all the new computed dynamical matrix - new_dyn.dynmats[0] = dynq[0, :, :] - for iq in range(1,len(q_tot)): - new_dyn.dynmats.append(dynq[iq, :, :]) + all_dynmats = [] + for iq in range(len(q_tot)): + all_dynmats.append(dynq[iq, :, :]) + new_dyn.dynmats = all_dynmats # Adjust the dynamical matrix q points and the stars new_dyn.AdjustQStar() @@ -3714,10 +3715,12 @@ def get_os_perturb_dynamic_correction_along_path(dyn, tensor3, #------------------------------------------------------------------------------- def get_dielectric_function(dyn, k_grid, T, e0 ,e1, de, ie, ismear , sm0, sm0_id - , diag_approx=False, nsm=1, static_limit=False): #skeleton function for TESTING... + , diag_approx=False, nsm=1, static_limit=False): #Function for TESTING... # ( tensor3,omega,N,nu,q, d_bubble_cart, ener, epsilon_inf,atom_a, atom_b, ne,frequency,dielectric_tensor,tensor2,effective_charges,energies,spectralf,N,Big_omega) """ + This function computes the dielectric function. + Input data: epsilon_inf = dielctric constant of vacuum ---> Phonon.Phonon.dielectric_tensor(3x3) a = atom a -> M(a) mass of atom a ---> tensor2 = CC.ForceTensor.Tensor2(dyn.structure, dyn_gemnerate_supwercell(dyn.GetSupercell()),dyn_GetSupercell()); tensor2.SetupFromPhonons(dyn); tensor2.center() ---> structure = tensor2.unitcell_structure ---> structure.get_masses_array() @@ -3779,6 +3782,9 @@ def get_dielectric_function(dyn, k_grid, T, e0 ,e1, de, ie, ismear # ========================================================================================== #---------------------------------------------------------------- def compute_k(k): + """ + This function computes the k value. + """ # phi3 in q, k, -q - k t1 = time.time() phi3=tensor3.Interpolate(k,-q-k, asr = False) diff --git a/meson.build b/meson.build new file mode 100644 index 00000000..969dbd65 --- /dev/null +++ b/meson.build @@ -0,0 +1,329 @@ +project('CellConstructor', + ['c','fortran'], + version: '1.5.0', + license: 'GPL', + meson_version: '>= 1.1.0', # <- set min version of meson. + default_options : [ + 'warning_level=1', + 'buildtype=release', + 'fortran_args=-O2', + 'fortran_args=-cpp' + ] + ) + +# --- Compilation options --- +use_mkl = get_option('use_mkl') + +# --- System and Python Dependencies --- +# Find the necessary installations +py = import('python').find_installation(pure: false) +py_dep = py.dependency() +fc = meson.get_compiler('fortran') + +# Additional dependencies + +# The LAPACK and BLAS libraries are essential for Fortran matrix operations. +#lapack_dep = dependency('lapack') +#blas_dep = dependency('blas') +openblas_dep = dependency('openblas', required: false) +if use_mkl + mkl_dep = dependency('mkl', required: true) + blas_dep = mkl_dep + lapack_dep = mkl_dep +else + lapack_dep = dependency('lapack', required: true) + blas_dep = dependency('blas', required: true) +endif + +# The openmp dependency is necessary for thermal_transport +openmp_dep = dependency('openmp', required: true) + +# --- MPI Detection --- +# This overrides the logic in os.environ["MPICC"] and os.popen("%s -show" % mpicc). +# Meson has a built-in MPI module. +mpi_args = [] +mpi_link_args = [] +mpi_compile_args = [] +has_mpi = false + +# Attempts to find the MPI dependency. +# You can specify a specific MPI compiler with the 'mpi_compiler' parameter +# or, if you want, a specific Fortran compiler with 'mpi_fortran_compiler'. +# For OpenMPI, IntelMPI, MPICH, etc., Meson usually finds it automatically. +#mpi_dep = dependency('mpi', required: false, language: ['c', 'fortran']) +mpi_dep = dependency('mpi', required: false) + +if mpi_dep.found() + message('MPI environment detected correctly.') + has_mpi = true + # Meson handles adding appropriate flags. We just add the define. + # If you need specific MPI flags beyond what Meson adds automatically, + # you can get them via mpi_dep.get_compile_args() and mpi_dep.get_link_args() + # and add them to extra_compile_args/extra_link_args. + mpi_compile_args += ['-D_MPI'] +else + # Here you can add warning logic if MPI is not found. + # Meson prints a warning if required: true and it is not found. + # For required: false, you can print your own warning. + warning('No MPI compiler found, please ensure MPI is installed and configured.') + warning('If you wish to activate MPI acceleration, consider setting MPICC environment variable or providing Meson with appropriate flags.') +endif +# Find the quadmath library, if available +quadmath_dep = fc.find_library('quadmath', required: false) + +# --- NUMPY CONFIGURATION --- +# Gets the path to the NumPy and f2py header directories using the Python command +incdir_numpy = run_command(py, + ['-c', 'import numpy; print(numpy.get_include())'], + check : true +).stdout().strip() + +# f2py also requires the fortranobject.h header +incdir_f2py = run_command(py, + ['-c', 'import numpy.f2py; print(numpy.f2py.get_include())'], + check : true +).stdout().strip() + +inc_np = include_directories(incdir_numpy, incdir_f2py) +np_dep = declare_dependency(include_directories: inc_np) + +inc_f2py = include_directories(incdir_f2py) +fortranobject_c = incdir_f2py / 'fortranobject.c' + +# --- END OF NUMPY CONFIGURATION --- +if openblas_dep.found() + message('openblas environment detected correctly.') + list_dep = [py_dep, mpi_dep, quadmath_dep, openblas_dep, lapack_dep, blas_dep] +else + warning('No openblas found.') + list_dep = [py_dep, mpi_dep, quadmath_dep, lapack_dep, blas_dep] +endif +# --- Definition of each Python extension (Fortran) --- + +# 'symph' extension + +# Compilation of the Fortran module: symph +fortran_sources_symph = [ + 'FModules/constants.f90', + 'FModules/error_handler.f90', + 'FModules/get_latvec.f90', + 'FModules/io_global.f90', + 'FModules/rotate_and_add_dyn.f90', + 'FModules/smallgq.f90', + 'FModules/symm_matrix.f90', + 'FModules/contract_two_phonon_propagator.f90', + 'FModules/fc_supercell_from_dyn.f90', + 'FModules/get_q_grid_fast.f90', + 'FModules/kind.f90', + 'FModules/star_q.f90', + 'FModules/symvector.f90', + 'FModules/cryst_to_car.f90', + 'FModules/flush_unit.f90', + 'FModules/get_translations.f90', + 'FModules/q2qstar_out.f90', + 'FModules/set_asr.f90', + 'FModules/symdynph_gq_new.f90', + 'FModules/trntnsc.f90', + 'FModules/eff_charge_interp.f90', + 'FModules/from_matdyn.f90', + 'FModules/interp.f90', + 'FModules/q_gen.f90', + 'FModules/set_tau.f90', + 'FModules/symm_base.f90', + 'FModules/unwrap_tensors.f90', + 'FModules/eqvect.f90', + 'FModules/get_equivalent_atoms.f90', + 'FModules/invmat.f90', + 'FModules/recips.f90', + 'FModules/sgam_ph.f90', + 'FModules/symmetry_high_rank.f90' +] +## Generate the C wrapper with f2py using a custom target +f2py_symph_target = custom_target('symph-f2py-wrapper', + input: fortran_sources_symph, + output: ['symphmodule.c','symph-f2pywrappers.f','symph-f2pywrappers2.f90'], +# command: [py.full_path(), '-m', 'numpy.f2py', '--backend', 'meson', +# '--dep', 'mpi', '--quiet', '-c', '@INPUT0@', '-m', 'symph'], + command : [py, '-m', 'numpy.f2py', '@INPUT@', '-m', 'symph', '--lower'], + install: false +) +py.extension_module('symph', + [ + fortran_sources_symph, + f2py_symph_target, fortranobject_c], + include_directories: inc_np, + dependencies: list_dep, +# link_args: ['-L' + py.get_install_dir() / 'numpy' / 'f2py' / 'src' / 'fortranobject.c', '-lfortranobject'], + install: true +) + +# 'secondorder' extension + +# Compilation of the Fortran module: secondorder +fortran_sources_secondorder = [ + 'FModules/second_order_centering.f90', + 'FModules/second_order_ASR.f90' +] +## Generate the C wrapper with f2py using a custom target +f2py_secondorder_target = custom_target('secondorder-f2py-wrapper', + input: fortran_sources_secondorder, + output: ['secondordermodule.c','secondorder-f2pywrappers2.f90'], +# command: [py.full_path(), '-m', 'numpy.f2py', '--backend', 'meson', +# '--dep', 'mpi', '--quiet', '-c', '@INPUT0@', '-m', 'secondorder'], + command : [py, '-m', 'numpy.f2py', '@INPUT@', '-m', 'secondorder', '--lower'], + install: false +) +py.extension_module('secondorder', + [ + fortran_sources_secondorder, + f2py_secondorder_target, fortranobject_c], + include_directories: inc_np, + dependencies: list_dep, +# link_args: ['-L' + py.get_install_dir() / 'numpy' / 'f2py' / 'src' / 'fortranobject.c', '-lfortranobject'], + install: true +) + +# 'thirdorder' extension + +# Compilation of the Fortran module: thirdorder + +fortran_sources_thirdorder = [ + 'FModules/third_order_ASR.f90', + 'FModules/third_order_centering.f90', + 'FModules/third_order_cond_centering.f90', + 'FModules/third_order_cond.f90', + 'FModules/third_order_dynbubble.f90', + 'FModules/third_order_interpol.f90' +] +## Generate the C wrapper with f2py using a custom target +f2py_thirdorder_target = custom_target('thirdorder-f2py-wrapper', + input: fortran_sources_thirdorder, + output: ['thirdordermodule.c','thirdorder-f2pywrappers2.f90'], +# command: [py.full_path(), '-m', 'numpy.f2py', '--backend', 'meson', +# '--dep', 'mpi', '--quiet', '-c', '@INPUT0@', '-m', 'thirdorder'], + command : [py, '-m', 'numpy.f2py', '@INPUT@', '-m', 'thirdorder', '--lower'], + install: false +) +py.extension_module('thirdorder', + [ + fortran_sources_thirdorder, + f2py_thirdorder_target, fortranobject_c], + include_directories: inc_np, + dependencies: list_dep, +# link_args: ['-L' + py.get_install_dir() / 'numpy' / 'f2py' / 'src' / 'fortranobject.c', '-lfortranobject'], + install: true +) + +# 'thermal_conductivity' extension + +fortran_sources_thermal_conductivity = [ +'FModules/get_scattering_q_grid.f90', +'FModules/third_order_cond.f90', +'FModules/third_order_cond_centering.f90', +'FModules/get_lf.f90' +] +## Generate the C wrapper with f2py using a custom target +f2py_thermal_conductivity_target = custom_target('thermal_conductivity-f2py-wrapper', + input: fortran_sources_thermal_conductivity, + output: ['thermal_conductivitymodule.c','thermal_conductivity-f2pywrappers2.f90'], +# command: [py.full_path(), '-m', 'numpy.f2py', '--backend', 'meson', +# '--dep', 'mpi', '--quiet', '-c', '@INPUT0@', '-m', 'thermal_conductivity'], + command : [py, '-m', 'numpy.f2py', '@INPUT@', '-m', 'thermal_conductivity', '--lower'], + install: false +) +py.extension_module('thermal_conductivity', + [ + fortran_sources_thermal_conductivity, + f2py_thermal_conductivity_target, fortranobject_c], + include_directories: inc_np, + dependencies: [list_dep, openmp_dep], +# link_args: ['-L' + py.get_install_dir() / 'numpy' / 'f2py' / 'src' / 'fortranobject.c', '-lfortranobject'], + install: true +) + +# --- Definition of the 'cc_linalg' C extension --- +wrapper_file = '' +if py.version().version_compare('<3.0') + wrapper_file = 'CModules/wrapper.c' +else + wrapper_file = 'CModules/wrapper3.c' +endif + +# Compilation of the C module: cc_linalg +c_linalg_sources = [ + 'CModules/LinAlg.c', + wrapper_file +] + +py.extension_module('cc_linalg', + c_linalg_sources, + include_directories: inc_np, # Add the NumPy header for the C module + dependencies: py_dep, + install: true +) + + +# --- Installation of the 'cellconstructor' Python package --- +#install_data( +# 'cellconstructor/__init__.py', 'cellconstructor/AnharmonicForceFields.py', 'cellconstructor/calculators.py', +# 'cellconstructor/Methods.py', 'cellconstructor/Phonons.py', 'cellconstructor/Spectral.py', +# 'cellconstructor/ThermalConductivity.py', 'cellconstructor/Units.py', 'cellconstructor/Bands.py', +# 'cellconstructor/ForceTensor.py', 'cellconstructor/Manipulate.py', 'cellconstructor/Moro_object.py', +# 'cellconstructor/Settings.py', 'cellconstructor/Structure.py', 'cellconstructor/symmetries.py', +# 'cellconstructor/Timer.py', +# install_dir: py.get_install_dir() / 'cellconstructor', +#) +py.install_sources( + [ + 'cellconstructor/__init__.py', + 'cellconstructor/AnharmonicForceFields.py', + 'cellconstructor/Bands.py', + 'cellconstructor/calculators.py', + 'cellconstructor/ForceTensor.py', + 'cellconstructor/Manipulate.py', + 'cellconstructor/Methods.py', + 'cellconstructor/Moro_object.py', + 'cellconstructor/Phonons.py', + 'cellconstructor/Settings.py', + 'cellconstructor/Spectral.py', + 'cellconstructor/Structure.py', + 'cellconstructor/symmetries.py', + 'cellconstructor/SymData/15.dat', + 'cellconstructor/SymData/36_red.dat', + 'cellconstructor/SymData/36.dat', + 'cellconstructor/SymData/60.dat', + 'cellconstructor/SymData/64.bcs', + 'cellconstructor/SymData/64.dat', + 'cellconstructor/SymData/convert_sym.py', + 'cellconstructor/ThermalConductivity.py', + 'cellconstructor/Timer.py', + 'cellconstructor/Units.py' + ], + subdir: 'cellconstructor' +) + +install_data( + 'cellconstructor/SymData/15.dat', 'cellconstructor/SymData/36_red.dat', 'cellconstructor/SymData/36.dat', + 'cellconstructor/SymData/60.dat', 'cellconstructor/SymData/64.bcs', 'cellconstructor/SymData/64.dat', + 'cellconstructor/SymData/convert_sym.py', + install_dir: py.get_install_dir() / 'cellconstructor' / 'SymData' +) + +# --- Installation of executable scripts --- +py.install_sources([ + 'scripts/symmetrize_dynmat.py', + 'scripts/cellconstructor_test.py', + 'scripts/view_scf_atoms.py' +]) + +# Set the tests by pytest. +pytest_exe = find_program('pytest', required: false) + +if pytest_exe.found() + test('pytest', pytest_exe, + args : ['-v'], + workdir : meson.project_source_root() + ) +else + message('pytest not found; pytest tests are skipped.') +endif diff --git a/meson.build.secondorder b/meson.build.secondorder new file mode 100644 index 00000000..1152aba1 --- /dev/null +++ b/meson.build.secondorder @@ -0,0 +1,57 @@ +project('secondorder', + ['c', 'fortran'], + version : '0.1', + meson_version: '>= 1.1.0', + default_options : [ + 'warning_level=1', + 'buildtype=release' + ]) +fc = meson.get_compiler('fortran') + +py = import('python').find_installation(pure: false) +py_dep = py.dependency() + +incdir_numpy = run_command(py, + ['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'], + check : true +).stdout().strip() # -> /home/diego/miniforge3/envs/sscha_env/lib/python3.13/site-packages/numpy/_core/include + +incdir_f2py = run_command(py, + ['-c', 'import os; os.chdir(".."); import numpy.f2py; print(numpy.f2py.get_include())'], + check : true +).stdout().strip() # -> /home/diego/miniforge3/envs/sscha_env/lib/python3.13/site-packages/numpy/f2py/src + +inc_np = include_directories(incdir_numpy) +np_dep = declare_dependency(include_directories: inc_np) + +incdir_f2py = incdir_numpy / '..' / '..' / 'f2py' / 'src' +inc_f2py = include_directories(incdir_f2py) +fortranobject_c = incdir_f2py / 'fortranobject.c' + +inc_np = include_directories(incdir_numpy, incdir_f2py) +# gh-25000 +quadmath_dep = fc.find_library('quadmath', required: false) + + + + +py.extension_module('secondorder', + [ + 'second_order_centering.f90', + 'second_order_ASR.f90', + 'secondordermodule.c', + 'secondorder-f2pywrappers2.f90', + fortranobject_c + ], + include_directories: [ + inc_np, + + ], + dependencies : [ + py_dep, + quadmath_dep, + dependency('mpi') + + + ], + install : true) diff --git a/meson.build.thermal_conductivity b/meson.build.thermal_conductivity new file mode 100644 index 00000000..c2ca694c --- /dev/null +++ b/meson.build.thermal_conductivity @@ -0,0 +1,59 @@ +project('thermal_conductivity', + ['c', 'fortran'], + version : '0.1', + meson_version: '>= 1.1.0', + default_options : [ + 'warning_level=1', + 'buildtype=release' + ]) +fc = meson.get_compiler('fortran') + +py = import('python').find_installation(pure: false) +py_dep = py.dependency() + +incdir_numpy = run_command(py, + ['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'], + check : true +).stdout().strip() + +incdir_f2py = run_command(py, + ['-c', 'import os; os.chdir(".."); import numpy.f2py; print(numpy.f2py.get_include())'], + check : true +).stdout().strip() + +inc_np = include_directories(incdir_numpy) +np_dep = declare_dependency(include_directories: inc_np) + +incdir_f2py = incdir_numpy / '..' / '..' / 'f2py' / 'src' +inc_f2py = include_directories(incdir_f2py) +fortranobject_c = incdir_f2py / 'fortranobject.c' + +inc_np = include_directories(incdir_numpy, incdir_f2py) +# gh-25000 +quadmath_dep = fc.find_library('quadmath', required: false) + + + + +py.extension_module('thermal_conductivity', + [ + 'get_lf.f90', + 'get_scattering_q_grid.f90', + 'third_order_centering.f90', + 'third_order_cond.f90', + 'thermal_conductivitymodule.c', + 'thermal_conductivity-f2pywrappers2.f90', + fortranobject_c + ], + include_directories: [ + inc_np, + + ], + dependencies : [ + py_dep, + quadmath_dep, + dependency('mpi') + + + ], + install : true) diff --git a/meson.build.thirdorder b/meson.build.thirdorder new file mode 100644 index 00000000..fd59806b --- /dev/null +++ b/meson.build.thirdorder @@ -0,0 +1,61 @@ +project('thirdorder', + ['c', 'fortran'], + version : '0.1', + meson_version: '>= 1.1.0', + default_options : [ + 'warning_level=1', + 'buildtype=release' + ]) +fc = meson.get_compiler('fortran') + +py = import('python').find_installation(pure: false) +py_dep = py.dependency() + +incdir_numpy = run_command(py, + ['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'], + check : true +).stdout().strip() + +incdir_f2py = run_command(py, + ['-c', 'import os; os.chdir(".."); import numpy.f2py; print(numpy.f2py.get_include())'], + check : true +).stdout().strip() + +inc_np = include_directories(incdir_numpy) +np_dep = declare_dependency(include_directories: inc_np) + +incdir_f2py = incdir_numpy / '..' / '..' / 'f2py' / 'src' +inc_f2py = include_directories(incdir_f2py) +fortranobject_c = incdir_f2py / 'fortranobject.c' + +inc_np = include_directories(incdir_numpy, incdir_f2py) +# gh-25000 +quadmath_dep = fc.find_library('quadmath', required: false) + + + + +py.extension_module('thirdorder', + [ + 'third_order_ASR.f90', + 'third_order_centering.f90', + 'third_order_cond_centering.f90', + 'third_order_cond.f90', + 'third_order_dynbubble.f90', + 'third_order_interpol.f90', + 'thirdordermodule.c', + 'thirdorder-f2pywrappers2.f90', + fortranobject_c + ], + include_directories: [ + inc_np, + + ], + dependencies : [ + py_dep, + quadmath_dep, + dependency('mpi') + + + ], + install : true) diff --git a/meson.build_symph b/meson.build_symph new file mode 100644 index 00000000..7a927dd8 --- /dev/null +++ b/meson.build_symph @@ -0,0 +1,89 @@ +project('symph', + ['c', 'fortran'], + version : '0.1', + meson_version: '>= 1.1.0', + default_options : [ + 'warning_level=1', + 'buildtype=release', + 'fortran_args=-O2', 'fortran_args=-cpp']) +fc = meson.get_compiler('fortran') + +py = import('python').find_installation(pure: false) +py_dep = py.dependency() + +incdir_numpy = run_command(py, + ['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'], + check : true +).stdout().strip() + +incdir_f2py = run_command(py, + ['-c', 'import os; os.chdir(".."); import numpy.f2py; print(numpy.f2py.get_include())'], + check : true +).stdout().strip() + +inc_np = include_directories(incdir_numpy) +np_dep = declare_dependency(include_directories: inc_np) + +incdir_f2py = incdir_numpy / '..' / '..' / 'f2py' / 'src' +inc_f2py = include_directories(incdir_f2py) +fortranobject_c = incdir_f2py / 'fortranobject.c' + +inc_np = include_directories(incdir_numpy, incdir_f2py) +# gh-25000 +quadmath_dep = fc.find_library('quadmath', required: false) + + + + +py.extension_module('symph', + [ + 'constants.f90', + 'error_handler.f90', + 'get_latvec.f90', + 'io_global.f90', + 'rotate_and_add_dyn.f90', + 'smallgq.f90', + 'symm_matrix.f90', + 'contract_two_phonon_propagator.f90', + 'fc_supercell_from_dyn.f90', + 'get_q_grid_fast.f90', + 'kind.f90', + 'star_q.f90', + 'symvector.f90', + 'cryst_to_car.f90', + 'flush_unit.f90', + 'get_translations.f90', + 'q2qstar_out.f90', + 'set_asr.f90', + 'symdynph_gq_new.f90', + 'trntnsc.f90', + 'eff_charge_interp.f90', + 'from_matdyn.f90', + 'interp.f90', + 'q_gen.f90', + 'set_tau.f90', + 'symm_base.f90', + 'unwrap_tensors.f90', + 'eqvect.f90', + 'get_equivalent_atoms.f90', + 'invmat.f90', + 'recips.f90', + 'sgam_ph.f90', + 'symmetry_high_rank.f90', + 'symphmodule.c', + 'symph-f2pywrappers2.f90', + 'symph-f2pywrappers.f', + fortranobject_c + ], + include_directories: [ + inc_np, + + ], + dependencies : [ + py_dep, + quadmath_dep, + dependency('mpi') + + + ], + install : true) diff --git a/meson.options b/meson.options new file mode 100644 index 00000000..d6853da8 --- /dev/null +++ b/meson.options @@ -0,0 +1,3 @@ +# meson.options +option('use_mkl', type: 'boolean', value: false, + description: 'Use Intel Math Kernel Library (MKL) for BLAS/LAPACK') diff --git a/setup.py b/old_setup.py similarity index 100% rename from setup.py rename to old_setup.py diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..b05cc195 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,54 @@ +# pyproject.toml + +[build-system] +# Declare the build backends and their dependencies that pip needs to build the project. +# 'meson-python' is the backend that translates pip calls to Meson. +# 'meson' is the actual build tool. +# 'ninja' is the low-level build system that Meson uses by default for rapid compilation. +requires = ["meson-python>=0.13.0", "meson>=1.1.0", "ninja>=1.10", "meson-python", "numpy>=1.20.0"] +build-backend = "mesonpy" + +[project] +# Project metadata, which was previously in the `setup()` call of setup.py. +name = "CellConstructor" +version = "1.5.0" # Make sure this version matches meson.build +description = "Python utilities interfaced with ASE for atomic crystal analysis" +authors = [{name = "Lorenzo Monacelli"}] +readme = "README.md" +requires-python = ">=3.8" # The minimum version of Python supported by your project +license = { text = "GPL" } + +keywords = [ # Optional keywords to describe your package + "crystallography", + "phonons", + "materials science", + "quantum espresso", + "ab initio" +] + +# Project runtime dependencies. +# These are the dependencies that will be installed when someone runs `pip install cellconstructor`. +dependencies = [ + "numpy", + "ase", + "scipy", + # If any of your Python extensions had an *additional* dependency + # other than numpy, ase, or scipy (and not a system library like BLAS/LAPACK), + # it would go here. +] + +[project.urls] +Homepage = "https://sscha.eu/" +Repository = "https://github.com/SSCHAcode/CellConstructor" # Puede ser el mismo que Homepage +# Documentation = "https://documentacion.readthedocs.io/" +Issues = "https://github.com/SSCHAcode/CellConstructor/issues" + + +# --- Meson-python specific configuration (Optional but useful) --- +[tool.meson-python] +# Here you can pass options to Meson that control the build process. +# For example, to enable debugging or specify a different installation path. +# By default, meson-python takes care of using the virtual environment if it exists. + +# build-args = ["-Dbuildtype=debug"] # Uncomment for a debug build +# setup-args = ["--prefix=/opt/cellconstructor"] # For a non-standard installation diff --git a/requirements2.txt b/requirements2.txt index b77539ae..590aa382 100644 --- a/requirements2.txt +++ b/requirements2.txt @@ -2,4 +2,4 @@ setuptools numpy scipy ase==3.16.0 -spglib +spglib<=2.2