From 7c4502dcf90c136883dba8a58ca7b941b6ea0a10 Mon Sep 17 00:00:00 2001 From: Sebastian Ehlert <28669218+awvwgk@users.noreply.github.com> Date: Sun, 31 May 2020 14:18:50 +0200 Subject: [PATCH] Adjust build instructions for conda-forge (#12) - allow to depend on the xtb shared library - include the xtb header also in this repository - remove numpy from build dependencies - move tests into the xtb directory - change versioning to year based scheme - fix packages to include whole source tree - more detailed installation introduction --- .travis.yml | 2 +- docs/ase-calculator.rst | 1 + docs/index.rst | 36 ++- docs/installation.rst | 138 ++++++++++- include/xtb.h | 301 +++++++++++++++++++++++ meson.build | 41 +-- setup.cfg | 21 +- setup.py | 2 +- subprojects/xtb.wrap | 6 + xtb/__init__.py | 3 +- xtb/ase/__init__.py | 4 +- {tests => xtb/ase}/test_ase.py | 0 xtb/interface.py | 22 +- xtb/libxtb.py | 2 +- xtb/qcschema/__init__.py | 4 +- {tests => xtb/qcschema}/test_qcschema.py | 0 {tests => xtb}/test_interface.py | 0 {tests => xtb}/test_libxtb.py | 10 +- {tests => xtb}/test_utils.py | 0 19 files changed, 548 insertions(+), 45 deletions(-) create mode 100644 include/xtb.h create mode 100644 subprojects/xtb.wrap rename {tests => xtb/ase}/test_ase.py (100%) rename {tests => xtb/qcschema}/test_qcschema.py (100%) rename {tests => xtb}/test_interface.py (100%) rename {tests => xtb}/test_libxtb.py (74%) rename {tests => xtb}/test_utils.py (100%) diff --git a/.travis.yml b/.travis.yml index fa00c7a..1c73566 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,7 @@ install: - pip install -e . script: - - pytest -v --cov=xtb tests/ + - pytest -v --cov=xtb --pyargs xtb after_success: - codecov diff --git a/docs/ase-calculator.rst b/docs/ase-calculator.rst index db24395..e77120a 100644 --- a/docs/ase-calculator.rst +++ b/docs/ase-calculator.rst @@ -1,3 +1,4 @@ +.. _ase: .. module:: xtb.ase Atomic Simulation Environment diff --git a/docs/index.rst b/docs/index.rst index 26048a6..df93c58 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -5,8 +5,42 @@ This is the documentation of the Python API for the extended tight binding program (``xtb``). The project is hosted at `GitHub `_. + +.. code:: + + >>> from xtb.interface import Calculator + >>> from xtb.utils import get_method + >>> import numpy as np + >>> numbers = np.array([8, 1, 1]) + >>> positions = np.array([ + ... [ 0.00000000000000, 0.00000000000000,-0.73578586109551], + ... [ 1.44183152868459, 0.00000000000000, 0.36789293054775], + ... [-1.44183152868459, 0.00000000000000, 0.36789293054775]]) + ... + >>> calc = Calculator(get_method("GFN2-xTB"), numbers, positions) + >>> res = calc.singlepoint() # energy printed is only the electronic part + 1 -5.1027888 -0.510279E+01 0.421E+00 14.83 0.0 T + 2 -5.1040645 -0.127572E-02 0.242E+00 14.55 1.0 T + 3 -5.1042978 -0.233350E-03 0.381E-01 14.33 1.0 T + 4 -5.1043581 -0.602769E-04 0.885E-02 14.48 1.0 T + 5 -5.1043609 -0.280751E-05 0.566E-02 14.43 1.0 T + 6 -5.1043628 -0.188160E-05 0.131E-03 14.45 44.1 T + 7 -5.1043628 -0.455326E-09 0.978E-04 14.45 59.1 T + 8 -5.1043628 -0.572169E-09 0.192E-05 14.45 3009.1 T + SCC iter. ... 0 min, 0.022 sec + gradient ... 0 min, 0.000 sec + >>> res.get_energy() + -5.070451354836705 + >>> res.get_gradient() + array([[ 6.24500451e-17 -3.47909735e-17 -5.07156941e-03] + [-1.24839222e-03 2.43536791e-17 2.53578470e-03] + [ 1.24839222e-03 1.04372944e-17 2.53578470e-03]]) + >>> res.get_charges() + array([-0.56317912 0.28158956 0.28158956]) + + .. toctree:: - :maxdepth: 2 + :maxdepth: 3 :caption: Contents installation diff --git a/docs/installation.rst b/docs/installation.rst index e2bd8c9..1e1da2a 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -1,6 +1,29 @@ +.. _install: + Installation ============ +For the basic functionalities the ``xtb-python`` project requires following +packages: + +.. code:: + + cffi + numpy + +Additionally the project provides a calculator implementation for ASE (see :ref:`ase`) which becomes available if the ``ase`` package is installed. +For integration with the QCArchive infrastructure (see :ref:`qcarchive`) the ``qcelemental`` package is required. + +Of course, the package depends on the `extended tight binding program package `_ as well, directly or indirectly. +Depending on how ``xtb-python`` was packaged it requires an installation of ``xtb`` or it will be able to provide its own. +For more details on the ``xtb`` API dependency see :ref:`building`. + + +.. _building: + +Building from Source +-------------------- + To install ``xtb-python`` from source clone the repository from GitHub with .. code:: @@ -10,9 +33,12 @@ To install ``xtb-python`` from source clone the repository from GitHub with git submodule update --init This will ensure that you have access to the ``xtb-python`` and the parent ``xtb`` repository, with the latter to be found in ``subprojects/xtb``. -It is highly recommend to make yourself familiar with building ``xtb`` first. -To work with ``xtb-python`` it is necessary to build the extension to the ``xtb`` API first, this is accomplised by using meson and the C foreign function interface. + +Building the Extension Module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To work with ``xtb-python`` it is necessary to build the extension to the ``xtb`` API first, this is accomplised by using meson and the C foreign function interface (CFFI). Following modules should be available to build this project: .. code:: @@ -21,8 +47,6 @@ Following modules should be available to build this project: numpy meson # build only -Additionally you will need a development version of Python, for the Python headers, a Fortran and a C compiler (GCC 7 or newer or Intel 17 or newer) and a linear algebra backend (providing LAPACK and BLAS API). - To install the meson build system first check your package manager for an up-to-date meson version, usually this will also install ninja as dependency. Alternatively, you can install the latest version of meson and ninja with ``pip`` (or ``pip3`` depending on your system): @@ -42,14 +66,51 @@ Now, setup the project by building the CFFI extension module from the ``xtb`` AP .. code:: - meson setup build --prefix=$PWD --libdir=xtb + meson setup build --prefix=$PWD --libdir=xtb --default-library=shared ninja -C build install +This step will create the CFFI extension ``_libxtb`` and place it in the ``xtb`` directory. + + +Meson cannot find xtb dependency +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +If meson cannot find your ``xtb`` installation check if you have ``pkg-config`` installed and that ``xtb`` can be found using + +.. code:: + + pkg-config xtb --print-errors + +In case this fails ensure that the ``xtb.pc`` file is in a directory in the ``PKG_CONFIG_PATH`` and retry. +For the official release tarball you possible have to edit the first line of ``xtb.pc`` to point to the location where you installed ``xtb``: + +.. code:: diff + + --- a/lib/pkgconfig/xtb.pc + +++ b/lib/pkgconfig/xtb.pc + @@ -1,4 +1,4 @@ + -prefix=/ + +prefix=/absolute/path/to/xtb + libdir=${prefix}/lib + includedir=${prefix}/include/xtb + +.. note:: + + Installs from conda-forge should work out-of-box. + + +Dealing with Several Versions of Python +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + If you have several versions of Python installed you can point meson with the ``-Dpy=`` option to the correct one. Depending on your setup you have to export your compilers (``CC`` and ``FC``) first and set the ``-Dla_backend=`` and ``-Dopenmp=`` option accordingly. -For more information on the build with meson, follow the guide in the ``xtb`` repository `here `_. -This step will create the CFFI extension ``_libxtb`` and place it in the ``xtb`` directory. + +.. _devel-install: + +Installing in Development Mode +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + After creating the ``_libxtb`` extension, the Python module can be installed as usual with .. code:: @@ -62,3 +123,66 @@ You can test your setup by opening a new Python interpreter and try to import th .. code:: >>> import xtb.interface + +If you also want to use extensions install with + +.. code:: + + pip install -e '.[ase,qcschema]' + +Now you can test your installation with + +.. code:: + + pytest --pyargs xtb + + +Helpful Tools +^^^^^^^^^^^^^ + +We aim for a high quality code base and encourage substainable development models. + +Please, install a linter like ``flake8`` or ``pylint`` to catch errors before they become bugs. +Also, typehints are mandatory in this project, you should typecheck locally with ``mypy``. +A consistent coding style is enforced by using ``black``, every source file should be reformatted using ``black``, the only exceptions are tests. + + +Building without Upstream Dependency +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +For convenience we also offer a mode to work without an upstream ``xtb`` dependency, this can be quite handy if you also want to work on the ``xtb`` API itself or want to create a failsafe package that cannot break due to ABI or API incompatibilities. + +.. note:: + + It is highly recommend to make yourself familiar with building ``xtb`` first. + +For this approach we follow the same scheme as with the normal extension build. +You will need the following packages installed + +.. code:: + + cffi + numpy + meson # build only + +Additionally you will need a development version of Python, for the Python headers, a Fortran and a C compiler (GCC 7 or newer or Intel 17 or newer) and a linear algebra backend (providing LAPACK and BLAS API). + +We closely follow the approach from before, but we change the configuration of the extension build to + +.. code:: + + meson setup build --prefix=$PWD --libdir=xtb --default-library=static + ninja -C build install + + +Depending on how you acquired the project mesons wrap-tool will first need to download the ``xtb`` source code. +Instead of dynamically depending on ``xtb`` the complete project will be build and included as a whole into the CFFI extension module, making your ``xtb-python`` effectively independent of ``xtb``. + +You can pass the ``-Dopenmp=`` and ``-Dla_backend=`` in the configuration step to configure the ``xtb`` build. +To change the compiler used export them in the environment variables ``CC`` and ``FC``. + +.. tip:: + + For more information on the build with meson, follow the guide in the ``xtb`` repository `here `_. + +From here you can proceed with :ref:`devel-install`. diff --git a/include/xtb.h b/include/xtb.h new file mode 100644 index 0000000..c9e1050 --- /dev/null +++ b/include/xtb.h @@ -0,0 +1,301 @@ +/* This file is part of xtb. + * + * Copyright (C) 2019-2020 Sebastian Ehlert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ +#pragma once + +#define XTB_API_ENTRY +#define XTB_API_CALL +#define XTB_API_SUFFIX__VERSION_6_3_0 + +/// Define proprocessor to allow to check for specific API features +#define XTB_API_VERSION 10000 +#define XTB_VERSION_6_3_0 1 + +/// Possible print levels for API calls +#define XTB_VERBOSITY_FULL 2 +#define XTB_VERBOSITY_MINIMAL 1 +#define XTB_VERBOSITY_MUTED 0 + +#ifdef __cplusplus +extern "C" { +#else +#include +#endif + +/* + * Opaque pointers to Fortran objects +**/ + +/// Calculation environment class +typedef struct _xtb_TEnvironment* xtb_TEnvironment; + +/// Molecular structure data class +typedef struct _xtb_TMolecule* xtb_TMolecule; + +/// Single point calculator class +typedef struct _xtb_TCalculator* xtb_TCalculator; + +/// Single point results class +typedef struct _xtb_TResults* xtb_TResults; + +/* + * Query for semantic API version +**/ + +/// Returns API version as 10000 * major + 100 * minor + 1 * patch +extern XTB_API_ENTRY int XTB_API_CALL +xtb_getAPIVersion() XTB_API_SUFFIX__VERSION_6_3_0; + +/* + * Calculation environment +**/ + +/// Create new xtb calculation environment object +extern XTB_API_ENTRY xtb_TEnvironment XTB_API_CALL +xtb_newEnvironment(void) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Delete a xtb calculation environment object +extern XTB_API_ENTRY void XTB_API_CALL +xtb_delEnvironment(xtb_TEnvironment* /* env */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Check current status of calculation environment +extern XTB_API_ENTRY int XTB_API_CALL +xtb_checkEnvironment(xtb_TEnvironment /* env */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Show and empty error stack +extern XTB_API_ENTRY void XTB_API_CALL +xtb_showEnvironment(xtb_TEnvironment /* env */, + const char* /* message */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Return and empty error stack +extern XTB_API_ENTRY void XTB_API_CALL +xtb_getError(xtb_TEnvironment /* env */, + char* /* buffer */, + const int* /* buffersize */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Bind output from this environment +extern XTB_API_ENTRY void XTB_API_CALL +xtb_setOutput(xtb_TEnvironment /* env */, + const char* /* filename */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Release output unit from this environment +extern XTB_API_ENTRY void XTB_API_CALL +xtb_releaseOutput(xtb_TEnvironment /* env */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Set verbosity of calculation output +extern XTB_API_ENTRY void XTB_API_CALL +xtb_setVerbosity(xtb_TEnvironment /* env */, + int /* verbosity */) XTB_API_SUFFIX__VERSION_6_3_0; + +/* + * Molecular structure data class +**/ + +/// Create new molecular structure data (quantities in Bohr) +extern XTB_API_ENTRY xtb_TMolecule XTB_API_CALL +xtb_newMolecule(xtb_TEnvironment /* env */, + const int* /* natoms */, + const int* /* numbers [natoms] */, + const double* /* positions [natoms][3] */, + const double* /* charge in e */, + const int* /* uhf */, + const double* /* lattice [3][3] */, + const bool* /* periodic [3] */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Delete molecular structure data +extern XTB_API_ENTRY void XTB_API_CALL +xtb_delMolecule(xtb_TMolecule* /* mol */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Update coordinates and lattice parameters (quantities in Bohr) +extern XTB_API_ENTRY void XTB_API_CALL +xtb_updateMolecule(xtb_TEnvironment /* env */, + xtb_TMolecule /* mol */, + const double* /* positions [natoms][3] */, + const double* /* lattice [3][3] */) XTB_API_SUFFIX__VERSION_6_3_0; + +/* + * Singlepoint calculator +**/ + +/// Create new calculator object +extern XTB_API_ENTRY xtb_TCalculator XTB_API_CALL +xtb_newCalculator(void) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Delete calculator object +extern XTB_API_ENTRY void XTB_API_CALL +xtb_delCalculator(xtb_TCalculator* /* calc */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Load GFN0-xTB calculator +extern XTB_API_ENTRY void XTB_API_CALL +xtb_loadGFN0xTB(xtb_TEnvironment /* env */, + xtb_TMolecule /* mol */, + xtb_TCalculator /* calc */, + char* /* filename */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Load GFN1-xTB calculator +extern XTB_API_ENTRY void XTB_API_CALL +xtb_loadGFN1xTB(xtb_TEnvironment /* env */, + xtb_TMolecule /* mol */, + xtb_TCalculator /* calc */, + char* /* filename */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Load GFN2-xTB calculator +extern XTB_API_ENTRY void XTB_API_CALL +xtb_loadGFN2xTB(xtb_TEnvironment /* env */, + xtb_TMolecule /* mol */, + xtb_TCalculator /* calc */, + char* /* filename */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Load GFN-FF calculator +extern XTB_API_ENTRY void XTB_API_CALL +xtb_loadGFNFF(xtb_TEnvironment /* env */, + xtb_TMolecule /* mol */, + xtb_TCalculator /* calc */, + char* /* filename */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Add a solvation model to calculator (requires loaded parametrisation) +extern XTB_API_ENTRY void XTB_API_CALL +xtb_setSolvent(xtb_TEnvironment /* env */, + xtb_TCalculator /* calc */, + char* /* solvent */, + int* /* state */, + double* /* temp */, + int* /* grid */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Unset the solvation model +extern XTB_API_ENTRY void XTB_API_CALL +xtb_releaseSolvent(xtb_TEnvironment /* env */, + xtb_TCalculator /* calc */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Add a external charge potential to calculator (only supported in GFN1/2-xTB) +extern XTB_API_ENTRY void XTB_API_CALL +xtb_setExternalCharges(xtb_TEnvironment /* env */, + xtb_TCalculator /* calc */, + int* /* n */, + int* /* numbers [n] */, + double* /* charges [n] */, + double* /* positions [n][3] */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Unset the external charge potential +extern XTB_API_ENTRY void XTB_API_CALL +xtb_releaseExternalCharges(xtb_TEnvironment /* env */, + xtb_TCalculator /* calc */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Set numerical accuracy of calculator in the range of 1000 to 0.0001 +extern XTB_API_ENTRY void XTB_API_CALL +xtb_setAccuracy(xtb_TEnvironment /* env */, + xtb_TCalculator /* calc */, + double /* accuracy */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Set maximum number of iterations for self-consistent TB calculators +extern XTB_API_ENTRY void XTB_API_CALL +xtb_setMaxIter(xtb_TEnvironment /* env */, + xtb_TCalculator /* calc */, + int /* iterations */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Set electronic temperature for level filling in tight binding calculators in K +extern XTB_API_ENTRY void XTB_API_CALL +xtb_setElectronicTemp(xtb_TEnvironment /* env */, + xtb_TCalculator /* calc */, + double /* temperature */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Perform singlepoint calculation +extern XTB_API_ENTRY void XTB_API_CALL +xtb_singlepoint(xtb_TEnvironment /* env */, + xtb_TMolecule /* mol */, + xtb_TCalculator /* calc */, + xtb_TResults /* res */) XTB_API_SUFFIX__VERSION_6_3_0; + +/* + * Calculation results +**/ + +/// Create new singlepoint results object +extern XTB_API_ENTRY xtb_TResults XTB_API_CALL +xtb_newResults(void) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Delete singlepoint results object +extern XTB_API_ENTRY void XTB_API_CALL +xtb_delResults(xtb_TResults* /* res */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Create copy from a singlepoint results object +extern XTB_API_ENTRY xtb_TResults XTB_API_CALL +xtb_copyResults(xtb_TResults /* res */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Query singlepoint results object for energy in Hartree +extern XTB_API_ENTRY void XTB_API_CALL +xtb_getEnergy(xtb_TEnvironment /* env */, + xtb_TResults /* res */, + double* /* energy */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Query singlepoint results object for gradient in Hartree / Bohr +extern XTB_API_ENTRY void XTB_API_CALL +xtb_getGradient(xtb_TEnvironment /* env */, + xtb_TResults /* res */, + double* /* gradient [natoms][3] */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Query singlepoint results object for virial in Hartree +extern XTB_API_ENTRY void XTB_API_CALL +xtb_getVirial(xtb_TEnvironment /* env */, + xtb_TResults /* res */, + double* /* virial [3][3] */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Query singlepoint results object for dipole in e Bohr +extern XTB_API_ENTRY void XTB_API_CALL +xtb_getDipole(xtb_TEnvironment /* env */, + xtb_TResults /* res */, + double* /* dipole [3] */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Query singlepoint results object for partial charges in e +extern XTB_API_ENTRY void XTB_API_CALL +xtb_getCharges(xtb_TEnvironment /* env */, + xtb_TResults /* res */, + double* /* charges [natoms] */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Query singlepoint results object for bond orders +extern XTB_API_ENTRY void XTB_API_CALL +xtb_getBondOrders(xtb_TEnvironment /* env */, + xtb_TResults /* res */, + double* /* wbo [natoms][natoms] */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Query singlepoint results object for the number of basis functions +extern XTB_API_ENTRY void XTB_API_CALL +xtb_getNao(xtb_TEnvironment /* env */, + xtb_TResults /* res */, + int* /* nao */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Query singlepoint results object for orbital energies in Hartree [nao] +extern XTB_API_ENTRY void XTB_API_CALL +xtb_getOrbitalEigenvalues(xtb_TEnvironment /* env */, + xtb_TResults /* res */, + double* /* emo */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Query singlepoint results object for occupation numbers [nao] +extern XTB_API_ENTRY void XTB_API_CALL +xtb_getOrbitalOccupations(xtb_TEnvironment /* env */, + xtb_TResults /* res */, + double* /* focc */) XTB_API_SUFFIX__VERSION_6_3_0; + +/// Query singlepoint results object for orbital coefficients [nao][nao] +extern XTB_API_ENTRY void XTB_API_CALL +xtb_getOrbitalCoefficients(xtb_TEnvironment /* env */, + xtb_TResults /* res */, + double* /* c */) XTB_API_SUFFIX__VERSION_6_3_0; + +#ifdef __cplusplus +} +#endif diff --git a/meson.build b/meson.build index 2912d3a..299013f 100644 --- a/meson.build +++ b/meson.build @@ -19,32 +19,43 @@ project( 'xtb-python', 'c', license: 'LGPL3', + default_options: [ + 'default_library=static', + ] ) cc = meson.get_compiler('c') +# In case you actually want to depend on the xtb shared library +if get_option('default_library') == 'shared' + xtb_dep = declare_dependency( + include_directories: include_directories('include'), + dependencies: dependency('xtb', version: '>=6.3', required: true), + ) + xtb_header = files('include/xtb.h') +else # Import xtb as subproject, we need the API of version 6.3 or newer, -# also we disable the internal ctypes Python API of xtb since we provide our own -# and force xtb to provide a _static_ library to avoid depending on xtb at runtime -xtb_prj = subproject( - 'xtb', - version: '>=6.3', - default_options: [ - 'default_library=static', - 'static=false', - 'openmp=@0@'.format(get_option('openmp')), - 'la_backend=@0@'.format(get_option('la_backend')), - ], -) -xtb_dep = xtb_prj.get_variable('xtb_dep') -xtb_header = xtb_prj.get_variable('xtb_header') +# in this mode we want to dependency free regarding xtb, therefore, +# we force xtb to provide a _static_ library to avoid depending on xtb at runtime + xtb_prj = subproject( + 'xtb', + version: '>=6.3', + default_options: [ + 'default_library=static', + 'static=false', + 'openmp=@0@'.format(get_option('openmp')), + 'la_backend=@0@'.format(get_option('la_backend')), + ], + ) + xtb_dep = xtb_prj.get_variable('xtb_dep') + xtb_header = xtb_prj.get_variable('xtb_header') +endif pymod = import('python') python = pymod.find_installation( 'python@0@'.format(get_option('py')), modules: [ 'cffi', - 'numpy', ], ) python_dep = python.dependency(required: true) diff --git a/setup.cfg b/setup.cfg index ee8624a..a0a73f1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = xtb-python -version = 1.0.0 +version = 20.1 desciption = Python API of the extended tight binding program long_desciption = file: README.rst long_description_content_type = text/x-rst @@ -10,21 +10,36 @@ url = https://github.com/grimme-lab/xtb-python license = LGPL3 classifiers = Development Status :: 4 - Beta - Environment :: Console Intended Audience :: Science/Research Operating System :: MacOS :: MacOS X Operating System :: POSIX :: Linux Programming Language :: Fortran + Programming Language :: Python :: 3 :: Only Programming Language :: Python :: 3 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 Topic :: Scientific/Engineering :: Chemistry [options] -packages = xtb +packages = find: install_requires = cffi numpy +tests_require = + pytest + pytest-cov + ase + qcelemental python_requires = >=3.5 [options.extras_require] ase = ase qcschema = qcelemental + +[coverage:run] +omit = + */test_*.py + +[aliases] +test=pytest diff --git a/setup.py b/setup.py index c22c594..766f4f8 100644 --- a/setup.py +++ b/setup.py @@ -17,4 +17,4 @@ from setuptools import setup -setup() +setup(package_data={"xtb": ["_libxtb*.so"]}) diff --git a/subprojects/xtb.wrap b/subprojects/xtb.wrap new file mode 100644 index 0000000..0825ed7 --- /dev/null +++ b/subprojects/xtb.wrap @@ -0,0 +1,6 @@ +[wrap-file] +directory = xtb + +source_url = https://github.com/grimme-lab/xtb/archive/v6.3.0.tar.gz +source_filename = xtb-6.3.0.tar.gz +source_hash = 5ef138ad777c5c7dc011b342427b8696a3e7ed13a4708d10ec82f4ad5e1ba621 diff --git a/xtb/__init__.py b/xtb/__init__.py index ed36405..374b99c 100644 --- a/xtb/__init__.py +++ b/xtb/__init__.py @@ -19,4 +19,5 @@ # make sure we have a CFFI available import cffi -__version__ = "1.0.0" +__version__ = "20.1" +API_VERSION = "1.0.0" diff --git a/xtb/ase/__init__.py b/xtb/ase/__init__.py index ac2e62f..6a609a6 100644 --- a/xtb/ase/__init__.py +++ b/xtb/ase/__init__.py @@ -17,5 +17,5 @@ try: import ase -except ImportError: - raise ImportError("This submodule requires ASE installed") +except ModuleNotFoundError: + raise ModuleNotFoundError("This submodule requires ASE installed") diff --git a/tests/test_ase.py b/xtb/ase/test_ase.py similarity index 100% rename from tests/test_ase.py rename to xtb/ase/test_ase.py diff --git a/xtb/interface.py b/xtb/interface.py index 78b05ca..6d5922b 100644 --- a/xtb/interface.py +++ b/xtb/interface.py @@ -137,7 +137,8 @@ class Solvent(Enum): class Environment: - """Calculation environment + """ + .. Calculation environment Wraps an API object representing a TEnvironment class in ``xtb``. The API object is constructed automatically and deconstructed on garbage @@ -210,7 +211,8 @@ def set_verbosity(self, verbosity: int) -> None: class Molecule(Environment): - """Molecular structure data + """ + .. Molecular structure data Represents a wrapped TMolecule API object in ``xtb``. The molecular structure data object has a fixed number of atoms and @@ -344,7 +346,8 @@ def update( class Results(Environment): - """Calculation results + """ + .. Calculation results Holds ``xtb`` API object containing results from a single point calculation. It can be queried for indiviual properties or used to restart calculations. @@ -581,7 +584,18 @@ def get_orbital_coefficients(self) -> np.ndarray: class Calculator(Molecule): - """Singlepoint calculator + """ + .. Singlepoint calculator + + This calculator represents a calculator object in the ``xtb`` API and + provides access to all methods implemented with a unified interface. + The API object must be loaded with a parametrisation before it can be + used in any other API request. + + The parametrisation loading is included in the initialization in this + class, which has the advantage that all API functionality is readily + available, the downside is that a calculator object on the Python side + can only carry one distinct parametrisation, which is not allowed to change. Examples -------- diff --git a/xtb/libxtb.py b/xtb/libxtb.py index 2c0d581..db49004 100644 --- a/xtb/libxtb.py +++ b/xtb/libxtb.py @@ -25,7 +25,7 @@ ------- >>> from xtb.libxtb import get_api_version >>> get_api_version() -"1.0.0" +'1.0.0' """ try: diff --git a/xtb/qcschema/__init__.py b/xtb/qcschema/__init__.py index f154d4d..ff847a9 100644 --- a/xtb/qcschema/__init__.py +++ b/xtb/qcschema/__init__.py @@ -17,5 +17,5 @@ try: import qcelemental -except ImportError: - raise ImportError("This submodule requires QCElemental installed") +except ModuleNotFoundError: + raise ModuleNotFoundError("This submodule requires QCElemental installed") diff --git a/tests/test_qcschema.py b/xtb/qcschema/test_qcschema.py similarity index 100% rename from tests/test_qcschema.py rename to xtb/qcschema/test_qcschema.py diff --git a/tests/test_interface.py b/xtb/test_interface.py similarity index 100% rename from tests/test_interface.py rename to xtb/test_interface.py diff --git a/tests/test_libxtb.py b/xtb/test_libxtb.py similarity index 74% rename from tests/test_libxtb.py rename to xtb/test_libxtb.py index 5e5b4f2..aaddde4 100644 --- a/tests/test_libxtb.py +++ b/xtb/test_libxtb.py @@ -16,14 +16,10 @@ # along with xtb. If not, see . -from xtb import __version__ +from xtb import API_VERSION from xtb.libxtb import get_api_version def test_api_version(): - """Ensure that the API version is compatible. - - We currently enforce an exact match between the version of this package - and the API version, but this might change in the future. - """ - assert get_api_version() == __version__ + """Ensure that the API version is compatible.""" + assert get_api_version() >= API_VERSION diff --git a/tests/test_utils.py b/xtb/test_utils.py similarity index 100% rename from tests/test_utils.py rename to xtb/test_utils.py