Code Monkey home page Code Monkey logo

tblite's Introduction

Light-weight tight-binding framework

License Build Status Doxygen Status Documentation Status codecov

This project is an effort to create a library implementation of the extended tight binding (xTB) Hamiltonian which can be shared between xtb and dftb+.

Goals of this project are

  • create a high-level interface to the extended tight binding methods
  • allow low-level access to the components forming the actual energy expression
  • provide a framework to handle and manipulate parametrization data

Explicit non-goals are

  • provide functionality beyond singlepoint calculations in this library (like geometry optimization or molecular dynamics)

Installation

Conda package

Conda Version Conda Version

This project is packaged for the conda package manager and available on the conda-forge channel. To install the mamba package manager we recommend the mambaforge installer. If the conda-forge channel is not yet enabled, add it to your channels with

mamba config --add channels conda-forge
mamba config --set channel_priority strict

Once the conda-forge channel has been enabled, this project can be installed with:

mamba install tblite

If you want to enable the Python API as well install

mamba install tblite-python

It is possible to list all of the versions available on your platform with:

mamba repoquery search tblite --channel conda-forge

Now you are ready to use tblite.

FreeBSD Port

FreeBSD port

A port for FreeBSD is available

pkg install science/tblite

In case no package is available build the port using

cd /usr/ports/science/tblite
make install clean

For more information see the tblite port details.

Building from source

To build tblite from the source code in this repository you need to have a Fortran compiler supporting Fortran 2008 and one of the supported build systems:

  • meson version 0.57.2 or newer, with a build-system backend, i.e. ninja version 1.10 or newer
  • cmake version 3.14 or newer, with a build-system backend, i.e. ninja version 1.10 or newer
  • fpm version 0.3.0 or newer

To build this project from the source code in this repository you need to have

  • a Fortran compiler supporting Fortran 2008
  • meson version 0.57.2 or newer
  • a build-system backend, i.e. ninja version 1.10 or newer
  • a LAPACK / BLAS provider, like MKL or OpenBLAS

Meson is the primary build system and provides feature-complete functionality of this project. CMake and fpm support are available but the functionality of the project is limited. Currently, tblite support GCC 8 and newer or Intel 18 and newer.

Detailed installation instruction are available in the project documentation under the installation category.

Building with meson

Optional dependencies are

  • asciidoctor to build the manual page
  • C compiler to test the C-API and compile the Python extension module
  • Python 3.6 or newer with the CFFI package installed to build the Python API

Setup a build with

meson setup _build

You can select the Fortran compiler by the FC environment variable. To compile and run the projects testsuite use

meson test -C _build --print-errorlogs

To run the more extensive testing for the available parametrizations use

meson test -C _build --print-errorlogs --benchmark

If the testsuites pass you can install with

meson configure _build --prefix=/path/to/install
meson install -C _build

This might require administrator access depending on the chosen install prefix. For more details see the meson installation instructions.

Usage

This project provides multiple entry points for different usage scenarios. The simplest way to check out this project is by using the command line driver.

Command line interface

The tblite runner executable provides full access to the implemented Hamiltonians, with the tblite-run subcommand. You can run a single point calculation by providing a geometry input with

tblite run --method gfn2 coord

To export a parametrization use the tblite-param subcommand

tblite param --method gfn2 --output gfn2-xtb.toml

The parameter file can be inspected or modified and than used to perform single point calculations with

tblite run --param gfn2-xtb.toml coord

A preliminary interfaces for the parameter optimization is provided by the tblite-fit subcommand. By providing a external command to evaluate the data set in the input file and setting the parameters to relax the fit can be started with

tblite fit gfn2-xtb.toml input.toml

The provided external program can callback to the main program to evaluate single points or create differences between data outputs using the tblite-tagdiff subcommand. By adding the --dry-run option the setup of the parameter optimization can be inspected and with --copy copy.toml the input settings can be dumped for user inspection and tweaking.

For more details on all available subcommands checkout the tblite(1) man page and the respective subcommand man pages.

Documentation

The user documentation is available at readthedocs. Additionally, the doxygen generated API documentation is available here.

To build the user documentation locally we use sphinx, install the dependencies you can use the mamba package manager

mamba create -n sphinx --file doc/requirements.txt
mamba activate sphinx

The documentation is build with

sphinx-build doc _doc

You can inspect the generated documentation by starting a webserver

python3 -m http.server -d _doc

And open the down URL in a browser.

Contributing

This is a volunteer open source projects and contributions are always welcome. Please, take a moment to read the contributing guidelines on how to get involved in tblite.

License

This project is free software: you can redistribute it and/or modify it under the terms of the Lesser GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This project 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 Lesser GNU General Public License for more details.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Lesser GNU General Public license, shall be licensed as above, without any additional terms or conditions.

tblite's People

Contributors

albkat avatar andrew-s-rosen avatar awvwgk avatar benbaed avatar dmejiar avatar haneug avatar kvkarandashev avatar lgtm-com[bot] avatar marcelmbn avatar marvinfriede avatar pitsteinbach avatar pprcht avatar thfroitzheim avatar zyt0y avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

tblite's Issues

FPM compilation fails due to new version of toml-f

Compilation with FPM currently fails with:

./src/tblite/param/serde.f90:159:10:

  159 |    ser = toml_serializer(unit)
      |          1
Error: Component ‘output’ at (1) is a PRIVATE component of ‘toml_serializer’
<ERROR> Compilation failed for object " src_tblite_param_serde.f90.o "
<ERROR>stopping due to failed compilation
STOP 1

In FPM, the version of toml-f is not pinned. For meson and cmake, it is pinned to v0.2.4 and compilation works.
(v0.3.1 also seems to work, both build and tests. )

python API hangs on cluster during `res.dict()`

hello,

I wish to run tblite via the python API on an HPC cluster. i installed version 0.3.0 via pip install tblite, and did not see any errors during the installation. then, i can also load it in python without errors either: import tblite.interface as tb

However, when I try to run any calculation, I can see the iterations being printed up to the point of convergence, but the program simply hangs there.

import numpy as np
import tblite.interface as tb

xtb_method = "GFN1-xTB"
charge = 0
atomic_nums = np.array([6, 6, 6, 6, 6, 6, 6, 6, 6, 6], dtype=np.int32)
xyzs_bohr = np.array(
    [
        [0.000000000000000, 0.000000000000000, 0.000000000000000],
        [0.000000000000000, 0.000000000000000, 1.397000000000000],
        [1.209000000000000, 0.000000000000000, -0.466000000000000],
        [-1.209000000000000, 0.000000000000000, -0.466000000000000],
        [0.000000000000000, 1.209000000000000, -0.466000000000000],
        [0.000000000000000, -1.209000000000000, -0.466000000000000],
        [1.209000000000000, 0.000000000000000, 1.863000000000000],
        [-1.209000000000000, 0.000000000000000, 1.863000000000000],
        [0.000000000000000, 1.209000000000000, 1.863000000000000],
        [0.000000000000000, -1.209000000000000, 1.863000000000000],
    ],
    dtype=np.float32,
)

calc = tb.Calculator(xtb_method, atomic_nums, xyzs_bohr, charge=charge)
calc.set("save-integrals", 1)
print("running calc")
res = calc.singlepoint()
print("finished calc")
res_dict = res.dict()
print(res_dict)

i get this output but the python script will just hang after printing "finished calc" and not move on to the next step (fetching the results dictionary). If I try to CTRL+C to kill the shell, it won't work as well.

running calc
------------------------------------------------------------
  cycle        total energy    energy error   density error
------------------------------------------------------------
      1      10.74693238727  -1.6184161E+01   1.2979420E+00
      2      10.40765017938  -3.3928221E-01   7.3480484E-01
      3      10.41277268629   5.1225069E-03   1.7991844E-01
      4      10.41109929350  -1.6733928E-03   1.2930821E-01
      5      10.37942792884  -3.1671365E-02   1.9564294E-04
      6      10.37942858602   6.5717790E-07   6.2199724E-04
      7      10.37942793611  -6.4990886E-07   8.2217524E-05
      8      10.37942792308  -1.3030999E-08   3.0118601E-06
------------------------------------------------------------

 total:                                   1.553 sec
