From fa1d256af826cc3270248f1166fdc8a6b4fea2af Mon Sep 17 00:00:00 2001 From: Harrison LaBollita Date: Tue, 4 Nov 2025 09:39:01 -0500 Subject: [PATCH 1/7] replace linear tetrahedron c code with python impl --- CMakeLists.txt | 3 - c++/CMakeLists.txt | 1 - c++/triqs_dft_tools/CMakeLists.txt | 101 ---- c++/triqs_dft_tools/converters/vasp.hpp | 3 - .../converters/vasp/__init__.py | 27 - .../converters/vasp/argsort.cpp | 67 --- .../converters/vasp/argsort.hpp | 27 - .../converters/vasp/dos_tetra3d.cpp | 482 ------------------ .../converters/vasp/dos_tetra3d.hpp | 44 -- .../converters/vasp/makefile.linux | 4 - c++/triqs_dft_tools/converters/vasp/setup.py | 33 -- c++/triqs_dft_tools/triqs_dft_tools.hpp | 3 - python/triqs_dft_tools/CMakeLists.txt | 2 +- .../converters/plovasp/atm_desc.py | 21 - .../converters/plovasp/lintetra.py | 139 +++++ .../converters/plovasp/proj_shell.py | 5 +- test/CMakeLists.txt | 2 +- test/c++/CMakeLists.txt | 35 -- test/c++/converters/vasp/reorder_flag.cpp | 23 - test/c++/converters/vasp/reorder_inds.cpp | 27 - test/c++/converters/vasp/testing.hpp | 91 ---- test/c++/converters/vasp/tet_weights.cpp | 33 -- test/c++/converters/vasp/weights1.cpp | 27 - test/python/plovasp/atm/test_atm.py | 2 +- 24 files changed, 145 insertions(+), 1057 deletions(-) delete mode 100644 c++/CMakeLists.txt delete mode 100644 c++/triqs_dft_tools/CMakeLists.txt delete mode 100644 c++/triqs_dft_tools/converters/vasp.hpp delete mode 100644 c++/triqs_dft_tools/converters/vasp/__init__.py delete mode 100644 c++/triqs_dft_tools/converters/vasp/argsort.cpp delete mode 100644 c++/triqs_dft_tools/converters/vasp/argsort.hpp delete mode 100644 c++/triqs_dft_tools/converters/vasp/dos_tetra3d.cpp delete mode 100644 c++/triqs_dft_tools/converters/vasp/dos_tetra3d.hpp delete mode 100644 c++/triqs_dft_tools/converters/vasp/makefile.linux delete mode 100644 c++/triqs_dft_tools/converters/vasp/setup.py delete mode 100644 c++/triqs_dft_tools/triqs_dft_tools.hpp delete mode 100644 python/triqs_dft_tools/converters/plovasp/atm_desc.py create mode 100644 python/triqs_dft_tools/converters/plovasp/lintetra.py delete mode 100644 test/c++/CMakeLists.txt delete mode 100644 test/c++/converters/vasp/reorder_flag.cpp delete mode 100644 test/c++/converters/vasp/reorder_inds.cpp delete mode 100644 test/c++/converters/vasp/testing.hpp delete mode 100644 test/c++/converters/vasp/tet_weights.cpp delete mode 100644 test/c++/converters/vasp/weights1.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 126ba68b4..9de7152c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,9 +131,6 @@ include(GNUInstallDirs) # Find / Build dependencies add_subdirectory(deps) -# Build and install the library -add_subdirectory(c++/${PROJECT_NAME}) - # add here stuff for the Fortran part in DFTTools add_subdirectory(fortran/dmftproj) diff --git a/c++/CMakeLists.txt b/c++/CMakeLists.txt deleted file mode 100644 index 30655944a..000000000 --- a/c++/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(plovasp/atm) diff --git a/c++/triqs_dft_tools/CMakeLists.txt b/c++/triqs_dft_tools/CMakeLists.txt deleted file mode 100644 index b667c0626..000000000 --- a/c++/triqs_dft_tools/CMakeLists.txt +++ /dev/null @@ -1,101 +0,0 @@ -file(GLOB_RECURSE sources *.cpp) -add_library(${PROJECT_NAME}_c ${sources}) -add_library(${PROJECT_NAME}::${PROJECT_NAME}_c ALIAS ${PROJECT_NAME}_c) - -# Link against triqs and enable warnings -target_link_libraries(${PROJECT_NAME}_c PUBLIC triqs PRIVATE $) - -# Configure target and compilation -set_target_properties(${PROJECT_NAME}_c PROPERTIES - POSITION_INDEPENDENT_CODE ON - VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} -) -target_include_directories(${PROJECT_NAME}_c PUBLIC $) -target_include_directories(${PROJECT_NAME}_c SYSTEM INTERFACE $) -target_link_directories(${PROJECT_NAME}_c PUBLIC $) -target_link_directories(${PROJECT_NAME}_c INTERFACE $) -target_compile_definitions(${PROJECT_NAME}_c PUBLIC - TRIQS_DFT_TOOLS_GIT_HASH=${PROJECT_GIT_HASH} - TRIQS_GIT_HASH=${TRIQS_GIT_HASH} - $<$:TRIQS_DFT_TOOLS_DEBUG> - $<$:TRIQS_DEBUG> - $<$:TRIQS_ARRAYS_ENFORCE_BOUNDCHECK> - ) - -# Install library and headers -install(TARGETS ${PROJECT_NAME}_c EXPORT ${PROJECT_NAME}-targets DESTINATION ${CMAKE_INSTALL_LIBDIR}) -install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION include FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h") - - -# ========= Static Analyzer Checks ========== - -option(ANALYZE_SOURCES OFF "Run static analyzer checks if found (clang-tidy, cppcheck)") -if(ANALYZE_SOURCES) - - # Locate static analyzer tools - find_program(CPPCHECK_EXECUTABLE NAMES "cppcheck" PATHS ENV PATH) - find_program(CLANG_TIDY_EXECUTABLE NAMES "clang-tidy" PATHS ENV PATH) - - # Run clang-tidy if found - if(CLANG_TIDY_EXECUTABLE) - message(STATUS "clang-tidy found: ${CLANG_TIDY_EXECUTABLE}") - set_target_properties(${PROJECT_NAME}_c PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE}") - else() - message(STATUS "clang-tidy not found in $PATH. Please consider installing clang-tidy for additional checks!") - endif() - - # Run cppcheck if found - if(CPPCHECK_EXECUTABLE) - message(STATUS "cppcheck found: ${CPPCHECK_EXECUTABLE}") - add_custom_command( - TARGET ${PROJECT_NAME}_c - COMMAND ${CPPCHECK_EXECUTABLE} - --enable=warning,style,performance,portability - --std=c++23 - --template=gcc - --verbose - --force - --quiet - ${sources} - WORKING_DIRECTORY - ${CMAKE_CURRENT_SOURCE_DIR} - ) - else() - message(STATUS "cppcheck not found in $PATH. Please consider installing cppcheck for additional checks!") - endif() - -endif() - -# ========= Dynamic Analyzer Checks ========== - -option(ASAN OFF "Compile library and executables with LLVM Address Sanitizer") -if(ASAN) - if(NOT TARGET asan) - find_package(sanitizer REQUIRED COMPONENTS asan) - endif() - target_link_libraries(${PROJECT_NAME}_c PUBLIC $) -endif() - -option(UBSAN OFF "Compile library and executables with LLVM Undefined Behavior Sanitizer") -if(UBSAN) - if(NOT TARGET ubsan) - find_package(sanitizer REQUIRED COMPONENTS ubsan) - endif() - target_link_libraries(${PROJECT_NAME}_c PUBLIC $) -endif() - -option(MSAN OFF "Compile library and executables with LLVM Memory Sanitizer") -if(MSAN) - if(NOT TARGET msan) - find_package(sanitizer REQUIRED COMPONENTS msan) - endif() - target_link_libraries(${PROJECT_NAME}_c PUBLIC $) -endif() - -option(TSAN OFF "Compile library and executables with LLVM Thread Sanitizer") -if(TSAN) - if(NOT TARGET tsan) - find_package(sanitizer REQUIRED COMPONENTS tsan) - endif() - target_link_libraries(${PROJECT_NAME}_c PUBLIC $) -endif() diff --git a/c++/triqs_dft_tools/converters/vasp.hpp b/c++/triqs_dft_tools/converters/vasp.hpp deleted file mode 100644 index 0aa018d7c..000000000 --- a/c++/triqs_dft_tools/converters/vasp.hpp +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once -#include "./vasp/argsort.hpp" -#include "./vasp/dos_tetra3d.hpp" diff --git a/c++/triqs_dft_tools/converters/vasp/__init__.py b/c++/triqs_dft_tools/converters/vasp/__init__.py deleted file mode 100644 index db31c97b2..000000000 --- a/c++/triqs_dft_tools/converters/vasp/__init__.py +++ /dev/null @@ -1,27 +0,0 @@ - -################################################################################ -# -# TRIQS: a Toolbox for Research in Interacting Quantum Systems -# -# Copyright (C) 2011 by M. Ferrero, O. Parcollet -# -# DFT tools: Copyright (C) 2011 by M. Aichhorn, L. Pourovskii, V. Vildosola -# -# PLOVasp: Copyright (C) 2015 by O. E. Peil -# -# TRIQS is free software: you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -# details. -# -# You should have received a copy of the GNU General Public License along with -# TRIQS. If not, see . -# -################################################################################ - -__all__ = [] diff --git a/c++/triqs_dft_tools/converters/vasp/argsort.cpp b/c++/triqs_dft_tools/converters/vasp/argsort.cpp deleted file mode 100644 index 92fb86c22..000000000 --- a/c++/triqs_dft_tools/converters/vasp/argsort.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* -* -* This file is part of the ATM library. -* -* Copyright (C) 2010 by O. E. Peil -* -* TRIQS is free software: you can redistribute it and/or modify it under the -* terms of the GNU General Public License as published by the Free Software -* Foundation, either version 3 of the License, or (at your option) any later -* version. -* -* TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY -* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -* details. -* -* You should have received a copy of the GNU General Public License along with -* TRIQS. If not, see . -* -*******************************************************************************/ -#include - -int cmp(const void *a, const void *b) -{ - return (**(const double **)a) < (**(const double **)b) ? -1 : 1; -} - -int icmp(const void *a, const void *b) -{ - return (**(const int **)a) - (**(const int **)b); -} - -void argsort(double *arr, int *inds, double **ptrs, const int n) -{ - int i; - - for (i=0; i < n; i++) - { - ptrs[i] = arr + i; - } - - qsort(ptrs, n, sizeof(double *), cmp); - - for (i=0; i < n; i++) - { - inds[i] = (int)(ptrs[i] - arr); - } -} - -void iargsort(int *iarr, int *inds, int **ptrs, const int n) -{ - int i; - - for (i=0; i < n; i++) - { - ptrs[i] = iarr + i; - } - - qsort(ptrs, n, sizeof(int *), icmp); - - for (i=0; i < n; i++) - { - inds[i] = (int)(ptrs[i] - iarr); - } -} - - diff --git a/c++/triqs_dft_tools/converters/vasp/argsort.hpp b/c++/triqs_dft_tools/converters/vasp/argsort.hpp deleted file mode 100644 index fd4ace4d0..000000000 --- a/c++/triqs_dft_tools/converters/vasp/argsort.hpp +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* -* -* This file is part of the ATM library. -* -* Copyright (C) 2010 by O. E. Peil -* -* TRIQS is free software: you can redistribute it and/or modify it under the -* terms of the GNU General Public License as published by the Free Software -* Foundation, either version 3 of the License, or (at your option) any later -* version. -* -* TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY -* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -* details. -* -* You should have received a copy of the GNU General Public License along with -* TRIQS. If not, see . -* -*******************************************************************************/ -#ifndef __ARGSORT_H__ -#define __ARGSORT_H__ - -void argsort(double *arr, int *inds, double **ptrs, const int n); -void iargsort(int *iarr, int *inds, int **ptrs, const int n); - -#endif diff --git a/c++/triqs_dft_tools/converters/vasp/dos_tetra3d.cpp b/c++/triqs_dft_tools/converters/vasp/dos_tetra3d.cpp deleted file mode 100644 index 0e4e74889..000000000 --- a/c++/triqs_dft_tools/converters/vasp/dos_tetra3d.cpp +++ /dev/null @@ -1,482 +0,0 @@ -/******************************************************************************* -* -* This file is part of the ATM library. -* -* Copyright (C) 2010 by O. E. Peil -* -* TRIQS is free software: you can redistribute it and/or modify it under the -* terms of the GNU General Public License as published by the Free Software -* Foundation, either version 3 of the License, or (at your option) any later -* version. -* -* TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY -* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -* details. -* -* You should have received a copy of the GNU General Public License along with -* TRIQS. If not, see . -* -*******************************************************************************/ -#include -#include -#include - -#include "argsort.hpp" -#include "dos_tetra3d.hpp" - -//#define __TETRA_DEBUG -#define __TETRA_ARRAY_VIEW - -using nda::array; -using nda::array_view; - -/*************************************************** - - Analytical tetrahedron method as described in -Lambin et al., PRB 29, 6, 3430 (1984). - -***************************************************/ - -/// Main function -//#ifdef __TETRA_ARRAY_VIEW -//void tet_dos3d(double en, array_view& eigk, -// array_view& itt, int ntet, -// array& cti); -//#else -//void tet_dos3d(double en, array& eigk, -// array& itt, int ntet, -// array& cti); -//#endif - - -/// Internal functions -int dos_corner_weights(double en, double *eigs, int *inds, double *ci); -int dos_tet_weights(double en, double *eigs, int *inds, double *ct); -int dos_reorder(double en, double *e, int *inds); - -static double F(double en, double e1, double e2, double e3, double e4); -static double K2(double en, double e1, double e2, double e3); -static double K1(double en, double e1, double e2); - -static void fun_dos_case1(double en, double *eigs, double *ci); -static void fun_dos_case2(double en, double *eigs, double *ci); -static void fun_dos_case3(double en, double *eigs, double *ci); - -static const int NUM_TET_CORNERS = 4; -static const std::complex I(0.0, 1.0); -static const double tol = 1e-8; - -/* - Returns corner contributions to the DOS of a band -*/ -#ifdef __TETRA_ARRAY_VIEW -array dos_tetra_weights_3d(array_view eigk, double en, array_view itt) -#else -array dos_tetra_weights_3d(array eigk, double en, array itt) -#endif -{ - int ntet; /// Number of tetrahedra -// Auxiliary variables and loop indices - - if (itt.shape()[0] != NUM_TET_CORNERS + 1) - { - NDA_RUNTIME_ERROR << " The first dimension of 'itt' must be equal to 5"; - } - - ntet = itt.shape()[1]; - - array cti(NUM_TET_CORNERS, ntet); // Corner weights to be returned - -// tet_dos3d(e, eigk, itt, ntet, cti); - -// -// Main algorithm (transferred from 'tet_dos3d()') -// - double eigs[4], ci[4]; - - int i, it, ik, inds[4]; -#ifdef __TETRA_DEBUG - double ct, ci_sum; -#endif - -// Loop over tetrahedra (triangles) - for (it = 0; it < ntet; it++) - { - for (i = 1; i < 5; i++) - { - ik = itt(i, it); - eigs[i - 1] = eigk(ik); - } - -// Corner weights for a single tetrahedron - dos_corner_weights(en, eigs, inds, ci); - -#ifdef __TETRA_DEBUG - for(i = 0, ci_sum = 0.0; i < 4; i++) - ci_sum += ci[i]; - - flag = dos_tet_weights(en, eigs, inds, &ct); - if(std::abs(ct - ci_sum) > tol) - { - std::cout << " *** Error in weights: it = " << it <<" flag = " << flag << ", en = " << en; - for(i = 0; i < 4; i++) - std::cout << ", e[" << i << "] = " << eigs[i]; - std::cout << ", c_diff = " << std::abs(ct - ci_sum) << std::endl; - - TRIQS_RUNTIME_ERROR << " Failed consistency check"; - } -#endif - - for(i = 0; i < 4; i++) - { - cti(inds[i], it) = ci[i]; - } - - } // it = 1, ntet - - return array_view(cti); -} - -//#ifdef __TETRA_ARRAY_VIEW -//void tet_dos3d(double en, array_view& eigk, -// array_view& itt, int ntet, -// array& cti) -//#else -//void tet_dos3d(double en, array& eigk, -// array& itt, int ntet, -// array& cti) -//#endif -//{ -// double eigs[4], ci[4]; -// -// int i, it, ik, inds[4], flag; -//#ifdef __TETRA_DEBUG -// double ct, ci_sum; -//#endif -// -//// Loop over tetrahedra (triangles) -// for (it = 0; it < ntet; it++) -// { -// for (i = 1; i < 5; i++) -// { -// ik = itt(i, it); -// eigs[i - 1] = eigk(ik); -// } -// -//// Corner weights for a single tetrahedron -// dos_corner_weights(en, eigs, inds, ci); -// -//#ifdef __TETRA_DEBUG -// for(i = 0, ci_sum = 0.0; i < 4; i++) -// ci_sum += ci[i]; -// -// flag = dos_tet_weights(en, eigs, inds, &ct); -// if(std::abs(ct - ci_sum) > tol) -// { -// std::cout << " *** Error in weights: it = " << it <<" flag = " << flag << ", en = " << en; -// for(i = 0; i < 4; i++) -// std::cout << ", e[" << i << "] = " << eigs[i]; -// std::cout << ", c_diff = " << std::abs(ct - ci_sum) << std::endl; -// return; -// } -//#endif -// -// for(i = 0; i < 4; i++) -// { -// cti(inds[i], it) = ci[i]; -// } -// -// } // it = 1, ntet -//} - -/// Corner contributions to DOS -int dos_corner_weights(double en, double *eigs, int *inds, - double *ci) -{ - int flag, i; -// Sort eigenvalues and obtain indices of the sorted array -// eigs: sorted eigenvalues -// inds: index map - flag = dos_reorder(en, eigs, inds); - - switch(flag) - { -// E1 <= E <= E2 - case 1: - fun_dos_case1(en, eigs, ci); - break; - -// E2 <= E <= E3 - case 2: - fun_dos_case2(en, eigs, ci); - break; - -// E3 <= E <= E4 - case 3: - fun_dos_case3(en, eigs, ci); - break; - -// E < E1 || E4 < E - case 4: - case 5: - for(i = 0; i < 4; i++) ci[i] = 0.0; - break; - -// E1 == E4 == E - case 6: - for(i = 0; i < 4; i++) ci[i] = 0.25; - break; - } - - return flag; -} - -/// Total (tetrahedron) contribution to DOS. -/// Here, it is calculated directly using an analytical formula. -/// This is mainly needed for debugging. -int dos_tet_weights(double en, double *eigs, int *inds, - double *ct) -{ - double e1, e2, e3, e4; - std::complex s; - int flag; - flag = dos_reorder(en, eigs, inds); - - e1 = eigs[0]; - e2 = eigs[1]; - e3 = eigs[2]; - e4 = eigs[3]; - - switch(flag) - { -// E1 <= E <= E2 - case 1: - if(std::abs(e2 - e1) > tol && std::abs(e3 - e1) > tol && std::abs(e4 - e1) > tol) - *ct = 3.0 * (en - e1) * (en - e1) / ((e2 - e1) * (e3 - e1) * (e4 - e1)); - else - { - s = fmin(std::abs(e1 - e2), std::abs(e3 - e1)); - s = fmin(std::abs(s), std::abs(e4 - e1)); - s /= 100.0; - s = fmax(std::abs(s), 1.0e-20) * I; - - *ct = 3.0 * std::real((en - e1 + s) * (en - e1 + s) / ((e2 - e1 + s) * (e3 - e1 + s) * (e4 - e1 + s))); - } - - break; - -// E2 <= E <= E3 - case 2: - if(std::abs(e4 - e2) > tol && std::abs(e3 - e2) > tol && std::abs(e4 - e1) > tol && std::abs(e3 - e1) > tol) - *ct = 3.0 * ( - (e3 - en) * (en - e2) / ((e4 - e2) * (e3 - e2) * (e3 - e1)) + - (e4 - en) * (en - e1) / ((e4 - e1) * (e4 - e2) * (e3 - e1))); - else - { - s = fmin(std::abs(e3 - e2), std::abs(e3 - e1)); - s = fmin(std::abs(s), std::abs(e4 - e1)); - s = fmin(std::abs(s), std::abs(e4 - e2)); - s /= 100.0; - s = fmax(std::abs(s), 1.0e-20) * I; - - *ct = 3.0 * std::real(( - (e3 - en + s) * (en - e2 + s) / ((e4 - e2 + s) * (e3 - e2 + s) * (e3 - e1 + s)) + - (e4 - en + s) * (en - e1 + s) / ((e4 - e1 + s) * (e4 - e2 + s) * (e3 - e1 + s)))); - } - break; - -// E3 <= E <= E4 - case 3: - if(std::abs(e4 - e2) > tol && std::abs(e4 - e3) > tol && std::abs(e4 - e1) > tol) - *ct = 3.0 * (e4 - en) * (e4 - en) / ((e4 - e1) * (e4 - e2) * (e4 - e3)); - else - { - s = fmin(std::abs(e4 - e2), std::abs(e4 - e1)); - s = fmin(std::abs(s), std::abs(e4 - e3)); - s /= 100.0; - s = fmax(std::abs(s), 1.0e-20) * I; - - *ct = 3.0 * std::real((e4 - en + s) * (e4 - en + s) / ((e4 - e1 + s) * (e4 - e2 + s) * (e4 - e3 + s))); - } - - break; - -// E < E1 || E4 < E - case 4: - case 5: - *ct = 0.0; - break; - -// E1 == E4 == E - case 6: - *ct = 1.0; - break; - } - - return flag; -} - -/// Sorts eigenvalues and also determines eigenvalue degeneracies. -/// Returns a case number corresponding to a combination of degeneracies. -int dos_reorder(double en, double *e, int *inds) -{ - double *ptrs[4], e_tmp[4]; - int i; - - for(i = 0; i < 4; i++) - e_tmp[i] = e[i]; - - argsort(e_tmp, inds, ptrs, 4); - - for(i = 0; i < 4; i++) - e[i] = e_tmp[inds[i]]; - - if((e[0] <= en && en <= e[3]) && std::abs(e[3] - e[0]) < tol) return 6; - if(e[0] <= en && en <= e[1]) return 1; - if(e[1] <= en && en <= e[2]) return 2; - if(e[2] <= en && en <= e[3]) return 3; - if(en < e[0]) return 4; - if(e[3] < en) return 5; - return -1; -} - -static void fun_dos_case1(double en, double *eigs, double *ci) -{ - double e1, e2, e3, e4; - - e1 = eigs[0]; - e2 = eigs[1]; - e3 = eigs[2]; - e4 = eigs[3]; - - ci[0] = K2(en, e1, e2, e4) * F(en, e2, e1, e1, e3) + - K2(en, e1, e2, e3) * F(en, e3, e1, e1, e4) + - K2(en, e1, e3, e4) * F(en, e4, e1, e1, e2); - - ci[1] = -K1(en, e1, e2) * F(en, e1, e1, e3, e4); - - ci[2] = -K1(en, e1, e3) * F(en, e1, e1, e2, e4); - - ci[3] = -K1(en, e1, e4) * F(en, e1, e1, e2, e3); -} - -static void fun_dos_case2(double en, double *eigs, double *ci) -{ - double e1, e2, e3, e4; - - e1 = eigs[0]; - e2 = eigs[1]; - e3 = eigs[2]; - e4 = eigs[3]; - - ci[0] = 0.5 * (K1(en, e3, e1) * ( - F(en, e3, e2, e2, e4) + - F(en, e4, e1, e2, e4) + - F(en, e3, e1, e2, e4)) + - K1(en, e4, e1) * ( - F(en, e4, e1, e2, e3) + - F(en, e4, e2, e2, e3) + - F(en, e3, e1, e2, e3))); - - ci[1] = 0.5 * (K1(en, e3, e2) * ( - F(en, e3, e2, e1, e4) + - F(en, e4, e2, e1, e4) + - F(en, e3, e1, e1, e4)) + - K1(en, e4, e2) * ( - F(en, e3, e2, e1, e3) + - F(en, e4, e1, e1, e3) + - F(en, e4, e2, e1, e3))); - - ci[2] = 0.5 * (-K1(en, e2, e3) * ( - F(en, e3, e2, e1, e4) + - F(en, e4, e2, e1, e4) + - F(en, e3, e1, e1, e4)) - - K1(en, e1, e3) * ( - F(en, e3, e2, e2, e4) + - F(en, e4, e1, e2, e4) + - F(en, e3, e1, e2, e4))); - - ci[3] = 0.5 * (-K1(en, e2, e4) * ( - F(en, e3, e2, e1, e3) + - F(en, e4, e1, e1, e3) + - F(en, e4, e2, e1, e3)) - - K1(en, e1, e4) * ( - F(en, e4, e1, e2, e3) + - F(en, e4, e2, e2, e3) + - F(en, e3, e1, e2, e3))); -} - -static void fun_dos_case3(double en, double *eigs, double *ci) -{ - double e1, e2, e3, e4; - - e1 = eigs[0]; - e2 = eigs[1]; - e3 = eigs[2]; - e4 = eigs[3]; - - ci[0] = K1(en, e4, e1) * F(en, e4, e4, e2, e3); - - ci[1] = K1(en, e4, e2) * F(en, e4, e4, e1, e3); - - ci[2] = K1(en, e4, e3) * F(en, e4, e4, e1, e2); - - ci[3] = -K2(en, e4, e3, e1) * F(en, e4, e3, e2, e4) - - K2(en, e4, e2, e3) * F(en, e4, e2, e1, e4) - - K2(en, e4, e1, e2) * F(en, e4, e1, e3, e4); - -} - -static double F(double en, double e1, double e2, double e3, double e4) -{ - std::complex s; - - if(std::abs(e1 - e3) > tol && std::abs(e4 - e2) > tol) - return (e1 - en) * (en - e2) / ((e1 - e3) * (e4 - e2)); - else - { -// Regularization to avoid division by zero - s = fmin(std::abs(e3 - e1), std::abs(e4 - e2)); - s /= 100.0; - s = fmax(std::abs(s), 1.0e-20) * I; - - return std::real((e1 - en + s) * (en - e2 + s) / ((e1 - e3 + s) * (e4 - e2 + s))); - } -} - -static double K2(double en, double e1, double e2, double e3) -{ - std::complex s; - - if(std::abs(e1 - e3) > tol && std::abs(e1 - e2) > tol) - return (en - e1) / ((e2 - e1) * (e3 - e1)); - else - { -// Regularization to avoid division by zero - s = fmin(std::abs(e3 - e1), std::abs(e1 - e2)); - s /= 100.0; - s = fmax(std::abs(s), 1.0e-20) * I; - - return std::real((en - e1 + s) / ((e2 - e1 + s) * (e3 - e1 + s))); - } -} - -static double K1(double en, double e1, double e2) -{ - std::complex s; - - if(std::abs(e1 - e2) > tol) - return (e1 - en) / ((e2 - e1) * (e2 - e1)); - else - { -// Regularization to avoid division by zero - s = std::abs(e1 - e2); - s /= 100.0; - s = fmax(std::abs(s), 1.0e-20) * I; - - return std::real((e1 - en + s) / ((e2 - e1 + s) * (e2 - e1 + s))); - } -} - - diff --git a/c++/triqs_dft_tools/converters/vasp/dos_tetra3d.hpp b/c++/triqs_dft_tools/converters/vasp/dos_tetra3d.hpp deleted file mode 100644 index ffc16964e..000000000 --- a/c++/triqs_dft_tools/converters/vasp/dos_tetra3d.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* -* -* This file is part of the ATM library. -* -* Copyright (C) 2010 by O. E. Peil -* -* TRIQS is free software: you can redistribute it and/or modify it under the -* terms of the GNU General Public License as published by the Free Software -* Foundation, either version 3 of the License, or (at your option) any later -* version. -* -* TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY -* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -* details. -* -* You should have received a copy of the GNU General Public License along with -* TRIQS. If not, see . -* -*******************************************************************************/ -#pragma once - -#include - - -/// DOS of a band by analytical tetrahedron method -/// -/// Returns corner weights for all tetrahedra for a given band and real energy. -nda::array -dos_tetra_weights_3d(nda::array_view eigk, /// Band energies for each k-point - double en, /// Energy at which DOS weights are to be calculated - nda::array_view itt /// Tetrahedra defined by k-point indices -); -//array -//dos_tetra_weights_3d(array eigk, /// Band energies for each k-point -// double e, /// Energy at which DOS weights are to be calculated -// array itt /// Tetrahedra defined by k-point indices -//); -int dos_corner_weights(double en, double *eigs, int *inds, double *ci); -int dos_tet_weights(double en, double *eigs, int *inds, double *ct); -int dos_reorder(double en, double *e, int *inds); - - - diff --git a/c++/triqs_dft_tools/converters/vasp/makefile.linux b/c++/triqs_dft_tools/converters/vasp/makefile.linux deleted file mode 100644 index cc21c0ea6..000000000 --- a/c++/triqs_dft_tools/converters/vasp/makefile.linux +++ /dev/null @@ -1,4 +0,0 @@ - -c_atm_mod.so: argsort.c argsort.h dos_tetra3d.c dos_tetra3d.h - python setup.py build_ext --inplace - diff --git a/c++/triqs_dft_tools/converters/vasp/setup.py b/c++/triqs_dft_tools/converters/vasp/setup.py deleted file mode 100644 index 90334b33a..000000000 --- a/c++/triqs_dft_tools/converters/vasp/setup.py +++ /dev/null @@ -1,33 +0,0 @@ - -################################################################################ -# -# TRIQS: a Toolbox for Research in Interacting Quantum Systems -# -# Copyright (C) 2011 by M. Ferrero, O. Parcollet -# -# DFT tools: Copyright (C) 2011 by M. Aichhorn, L. Pourovskii, V. Vildosola -# -# PLOVasp: Copyright (C) 2015 by O. E. Peil -# -# TRIQS is free software: you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -# details. -# -# You should have received a copy of the GNU General Public License along with -# TRIQS. If not, see . -# -################################################################################ -from distutils.core import setup, Extension -import numpy - -c_atm_dos_mod = Extension('c_atm_dos', sources=['dos_tetra3d.c', 'argsort.c'], - include_dirs=[numpy.get_include()]) - -setup(ext_modules=[c_atm_dos_mod]) - diff --git a/c++/triqs_dft_tools/triqs_dft_tools.hpp b/c++/triqs_dft_tools/triqs_dft_tools.hpp deleted file mode 100644 index ee70a5dc8..000000000 --- a/c++/triqs_dft_tools/triqs_dft_tools.hpp +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once -#include "./converters/vasp.hpp" - diff --git a/python/triqs_dft_tools/CMakeLists.txt b/python/triqs_dft_tools/CMakeLists.txt index 753f31455..04e320b5b 100644 --- a/python/triqs_dft_tools/CMakeLists.txt +++ b/python/triqs_dft_tools/CMakeLists.txt @@ -3,7 +3,7 @@ configure_file(version.py.in version.py) # All Python files. Copy them in the build dir to have a complete package for the tests. file(GLOB_RECURSE python_sources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.py) -file(GLOB_RECURSE wrap_generators RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *_desc.py) +#file(GLOB_RECURSE wrap_generators RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *_desc.py) list(REMOVE_ITEM python_sources "${wrap_generators}") foreach(file ${python_sources}) configure_file(${file} ${file} COPYONLY) diff --git a/python/triqs_dft_tools/converters/plovasp/atm_desc.py b/python/triqs_dft_tools/converters/plovasp/atm_desc.py deleted file mode 100644 index 0dc18d394..000000000 --- a/python/triqs_dft_tools/converters/plovasp/atm_desc.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated automatically using the command : -# c++2py.py -m atm -o atm --moduledoc "Analytical Tetrahedron Method for DOS" ../../../../c++/triqs_dft_tools/converters/vasp/dos_tetra3d.hpp -from cpp2py.wrap_generator import * - -# The module -module = module_(full_name = "atm", doc = "Analytical Tetrahedron Method for calculating DOS", app_name = "atm") - -# All the triqs C++/Python modules - -# Add here all includes beyond what is automatically included by the triqs modules -module.add_include("triqs_dft_tools/converters/vasp/dos_tetra3d.hpp") - -# Add here anything to add in the C++ code at the start, e.g. namespace using -module.add_preamble(""" -#include -using namespace nda; -""") - -module.add_function ("array dos_tetra_weights_3d (array_view eigk, double en, array_view itt)", doc = """DOS of a band by analytical tetrahedron method\n\n Returns corner weights for all tetrahedra for a given band and real energy.""") - -module.generate_code() diff --git a/python/triqs_dft_tools/converters/plovasp/lintetra.py b/python/triqs_dft_tools/converters/plovasp/lintetra.py new file mode 100644 index 000000000..65177fc95 --- /dev/null +++ b/python/triqs_dft_tools/converters/plovasp/lintetra.py @@ -0,0 +1,139 @@ +import numpy as np + +_TOL = 1e-8 + +# Ensure strictly positive imaginary part with minimal scale +_regularize = lambda z : 1j * max(float(z), 1.0e-20) / 100.0 + +def _F(en, e1, e2, e3, e4): + if abs(e1 - e3) > _TOL and abs(e4 - e2) > _TOL: return (e1 - en) * (en - e2) / ((e1 - e3) * (e4 - e2)) + s = _regularize(min(abs(e3 - e1), abs(e4 - e2))) + num = (e1 - en + s) * (en - e2 + s) + den = (e1 - e3 + s) * (e4 - e2 + s) + return float(np.real(num / den)) + +def _K2(en, e1, e2, e3): + if abs(e1 - e3) > _TOL and abs(e1 - e2) > _TOL: return (en - e1) / ((e2 - e1) * (e3 - e1)) + s = _regularize(min(abs(e3 - e1), abs(e1 - e2))) + num = (en - e1 + s) + den = (e2 - e1 + s) * (e3 - e1 + s) + return float(np.real(num / den)) + +def _K1(en, e1, e2): + if abs(e1 - e2) > _TOL: return (e1 - en) / ((e2 - e1) * (e2 - e1)) + s = _regularize(abs(e1 - e2)) + num = (e1 - en + s) + den = (e2 - e1 + s) * (e2 - e1 + s) + return float(np.real(num / den)) + +def _dos_reorder(en, e): + # Returns (flag, order, sorted_e) + order = np.argsort(e) + se = e[order].copy() + + if (se[0] <= en <= se[3]) and abs(se[3] - se[0]) < _TOL: return 6, order, se + if se[0] <= en <= se[1]: return 1, order, se + if se[1] <= en <= se[2]: return 2, order, se + if se[2] <= en <= se[3]: return 3, order, se + if en < se[0]: return 4, order, se + if se[3] < en: return 5, order, se + + return -1, order, se + +def _fun_case1(en, e): + e1, e2, e3, e4 = e + ci = np.zeros(4, dtype=float) + ci[0] = _K2(en, e1, e2, e4) * _F(en, e2, e1, e1, e3) \ + + _K2(en, e1, e2, e3) * _F(en, e3, e1, e1, e4) \ + + _K2(en, e1, e3, e4) * _F(en, e4, e1, e1, e2) + ci[1] = -_K1(en, e1, e2) * _F(en, e1, e1, e3, e4) + ci[2] = -_K1(en, e1, e3) * _F(en, e1, e1, e2, e4) + ci[3] = -_K1(en, e1, e4) * _F(en, e1, e1, e2, e3) + return ci + +def _fun_case2(en, e): + e1, e2, e3, e4 = e + ci = np.zeros(4, dtype=float) + ci[0] = 0.5 * (_K1(en, e3, e1) * ( + _F(en, e3, e2, e2, e4) + + _F(en, e4, e1, e2, e4) + + _F(en, e3, e1, e2, e4)) + + _K1(en, e4, e1) * ( + _F(en, e4, e1, e2, e3) + + _F(en, e4, e2, e2, e3) + + _F(en, e3, e1, e2, e3))) + ci[1] = 0.5 * (_K1(en, e3, e2) * ( + _F(en, e3, e2, e1, e4) + + _F(en, e4, e2, e1, e4) + + _F(en, e3, e1, e1, e4)) + + _K1(en, e4, e2) * ( + _F(en, e3, e2, e1, e3) + + _F(en, e4, e1, e1, e3) + + _F(en, e4, e2, e1, e3))) + ci[2] = 0.5 * (-_K1(en, e2, e3) * ( + _F(en, e3, e2, e1, e4) + + _F(en, e4, e2, e1, e4) + + _F(en, e3, e1, e1, e4)) - + _K1(en, e1, e3) * ( + _F(en, e3, e2, e2, e4) + + _F(en, e4, e1, e2, e4) + + _F(en, e3, e1, e2, e4))) + ci[3] = 0.5 * (-_K1(en, e2, e4) * ( + _F(en, e3, e2, e1, e3) + + _F(en, e4, e1, e1, e3) + + _F(en, e4, e2, e1, e3)) - + _K1(en, e1, e4) * ( + _F(en, e4, e1, e2, e3) + + _F(en, e4, e2, e2, e3) + + _F(en, e3, e1, e2, e3))) + return ci + +def _fun_case3(en, e): + e1, e2, e3, e4 = e + ci = np.zeros(4, dtype=float) + ci[0] = _K1(en, e4, e1) * _F(en, e4, e4, e2, e3) + ci[1] = _K1(en, e4, e2) * _F(en, e4, e4, e1, e3) + ci[2] = _K1(en, e4, e3) * _F(en, e4, e4, e1, e2) + ci[3] = -_K2(en, e4, e3, e1) * _F(en, e4, e3, e2, e4) \ + -_K2(en, e4, e2, e3) * _F(en, e4, e2, e1, e4) \ + -_K2(en, e4, e1, e2) * _F(en, e4, e1, e3, e4) + return ci + +def _dos_corner_weights(en, e): + flag, order, se = _dos_reorder(en, e) + if flag == 1: ci = _fun_case1(en, se) + elif flag == 2: ci = _fun_case2(en, se) + elif flag == 3: ci = _fun_case3(en, se) + elif flag in (4, 5): + ci = np.zeros(4, dtype=float) + elif flag == 6: + ci = np.full(4, 0.25, dtype=float) + else: raise ValueError("Unexpected flag in tetra reorder") + return flag, order, ci + +def dos_tetra_weights_3d(eigenvalues, energy, k_points): + """ + Pure-Python version of dos_tetra_weights_3d. + Inputs: + - eigenvalues: 1D ndarray, band energies for each k-point (one band) + - energy: float, evaluation energy + - k_points: int ndarray with shape (5, ntet); corners are rows 1..4 + Returns: + - cti: float ndarray (4, ntet), corner weights per tetrahedron + """ + eigk = np.asarray(eigenvalues, dtype=float) + itt = np.asarray(k_points, dtype=np.int64) + if itt.ndim != 2 or itt.shape[0] != 5: + raise ValueError("k_points must have shape (5, ntet)") + ntet = itt.shape[1] + cti = np.zeros((4, ntet), dtype=float) + + for it in range(ntet): + # rows 1..4 index the four corners + corners = itt[1:5, it].astype(np.int64) + e = eigk[corners].astype(float).copy() + _, order, ci = _dos_corner_weights(energy, e) + # Map sorted corner weights back to original corner ordering + # order[j] is original corner index 0..3 for sorted position j + cti[order, it] = ci + return cti diff --git a/python/triqs_dft_tools/converters/plovasp/proj_shell.py b/python/triqs_dft_tools/converters/plovasp/proj_shell.py index eca79bfc8..6f9305a39 100644 --- a/python/triqs_dft_tools/converters/plovasp/proj_shell.py +++ b/python/triqs_dft_tools/converters/plovasp/proj_shell.py @@ -34,7 +34,7 @@ import logging import numpy as np -from . import atm +from .lintetra import dos_tetra_weights_3d np.set_printoptions(suppress=True) @@ -437,7 +437,8 @@ def density_of_states(self, el_struct, emesh): for ib, eigk in enumerate(el_struct.eigvals[:, self.ib_min:self.ib_max+1, isp].T): for ie, e in enumerate(emesh): eigk_ef = eigk - el_struct.efermi - cti = atm.dos_tetra_weights_3d(eigk_ef, e, itt) + #cti = atm.dos_tetra_weights_3d(eigk_ef, e, itt) + cti = atm_py.dos_tetra_weights_3d(eigk_ef, e, itt) for im in range(nlm): for io in range(nion): dos[ie, isp, io, im] += np.sum((cti * w_k[itt[1:, :], ib, isp, io, im].real).sum(0) * itt[0, :]) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 19467c6a0..9d95d9455 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,4 @@ -add_subdirectory(c++) +#add_subdirectory(c++) if(PythonSupport) add_subdirectory(python) diff --git a/test/c++/CMakeLists.txt b/test/c++/CMakeLists.txt deleted file mode 100644 index 14ac6ae1f..000000000 --- a/test/c++/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# Copy h5 files to binary dir -file(GLOB_RECURSE all_h5_ref_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.ref.h5) -foreach(file ${all_h5_ref_files}) - configure_file(${file} ${file} COPYONLY) -endforeach() - -# List of all tests -file(GLOB_RECURSE all_tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) - -foreach(test ${all_tests}) - get_filename_component(test_name ${test} NAME_WE) - get_filename_component(test_dir ${test} DIRECTORY) - add_executable(${test_name} ${test}) - target_link_libraries(${test_name} ${PROJECT_NAME}::${PROJECT_NAME}_c ${PROJECT_NAME}_warnings gtest_main) - set_property(TARGET ${test_name} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${test_dir}) - add_test(NAME ${test_name} COMMAND ${test_name} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${test_dir}) - # Run clang-tidy if found - if(CLANG_TIDY_EXECUTABLE) - set_target_properties(${test_name} PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE}") - endif() - # Run cppcheck if found - if(CPPCHECK_EXECUTABLE) - add_custom_command( - TARGET ${test_name} - COMMAND ${CPPCHECK_EXECUTABLE} - --enable=warning,style,performance,portability - --std=c++20 - --template=gcc - --verbose - --force - --quiet - ${CMAKE_CURRENT_SOURCE_DIR}/${test} - ) - endif() -endforeach() diff --git a/test/c++/converters/vasp/reorder_flag.cpp b/test/c++/converters/vasp/reorder_flag.cpp deleted file mode 100644 index 293b75b8b..000000000 --- a/test/c++/converters/vasp/reorder_flag.cpp +++ /dev/null @@ -1,23 +0,0 @@ - -#include "testing.hpp" - -int main() -{ - double e[4], en; - int inds[4]; - int flag, flag_should; - - e[0] = -1.5; - e[1] = -1.309017; - e[2] = -1.0; - e[3] = -0.5; - - en = -0.55; - printf("\n Test case 1\n\n"); - - flag = dos_reorder(en, e, inds); - flag_should = 3; - - if(check_reorder_flag(flag, flag_should)) return 1; -} - diff --git a/test/c++/converters/vasp/reorder_inds.cpp b/test/c++/converters/vasp/reorder_inds.cpp deleted file mode 100644 index 2e4df33ad..000000000 --- a/test/c++/converters/vasp/reorder_inds.cpp +++ /dev/null @@ -1,27 +0,0 @@ - -#include "testing.hpp" - -int main() -{ - double e[4], en; - int inds[4], inds_should[4]; - int flag; - - e[0] = -1.5; - e[1] = -1.0; - e[2] = -1.309017; - e[3] = -0.5; - - en = -0.55; - printf("\n Test case 2\n\n"); - - flag = dos_reorder(en, e, inds); - - inds_should[0] = 0; - inds_should[1] = 2; - inds_should[2] = 1; - inds_should[3] = 3; - - if(check_reorder_inds(inds, inds_should)) return 1; -} - diff --git a/test/c++/converters/vasp/testing.hpp b/test/c++/converters/vasp/testing.hpp deleted file mode 100644 index 79ff99e47..000000000 --- a/test/c++/converters/vasp/testing.hpp +++ /dev/null @@ -1,91 +0,0 @@ - -#include -#include -#include - -#define ASSERT(cond, message) if(!(cond)) { \ - printf("*** Fail: %s\n", message); return 1;} - -// -// Functions defined in 'atm_c' library -// -extern int dos_corner_weights(double en, double *eigs, int *inds, - double *ci); -extern int dos_tet_weights(double en, double *eigs, int *inds, - double *ct); -extern int dos_reorder(double en, double *e, int *inds); - - -int check_reorder_flag(int flag, int flag_should); -int check_reorder_inds(int *inds, int *inds_should); -int check_weights_result(double *res, double *r_should); - -// -// Test templates -// -int check_reorder_flag(int flag, int flag_should) -{ - char mess[128]; - sprintf(mess, "Reorder flag should be %d and not %d", flag_should, flag); - ASSERT(flag == flag_should, mess); - return 0; -} - -int check_reorder_inds(int *inds, int *inds_should) -{ - char mess[128], tmp[128], numb[128]; - int i, flag; - - strcpy(mess, "Inds should be "); - numb[0] = '\0'; - flag = 1; - for(i = 0; i < 4; i++) - { - if(inds_should[i] != inds[i]) flag = 0; - sprintf(tmp, " %d", inds_should[i]); - strcat(numb, tmp); - } - strcat(mess, numb); - strcat(mess, " and not"); - numb[0] = '\0'; - for(i = 0; i < 4; i++) - { - sprintf(tmp, " %d", inds[i]); - strcat(numb, tmp); - } - strcat(mess, numb); - - ASSERT(flag, mess); - - return 0; -} - -int check_weights_result(double *res, double *r_should) -{ - const double tol = 1e-14; - int i, flag; - char mess[128], tmp[128]; - - flag = 1; - for(i = 0; i < 4; i++) - { - if(fabs(r_should[i] - res[i]) > tol) - { - flag = 0; - break; - } - } - strcpy(mess, "Success"); - if(!flag) - { - sprintf(mess, "res[%d] should be %20.15lf", i, r_should[i]); - sprintf(tmp, " and not %20.15lf", res[i]); - strcat(mess, tmp); - } - - ASSERT(flag, mess); - - return 0; -} - - diff --git a/test/c++/converters/vasp/tet_weights.cpp b/test/c++/converters/vasp/tet_weights.cpp deleted file mode 100644 index 196786ae2..000000000 --- a/test/c++/converters/vasp/tet_weights.cpp +++ /dev/null @@ -1,33 +0,0 @@ - -#include "testing.hpp" - -int main() -{ - double e[4], en, ci_sum, ct, res[4]; - int inds[4]; - int i; - char mess[128]; - - e[0] = -1.5; - e[1] = -1.309017; - e[2] = -1.0; - e[3] = -0.5; - - en = -0.55; - printf("\n Test case 2\n\n"); - - dos_corner_weights(en, e, inds, res); - dos_tet_weights(en, e, inds, &ct); - - for(i = 0, ci_sum = 0.0; i < 4; i++) - { - printf(" res[%d] = %20.15lf\n", i, res[i]); - ci_sum += res[i]; - } - - printf(" Difference: %le\n", fabs(ci_sum - ct)); - - sprintf(mess, "Difference between 'ci_sum' and 'ct' is too large"); - ASSERT(fabs(ci_sum - ct) < 1e-12, mess); -} - diff --git a/test/c++/converters/vasp/weights1.cpp b/test/c++/converters/vasp/weights1.cpp deleted file mode 100644 index b04fa2970..000000000 --- a/test/c++/converters/vasp/weights1.cpp +++ /dev/null @@ -1,27 +0,0 @@ - -#include "testing.hpp" - -int main() -{ - double e[4], en, res[4], r_should[4]; - int inds[4]; - int flag; - - e[0] = -1.5; - e[1] = -1.309017; - e[2] = -1.0; - e[3] = -0.5; - - en = -0.55; - printf("\n Test case 4\n\n"); - - dos_corner_weights(en, e, inds, res); - - r_should[0] = 0.000309016992226; - r_should[1] = 0.000381966005939; - r_should[2] = 0.000618033984453; - r_should[3] = 0.017232002550965; - - if(check_weights_result(res, r_should)) return 1; -} - diff --git a/test/python/plovasp/atm/test_atm.py b/test/python/plovasp/atm/test_atm.py index 864d93b8e..4d9f30299 100644 --- a/test/python/plovasp/atm/test_atm.py +++ b/test/python/plovasp/atm/test_atm.py @@ -2,7 +2,7 @@ import os import numpy as np -from triqs_dft_tools.converters.plovasp.atm import dos_tetra_weights_3d +from triqs_dft_tools.converters.plovasp.lintetra import dos_tetra_weights_3d import mytest ################################################################################ From 628d1e330f5139a4323a439ac68097bc6d76f721 Mon Sep 17 00:00:00 2001 From: the-hampel Date: Wed, 5 Nov 2025 16:55:55 +0100 Subject: [PATCH 2/7] [build] remove export cmake command since no c++ code is wrapped anymore --- share/cmake/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/share/cmake/CMakeLists.txt b/share/cmake/CMakeLists.txt index c845b7b4d..61f4da427 100644 --- a/share/cmake/CMakeLists.txt +++ b/share/cmake/CMakeLists.txt @@ -7,4 +7,3 @@ install( DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) -install(EXPORT ${PROJECT_NAME}-targets NAMESPACE ${PROJECT_NAME}:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) From c197df36324b934fbae3388e1ee73ba0f324383c Mon Sep 17 00:00:00 2001 From: the-hampel Date: Thu, 6 Nov 2025 10:10:26 +0100 Subject: [PATCH 3/7] [bug] fix used module for dos_tetra_weights_3d --- python/triqs_dft_tools/converters/plovasp/proj_shell.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/triqs_dft_tools/converters/plovasp/proj_shell.py b/python/triqs_dft_tools/converters/plovasp/proj_shell.py index 6f9305a39..2e5aeb882 100644 --- a/python/triqs_dft_tools/converters/plovasp/proj_shell.py +++ b/python/triqs_dft_tools/converters/plovasp/proj_shell.py @@ -437,8 +437,7 @@ def density_of_states(self, el_struct, emesh): for ib, eigk in enumerate(el_struct.eigvals[:, self.ib_min:self.ib_max+1, isp].T): for ie, e in enumerate(emesh): eigk_ef = eigk - el_struct.efermi - #cti = atm.dos_tetra_weights_3d(eigk_ef, e, itt) - cti = atm_py.dos_tetra_weights_3d(eigk_ef, e, itt) + cti = dos_tetra_weights_3d(eigk_ef, e, itt) for im in range(nlm): for io in range(nion): dos[ie, isp, io, im] += np.sum((cti * w_k[itt[1:, :], ib, isp, io, im].real).sum(0) * itt[0, :]) From 0e8396269659fd84d00d276c8d9dd78e666d43c0 Mon Sep 17 00:00:00 2001 From: the-hampel Date: Thu, 6 Nov 2025 12:00:22 +0100 Subject: [PATCH 4/7] [feat] optimize tetrahedron integration for numpy --- .../converters/plovasp/lintetra.py | 349 +++++++++++------- 1 file changed, 223 insertions(+), 126 deletions(-) diff --git a/python/triqs_dft_tools/converters/plovasp/lintetra.py b/python/triqs_dft_tools/converters/plovasp/lintetra.py index 65177fc95..c96af5956 100644 --- a/python/triqs_dft_tools/converters/plovasp/lintetra.py +++ b/python/triqs_dft_tools/converters/plovasp/lintetra.py @@ -2,138 +2,235 @@ _TOL = 1e-8 -# Ensure strictly positive imaginary part with minimal scale -_regularize = lambda z : 1j * max(float(z), 1.0e-20) / 100.0 +def _regularize_scalar(value): + """Regularize a scalar to avoid numerical underflow or division by zero.""" + return max(float(value), 1.0e-20) / 100.0 -def _F(en, e1, e2, e3, e4): - if abs(e1 - e3) > _TOL and abs(e4 - e2) > _TOL: return (e1 - en) * (en - e2) / ((e1 - e3) * (e4 - e2)) - s = _regularize(min(abs(e3 - e1), abs(e4 - e2))) - num = (e1 - en + s) * (en - e2 + s) +def _select(mask, *arrays): + """Helper to select masked values for multiple arrays efficiently.""" + idx = np.nonzero(mask)[0] + return idx, [a[idx] for a in arrays] + +# === Auxiliary numerical functions (formerly F, K1, K2) === + +def _stable_fraction_F(e_eval, e1, e2, e3, e4): + """ + Stable evaluation of the F-term used in tetrahedron DOS integration. + + Parameters + ---------- + e_eval : float or ndarray + Evaluation energy. + e1, e2, e3, e4 : ndarray + Corner energies of the tetrahedron. + + Returns + ------- + ndarray + Evaluated F-term. + """ + e1, e2, e3, e4, e_eval = map(np.asarray, (e1, e2, e3, e4, e_eval)) + mask = (np.abs(e1 - e3) > _TOL) & (np.abs(e4 - e2) > _TOL) + safe_val = ((e1 - e_eval) * (e_eval - e2)) / ((e1 - e3) * (e4 - e2)) + + s_real = np.maximum(np.minimum(np.abs(e3 - e1), np.abs(e4 - e2)), 1.0e-20) / 100.0 + s = 1j * s_real + num = (e1 - e_eval + s) * (e_eval - e2 + s) den = (e1 - e3 + s) * (e4 - e2 + s) - return float(np.real(num / den)) + fallback = (num / den).real + return np.where(mask, safe_val, fallback.astype(np.float64)) + + +def _stable_fraction_K1(e_eval, e1, e2): + """ + Stable evaluation of the first K-term used in tetrahedron DOS integration. + + Parameters + ---------- + e_eval : float or ndarray + Evaluation energy. + e1, e2 : ndarray + Corner energies of the tetrahedron. -def _K2(en, e1, e2, e3): - if abs(e1 - e3) > _TOL and abs(e1 - e2) > _TOL: return (en - e1) / ((e2 - e1) * (e3 - e1)) - s = _regularize(min(abs(e3 - e1), abs(e1 - e2))) - num = (en - e1 + s) + Returns + ------- + ndarray + Evaluated K1-term. + """ + e1, e2, e_eval = map(np.asarray, (e1, e2, e_eval)) + mask = np.abs(e1 - e2) > _TOL + safe_val = (e1 - e_eval) / ((e2 - e1) ** 2) + + s_real = np.maximum(np.abs(e1 - e2), 1.0e-20) / 100.0 + s = 1j * s_real + num = e1 - e_eval + s + den = (e2 - e1 + s) ** 2 + fallback = (num / den).real + return np.where(mask, safe_val, fallback.astype(np.float64)) + + +def _stable_fraction_K2(e_eval, e1, e2, e3): + """ + Stable evaluation of the second K-term used in tetrahedron DOS integration. + + Parameters + ---------- + e_eval : float or ndarray + Evaluation energy. + e1, e2, e3 : ndarray + Corner energies of the tetrahedron. + + Returns + ------- + ndarray + Evaluated K2-term. + """ + e1, e2, e3, e_eval = map(np.asarray, (e1, e2, e3, e_eval)) + mask = (np.abs(e1 - e3) > _TOL) & (np.abs(e1 - e2) > _TOL) + safe_val = (e_eval - e1) / ((e2 - e1) * (e3 - e1)) + + s_real = np.maximum(np.minimum(np.abs(e3 - e1), np.abs(e1 - e2)), 1.0e-20) / 100.0 + s = 1j * s_real + num = e_eval - e1 + s den = (e2 - e1 + s) * (e3 - e1 + s) - return float(np.real(num / den)) - -def _K1(en, e1, e2): - if abs(e1 - e2) > _TOL: return (e1 - en) / ((e2 - e1) * (e2 - e1)) - s = _regularize(abs(e1 - e2)) - num = (e1 - en + s) - den = (e2 - e1 + s) * (e2 - e1 + s) - return float(np.real(num / den)) - -def _dos_reorder(en, e): - # Returns (flag, order, sorted_e) - order = np.argsort(e) - se = e[order].copy() - - if (se[0] <= en <= se[3]) and abs(se[3] - se[0]) < _TOL: return 6, order, se - if se[0] <= en <= se[1]: return 1, order, se - if se[1] <= en <= se[2]: return 2, order, se - if se[2] <= en <= se[3]: return 3, order, se - if en < se[0]: return 4, order, se - if se[3] < en: return 5, order, se - - return -1, order, se - -def _fun_case1(en, e): - e1, e2, e3, e4 = e - ci = np.zeros(4, dtype=float) - ci[0] = _K2(en, e1, e2, e4) * _F(en, e2, e1, e1, e3) \ - + _K2(en, e1, e2, e3) * _F(en, e3, e1, e1, e4) \ - + _K2(en, e1, e3, e4) * _F(en, e4, e1, e1, e2) - ci[1] = -_K1(en, e1, e2) * _F(en, e1, e1, e3, e4) - ci[2] = -_K1(en, e1, e3) * _F(en, e1, e1, e2, e4) - ci[3] = -_K1(en, e1, e4) * _F(en, e1, e1, e2, e3) - return ci - -def _fun_case2(en, e): - e1, e2, e3, e4 = e - ci = np.zeros(4, dtype=float) - ci[0] = 0.5 * (_K1(en, e3, e1) * ( - _F(en, e3, e2, e2, e4) + - _F(en, e4, e1, e2, e4) + - _F(en, e3, e1, e2, e4)) + - _K1(en, e4, e1) * ( - _F(en, e4, e1, e2, e3) + - _F(en, e4, e2, e2, e3) + - _F(en, e3, e1, e2, e3))) - ci[1] = 0.5 * (_K1(en, e3, e2) * ( - _F(en, e3, e2, e1, e4) + - _F(en, e4, e2, e1, e4) + - _F(en, e3, e1, e1, e4)) + - _K1(en, e4, e2) * ( - _F(en, e3, e2, e1, e3) + - _F(en, e4, e1, e1, e3) + - _F(en, e4, e2, e1, e3))) - ci[2] = 0.5 * (-_K1(en, e2, e3) * ( - _F(en, e3, e2, e1, e4) + - _F(en, e4, e2, e1, e4) + - _F(en, e3, e1, e1, e4)) - - _K1(en, e1, e3) * ( - _F(en, e3, e2, e2, e4) + - _F(en, e4, e1, e2, e4) + - _F(en, e3, e1, e2, e4))) - ci[3] = 0.5 * (-_K1(en, e2, e4) * ( - _F(en, e3, e2, e1, e3) + - _F(en, e4, e1, e1, e3) + - _F(en, e4, e2, e1, e3)) - - _K1(en, e1, e4) * ( - _F(en, e4, e1, e2, e3) + - _F(en, e4, e2, e2, e3) + - _F(en, e3, e1, e2, e3))) - return ci - -def _fun_case3(en, e): - e1, e2, e3, e4 = e - ci = np.zeros(4, dtype=float) - ci[0] = _K1(en, e4, e1) * _F(en, e4, e4, e2, e3) - ci[1] = _K1(en, e4, e2) * _F(en, e4, e4, e1, e3) - ci[2] = _K1(en, e4, e3) * _F(en, e4, e4, e1, e2) - ci[3] = -_K2(en, e4, e3, e1) * _F(en, e4, e3, e2, e4) \ - -_K2(en, e4, e2, e3) * _F(en, e4, e2, e1, e4) \ - -_K2(en, e4, e1, e2) * _F(en, e4, e1, e3, e4) - return ci - -def _dos_corner_weights(en, e): - flag, order, se = _dos_reorder(en, e) - if flag == 1: ci = _fun_case1(en, se) - elif flag == 2: ci = _fun_case2(en, se) - elif flag == 3: ci = _fun_case3(en, se) - elif flag in (4, 5): - ci = np.zeros(4, dtype=float) - elif flag == 6: - ci = np.full(4, 0.25, dtype=float) - else: raise ValueError("Unexpected flag in tetra reorder") - return flag, order, ci + fallback = (num / den).real + return np.where(mask, safe_val, fallback.astype(np.float64)) + + +# === Main driver === def dos_tetra_weights_3d(eigenvalues, energy, k_points): """ - Pure-Python version of dos_tetra_weights_3d. - Inputs: - - eigenvalues: 1D ndarray, band energies for each k-point (one band) - - energy: float, evaluation energy - - k_points: int ndarray with shape (5, ntet); corners are rows 1..4 - Returns: - - cti: float ndarray (4, ntet), corner weights per tetrahedron + Compute tetrahedron corner weights for 3D DOS integration. + + This version is fully vectorized in NumPy, operating on all tetrahedra + simultaneously without MPI or Python loops. + + Parameters + ---------- + eigenvalues : (n_kpoints,) array_like of float + Energies at k-points. + energy : float + Target energy for DOS evaluation. + k_points : (5, n_tetra) array_like of int + Tetrahedron connectivity. Only rows [1:5] are used for corner indices. + + Returns + ------- + corner_weights : (4, n_tetra) ndarray of float + Corner weights for each tetrahedron at the specified energy. """ eigk = np.asarray(eigenvalues, dtype=float) - itt = np.asarray(k_points, dtype=np.int64) - if itt.ndim != 2 or itt.shape[0] != 5: - raise ValueError("k_points must have shape (5, ntet)") - ntet = itt.shape[1] - cti = np.zeros((4, ntet), dtype=float) - - for it in range(ntet): - # rows 1..4 index the four corners - corners = itt[1:5, it].astype(np.int64) - e = eigk[corners].astype(float).copy() - _, order, ci = _dos_corner_weights(energy, e) - # Map sorted corner weights back to original corner ordering - # order[j] is original corner index 0..3 for sorted position j - cti[order, it] = ci - return cti + tetra = np.asarray(k_points, dtype=np.int64) + if tetra.ndim != 2 or tetra.shape[0] != 5: + raise ValueError("k_points must have shape (5, n_tetra)") + + n_tetra = tetra.shape[1] + corners = tetra[1:5, :] # (4, n_tetra) + corner_energies = eigk[corners] + + # Sort each tetrahedron's corner energies ascending + order = np.argsort(corner_energies, axis=0) + sorted_energies = np.take_along_axis(corner_energies, order, axis=0) + + e1, e2, e3, e4 = sorted_energies + e_eval = float(energy) + + # Determine which energy range each tetrahedron falls into + flag_uniform = (e1 <= e_eval) & (e_eval <= e4) & (np.abs(e4 - e1) < _TOL) + flag_case1 = (e1 <= e_eval) & (e_eval <= e2) & (~flag_uniform) + flag_case2 = (e2 <= e_eval) & (e_eval <= e3) + flag_case3 = (e3 <= e_eval) & (e_eval <= e4) + + weights_sorted = np.zeros_like(sorted_energies, dtype=float) + idx = lambda mask: np.nonzero(mask)[0] + + # === Case 6: uniform tetrahedra (degenerate energies) + if flag_uniform.any(): + weights_sorted[:, idx(flag_uniform)] = 0.25 + + # === Case 1 + if flag_case1.any(): + i, (ge1, ge2, ge3, ge4) = _select(flag_case1, e1, e2, e3, e4) + ee = e_eval + + w0 = (_stable_fraction_K2(ee, ge1, ge2, ge4) * _stable_fraction_F(ee, ge2, ge1, ge1, ge3) + + _stable_fraction_K2(ee, ge1, ge2, ge3) * _stable_fraction_F(ee, ge3, ge1, ge1, ge4) + + _stable_fraction_K2(ee, ge1, ge3, ge4) * _stable_fraction_F(ee, ge4, ge1, ge1, ge2)) + w1 = -_stable_fraction_K1(ee, ge1, ge2) * _stable_fraction_F(ee, ge1, ge1, ge3, ge4) + w2 = -_stable_fraction_K1(ee, ge1, ge3) * _stable_fraction_F(ee, ge1, ge1, ge2, ge4) + w3 = -_stable_fraction_K1(ee, ge1, ge4) * _stable_fraction_F(ee, ge1, ge1, ge2, ge3) + weights_sorted[:, i] = np.vstack([w0, w1, w2, w3]) + + # === Case 2 + if flag_case2.any(): + i, (ge1, ge2, ge3, ge4) = _select(flag_case2, e1, e2, e3, e4) + ee = e_eval + + w0 = 0.5 * ( + _stable_fraction_K1(ee, ge3, ge1) + * (_stable_fraction_F(ee, ge3, ge2, ge2, ge4) + + _stable_fraction_F(ee, ge4, ge1, ge2, ge4) + + _stable_fraction_F(ee, ge3, ge1, ge2, ge4)) + + _stable_fraction_K1(ee, ge4, ge1) + * (_stable_fraction_F(ee, ge4, ge1, ge2, ge3) + + _stable_fraction_F(ee, ge4, ge2, ge2, ge3) + + _stable_fraction_F(ee, ge3, ge1, ge2, ge3)) + ) + + w1 = 0.5 * ( + _stable_fraction_K1(ee, ge3, ge2) + * (_stable_fraction_F(ee, ge3, ge2, ge1, ge4) + + _stable_fraction_F(ee, ge4, ge2, ge1, ge4) + + _stable_fraction_F(ee, ge3, ge1, ge1, ge4)) + + _stable_fraction_K1(ee, ge4, ge2) + * (_stable_fraction_F(ee, ge3, ge2, ge1, ge3) + + _stable_fraction_F(ee, ge4, ge1, ge1, ge3) + + _stable_fraction_F(ee, ge4, ge2, ge1, ge3)) + ) + + w2 = 0.5 * ( + -_stable_fraction_K1(ee, ge2, ge3) + * (_stable_fraction_F(ee, ge3, ge2, ge1, ge4) + + _stable_fraction_F(ee, ge4, ge2, ge1, ge4) + + _stable_fraction_F(ee, ge3, ge1, ge1, ge4)) + - _stable_fraction_K1(ee, ge1, ge3) + * (_stable_fraction_F(ee, ge3, ge2, ge2, ge4) + + _stable_fraction_F(ee, ge4, ge1, ge2, ge4) + + _stable_fraction_F(ee, ge3, ge1, ge2, ge4)) + ) + + w3 = 0.5 * ( + -_stable_fraction_K1(ee, ge2, ge4) + * (_stable_fraction_F(ee, ge3, ge2, ge1, ge3) + + _stable_fraction_F(ee, ge4, ge1, ge1, ge3) + + _stable_fraction_F(ee, ge4, ge2, ge1, ge3)) + - _stable_fraction_K1(ee, ge1, ge4) + * (_stable_fraction_F(ee, ge4, ge1, ge2, ge3) + + _stable_fraction_F(ee, ge4, ge2, ge2, ge3) + + _stable_fraction_F(ee, ge3, ge1, ge2, ge3)) + ) + + weights_sorted[:, i] = np.vstack([w0, w1, w2, w3]) + + # === Case 3 + if flag_case3.any(): + i, (ge1, ge2, ge3, ge4) = _select(flag_case3, e1, e2, e3, e4) + ee = e_eval + + w0 = _stable_fraction_K1(ee, ge4, ge1) * _stable_fraction_F(ee, ge4, ge4, ge2, ge3) + w1 = _stable_fraction_K1(ee, ge4, ge2) * _stable_fraction_F(ee, ge4, ge4, ge1, ge3) + w2 = _stable_fraction_K1(ee, ge4, ge3) * _stable_fraction_F(ee, ge4, ge4, ge1, ge2) + w3 = ( + -_stable_fraction_K2(ee, ge4, ge3, ge1) * _stable_fraction_F(ee, ge4, ge3, ge2, ge4) + - _stable_fraction_K2(ee, ge4, ge2, ge3) * _stable_fraction_F(ee, ge4, ge2, ge1, ge4) + - _stable_fraction_K2(ee, ge4, ge1, ge2) * _stable_fraction_F(ee, ge4, ge1, ge3, ge4) + ) + + weights_sorted[:, i] = np.vstack([w0, w1, w2, w3]) + + # === Remap to original corner order + corner_weights = np.zeros_like(corner_energies, dtype=float) + corner_weights[order, np.arange(n_tetra)[None, :]] = weights_sorted + + return corner_weights From 872edfe5c72e797d2da3c6ff5f3450a7b0539e0f Mon Sep 17 00:00:00 2001 From: the-hampel Date: Mon, 10 Nov 2025 09:10:17 +0100 Subject: [PATCH 5/7] [build] remove commented c++ cmakelists commands --- python/triqs_dft_tools/CMakeLists.txt | 1 - test/CMakeLists.txt | 1 - 2 files changed, 2 deletions(-) diff --git a/python/triqs_dft_tools/CMakeLists.txt b/python/triqs_dft_tools/CMakeLists.txt index 04e320b5b..601eb1d17 100644 --- a/python/triqs_dft_tools/CMakeLists.txt +++ b/python/triqs_dft_tools/CMakeLists.txt @@ -3,7 +3,6 @@ configure_file(version.py.in version.py) # All Python files. Copy them in the build dir to have a complete package for the tests. file(GLOB_RECURSE python_sources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.py) -#file(GLOB_RECURSE wrap_generators RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *_desc.py) list(REMOVE_ITEM python_sources "${wrap_generators}") foreach(file ${python_sources}) configure_file(${file} ${file} COPYONLY) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9d95d9455..9a6c3c7d2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,3 @@ -#add_subdirectory(c++) if(PythonSupport) add_subdirectory(python) From 57425fc7bec7a1d0d9d9d25e5d20a13a3a25e36f Mon Sep 17 00:00:00 2001 From: the-hampel Date: Tue, 11 Nov 2025 09:43:12 +0100 Subject: [PATCH 6/7] Remove C++ support and cpp2py dependency C++ code has been completely removed from the codebase. This commit removes all related CMake configuration: - Remove PythonSupport option (Python is now always built) - Remove cpp2py dependency from deps/CMakeLists.txt - Remove cpp2py module building logic from python/triqs_dft_tools/ - Remove wrap_generators handling (no *_desc.py files exist) - Update project description to remove cpp2py reference The project now builds Python-only components without conditional C++ support checks. --- CMakeLists.txt | 17 +++-------------- deps/CMakeLists.txt | 11 ----------- python/triqs_dft_tools/CMakeLists.txt | 12 ------------ share/CMakeLists.txt | 6 ++---- test/CMakeLists.txt | 9 +++------ 5 files changed, 8 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9de7152c6..2983d9569 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ # ############################################################################## # -# triqs_dft_tools - An example application using triqs and cpp2py +# triqs_dft_tools - An example application using triqs # # Copyright (C) ... # @@ -28,7 +28,7 @@ project(triqs_dft_tools VERSION 3.3.1 LANGUAGES C CXX Fortran) get_directory_property(IS_SUBPROJECT PARENT_DIRECTORY) # ############ -# Load TRIQS and CPP2PY +# Load TRIQS find_package(TRIQS 3.3 REQUIRED) # Get the git hash & print status @@ -66,17 +66,8 @@ if(NOT IS_SUBPROJECT) message(STATUS "-------- BUILD-TYPE: ${CMAKE_BUILD_TYPE} --------") endif() -# Python Support -option(PythonSupport "Build with Python support" ON) -if(PythonSupport AND NOT TRIQS_WITH_PYTHON_SUPPORT) - message(FATAL_ERROR "TRIQS was installed without Python support. Cannot build the Python Interface. Disable the build with -DPythonSupport=OFF") -endif() - # Documentation option(Build_Documentation "Build documentation" OFF) -if(NOT IS_SUBPROJECT AND (Build_Documentation AND NOT PythonSupport)) - message(FATAL_ERROR "Build_Documentation=ON requires PythonSupport to be enabled") -endif() # Testing option(Build_Tests "Build tests" ON) @@ -140,9 +131,7 @@ if(Build_Tests) endif() # Python -if(PythonSupport) - add_subdirectory(python/${PROJECT_NAME}) -endif() +add_subdirectory(python/${PROJECT_NAME}) # Docs if(NOT IS_SUBPROJECT AND Build_Documentation) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 392370c11..755f88888 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -47,17 +47,6 @@ else() endif() endif() -# -- Cpp2Py -- -if(PythonSupport OR (NOT IS_SUBPROJECT AND Build_Documentation)) - external_dependency(Cpp2Py - GIT_REPO https://github.com/TRIQS/cpp2py - VERSION 3.3 - GIT_TAG main - BUILD_ALWAYS - EXCLUDE_FROM_ALL - ) -endif() - # -- GTest -- external_dependency(GTest GIT_REPO https://github.com/google/googletest diff --git a/python/triqs_dft_tools/CMakeLists.txt b/python/triqs_dft_tools/CMakeLists.txt index 601eb1d17..72fbf5adf 100644 --- a/python/triqs_dft_tools/CMakeLists.txt +++ b/python/triqs_dft_tools/CMakeLists.txt @@ -3,7 +3,6 @@ configure_file(version.py.in version.py) # All Python files. Copy them in the build dir to have a complete package for the tests. file(GLOB_RECURSE python_sources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.py) -list(REMOVE_ITEM python_sources "${wrap_generators}") foreach(file ${python_sources}) configure_file(${file} ${file} COPYONLY) endforeach() @@ -12,14 +11,3 @@ endforeach() set(PYTHON_LIB_DEST ${TRIQS_PYTHON_LIB_DEST_ROOT}/${PROJECT_NAME}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/version.py DESTINATION ${PYTHON_LIB_DEST}) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION ${TRIQS_PYTHON_LIB_DEST_ROOT} FILES_MATCHING PATTERN "*.py" PATTERN "*_desc.py" EXCLUDE) - -# Build and install any python modules -foreach(gen ${wrap_generators}) - string(REPLACE "_desc.py" "" gen ${gen}) - get_filename_component(module_name ${gen} NAME_WE) - get_filename_component(module_dir ${gen} DIRECTORY) - add_cpp2py_module(NAME ${module_name} DIRECTORY ${module_dir}) - add_library(${PROJECT_NAME}::${module_name} ALIAS ${module_name}) - target_link_libraries(${module_name} ${PROJECT_NAME}_c triqs_py) - install(TARGETS ${module_name} DESTINATION ${PYTHON_LIB_DEST}/${module_dir}) -endforeach() diff --git a/share/CMakeLists.txt b/share/CMakeLists.txt index 8d258a5f0..4df0478dc 100644 --- a/share/CMakeLists.txt +++ b/share/CMakeLists.txt @@ -6,10 +6,8 @@ if(NOT IS_SUBPROJECT AND NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr/local" ) - if(PythonSupport) - set(EXPORT_PYTHON_PATH "export PYTHONPATH=${CMAKE_INSTALL_PREFIX}/${CPP2PY_PYTHON_LIB_DEST_ROOT}:$PYTHONPATH") - set(MODFILE_PYTHON_PATH "prepend-path PYTHONPATH $root/${CPP2PY_PYTHON_LIB_DEST_ROOT}") - endif() + set(EXPORT_PYTHON_PATH "export PYTHONPATH=${CMAKE_INSTALL_PREFIX}/${CPP2PY_PYTHON_LIB_DEST_ROOT}:$PYTHONPATH") + set(MODFILE_PYTHON_PATH "prepend-path PYTHONPATH $root/${CPP2PY_PYTHON_LIB_DEST_ROOT}") configure_file(${PROJECT_NAME}.modulefile.in ${PROJECT_NAME}.modulefile @ONLY) configure_file(${PROJECT_NAME}vars.sh.in ${PROJECT_NAME}vars.sh @ONLY) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9a6c3c7d2..543107f70 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,3 @@ - -if(PythonSupport) - add_subdirectory(python) - add_subdirectory(python/plovasp) - add_subdirectory(python/elk) -endif() +add_subdirectory(python) +add_subdirectory(python/plovasp) +add_subdirectory(python/elk) From 0298f18979743a6c06a6a8f2c4f4686bb3589238 Mon Sep 17 00:00:00 2001 From: Nils Wentzell Date: Thu, 24 Aug 2023 13:00:00 -0400 Subject: [PATCH 7/7] Adjust app4triqs skeleton for python-only projects --- CMakeLists.txt | 47 +++-------------- Jenkinsfile | 4 +- deps/CMakeLists.txt | 8 --- doc/CMakeLists.txt | 57 --------------------- doc/install.rst | 1 - share/cmake/triqs_dft_tools-config.cmake.in | 10 +--- test/python/CMakeLists.txt | 2 +- 7 files changed, 12 insertions(+), 117 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2983d9569..8de1f959e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ cmake_policy(VERSION ${CMAKE_VERSION}) # ############ # Define Project -project(triqs_dft_tools VERSION 3.3.1 LANGUAGES C CXX Fortran) +project(triqs_dft_tools VERSION 3.3.1 LANGUAGES CXX Fortran) get_directory_property(IS_SUBPROJECT PARENT_DIRECTORY) # ############ @@ -66,6 +66,11 @@ if(NOT IS_SUBPROJECT) message(STATUS "-------- BUILD-TYPE: ${CMAKE_BUILD_TYPE} --------") endif() +# Python Support +if(NOT TRIQS_WITH_PYTHON_SUPPORT) + message(FATAL_ERROR "TRIQS was installed without Python support. Cannot build the Python Interface. Disable the build with -DPythonSupport=OFF") +endif() + # Documentation option(Build_Documentation "Build documentation" OFF) @@ -75,44 +80,6 @@ if(Build_Tests) enable_testing() endif() -# ############ -# Global Compilation Settings - -# Build static libraries by default -option(BUILD_SHARED_LIBS "Enable compilation of shared libraries" OFF) - -# Export the list of compile-commands into compile_commands.json -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - -# Disable compiler extensions -set(CMAKE_CXX_EXTENSIONS OFF) - -# Provide additional debugging information for Debug builds -add_compile_options($<$:-ggdb3>) - -# Create an Interface target for compiler warnings -add_library(${PROJECT_NAME}_warnings INTERFACE) -target_compile_options(${PROJECT_NAME}_warnings - INTERFACE - -Wall - -Wextra - -Wfloat-conversion - -Wpedantic - -Wno-sign-compare - $<$:-Wno-comma-subscript> - $<$:-Wno-psabi> # Disable notes about ABI changes - $<$:-Wshadow=local> - $<$:-Wno-attributes> - $<$:-Wno-deprecated-declarations> - $<$:-Wno-deprecated-comma-subscript> - $<$:-Wno-unknown-warning-option> - $<$:-Wshadow> - $<$:-Wno-gcc-compat> - $<$:-Wno-c++20-extensions> - $<$:-Wno-c++20-compat> - $<$:-Wno-tautological-constant-compare> -) - # Provide GNU Installation directories include(GNUInstallDirs) @@ -144,7 +111,7 @@ add_subdirectory(bin) # Additional configuration files add_subdirectory(share) -# add packaging for automatic Versioning +# add packaging for automatic versioning add_subdirectory(packaging) # ############# diff --git a/Jenkinsfile b/Jenkinsfile index 155320d43..bde8e3c01 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,8 +24,8 @@ properties([ def platforms = [:] /****************** linux builds (in docker) */ -/* Each platform must have a corresponding Dockerfile.PLATFORM in triqs/packaging */ -def dockerPlatforms = ["ubuntu-clang", "ubuntu-gcc", "ubuntu-intel", "sanitize"] +/* Each platform must have a cooresponding Dockerfile.PLATFORM in triqs/packaging */ +def dockerPlatforms = ["ubuntu-clang", "ubuntu-gcc"] /* .each is currently broken in jenkins */ for (int i = 0; i < dockerPlatforms.size(); i++) { def platform = dockerPlatforms[i] diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 755f88888..3b938a51a 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -46,11 +46,3 @@ else() message(WARNING "For builds with llvm sanitizers (ASAN/UBSAN) it is recommended to use -DBuild_Deps=Always to avoid false positives.") endif() endif() - -# -- GTest -- -external_dependency(GTest - GIT_REPO https://github.com/google/googletest - GIT_TAG main - BUILD_ALWAYS - EXCLUDE_FROM_ALL -) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 6b95f99db..6ac89abbb 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -1,51 +1,6 @@ # Generate the sphinx config file configure_file(${CMAKE_CURRENT_SOURCE_DIR}/conf.py.in ${CMAKE_CURRENT_BINARY_DIR}/conf.py @ONLY) -# ----------------------------------------------------------------------------- -# Create an optional target that allows us to regenerate the C++ doc with c++2rst -# ----------------------------------------------------------------------------- -add_custom_target(${PROJECT_NAME}_docs_cpp2rst) -include(${PROJECT_SOURCE_DIR}/share/cmake/extract_flags.cmake) -extract_flags(${PROJECT_NAME}_c BUILD_INTERFACE) -separate_arguments(${PROJECT_NAME}_c_CXXFLAGS) -macro(generate_docs header_file) - add_custom_command( - TARGET ${PROJECT_NAME}_docs_cpp2rst - POST_BUILD - COMMAND rm -rf ${CMAKE_CURRENT_SOURCE_DIR}/cpp2rst_generated - COMMAND - PYTHONPATH=${CPP2PY_BINARY_DIR}:$ENV{PYTHONPATH} - PATH=${CPP2PY_BINARY_DIR}/bin:${CPP2PY_ROOT}/bin:$ENV{PATH} - c++2rst - ${header_file} - -N ${PROJECT_NAME} - --output_directory ${CMAKE_CURRENT_SOURCE_DIR}/cpp2rst_generated - -I${PROJECT_SOURCE_DIR}/c++ - --cxxflags="${${PROJECT_NAME}_c_CXXFLAGS}" - ) -endmacro(generate_docs) - -generate_docs(${PROJECT_SOURCE_DIR}/c++/${PROJECT_NAME}/${PROJECT_NAME}.hpp) - -# -------------------------------------------------------- -# Build & Run the C++ doc examples and capture the output -# -------------------------------------------------------- - -add_custom_target(${PROJECT_NAME}_docs_example_output) -file(GLOB_RECURSE ExampleList RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) -foreach(example ${ExampleList}) - get_filename_component(f ${example} NAME_WE) - get_filename_component(d ${example} DIRECTORY) - add_executable(${PROJECT_NAME}_doc_${f} EXCLUDE_FROM_ALL ${example}) - set_property(TARGET ${PROJECT_NAME}_doc_${f} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${d}) - target_link_libraries(${PROJECT_NAME}_doc_${f} triqs) - add_custom_command(TARGET ${PROJECT_NAME}_doc_${f} POST_BUILD - COMMAND ${PROJECT_NAME}_doc_${f} > ${CMAKE_CURRENT_SOURCE_DIR}/${d}/${f}.output 2>/dev/null - WORKING_DIRECTORY ${d} - ) - add_dependencies(${PROJECT_NAME}_docs_example_output ${PROJECT_NAME}_doc_${f}) -endforeach() - # --------------------------------- # Top Sphinx target # --------------------------------- @@ -61,18 +16,6 @@ add_custom_command( COMMAND PYTHONPATH=${PROJECT_BINARY_DIR}/python:$ENV{PYTHONPATH} ${SPHINXBUILD_EXECUTABLE} -j auto -c . -b html ${CMAKE_CURRENT_SOURCE_DIR} html ) -option(Sphinx_Only "When building the documentation, skip the Python Modules and the generation of C++ Api and example outputs" OFF) -if(NOT Sphinx_Only) - # Autodoc usage requires the python modules to be built first - get_property(CPP2PY_MODULES_LIST GLOBAL PROPERTY CPP2PY_MODULES_LIST) - if(CPP2PY_MODULES_LIST) - add_dependencies(${PROJECT_NAME}_docs_sphinx ${CPP2PY_MODULES_LIST}) - endif() - - # Generation of C++ Api and Example Outputs - add_dependencies(${PROJECT_NAME}_docs_sphinx ${PROJECT_NAME}_docs_cpp2rst ${PROJECT_NAME}_docs_example_output) -endif() - # --------------------------------- # Install # --------------------------------- diff --git a/doc/install.rst b/doc/install.rst index d43daa86c..2a3f5cc1b 100644 --- a/doc/install.rst +++ b/doc/install.rst @@ -67,7 +67,6 @@ Installation steps #. Compile the code, run the tests and install the application:: - $ make $ make test $ make install diff --git a/share/cmake/triqs_dft_tools-config.cmake.in b/share/cmake/triqs_dft_tools-config.cmake.in index b6bb5bbdd..d91cf3e96 100644 --- a/share/cmake/triqs_dft_tools-config.cmake.in +++ b/share/cmake/triqs_dft_tools-config.cmake.in @@ -23,18 +23,12 @@ set(@PROJECT_NAME@_ROOT @CMAKE_INSTALL_PREFIX@ CACHE STRING "@PROJECT_NAME@ root #endfunction() #find_dep(depname 1.0) -# Include the exported targets of this project -include(@CMAKE_INSTALL_FULL_LIBDIR@/cmake/@PROJECT_NAME@/@PROJECT_NAME@-targets.cmake) +## Include the exported targets of this project +#include(@CMAKE_INSTALL_FULL_LIBDIR@/cmake/@PROJECT_NAME@/@PROJECT_NAME@-targets.cmake) message(STATUS "Found @PROJECT_NAME@-config.cmake with version @PROJECT_VERSION@, hash = @PROJECT_GIT_HASH@, root = @CMAKE_INSTALL_PREFIX@") # Was the Project built with Documentation? set(@PROJECT_NAME@_WITH_DOCUMENTATION @Build_Documentation@ CACHE BOOL "Was @PROJECT_NAME@ build with documentation?") -# Was the Project built with PythonSupport? -set(@PROJECT_NAME@_WITH_PYTHON_SUPPORT @PythonSupport@ CACHE BOOL "Was @PROJECT_NAME@ build with python support?") -if(@PythonSupport@) - set(@PROJECT_NAME@_MODULE_DIR @CMAKE_INSTALL_PREFIX@/@CPP2PY_PYTHON_LIB_DEST_ROOT@ CACHE BOOL "The @PROJECT_NAME@ python module directory") -endif() - endif() diff --git a/test/python/CMakeLists.txt b/test/python/CMakeLists.txt index 9c8f0ab55..7287c7a27 100644 --- a/test/python/CMakeLists.txt +++ b/test/python/CMakeLists.txt @@ -15,5 +15,5 @@ foreach(test ${all_tests}) get_filename_component(test_name ${test} NAME_WE) get_filename_component(test_dir ${test} DIRECTORY) add_test(NAME Py_${test_name} COMMAND ${TRIQS_PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${test_dir}/${test_name}.py WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${test_dir}) - set_property(TEST Py_${test_name} APPEND PROPERTY ENVIRONMENT PYTHONPATH=${PROJECT_BINARY_DIR}/python:$ENV{PYTHONPATH} ${SANITIZER_RT_PRELOAD}) + set_property(TEST Py_${test_name} APPEND PROPERTY ENVIRONMENT PYTHONPATH=${PROJECT_BINARY_DIR}/python:$ENV{PYTHONPATH}) endforeach()