From c6e576cb0fb4beb570e5f69343606332b6b14d51 Mon Sep 17 00:00:00 2001 From: Tammo van der Heide Date: Fri, 1 Dec 2023 12:20:37 +0100 Subject: [PATCH] Fix installation of Python components (#1267) --- tools/dptools/CMakeLists.txt | 3 +- tools/dptools/{README => README.rst} | 18 ++++---- tools/dptools/bin/dp_bands | 20 --------- tools/dptools/bin/dp_dos | 20 --------- tools/dptools/bin/gen2cif | 20 --------- tools/dptools/bin/gen2xyz | 20 --------- tools/dptools/bin/repeatgen | 20 --------- tools/dptools/bin/straingen | 20 --------- tools/dptools/bin/xyz2gen | 20 --------- tools/dptools/pyproject.toml | 3 ++ tools/dptools/setup.cfg | 37 +++++++++++++++++ tools/dptools/setup.py | 38 ----------------- tools/dptools/src/dptools/scripts/dp_bands.py | 0 tools/dptools/src/dptools/scripts/dp_dos.py | 0 tools/dptools/src/dptools/scripts/gen2cif.py | 0 tools/dptools/src/dptools/scripts/gen2xyz.py | 0 .../dptools/scripts/makecube.py} | 32 +++++++++++++-- tools/dptools/src/dptools/scripts/xyz2gen.py | 0 tools/pythonapi/CMakeLists.txt | 3 +- tools/pythonapi/{README => README.rst} | 41 +++++-------------- tools/pythonapi/pyproject.toml | 3 ++ tools/pythonapi/setup.cfg | 29 +++++++++++++ tools/pythonapi/setup.py | 29 ------------- 23 files changed, 123 insertions(+), 253 deletions(-) rename tools/dptools/{README => README.rst} (83%) delete mode 100755 tools/dptools/bin/dp_bands delete mode 100755 tools/dptools/bin/dp_dos delete mode 100755 tools/dptools/bin/gen2cif delete mode 100755 tools/dptools/bin/gen2xyz delete mode 100755 tools/dptools/bin/repeatgen delete mode 100755 tools/dptools/bin/straingen delete mode 100755 tools/dptools/bin/xyz2gen create mode 100644 tools/dptools/pyproject.toml create mode 100644 tools/dptools/setup.cfg delete mode 100644 tools/dptools/setup.py mode change 100755 => 100644 tools/dptools/src/dptools/scripts/dp_bands.py mode change 100755 => 100644 tools/dptools/src/dptools/scripts/dp_dos.py mode change 100755 => 100644 tools/dptools/src/dptools/scripts/gen2cif.py mode change 100755 => 100644 tools/dptools/src/dptools/scripts/gen2xyz.py rename tools/dptools/{bin/makecube => src/dptools/scripts/makecube.py} (83%) mode change 100755 => 100644 mode change 100755 => 100644 tools/dptools/src/dptools/scripts/xyz2gen.py rename tools/pythonapi/{README => README.rst} (61%) create mode 100644 tools/pythonapi/pyproject.toml create mode 100644 tools/pythonapi/setup.cfg delete mode 100644 tools/pythonapi/setup.py diff --git a/tools/dptools/CMakeLists.txt b/tools/dptools/CMakeLists.txt index 7f316977ff..ae56bd6905 100644 --- a/tools/dptools/CMakeLists.txt +++ b/tools/dptools/CMakeLists.txt @@ -1,6 +1,7 @@ +set(prefix ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_PREFIX}) set(cmake-command " execute_process( - COMMAND ${PYTHON_INTERPRETER} setup.py install --prefix=$DESTDIR/${CMAKE_INSTALL_PREFIX} + COMMAND ${PYTHON_INTERPRETER} -m pip install --no-deps --prefix ${prefix} . WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) ") diff --git a/tools/dptools/README b/tools/dptools/README.rst similarity index 83% rename from tools/dptools/README rename to tools/dptools/README.rst index 60c1caaf64..eae99f28cc 100644 --- a/tools/dptools/README +++ b/tools/dptools/README.rst @@ -26,11 +26,11 @@ gen2xyz xyz2gen Converts an xyz file to gen file. -straingen +straingen Applies uniaxial, isotropic or shear strains to geometries, with principle axes aligned with the cartesian directions. -repeatgen +repeatgen Can be used to build supercell structures for phonon bandstructures Each script can be invoked with the option ``-h`` to obtain a short @@ -40,9 +40,9 @@ summary about its usage and possible options. Testing dp_tools ================ -In the top directory of DFTB+, running +In the top directory of DFTB+, running:: -make test_dptools + make test_dptools will validate the source of dp_tools for your python interpreter and environment. @@ -51,10 +51,10 @@ For developers -------------- To perform pylint static checking, in the top DFTB+ directory the -individual scripts can be tested, for example by +individual scripts can be tested, for example by :: -env PYTHONPATH=$PWD/tools/dptools/src pylint3 --rcfile \ -utils/srccheck/pylint/pylintrc-3.ini tools/dptools/bin/* + env PYTHONPATH=$PWD/tools/dptools/src pylint3 --rcfile \ + utils/srccheck/pylint/pylintrc-3.ini tools/dptools/src/dptools/* Installation @@ -64,8 +64,6 @@ Please note, that the package needs at least **Python 2.6** or later, with Python 3.X preferred. It additionally needs Numerical Python (the numpy module). -You can install the script package via the standard 'python setup' -mechanism:: +You can install the script package via the standard 'pip' mechanism:: pip install . - diff --git a/tools/dptools/bin/dp_bands b/tools/dptools/bin/dp_bands deleted file mode 100755 index d2f3195dec..0000000000 --- a/tools/dptools/bin/dp_bands +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python3 -#------------------------------------------------------------------------------# -# DFTB+: general package for performing fast atomistic simulations # -# Copyright (C) 2006 - 2023 DFTB+ developers group # -# # -# See the LICENSE file for terms of usage and distribution. # -#------------------------------------------------------------------------------# -# - -'''Command line wrapper for dp_bands''' - -import sys -from dptools.scripts.common import ScriptError -import dptools.scripts.dp_bands as dp_bands - -try: - dp_bands.main() -except ScriptError as exc: - sys.stderr.write('ScriptError: ' + str(exc) + '\n') - sys.exit(1) diff --git a/tools/dptools/bin/dp_dos b/tools/dptools/bin/dp_dos deleted file mode 100755 index dc101d3d54..0000000000 --- a/tools/dptools/bin/dp_dos +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python3 -#------------------------------------------------------------------------------# -# DFTB+: general package for performing fast atomistic simulations # -# Copyright (C) 2006 - 2023 DFTB+ developers group # -# # -# See the LICENSE file for terms of usage and distribution. # -#------------------------------------------------------------------------------# -# - -'''Command line wrapper for dp_dos''' - -import sys -from dptools.scripts.common import ScriptError -import dptools.scripts.dp_dos as dp_dos - -try: - dp_dos.main() -except ScriptError as exc: - sys.stderr.write('ScriptError: ' + str(exc) + '\n') - sys.exit(1) diff --git a/tools/dptools/bin/gen2cif b/tools/dptools/bin/gen2cif deleted file mode 100755 index 09feb768e8..0000000000 --- a/tools/dptools/bin/gen2cif +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python3 -#------------------------------------------------------------------------------# -# DFTB+: general package for performing fast atomistic simulations # -# Copyright (C) 2006 - 2023 DFTB+ developers group # -# # -# See the LICENSE file for terms of usage and distribution. # -#------------------------------------------------------------------------------# -# - -'''Command line wrapper for gen2cif''' - -import sys -from dptools.scripts.common import ScriptError -import dptools.scripts.gen2cif as gen2cif - -try: - gen2cif.main() -except ScriptError as exc: - sys.stderr.write('ScriptError: ' + str(exc) + '\n') - sys.exit(1) diff --git a/tools/dptools/bin/gen2xyz b/tools/dptools/bin/gen2xyz deleted file mode 100755 index ea8e8a3e30..0000000000 --- a/tools/dptools/bin/gen2xyz +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python3 -#------------------------------------------------------------------------------# -# DFTB+: general package for performing fast atomistic simulations # -# Copyright (C) 2006 - 2023 DFTB+ developers group # -# # -# See the LICENSE file for terms of usage and distribution. # -#------------------------------------------------------------------------------# -# - -'''Command line wrapper for gen2xyz''' - -import sys -from dptools.scripts.common import ScriptError -import dptools.scripts.gen2xyz as gen2xyz - -try: - gen2xyz.main() -except ScriptError as exc: - sys.stderr.write('ScriptError: ' + str(exc) + '\n') - sys.exit(1) diff --git a/tools/dptools/bin/repeatgen b/tools/dptools/bin/repeatgen deleted file mode 100755 index 1908c1f019..0000000000 --- a/tools/dptools/bin/repeatgen +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python3 -#------------------------------------------------------------------------------# -# DFTB+: general package for performing fast atomistic simulations # -# Copyright (C) 2006 - 2023 DFTB+ developers group # -# # -# See the LICENSE file for terms of usage and distribution. # -#------------------------------------------------------------------------------# -# - -'''Command line wrapper for repeatgen''' - -import sys -from dptools.scripts.common import ScriptError -import dptools.scripts.repeatgen as repeatgen - -try: - repeatgen.main() -except ScriptError as exc: - sys.stderr.write('ScriptError: ' + str(exc) + '\n') - sys.exit(1) diff --git a/tools/dptools/bin/straingen b/tools/dptools/bin/straingen deleted file mode 100755 index ae8cc14bff..0000000000 --- a/tools/dptools/bin/straingen +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python3 -#------------------------------------------------------------------------------# -# DFTB+: general package for performing fast atomistic simulations # -# Copyright (C) 2006 - 2023 DFTB+ developers group # -# # -# See the LICENSE file for terms of usage and distribution. # -#------------------------------------------------------------------------------# -# - -'''Command line wrapper for straingen''' - -import sys -from dptools.scripts.common import ScriptError -import dptools.scripts.straingen as straingen - -try: - straingen.main() -except ScriptError as exc: - sys.stderr.write('ScriptError: ' + str(exc) + '\n') - sys.exit(1) diff --git a/tools/dptools/bin/xyz2gen b/tools/dptools/bin/xyz2gen deleted file mode 100755 index 54733f5c61..0000000000 --- a/tools/dptools/bin/xyz2gen +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python3 -#------------------------------------------------------------------------------# -# DFTB+: general package for performing fast atomistic simulations # -# Copyright (C) 2006 - 2023 DFTB+ developers group # -# # -# See the LICENSE file for terms of usage and distribution. # -#------------------------------------------------------------------------------# -# - -'''Command line wrapper for xyz2gen''' - -import sys -from dptools.scripts.common import ScriptError -import dptools.scripts.xyz2gen as xyz2gen - -try: - xyz2gen.main() -except ScriptError as exc: - sys.stderr.write('ScriptError: ' + str(exc) + '\n') - sys.exit(1) diff --git a/tools/dptools/pyproject.toml b/tools/dptools/pyproject.toml new file mode 100644 index 0000000000..7e01ab27fe --- /dev/null +++ b/tools/dptools/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ['setuptools', 'wheel'] +build-backend = 'setuptools.build_meta' diff --git a/tools/dptools/setup.cfg b/tools/dptools/setup.cfg new file mode 100644 index 0000000000..8d74841795 --- /dev/null +++ b/tools/dptools/setup.cfg @@ -0,0 +1,37 @@ +[metadata] +name = dptools +version = 23.1 +author = DFTB+ developers +url = http://www.dftbplus.org +description = Tools to process DFTB+ related data +long_description = file: README.rst +long_description_content_type = text/x-rst +license = LGPL License +platform = platform independent +classifiers = + Intended Audience :: Science/Research + License :: OSI Approved :: LGPL License + Programming Language :: Python + Environment :: Console + Operating System :: OS Independent + Topic :: Scientific/Engineering + +[options] +include_package_data = True +packages = find: +install_requires = + numpy + +[options.entry_points] +console_scripts = + dp_bands = dptools.scripts.dp_bands:main + dp_dos = dptools.scripts.dp_dos:main + gen2cif = dptools.scripts.gen2cif:main + gen2xyz = dptools.scripts.gen2xyz:main + makecube = dptools.scripts.makecube:main + repeatgen = dptools.scripts.repeatgen:main + straingen = dptools.scripts.straingen:main + xyz2gen = dptools.scripts.xyz2gen:main + +[options.packages.find] +where = src diff --git a/tools/dptools/setup.py b/tools/dptools/setup.py deleted file mode 100644 index 948a3c06e6..0000000000 --- a/tools/dptools/setup.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python3 -from distutils.core import setup - -setup( - name="dptools", - version='23.1', - description="Tools to process DFTB+ related data", - author="DFTB+ developers", - url="http://www.dftbplus.org", - platforms="platform independent", - package_dir={"": "src"}, - packages=["dptools", "dptools.scripts"], - scripts=[ - "bin/dp_bands", - "bin/dp_dos", - "bin/gen2cif", - "bin/gen2xyz", - "bin/makecube", - "bin/repeatgen", - "bin/xyz2gen", - "bin/straingen", - ], - classifiers=[ - "Programming Language :: Python", - "Environment :: Console", - "Intended Audience :: Science/Research", - "License :: OSI Approved :: LGPL License", - "Operating System :: OS Independent", - "Topic :: Scientific/Engineering", - ], - long_description=""" -Processing and converting data related to the DFTB+ package ------------------------------------------------------------ -A few scripts which should make the life of DFTB+ users easier, by providing -functions to process and convert various DFTB+ data formats. -""", - requires=[ "numpy" ] -) diff --git a/tools/dptools/src/dptools/scripts/dp_bands.py b/tools/dptools/src/dptools/scripts/dp_bands.py old mode 100755 new mode 100644 diff --git a/tools/dptools/src/dptools/scripts/dp_dos.py b/tools/dptools/src/dptools/scripts/dp_dos.py old mode 100755 new mode 100644 diff --git a/tools/dptools/src/dptools/scripts/gen2cif.py b/tools/dptools/src/dptools/scripts/gen2cif.py old mode 100755 new mode 100644 diff --git a/tools/dptools/src/dptools/scripts/gen2xyz.py b/tools/dptools/src/dptools/scripts/gen2xyz.py old mode 100755 new mode 100644 diff --git a/tools/dptools/bin/makecube b/tools/dptools/src/dptools/scripts/makecube.py old mode 100755 new mode 100644 similarity index 83% rename from tools/dptools/bin/makecube rename to tools/dptools/src/dptools/scripts/makecube.py index 5ab6499c43..0461790ecf --- a/tools/dptools/bin/makecube +++ b/tools/dptools/src/dptools/scripts/makecube.py @@ -20,9 +20,24 @@ """ -def main(): - '''Main driver routine for makecube.''' +def main(cmdlineargs=None): + '''Main driver for makecube. + Args: + cmdlineargs: List of command line arguments. When None, arguments in + sys.argv are parsed (Default: None). + ''' + args = parse_arguments(cmdlineargs) + makecube(args) + + +def parse_arguments(cmdlineargs=None): + '''Parses command line arguments. + + Args: + cmdlineargs: List of command line arguments. When None, arguments in + sys.argv are parsed (Default: None). + ''' parser = argparse.ArgumentParser(description=USAGE) helpstring = 'file containing X vector coordinates (default Xvector.dat)' @@ -45,8 +60,18 @@ def main(): helpstring = 'output cube/vtk file name' parser.add_argument('dest', help=helpstring) - args = parser.parse_args() + args = parser.parse_args(cmdlineargs) + + return args + +def makecube(args): + '''Converts the potential or charge data file from DFTB+ transport + calculations to a Gaussian Cube format. + + Args: + args: Containing the obtained parsed arguments. + ''' # Build the grid with open(args.xvec, 'r') as xvecfile: xvec = np.array(xvecfile.read().split(), dtype=float) @@ -90,5 +115,6 @@ def main(): raise ValueError('Cannot determine output format in ' 'makecube:unknown file extension') + if __name__ == "__main__": main() diff --git a/tools/dptools/src/dptools/scripts/xyz2gen.py b/tools/dptools/src/dptools/scripts/xyz2gen.py old mode 100755 new mode 100644 diff --git a/tools/pythonapi/CMakeLists.txt b/tools/pythonapi/CMakeLists.txt index 7f316977ff..ae56bd6905 100644 --- a/tools/pythonapi/CMakeLists.txt +++ b/tools/pythonapi/CMakeLists.txt @@ -1,6 +1,7 @@ +set(prefix ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_PREFIX}) set(cmake-command " execute_process( - COMMAND ${PYTHON_INTERPRETER} setup.py install --prefix=$DESTDIR/${CMAKE_INSTALL_PREFIX} + COMMAND ${PYTHON_INTERPRETER} -m pip install --no-deps --prefix ${prefix} . WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) ") diff --git a/tools/pythonapi/README b/tools/pythonapi/README.rst similarity index 61% rename from tools/pythonapi/README rename to tools/pythonapi/README.rst index 045024068a..b6a4d3fde4 100644 --- a/tools/pythonapi/README +++ b/tools/pythonapi/README.rst @@ -17,15 +17,15 @@ Compiling DFTB+ In order to be able to use the Python interface, DFTB+ has to be compiled as a shared library with API support enabled. To instruct cmake that a dynamically linked shared library should be created -containing DFTB+. This can be done by setting the WITH_API, -WITH_PYTHON, and BUILD_SHARED_LIBS flags to be TRUE in the -configuration file config.cmake, before starting the configuration -and compilation process. Alternatively, if you do not want to -modify files, a construct like the following is a convenient way -to specify these flags on the command line while configuring with +containing DFTB+. This can be done by setting the WITH_API, WITH_PYTHON, +BUILD_SHARED_LIBS and ENABLE_DYNAMIC_LOADING flags to be TRUE in the +configuration file config.cmake, before starting the configuration +and compilation process. Alternatively, if you do not want to +modify files, a construct like the following is a convenient way +to specify these flags on the command line while configuring with CMake: -cmake -DBUILD_SHARED_LIBS=1 -DWITH_API=1 -DWITH_PYTHON=1 .. +cmake -DENABLE_DYNAMIC_LOADING=1 -DBUILD_SHARED_LIBS=1 -DWITH_API=1 -DWITH_PYTHON=1 .. Testing pythonapi @@ -53,30 +53,9 @@ Installation Please note, that this package has been tested for **Python 3.X** support. It additionally needs Numerical Python (the numpy module). -System install --------------- - -You can install the script package via the standard 'python setup' -mechanism. If you want to install it system-wide into your normal -python installation, for the script in the tools/pythonapi/ -sub-directory you simply issue:: +You can install the script package via the standard 'pip' +mechanism:: - python setup.py + python -m pip install . with an appropriate level of permission. - -Local install -------------- - -Alternatively, you can install it locally in your home space, e.g.:: - - python setup.py install --user - -If the local python install directory is not in your path, you should -add this. For the bash shell you should include in .bashrc:: - - export PATH=$PATH:/home/user/.local/bin - -while in tcsh shell, you would have to add to your .cshrc:: - - setenv PATH $PATH:/home/user/.local/bin diff --git a/tools/pythonapi/pyproject.toml b/tools/pythonapi/pyproject.toml new file mode 100644 index 0000000000..7e01ab27fe --- /dev/null +++ b/tools/pythonapi/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ['setuptools', 'wheel'] +build-backend = 'setuptools.build_meta' diff --git a/tools/pythonapi/setup.cfg b/tools/pythonapi/setup.cfg new file mode 100644 index 0000000000..da728074af --- /dev/null +++ b/tools/pythonapi/setup.cfg @@ -0,0 +1,29 @@ +[metadata] +name = pythonapi +version = 0.1 +author = DFTB+ developers +url = http://www.dftbplus.org +description = Python interface to DFTB+ +long_description = file: README.rst +long_description_content_type = text/x-rst +license = BSD +license_file = LICENSE +platform = any +classifiers = + Intended Audience :: Developers + License :: OSI Approved :: BSD License + Programming Language :: Python :: 3 :: Only + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.7 + +[options] +include_package_data = True +package_dir = + = src +install_requires = + numpy + +[options.packages.find] +where = src diff --git a/tools/pythonapi/setup.py b/tools/pythonapi/setup.py deleted file mode 100644 index 4188736f9f..0000000000 --- a/tools/pythonapi/setup.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env python3 -from distutils.core import setup - -setup( - name='pythonapi', - version='0.1', - description='Python interface to DFTB+', - author='DFTB+ developers', - url='http://www.dftbplus.org', - platforms='platform independent', - package_dir={'': 'src'}, - packages=[''], - classifiers=[ - 'Programming Language :: Python', - 'Environment :: Console', - 'Intended Audience :: Science/Research', - 'License :: OSI Approved :: LGPL', - 'Operating System :: OS Independent', - 'Topic :: Scientific/Engineering', - ], - long_description=''' - A ctypes based Python interface for DFTB+ - ----------------------------------------- - Interface module for the communication between DFTB+ and - Python via the foreign function C-library ctypes. Provides - methods for initializing and configuring a DFTB+ calculator. - ''', - requires=['numpy'] -)