finished calc

would you have any ideas as to what the problem is?
I am just running it as python3 test_tblite.py where test_tblite.py contains only the lines of code I've shared above.
I have these modules loaded which are LAPACK & BLAS,and it's a SLURM cluster. Not sure if anyone has experience running tblite on a SLURM cluster? I am not sure if there's something I have to configure with srun to handle multithreading correctly, perhaps. This issue mightttt be due to CPU cores/threads not being freed after the calculation finishes.

module load netlib-lapack/3.9.1
module load openblas/0.3.15

Document feature stability

Not all features in tblite are currently stable, for some the defaults and/or the energy expression might be subject to change, those experimental APIs should be marked. Breakage in the experimental APIs should still result in a minor version bump.

Tests fail with Intel 19.0.5 in release mode

Due to some optimization with Intel 19.0.5 the tests fail in release builds, manifests as symmetry-breaking for dihydrogen and other simple examples. This issue is reproducible without OpenMP.

This issue is for documentation purpose and working around the optimization problems with Intel 19.0.5 is not planned since later versions of Intel seem to not have such problems.

PBC Question

Hi Sebastian,

This looks like a really cool project. I have been following the PBC discussions on the main xTB repo grimme-lab/xtb#491, grimme-lab/xtb#257, is the updated pbc method reference in grimme-lab/xtb#491 currently implemented in this repo or is that for a future commit? Also, does highly experimental mean it is worth trying to run some calculations or it best to wait?

Thanks!

-Brandon

Inlined transformation matrix uses wrong orbital ordering

If one uses the transformation matrix for the transformation from cartesian to spherical basis functions, many tests throw an error. To be precise, using sphr = matmul(dtrafo, matmul(cart, transpose(dtrafo))) does not yield the same result as the explicit transformation.
If I change the ordering from [-l, ..., 0, ..., l] to [0, ..., l-1, -(l-1), l, -l], it works again.

real(wp), parameter :: dtrafo(5, 6) = reshape([&
   !  0       1       -1      2       -2
   & -0.5_wp, 0.0_wp, 0.0_wp,   s3_4, 0.0_wp, & ! xx
   & -0.5_wp, 0.0_wp, 0.0_wp,  -s3_4, 0.0_wp, & ! yy
   &  1.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, & ! zz
   &  0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,     s3, & ! xy
   &  0.0_wp,     s3, 0.0_wp, 0.0_wp, 0.0_wp, & ! xz
   &  0.0_wp, 0.0_wp,     s3, 0.0_wp, 0.0_wp],& ! yz
   & shape(dtrafo))

I suspect that the same applies to the transformation matrices for higher (than 2) angular momenta.

More general solver object for returning density matrix

Currently the solver object only returns the eigenvalues and coefficient matrices, for solvers working without diagonalization we usually only return the density matrix.

  • handle electronic filling (finite temperature)
  • collect get_density routine in solver object

subroutine get_density(wfn, solver, ints, ts, error)
!> Tight-binding wavefunction data
type(wavefunction_type), intent(inout) :: wfn
!> Solver for the general eigenvalue problem
class(solver_type), intent(inout) :: solver
!> Integral container
type(integral_type), intent(in) :: ints
!> Electronic entropy
real(wp), intent(out) :: ts
!> Error handling
type(error_type), allocatable, intent(out) :: error
real(wp) :: e_fermi, stmp(2)
real(wp), allocatable :: focc(:)
integer :: spin
select case(wfn%nspin)
case default
call solver%solve(wfn%coeff(:, :, 1), ints%overlap, wfn%emo(:, 1), error)
if (allocated(error)) return
allocate(focc(size(wfn%focc, 1)))
wfn%focc(:, :) = 0.0_wp
do spin = 1, 2
call get_fermi_filling(wfn%nel(spin), wfn%kt, wfn%emo(:, 1), &
& wfn%homo(spin), focc, e_fermi, stmp(spin))
wfn%focc(:, 1) = wfn%focc(:, 1) + focc
end do
ts = sum(stmp)
call get_density_matrix(wfn%focc(:, 1), wfn%coeff(:, :, 1), wfn%density(:, :, 1))
case(2)
wfn%coeff = 2*wfn%coeff
do spin = 1, 2
call solver%solve(wfn%coeff(:, :, spin), ints%overlap, wfn%emo(:, spin), error)
if (allocated(error)) return
call get_fermi_filling(wfn%nel(spin), wfn%kt, wfn%emo(:, spin), &
& wfn%homo(spin), wfn%focc(:, spin), e_fermi, stmp(spin))
call get_density_matrix(wfn%focc(:, spin), wfn%coeff(:, :, spin), &
& wfn%density(:, :, spin))
end do
ts = sum(stmp)
end select
end subroutine get_density

cc @cbannwarth

Interface for higher derivatives

Provide a possibility to query interaction containers for higher derivatives, by default the base container should implement a numerical differentiation, which while inefficient, would allow to use any interaction container for higher derivative calculations.

  • handle derivatives with respect to cartesian coordinates or cell vectors
  • handle derivatives with respect to the wavefunction
  • possibility for general derivatives, which cannot map to the above cases
  • information query for containers to get coordinate / wavefunction dependency

cc @bhourahine

Support for non-selfconsistent xTB methods

Support for non-selfconsistent xTB methods would be useful here, the SCF needs a way to recognize that no iterations are required to avoid wasting computation time.

One half-finished method of this kind would be GFN0-xTB.

Integration with QCArchive infrastructure

Would be useful to also provide an integration with the QCArchive infrastructure. For this purpose a function is needed which can take a QCSchema compliant input, e.g. provided by QCElemental, use tblite.interface to perform the requested computation, and return a QCSchema compliant output.

Example implementations:

Read .CHRG / .UHF from dirname of coordinate file

Like in xtb the .CHRG and .UHF files can be used to specify the total charge and number of unpaired electrons, respectively. However, this behavior seems somewhat uninituitive in case a path to a coordinate file is given while .CHRG / .UHF can only be in the working directory.

tblite/app/driver_run.f90

Lines 93 to 105 in 5db81cc

inquire(file='.CHRG', exist=exist)
if (exist) then
open(file='.CHRG', newunit=unit)
read(unit, *, iostat=stat) charge
if (stat == 0) then
mol%charge = charge
if (config%verbosity > 0) call info(ctx, "Molecular charge read from .CHRG")
else
if (config%verbosity > 0) call warn(ctx, &
"Could not read molecular charge read from .CHRG")
end if
close(unit)
end if

An alternative implementation using the dirname of the coordinate file can be found in mctc-convert.

cc @marvinfriede

Properties do not appear to be affected by `Atoms.get_initial_magnetic_moments()`

As in the xtb-python ASE interface, one would assume that the ASE calculator interface for tblite would set the spin multiplicity of the system based on the provide initial magnetic moments.

Based on the example below, one would expect that if the spin multiplicity is correctly set, then e1 != e2. However, the two values are the same after running the code, indicating that changing the initial magnetic moments does not change the total energy.

from tblite.ase import TBLite
from ase.build import molecule

atoms1 = molecule("CH3")
assert atoms1.get_initial_magnetic_moments().sum() == 1
atoms1.calc = TBLite()
e1 = atoms1.get_potential_energy()

atoms2 = molecule("CH3")
atoms2.set_initial_magnetic_moments([0] * len(atoms2))
assert atoms2.get_initial_magnetic_moments().sum() == 0
atoms2.calc = TBLite()
e2 = atoms2.get_potential_energy()

print(e1, e2)

Output:

-96.94687655923573 -96.94687655923572

I'm confused because the code does suggest that the _uhf parameter is being set:

tblite/python/tblite/ase.py

Lines 221 to 231 in b3dcf32

_uhf = int(self.atoms.get_initial_magnetic_moments().sum().round())
calc = Calculator(
self.parameters.method,
self.atoms.numbers,
self.atoms.positions / Bohr,
_charge,
_uhf,
_cell / Bohr,
_periodic,
)

However, even if you set the initial magnetic moments to 100, you still get the same answer for the energy suggesting that it's not making a difference.

Segmentation fault for large number of atoms

Hello,

I get a segmentation fault linked to tblite with DFTB+ for systems with thousands of atoms. These same systems work fine with DFTB+ and DFTB methods, and with X1TB software.

Regards,
Pierre

setting temperature manually yields incorrect energies

When I set the temperature manually, the calculation converges to an incorrect energy (conda install):

In [1]: from tblite.interface import Calculator
   ...: import numpy as np
   ...: numbers = np.array([1, 1, 6, 5, 1, 15, 8, 17, 13, 15, 5, 1, 9, 15, 1, 15])
   ...: positions = np.array([  # Coordinates in Bohr
   ...:     [+2.79274810283778, +3.82998228828316, -2.79287054959216],
   ...:     [-1.43447454186833, +0.43418729987882, +5.53854345129809],
   ...:     [-3.26268343665218, -2.50644032426151, -1.56631149351046],
   ...:     [+2.14548759959147, -0.88798018953965, -2.24592534506187],
   ...:     [-4.30233097423181, -3.93631518670031, -0.48930754109119],
   ...:     [+0.06107643564880, -3.82467931731366, -2.22333344469482],
   ...:     [+0.41168550401858, +0.58105573172764, +5.56854609916143],
   ...:     [+4.41363836635653, +3.92515871809283, +2.57961724984000],
   ...:     [+1.33707758998700, +1.40194471661647, +1.97530004949523],
   ...:     [+3.08342709834868, +1.72520024666801, -4.42666116106828],
   ...:     [-3.02346932078505, +0.04438199934191, -0.27636197425010],
   ...:     [+1.11508390868455, -0.97617412809198, +6.25462847718180],
   ...:     [+0.61938955433011, +2.17903547389232, -6.21279842416963],
   ...:     [-2.67491681346835, +3.00175899761859, +1.05038813614845],
   ...:     [-4.13181080289514, -2.34226739863660, -3.44356159392859],
   ...:     [+2.85007173009739, -2.64884892757600, +0.71010806424206],
   ...: ])
   ...: calc = Calculator("GFN2-xTB", numbers, positions)
   ...: res = calc.singlepoint()
------------------------------------------------------------
  cycle        total energy    energy error   density error
------------------------------------------------------------
      1     -31.30086746450  -3.1478794E+01   3.3527171E-01
      2     -31.42591394352  -1.2504648E-01   2.5461057E-01
      3     -31.38390717766   4.2006766E-02   2.0097000E-01
      4     -31.65430714370  -2.7039997E-01   1.0795467E-01
      5     -31.70760519808  -5.3298054E-02   6.5352946E-02
      6     -31.69491239413   1.2692804E-02   4.8412026E-02
      7     -31.70847149422  -1.3559100E-02   4.2919999E-02
      8     -31.71179791884  -3.3264246E-03   2.7709746E-02
      9     -31.71584307249  -4.0451537E-03   8.0391049E-03
     10     -31.71608246713  -2.3939464E-04   3.8893373E-03
     11     -31.71614905343  -6.6586301E-05   1.5702043E-03
     12     -31.71615588054  -6.8271154E-06   8.7835837E-04
     13     -31.71615718646  -1.3059193E-06   5.4461612E-04
     14     -31.71615864453  -1.4580625E-06   2.0982621E-04
     15     -31.71615881351  -1.6898782E-07   1.2777352E-04
     16     -31.71615885169  -3.8178211E-08   8.0880218E-05
     17     -31.71615888938  -3.7685925E-08   3.4352168E-05
     18     -31.71615889120  -1.8267485E-09   1.5041592E-05
------------------------------------------------------------

 total:                                   3.585 sec

In [2]: calc.set("temperature",300.0)

In [3]: res = calc.singlepoint()
------------------------------------------------------------
  cycle        total energy    energy error   density error
------------------------------------------------------------
      1     -31158.75974285  -3.1158938E+04   1.1442629E+00
      2     -31158.77521944  -1.5476588E-02   6.8619728E-01
      3     -31158.78466655  -9.4471109E-03   9.9562232E-04
      4     -31158.78466663  -7.9722668E-08   5.9206773E-04
      5     -31158.78466668  -4.7875801E-08   1.1448524E-06
------------------------------------------------------------

 total:                                   1.813 sec

Allow selection of electronic solvers

Implement a dispatch mechanism to select the solver for the self-consistent iterations.

  • attach solver factory to calculation context
  • allow other LAPACK solvers (like ?syevr or ?sygv)
  • implement callback class for C-API to provide solver

cc @cbannwarth

GFN1-xTB fails to converge on a protein polypeptide

hi all,

I'm running GFN1-xTB calculations (v0.3.0) via the Python API, and after fixing some weird numerical instability issues #103 I've got GFN1-xTB to converge well on many protein polypeptides and biological ligands.

however, from my test runs, I'm noticing that the convergence rate is not 100% (but close to 100%)
so far, i encountered a few polypeptide molecules that failed to converge within 150 iterations.

there should, in theory, be nothing too special about it - it was extracted from a protein molecule, where other parts of the same protein converged with GFN1-xTB. because they're from proteins, they only have H, C, N, O, and the occasional S.

update:
more molecules that didn't converge (they come from different proteins)

the code i'm running is:

import tblite.interface as tb


calc = tb.Calculator("GFN1-xTB", frag_atom_nums, frag_xyzs, charge=frag_charge)
calc.set("save-integrals", 1)  # 1 = yes, save integrals, default = 0 (False)
calc.set("accuracy", 0.01)  # lowered from the default of 1
calc.set("guess", 0)  # SAD guess
calc.set("max-iter", 150)
calc.set("mixer-damping", 0.4)  # this is the default
calc.set("temperature", 300 * 3.166808578545117e-6)  # in Hartrees, not Kelvins.
res = calc.singlepoint()

what are common reasons why a molecule could fail to converge with GFN1-xTB? and is there anything that could be done to rescue such molecules? eg improve the initial guess, somehow

thanks a lot.

compilation failure on linux with ifort 17.0.1

ninja: Entering directory `/home/jacobson/software/tblite/_build'                
[1/185] Compiling Fortran object subprojects/dftd4/libdftd4.a.p/src_dftd4_data_covrad.f90.o
[2/185] Compiling Fortran object subprojects/dftd4/libdftd4.a.p/src_dftd4_data_hardness.f90.o
[3/185] Compiling Fortran object subprojects/dftd4/libdftd4.a.p/src_dftd4_data_r4r2.f90.o
[4/185] Compiling Fortran object subprojects/dftd4/libdftd4.a.p/src_dftd4_data_en.f90.o
[5/185] Compiling Fortran object subprojects/dftd4/libdftd4.a.p/src_dftd4_data_zeff.f90.o
[6/185] Compiling Fortran object subprojects/dftd4/libdftd4.a.p/src_dftd4_damping.f90.o
[7/185] Compiling Fortran object subprojects/dftd4/libdftd4.a.p/src_dftd4_charge.f90.o
[8/185] Compiling Fortran object subprojects/dftd4/libdftd4.a.p/src_dftd4_cutoff.f90.o
[9/185] Compiling Fortran object subprojects/dftd4/libdftd4.a.p/src_dftd4_blas.f90.o
[10/185] Compiling Fortran object subprojects/mstore/libmstore.a.p/src_mstore.f90.o
[11/185] Linking static target subprojects/mstore/libmstore.a                    
[12/185] Compiling Fortran object subprojects/toml-f/test/tftester.p/tftest_sort.f90.o
FAILED: subprojects/toml-f/test/tftester.p/tftest_sort.f90.o subprojects/toml-f/test/tftester.p/tftest_sort.mod
/software/lib/Linux-x86_64/ifort_2017.1.132/bin/intel64/ifort -Isubprojects/toml-f/test/tftester.p -Isubprojects/toml-f/test -I../subprojects/toml-f/test -Isubprojects/toml-f/libtoml-f.a.p -D_FILE_OFFSET_BITS=64 -warn general -warn truncated_source -g -traceback -O2 -g -traceback -module subprojects/toml-f/test/tftester.p -gen-dep=subprojects/toml-f/test/tftester.p/tftest_sort.f90.o -gen-depformat=make -o subprojects/toml-f/test/tftester.p/tftest_sort.f90.o -c ../subprojects/toml-f/test/tftest/sort.f90
../subprojects/toml-f/test/tftest/sort.f90(16): error #6580: Name in only-list does not exist.   [TOML_KEY]
   use tomlf, only : toml_key, sort                                              
---------------------^                                                           
../subprojects/toml-f/test/tftest/sort.f90(46): error #6457: This derived type name has not been declared.   [TOML_KEY]
   type(toml_key), allocatable :: list(:)                                        
--------^                                                                        
../subprojects/toml-f/test/tftest/sort.f90(81): error #6457: This derived type name has not been declared.   [TOML_KEY]
   type(toml_key), allocatable :: list(:)                                        
--------^                                                                        
../subprojects/toml-f/test/tftest/sort.f90(116): error #6457: This derived type name has not been declared.   [TOML_KEY]
   type(toml_key), allocatable :: list(:)                                        
--------^                                                                        
../subprojects/toml-f/test/tftest/sort.f90(51): error #6404: This name does not have a type, and must have an explicit type.   [LIST]
   list = [ &                                                                    
---^                                                                             
../subprojects/toml-f/test/tftest/sort.f90(51): error #6366: The shapes of the array expressions do not conform.   [LIST]
   list = [ &                                                                    
---^                                                                             
../subprojects/toml-f/test/tftest/sort.f90(63): error #6285: There is no matching specific subroutine for this generic subroutine call.   [SORT]
   call sort(list)                                                               
--------^                                                                        
../subprojects/toml-f/test/tftest/sort.f90(65): error #6361: An array-valued argument is required in this context.   [SIZE]
   do i = 1, size(list)                                                          
------------------^                                                              
../subprojects/toml-f/test/tftest/sort.f90(66): error #6837: The leftmost part-ref in a data-ref can not be a function reference.   [LIST]
      if (list(i)%key /= expected(i)) then                                       
----------^                                                                      
../subprojects/toml-f/test/tftest/sort.f90(66): error #6158: The structure-name is invalid or is missing.   [LIST]
      if (list(i)%key /= expected(i)) then                                       
----------^                                                                      
../subprojects/toml-f/test/tftest/sort.f90(66): error #6303: The assignment operation or the binary expression operation is invalid for the data types of the two operands.
      if (list(i)%key /= expected(i)) then                                       
----------^                                                                      
../subprojects/toml-f/test/tftest/sort.f90(86): error #6404: This name does not have a type, and must have an explicit type.   [LIST]
   list = [ &                                                                    
---^                                                                             
../subprojects/toml-f/test/tftest/sort.f90(87): error #6404: This name does not have a type, and must have an explicit type.   [TOML_KEY]
      & toml_key("9"), &                                                         
--------^                                                                        
../subprojects/toml-f/test/tftest/sort.f90(86): error #6366: The shapes of the array expressions do not conform.   [LIST]
   list = [ &                                                                    
---^                                                                             
../subprojects/toml-f/test/tftest/sort.f90(98): error #6285: There is no matching specific subroutine for this generic subroutine call.   [SORT]
   call sort(list)                                                               
--------^                                                                        
../subprojects/toml-f/test/tftest/sort.f90(100): error #6361: An array-valued argument is required in this context.   [SIZE]
   do i = 1, size(list)                                                          
------------------^                                                              
../subprojects/toml-f/test/tftest/sort.f90(101): error #6837: The leftmost part-ref in a data-ref can not be a function reference.   [LIST]
      if (list(i)%key /= expected(i)) then                                       
----------^                                                                      
../subprojects/toml-f/test/tftest/sort.f90(101): error #6158: The structure-name is invalid or is missing.   [LIST]
      if (list(i)%key /= expected(i)) then                                       
----------^                                                                      
../subprojects/toml-f/test/tftest/sort.f90(101): error #6158: The structure-name is invalid or is missing.   [LIST]
      if (list(i)%key /= expected(i)) then                                       
----------^                                                                      
../subprojects/toml-f/test/tftest/sort.f90(101): error #6303: The assignment operation or the binary expression operation is invalid for the data types of the two operands.
      if (list(i)%key /= expected(i)) then                                       
----------^                                                                      
../subprojects/toml-f/test/tftest/sort.f90(121): error #6404: This name does not have a type, and must have an explicit type.   [LIST]
   list = [ &                                                                    
---^                                                                             
../subprojects/toml-f/test/tftest/sort.f90(122): error #6404: This name does not have a type, and must have an explicit type.   [TOML_KEY]
      & toml_key("7"), &                                                         
--------^                                                                        
../subprojects/toml-f/test/tftest/sort.f90(121): error #6366: The shapes of the array expressions do not conform.   [LIST]
   list = [ &                                                                    
---^                                                                             
../subprojects/toml-f/test/tftest/sort.f90(133): error #6285: There is no matching specific subroutine for this generic subroutine call.   [SORT]
   call sort(list)                                                               
--------^                                                                        
../subprojects/toml-f/test/tftest/sort.f90(135): error #6361: An array-valued argument is required in this context.   [SIZE]
   do i = 1, size(list)                                                          
------------------^                                                              
../subprojects/toml-f/test/tftest/sort.f90(136): error #6837: The leftmost part-ref in a data-ref can not be a function reference.   [LIST]
      if (list(i)%key /= expected(i)) then                                       
----------^                                                                      
../subprojects/toml-f/test/tftest/sort.f90(136): error #6158: The structure-name is invalid or is missing.   [LIST]
      if (list(i)%key /= expected(i)) then                                       
----------^                                                                      
../subprojects/toml-f/test/tftest/sort.f90(136): error #6303: The assignment operation or the binary expression operation is invalid for the data types of the two operands.
      if (list(i)%key /= expected(i)) then                                       
----------^                                                                      
compilation aborted for ../subprojects/toml-f/test/tftest/sort.f90 (code 1)      
[13/185] Compiling Fortran object subprojects/toml-f/test/example-1/example.p/src_pkg_toml.f90.o
[14/185] Compiling Fortran object subprojects/toml-f/test/example-1/example.p/src_pkg_source.f90.o
[15/185] Compiling Fortran object subprojects/dftd4/libdftd4.a.p/src_dftd4_version.f90.o
[16/185] Compiling Fortran object subprojects/dftd4/libdftd4.a.p/src_dftd4_data.f90.o
[17/185] Compiling Fortran object subprojects/dftd4/libdftd4.a.p/src_dftd4_utils.f90.o
[18/185] Compiling Fortran object subprojects/dftd4/libdftd4.a.p/src_dftd4_ncoord.f90.o
[19/185] Compiling Fortran object subprojects/s-dftd3/libs-dftd3.a.p/src_dftd3_model.f90.o
[20/185] Compiling Fortran object subprojects/multicharge/test/tester.p/test_ncoord.f90.o
[21/185] Compiling Fortran object subprojects/multicharge/test/tester.p/test_model.f90.o
ninja: build stopped: subcommand failed.                                         
Could not rebuild /home/jacobson/software/tblite/_build                          

Convergence of GFNn in PBC mode

I am attaching a simple slab optimization using ASE+TBLITE. For similar models, GFN1 converges in most of the cases, but GFN2 never does.
Is there a specific reason for such behaviour of GFN2? Maybe related to the PBC?
Are there way to affect the convergence with adding a mixture?
GFNn.zip

The same problem exists for CP2k and XTB. I have not checked DFTB+ as it is difficult to make slabs with that.

GFN1-xTB non-convergence with biological ligands

hello,

I've been using tblite with great success on many small molecules (1-30 atoms). I am moving on to try it on larger biologically active ligand (drug) molecules, which have more atoms (30-150).

However, I am starting to notice GFN1-xTB fails to converge for several molecules. I've also tried GFN2-xTB, and it also fails to converge.

Might it be because many of these molecules are not in their equilibrium position? Due to their interaction with the protein molecule they're binding to, some of their bonds would be slightly distorted from the equilibrium position. Some of these are from the open-sourced QMugs dataset, which has 2 million+ drug-like molecules.
On a 3000 molecule subset from QMugs, at least 2% failed to converge. It's small, but non-trivial.

It should also be noted that these molecules could be converged with both Hartree-Fock & DFT calculations.

Any help or advice would be greatly appreciated! :)

Here is an example code snippet that I'm running:

calc = tb.Calculator("GFN1-xTB", atomic_nums, xyzs_bohr, charge=charge)
calc.set("save-integrals", 1)  # 1 = yes, save integrals, default = 0 (False)
calc.set("accuracy", 0.1)  # lowered from the default of 1
calc.set("guess", 0)
calc.set("max-iter", 150)
calc.set(
    "mixer-damping", 0.4
)  # default 0.4, not sure what this changes... if too low seems to increase no. of iterations.
calc.set("temperature", 300 * 3.166808578545117e-6)  # in Hartrees, not Kelvins.
# calc.set("verbosity", 0)  # STILL not supported in v0.3.0 (latest conda release)...

res = calc.singlepoint()
res_dict = res.dict()  # energy is in atomic units, aka Hartrees

Here's an example molecule with 42 atoms that fails to converge within 150 iterations:

atomic_nums = np.array([6, 6, 6, 6, 6, 8, 6, 6, 6, 7, 6, 7, 7, 6, 6, 6, 8, 6, 6, 6, 6, 6,
       6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
charge = 0
xyzs_bohr = np.array([[-63.91676791, 329.07330697, 157.05191297],
       [-64.42548096, 326.63724556, 158.53288941],
       [-62.60492276, 324.4927918 , 157.81498615],
       [-63.14311232, 322.01099818, 159.22736428],
       [-61.17987888, 319.97406988, 158.56426181],
       [-63.08056214, 322.52671091, 161.8739351 ],
       [-65.34899169, 323.22232477, 162.93350345],
       [-67.37837245, 321.52723456, 163.39269971],
       [-69.6193944 , 322.48873531, 164.52275505],
       [-69.99261932, 324.9365037 , 165.19776635],
       [-68.0681184 , 326.58661142, 164.714565  ],
       [-67.98723642, 329.06102329, 165.17376127],
       [-65.60410873, 329.92122693, 164.34210421],
       [-64.28696516, 327.96552662, 163.39894248],
       [-65.79950143, 325.76513309, 163.59982102],
       [-67.2551608 , 318.82303713, 162.64493789],
       [-66.058021  , 318.15899752, 160.76465534],
       [-68.62653566, 316.96638481, 164.26518703],
       [-69.88716998, 317.82298408, 166.46010192],
       [-71.21375699, 316.11601388, 168.01270433],
       [-71.30352012, 313.5342784 , 167.38172397],
       [-70.07123054, 312.66216593, 165.19284999],
       [-68.74369919, 314.36688701, 163.63874817],
       [-65.23334199, 330.55709481, 157.60844154],
       [-64.12993013, 328.77244331, 155.02480296],
       [-62.00739092, 329.76756559, 157.39451519],
       [-64.26995976, 327.03332216, 160.54904215],
       [-66.36982031, 326.03724833, 158.20445955],
       [-62.74551467, 324.15718204, 155.78617487],
       [-60.66228467, 325.08408088, 158.17026132],
       [-65.00090362, 321.32769684, 158.65516393],
       [-61.13414668, 319.62522489, 156.53431156],
       [-59.28807317, 320.54456897, 159.14780871],
       [-61.61111247, 318.18033537, 159.48021779],
       [-71.19580724, 321.24133623, 164.88425857],
       [-71.65765632, 325.43595353, 165.98634402],
       [-62.39364923, 328.13297106, 162.64078566],
       [-69.84276418, 319.79889768, 166.97562722],
       [-72.16485553, 316.7898862 , 169.68851838],
       [-72.32264748, 312.22600878, 168.57205872],
       [-70.14908486, 310.68247496, 164.70076749],
       [-67.83606209, 313.64650395, 161.95783033]])

Provide callback object for electronic solvers

Implement callback class for C-API to provide solver

  • constructor callback to create new solver object
  • finalizer callback to delete solver object
  • actual solver object to transfer pointer to matrices (float + double)

ASE calculator results in ImportError

I installed tblite by git clone'ing the repo and then doing export CC=gcc, pip install ., and pip install '.[ase] as mentioned in the docs.

Then, doing

from tblite.ase import TBLite

results in

Traceback (most recent call last):
  File "/home/arosen/software/tblite/python/tblite/library.py", line 27, in <module>
    from ._libtblite import ffi, lib
ModuleNotFoundError: No module named 'tblite._libtblite'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/arosen/software/tblite/python/tblite/ase.py", line 32, in <module>
    from .interface import Calculator
  File "/home/arosen/software/tblite/python/tblite/interface.py", line 26, in <module>
    from . import library
  File "/home/arosen/software/tblite/python/tblite/library.py", line 29, in <module>
    raise ImportError("tblite C extension unimportable, cannot use C-API")
ImportError: tblite C extension unimportable, cannot use C-API

Using conda install tblite doesn't help either.

Python API hangs at error

I'm running a large dataset of xTB, and have run into an issue where if the error "ERROR STOP Error in Broyden matrix inversion!" gets printed the calculation hangs. Would it be possible to make this instead throw an exception?

Issues with meson build

I am trying to install the python API and having difficulties. I first tried a pip install to install the python API interface with an existing tblite installation. I got the error that this import couldn't be made from ._libtblite import ffi, lib when loading python/tblite/library.py. Indeed the file _libtblite was located nowhere. Since building on top didn't work, I then proceeded to delete everything and start over using the recommended meson build method. I'm using meson version 0.59.0, which satisfies the suggested requirements > 0.55.0. Unfortunately ,cloning this git repo and trying meson setup _build -Dpython_version=3 immediately yields the following error:

Traceback (most recent call last):
  File "/home/gridsan/gawinter/.conda/envs/meson/lib/python3.9/site-packages/mesonbuild/mesonmain.py", line 227, in run
    return options.run_func(options)
  File "/home/gridsan/gawinter/.conda/envs/meson/lib/python3.9/site-packages/mesonbuild/msetup.py", line 281, in run
    app.generate()
  File "/home/gridsan/gawinter/.conda/envs/meson/lib/python3.9/site-packages/mesonbuild/msetup.py", line 183, in generate
    with mesonlib.BuildDirLock(self.build_dir):
  File "/home/gridsan/gawinter/.conda/envs/meson/lib/python3.9/site-packages/mesonbuild/mesonlib/posix.py", line 32, in __enter__
    fcntl.flock(self.lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
OSError: [Errno 38] Function not implemented

In my environment containing meson, I am able to import fcntl in a python session. Any ideas on what either of my problems here are caused by?

Compilation fails on Windows-mingw64

I came from this link, just out of curiosity, I used mingw64-gfortran to compile tblite on windows and found an unexpected error, I am not sure if it is a bug of mingw64-gfortran, but it can be done by replacing the setenv routine with putenv and solved (see my code), the code becomes less, and it seems to be able to compile on windows-ifort and wsl2-gfortran (not very sure)?

>> fpm build
...
main.f90                               done.
tblite.exe                             failed.
[ 100%]Compiling...
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: build\gfortran_232594290C1E0524\tblite\libtblite.a(src_tblite_os.F90.o): in function `__tblite_os_MOD_setenv':C:\Users\zoziha\com.zoziha\fortran\tmp\tblite/./src/tblite/os.F90:69: undefined reference to `setenv'     
collect2.exe: error: ld returned 1 exit status
<ERROR> Compilation failed for object " tblite.exe "
<ERROR>stopping due to failed compilation
STOP 1

I'm not familiar with xblite, probably xblite is not intended to support windows-gfortran, if so, please ignore this issue.

k-point sampling

In one of the comments you mentioned k-point sampling. It is a great idea to have it in tblite.
I have been testing tblite, DFTB+, and CP2k for a while. Among others, tblibe is the most easy-to-use tool. Especially, as a stand-alone calculator to ASE. Yet, it does luck some features, like k-point sampling and a detailed output.

How difficult is to implement k-points?
How about linking the corresponding module to https://pypi.org/project/kpLib/?

Allow setting verbosity in API

Would be useful to have the possibility for adjusting the verbosity of the output using a setter for the context handle.

Support returning atom-resolved energies

Most calculations internally use atom-resolved energies, which would make it rather straight-forward to expose those quantities to the user via an optional output or via an API function.

Care should be taken to not break the API and also not require the external integrations to account for atom-resolved energies. In case only a total energies is required, the usage of atom-resolved energies should remain an implementation detail.

energy of supercell is inconsistent with converged kpoint mesh using dftb+

I'm filing this issue here as it seems likely that the issue originates with the tblite library. If you prefer I file this as a DFTB+ issues let me know and I can report it there.

Using ammonia crystal as an example, if I compute the energy/molecule of the ammonia crystal with DFTB+, using the GFN2-xTB hamiltonian the energy of a supercell is inconsistent with a converged k-point mesh. Though I can't clearly converge the energy of the supercell it appears to be clearly inconsistent.

The energy/molecule in atomic units for unit cell, 2x2x2, 3x3x3 supercell is -4.431179568, -4.440716078 and -4.442071631. The energy/molecule using kpoint meshes of 1x1x1, 2x2x2, 3x3x3 is -4.431179568, -4.433776963 and -4.433775811.

I also tested this using a DFTB hamiltonian using the slater-koster files from:
https://dftb.org/parameters/download/ob2/ob2-1-1

and the energies are consistent. The supercell and kpoint mesh both converge to about -4.103043743 and the energy of a 4x4x4 supercell and a 4x4x4 kpoint mesh agree to 1.0e-7 a.u.

The unit cell geometry is given here in dftb+ format:

16  S    
H    N    
1      1      1.859600000000000      1.355800000000000      0.523200000000000
2      1      1.355800000000000      0.523200000000000      1.859600000000000
3      1      0.523200000000000      1.859600000000000      1.355800000000000
4      1      4.340700000000000      1.125300000000000      4.439000000000000
5      1      3.836800000000000      1.957900000000000      3.102500000000000
6      1      3.004300000000000      0.621400000000000      3.606400000000000
7      1      3.606400000000000      3.004300000000000      0.621400000000000
8      1      4.439000000000000      4.340700000000000      1.125300000000000
9      1      1.957900000000000      3.102500000000000      3.836800000000000
10     1      0.621400000000000      3.606400000000000      3.004300000000000
11     1      1.125300000000000      4.439000000000000      4.340700000000000
12     1      3.102500000000000      3.836800000000000      1.957900000000000
13     2      1.034200000000000      1.034200000000000      1.034200000000000
14     2      3.515200000000000      1.446900000000000      3.928000000000000
15     2      3.928000000000000      3.515200000000000      1.446900000000000
16     2      1.446900000000000      3.928000000000000      3.515200000000000
     0.000000000000000      0.000000000000000      0.000000000000000 
     4.962163925170898      0.000000000000000      0.000000000000000 
     0.000000000000000      4.962163925170898      0.000000000000000 
     0.000000000000000      0.000000000000000      4.962163925170898 

feature request: output intermediate matrices via commandline executable

hello,

I would like to request a feature, which is that just running tblite run <coord> would also have an option to save, in the output --json <output.json> file, the intermediate matrices that one could get from the Python API (via the res.dict() call).

there could be a commandline flag to trigger this behavior, e.g. --save_integrals, and addiitonally another commandline flag to specify exactly which matrices/properties to be included in the output JSON, e.g. --integrals_list "hamiltonian" "overlap" "density" "orbitals".

specifically, I'd like the above 4 matrices exportable (core hamiltonian H, overlap S, density D and MO orbital coefficients C) and the orbital MO energies.

the reason for my request is that the commandline executable is much easier to install and use. I'm having a lot of issues getting the python bindings to work on my OS (Nix-OS). Recently there's been issues of numerical instability as well. (this gives a hint: Nix-QChem/NixOS-QChem#250 (comment))

thanks a lot, this package is really awesome.

Export C++ bindings

Provide bindings for C++ based on the existing C API. The C++ API should translate the existing C objects to C++ classes and handle construction and deconstruction automatically.

The C++ bindings are likely to be header-only, in case we need C++ implementations of the glue code, the C++ bindings should be optional to not introduce a hard dependency on a C++ compiler for building and the C++ runtime for the final shared library.

cube files

Is it possible to save wavefunctions or, better, electron density in a cube-file format?
xtb can do that but it still lucks periodicity of tblite within it.

Question: Parametrization optimization tutorial

In the tutorial for parameter optimation, it states that a data set to fit against is assumed to be already existing and prepared.

My question is what is the format of this data set and how can it be prepared?

Implement k-points sampling

This could easily be a feature but I'm filing as an issue in case it's not. As a test I computed the cohesive energy of ammonia crystal (from the X23 test set) using the given unit cell as well as 2x2x2, 3x3x3, etc supercells. The energy I compute is 3.25, 9.25 and 10.10 kcal/mol/molecule for the unitcell, 2x2x2, and 3x3x3 respectively. For larger supercells I get a segfault.

Can you advise? Is this due to lack of k-point sampling (gamma point approx)? Is this expected? Is there a hard limit on the system size?

Molecule geometry:
$coord angs
1.8596000000 1.3558000000 0.5232000000 H
1.3558000000 0.5232000000 1.8596000000 H
0.5232000000 1.8596000000 1.3558000000 H
1.0342000000 1.0342000000 1.0342000000 N
$end                                                
Unit cell geometry:
$coord angs
1.8596000000 1.3558000000 0.5232000000 H
1.3558000000 0.5232000000 1.8596000000 H
0.5232000000 1.8596000000 1.3558000000 H
4.3407000000 1.1253000000 4.4390000000 H
3.8368000000 1.9579000000 3.1025000000 H
3.0043000000 0.6214000000 3.6064000000 H
3.6064000000 3.0043000000 0.6214000000 H
4.4390000000 4.3407000000 1.1253000000 H
1.9579000000 3.1025000000 3.8368000000 H
0.6214000000 3.6064000000 3.0043000000 H
1.1253000000 4.4390000000 4.3407000000 H
3.1025000000 3.8368000000 1.9579000000 H
1.0342000000 1.0342000000 1.0342000000 N
3.5152000000 1.4469000000 3.9280000000 N
3.9280000000 3.5152000000 1.4469000000 N
1.4469000000 3.9280000000 3.5152000000 N
$periodic 3
$lattice angs
4.9621637000 0.0000000000 0.0000000000
0.0000000000 4.9621637000 0.0000000000
0.0000000000 0.0000000000 4.9621637000
$end                                                    
2x2x2 cell
$coord angs                                                                                                                                                                                                                                   
0.5539040000 2.7226850000 -3.7759750000 H                                                                                                                                                                                                     
0.0501040000 1.8900850000 -2.4395750000 H                                                                                                                                                                                                     
-0.7824960000 3.2264850000 -2.9433750000 H                                                                                                                                                                                                    
3.0350040000 2.4921850000 0.1398250000 H                                                                                                                                                                                                      
2.5311040000 3.3247850000 -1.1966750000 H                                                                                                                                                                                                     
1.6986040000 1.9882850000 -0.6927750000 H                                                                                                                                                                                                     
2.3007040000 4.3711850000 -3.6777750000 H                                                                                                                                                                                                     
3.1333040000 5.7075850000 -3.1738750000 H                                                                                                                                                                                                     
0.6522040000 4.4693850000 -0.4623750000 H                                                                                                                                                                                                     
-0.6842960000 4.9732850000 -1.2948750000 H                                                                                                                                                                                                    
-0.1803960000 5.8058850000 0.0415250000 H                                                                                                                                                                                                     
1.7968040000 5.2036850000 -2.3412750000 H                                                                                                                                                                                                     
-0.2714960000 2.4010850000 -3.2649750000 N                                                                                                                                                                                                    
2.2095040000 2.8137850000 -0.3711750000 N                                                                                                                                                                                                     
2.6223040000 4.8820850000 -2.8522750000 N                                                                                                                                                                                                     
0.1412040000 5.2948850000 -0.7839750000 N                                                                                                                                                                                                     
0.5539040000 2.7226850000 1.1861890000 H                                                                                                                                                                                                      
0.0501040000 1.8900850000 2.5225890000 H                                                                                                                                                                                                      
-0.7824960000 3.2264850000 2.0187890000 H                                                                                                                                                                                                     
3.0350040000 2.4921850000 5.1019890000 H                                                                                                                                                                                                      
2.5311040000 3.3247850000 3.7654890000 H                                                                                                                                                                                                      
1.6986040000 1.9882850000 4.2693890000 H                                                                                                                                                                                                      
2.3007040000 4.3711850000 1.2843890000 H                                                                                                                                                                                                      
3.1333040000 5.7075850000 1.7882890000 H                                                                                                                                                                                                      
0.6522040000 4.4693850000 4.4997890000 H                                                                                                                                                                                                      
-0.6842960000 4.9732850000 3.6672890000 H                                                                                                                                                                                                     
-0.1803960000 5.8058850000 5.0036890000 H                                                                                                                                                                                                     
1.7968040000 5.2036850000 2.6208890000 H                                                                                                                                                                                                      
-0.2714960000 2.4010850000 1.6971890000 N                                                                                                                                                                                                     
2.2095040000 2.8137850000 4.5909890000 N                                                                                                                                                                                                      
2.6223040000 4.8820850000 2.1098890000 N                                                                                                                                                                                                      
0.1412040000 5.2948850000 4.1781890000 N                                                                                                                                                                                                      
0.5539040000 7.6848490000 -3.7759750000 H                                                                                                                                                                                                     
0.0501040000 6.8522490000 -2.4395750000 H                                                                                                                                                                                                     
-0.7824960000 8.1886490000 -2.9433750000 H                                                                                                                                                                                                    
3.0350040000 7.4543490000 0.1398250000 H                                                                                                                                                                                                      
2.5311040000 8.2869490000 -1.1966750000 H                                                                                                                                                                                                     
1.6986040000 6.9504490000 -0.6927750000 H                                                                                                                                                                                                     
2.3007040000 9.3333490000 -3.6777750000 H                                                                                                                                                                                                     
3.1333040000 10.6697490000 -3.1738750000 H                                                                                                                                                                                                    
0.6522040000 9.4315490000 -0.4623750000 H                                                                                                                                                                                                     
-0.6842960000 9.9354490000 -1.2948750000 H                                                                                                                                                                                                    
-0.1803960000 10.7680490000 0.0415250000 H                                                                                                                                                                                                    
1.7968040000 10.1658490000 -2.3412750000 H                                                                                                                                                                                                    
-0.2714960000 7.3632490000 -3.2649750000 N                                                                                                                                                                                                    
2.2095040000 7.7759490000 -0.3711750000 N                                                                                                                                                                                                     
2.6223040000 9.8442490000 -2.8522750000 N                                                                                                                                                                                                     
0.1412040000 10.2570490000 -0.7839750000 N                                                                                                                                                                                                    
0.5539040000 7.6848490000 1.1861890000 H                                                                                                                                                                                                      
0.0501040000 6.8522490000 2.5225890000 H                                                                                                                                                                                                      
-0.7824960000 8.1886490000 2.0187890000 H                                                                                                                                                                                                     
3.0350040000 7.4543490000 5.1019890000 H                                                                                                                                                                                                      
2.5311040000 8.2869490000 3.7654890000 H
1.6986040000 6.9504490000 4.2693890000 H
2.3007040000 9.3333490000 1.2843890000 H
3.1333040000 10.6697490000 1.7882890000 H
0.6522040000 9.4315490000 4.4997890000 H
-0.6842960000 9.9354490000 3.6672890000 H
-0.1803960000 10.7680490000 5.0036890000 H
1.7968040000 10.1658490000 2.6208890000 H
-0.2714960000 7.3632490000 1.6971890000 N
2.2095040000 7.7759490000 4.5909890000 N
2.6223040000 9.8442490000 2.1098890000 N
0.1412040000 10.2570490000 4.1781890000 N
5.5160680000 2.7226850000 -3.7759750000 H
5.0122680000 1.8900850000 -2.4395750000 H
4.1796680000 3.2264850000 -2.9433750000 H
7.9971680000 2.4921850000 0.1398250000 H
7.4932680000 3.3247850000 -1.1966750000 H
6.6607680000 1.9882850000 -0.6927750000 H
7.2628680000 4.3711850000 -3.6777750000 H
8.0954680000 5.7075850000 -3.1738750000 H
5.6143680000 4.4693850000 -0.4623750000 H
4.2778680000 4.9732850000 -1.2948750000 H
4.7817680000 5.8058850000 0.0415250000 H
6.7589680000 5.2036850000 -2.3412750000 H
4.6906680000 2.4010850000 -3.2649750000 N
7.1716680000 2.8137850000 -0.3711750000 N
7.5844680000 4.8820850000 -2.8522750000 N
5.1033680000 5.2948850000 -0.7839750000 N
5.5160680000 2.7226850000 1.1861890000 H
5.0122680000 1.8900850000 2.5225890000 H
4.1796680000 3.2264850000 2.0187890000 H
7.9971680000 2.4921850000 5.1019890000 H
7.4932680000 3.3247850000 3.7654890000 H
6.6607680000 1.9882850000 4.2693890000 H
7.2628680000 4.3711850000 1.2843890000 H
8.0954680000 5.7075850000 1.7882890000 H
5.6143680000 4.4693850000 4.4997890000 H
4.2778680000 4.9732850000 3.6672890000 H
4.7817680000 5.8058850000 5.0036890000 H
6.7589680000 5.2036850000 2.6208890000 H
4.6906680000 2.4010850000 1.6971890000 N
7.1716680000 2.8137850000 4.5909890000 N
7.5844680000 4.8820850000 2.1098890000 N
5.1033680000 5.2948850000 4.1781890000 N
5.5160680000 7.6848490000 -3.7759750000 H
5.0122680000 6.8522490000 -2.4395750000 H
4.1796680000 8.1886490000 -2.9433750000 H
7.9971680000 7.4543490000 0.1398250000 H
7.4932680000 8.2869490000 -1.1966750000 H
6.6607680000 6.9504490000 -0.6927750000 H
7.2628680000 9.3333490000 -3.6777750000 H
8.0954680000 10.6697490000 -3.1738750000 H
5.6143680000 9.4315490000 -0.4623750000 H
4.2778680000 9.9354490000 -1.2948750000 H
4.7817680000 10.7680490000 0.0415250000 H
6.7589680000 10.1658490000 -2.3412750000 H
4.6906680000 7.3632490000 -3.2649750000 N
7.1716680000 7.7759490000 -0.3711750000 N
7.5844680000 9.8442490000 -2.8522750000 N
5.1033680000 10.2570490000 -0.7839750000 N
5.5160680000 7.6848490000 1.1861890000 H
5.0122680000 6.8522490000 2.5225890000 H
4.1796680000 8.1886490000 2.0187890000 H
7.9971680000 7.4543490000 5.1019890000 H
7.4932680000 8.2869490000 3.7654890000 H
6.6607680000 6.9504490000 4.2693890000 H
7.2628680000 9.3333490000 1.2843890000 H
8.0954680000 10.6697490000 1.7882890000 H
5.6143680000 9.4315490000 4.4997890000 H
4.2778680000 9.9354490000 3.6672890000 H
4.7817680000 10.7680490000 5.0036890000 H
6.7589680000 10.1658490000 2.6208890000 H
4.6906680000 7.3632490000 1.6971890000 N
7.1716680000 7.7759490000 4.5909890000 N
7.5844680000 9.8442490000 2.1098890000 N
5.1033680000 10.2570490000 4.1781890000 N
$periodic 3
$lattice angs
9.9243278503 0.0000000000 0.0000000000
0.0000000000 9.9243278503 0.0000000000
0.0000000000 0.0000000000 9.9243278503

any way to extract/print the Fock matrix from GFN-xTB ?

Hello,

first of all thank you for your awesome work! my main use of tblite has been to extract the intermediate matrices, like the overlap matrix, the hamiltonian matrix and so on, which was not so trivial with xTB. I've tried it on a few examples and everything has worked wonderfully well.

however, I am also in need of the Fock matrix F for the machine learning model that I want to build. Is there any way I can also extract the last iteration's fock matrix somehow? I was thinking it shouldn't be too complicated given that we already extract the other matrices as part of the self-iterative procedure. and surely F must have been calculated to obtain the solution, which is the energy.

Please pardon if my question is very simple as I have basically 0 knowledge of Fortran, and only rudimentary understanding of quantum physics.

Thank you very much!

Best,
Min Htoo

Suggestion: Raise warning in ASE calculator if `_uhf` is not valid

The ASE calculator sets the _uhf parameter as follows:

tblite/python/tblite/ase.py

Lines 217 to 231 in b3dcf32

try:
_cell = self.atoms.cell
_periodic = self.atoms.pbc
_charge = self.atoms.get_initial_charges().sum()
_uhf = int(self.atoms.get_initial_magnetic_moments().sum().round())
calc = Calculator(
self.parameters.method,
self.atoms.numbers,
self.atoms.positions / Bohr,
_charge,
_uhf,
_cell / Bohr,
_periodic,
)

However, as described in #111, if the value for _uhf is invalid given the number of electrons in the molecule, no warnings or errors are raised. For instance, a CH3 molecule with 0 initial magnetic moments will run without any error or warning to the user (and in fact, I think tblite automatically sets it to _uhf 1 internally). This can lead to unexpected behavior.

I propose that a UserWarning should be raised if _uhf is ultimately going to be ignored by the tblite executable.

Documentation of C API

We should have a full documentation of the C API capabilities. This can either be done manually (error prone with the currently fast growing API functionality) or by an automatic tool like doxygen. Using doxygen would allow integration via breathe in our existing sphinx documentation.

Compatibility issue with Pytorch

I found this strange behavior of tblite in Python if PyTorch was imported.

import torch
from tblite.ase import TBLite
from ase.atoms import Atoms
import numpy as np
atoms = Atoms(
    symbols="C4O8",
    positions=np.array(
        [
            [0.9441259872, 0.9437851680, 0.9543505632],
            [3.7179966528, 0.9556570368, 3.7316862240],
            [3.7159517376, 3.7149292800, 0.9692330016],
            [0.9529872864, 3.7220864832, 3.7296981120],
            [1.6213905408, 1.6190616096, 1.6313879040],
            [0.2656685664, 0.2694175776, 0.2776540416],
            [4.3914553920, 1.6346256864, 3.0545920000],
            [3.0440834880, 0.2764611744, 4.4080419264],
            [4.3910577696, 3.0416409504, 0.2881058304],
            [3.0399936576, 4.3879335936, 1.6497353376],
            [0.2741322432, 4.4003734944, 3.0573754368],
            [1.6312174944, 3.0434586528, 4.4023048032],
        ]
    ),
    cell=np.array([5.68032, 5.68032, 5.68032]),
    pbc=np.array([True, True, True]),
)
atoms.calc = TBLite(method="GFN1-xTB")
atoms.get_potential_energy()  # result in eV

I got below output and it will never converge.

------------------------------------------------------------
  cycle        total energy    energy error   density error
------------------------------------------------------------
      1     -220145.1130691  -2.2014835E+05   2.2662454E+01
      2     -40994493.39613  -4.0774348E+07   2.5360774E+01
      3     -41798970.97528  -8.0447758E+05   2.1118388E+01
      4     -41231779.00001   5.6719198E+05   4.2775653E+00
      5     -41176517.54710   5.5261453E+04   2.1617182E+00
      6     -40929947.88949   2.4656966E+05   2.0241658E+00
      7     -40916228.61312   1.3719276E+04   1.5423235E+00
      8     -41175248.31226  -2.5901970E+05   1.8033720E+00
      9     -41075903.51087   9.9344801E+04   1.8529595E+00
     10     -41214458.36624  -1.3855486E+05   1.6252884E+00
     11     -41186215.84712   2.8242519E+04   1.2174420E+00
     12     -41076999.56984   1.0921628E+05   1.5036796E+00
     13     -40914319.21158   1.6268036E+05   1.0555325E+00
     14     -41803486.23037  -8.8916702E+05   1.1167128E+00
     15     -41425955.91671   3.7753031E+05   7.6022145E-01
     16     -41304348.50592   1.2160741E+05   1.2073868E+00
     17     -41771834.81548  -4.6748631E+05   9.9171739E-01
     18     -41090587.65317   6.8124716E+05   9.7361783E-01
     19     -41803487.78510  -7.1290013E+05   9.0392384E-01
     20     -40980774.06874   8.2271372E+05   8.5913280E-01
     21     -41803489.59767  -8.2271553E+05   5.3896947E-01
     22     -39982953.84887   1.8205357E+06   9.5528544E-01
     23     -41305192.47564  -1.3222386E+06   6.9177270E-01
     24     -41268485.27003   3.6707206E+04   5.5739283E-01
     25     -41478496.45580  -2.1001119E+05   6.3010293E-01
     26     -40702421.14412   7.7607531E+05   7.1690218E-01
     27     -39651186.85413   1.0512343E+06   1.2553164E+00
     28     -40949242.17474  -1.2980553E+06   6.1052683E-01
     29     -41001412.34763  -5.2170173E+04   5.5212886E-01
     30     -41073869.01141  -7.2456664E+04   7.7515769E-01
     31     -41737795.31617  -6.6392630E+05   1.9723712E-01
     32     -41801158.60198  -6.3363286E+04   2.2661286E-01
     33     -41661436.55195   1.3972205E+05   4.3782619E-01
     34     -41674543.69094  -1.3107139E+04   3.5255131E-01
     35     -41173591.11277   5.0095258E+05   4.4963589E-01
     36     -41788959.06234  -6.1536795E+05   2.8875074E-01
     37     -41797570.46348  -8.6114011E+03   2.4509764E-01
     38     -41668462.37089   1.2910809E+05   4.0788906E-01
     39     -41803490.37610  -1.3502801E+05   2.4518633E-01
     40     -41803490.44519  -6.9086663E-02   1.9533992E-01
     41     -41703372.46342   1.0011798E+05   3.2203525E-01
...

change the order of import solve the issue:

from tblite.ase import TBLite
import torch
from ase.atoms import Atoms
import numpy as np
atoms = Atoms(
    symbols="C4O8",
    positions=np.array(
        [
            [0.9441259872, 0.9437851680, 0.9543505632],
            [3.7179966528, 0.9556570368, 3.7316862240],
            [3.7159517376, 3.7149292800, 0.9692330016],
            [0.9529872864, 3.7220864832, 3.7296981120],
            [1.6213905408, 1.6190616096, 1.6313879040],
            [0.2656685664, 0.2694175776, 0.2776540416],
            [4.3914553920, 1.6346256864, 3.0545920000],
            [3.0440834880, 0.2764611744, 4.4080419264],
            [4.3910577696, 3.0416409504, 0.2881058304],
            [3.0399936576, 4.3879335936, 1.6497353376],
            [0.2741322432, 4.4003734944, 3.0573754368],
            [1.6312174944, 3.0434586528, 4.4023048032],
        ]
    ),
    cell=np.array([5.68032, 5.68032, 5.68032]),
    pbc=np.array([True, True, True]),
)
atoms.calc = TBLite(method="GFN1-xTB")
atoms.get_potential_energy()  # result in eV
------------------------------------------------------------
  cycle        total energy    energy error   density error
------------------------------------------------------------
      1     -44.18466375638  -4.4584172E+01   9.5746031E-01
      2     -46.17349195524  -1.9888282E+00   3.7709276E-01
      3     -46.19352636164  -2.0034406E-02   2.1480769E-01
      4     -46.18634789943   7.1784622E-03   6.1688940E-02
      5     -46.19681129475  -1.0463395E-02   3.3123492E-03
      6     -46.19683700903  -2.5714277E-05   1.4081482E-03
      7     -46.19684187755  -4.8685184E-06   4.2127827E-04
      8     -46.19684228849  -4.1094205E-07   1.2814394E-04
      9     -46.19684233075  -4.2263878E-08   5.6634669E-06
------------------------------------------------------------
 total:                                   0.550 sec
Out[6]: -1257.0801097690023

my environment is python3.9
conda-forge installed tblite 0.3.0
I tested both Torch version 1.8.1+cu102 and 2.0.1+cpu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.