Skip to content

Commit

Permalink
C-API version 6.3 (#222)
Browse files Browse the repository at this point in the history
- direct control over the Fortran objects
- (almost) thread-safe implementation
- separated APIs for IO, structure and calculations
  • Loading branch information
awvwgk committed May 22, 2020
1 parent 8440ffa commit 37ae399
Show file tree
Hide file tree
Showing 55 changed files with 3,006 additions and 4,287 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/fortran-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ jobs:
python-version: '3.x'
- run: brew install gcc@8 ninja
- run: pip install meson==0.53.2
- run: FC=gfortran-8 CC=gcc-8 meson setup build_gcc --buildtype release -Dla_backend=netlib --warnlevel 0
- run: FC=gfortran-8 CC=gcc-8 meson setup build_gcc --buildtype release -Dla_backend=netlib --warnlevel 0 -Dpython=false
- run: OMP_NUM_THREADS=2 ninja -C build_gcc test
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
- OMP_NUM_THREADS=2 make -j all test install

install:
- pip3 install meson==0.53.2 ninja ase pytest
- pip3 install meson==0.53.2 ninja pytest numpy
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.9)

# Setup the XTB Project
project(xtb
VERSION 6.2.2
VERSION 6.3.0
)
enable_language(Fortran)
enable_testing()
Expand Down Expand Up @@ -59,9 +59,6 @@ target_include_directories(lib-xtb-static
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include/xtb>
)

message("BLAS_LIBRARIES ${BLAS_LIBRARIES}")
message("LAPACK_LIBRARIES ${LAPACK_LIBRARIES}")

# Shared Library
add_library(lib-xtb-shared SHARED $<TARGET_OBJECTS:xtb-object> )
target_link_libraries(lib-xtb-shared
Expand Down
4 changes: 2 additions & 2 deletions TESTSUITE/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ add_test("GFN2-xTB_SCC" ${XTB-TESTER} gfn2 scc)
add_test("GFN2-xTB_API" ${XTB-TESTER} gfn2 api)
add_test("GFN2-xTB_API_GBSA" ${XTB-TESTER} gfn2 gbsa)
add_test("GFN2-xTB_API_GBSA_salt" ${XTB-TESTER} gfn2 salt)
add_test("GFN2-xTB_API_PCEM" ${XTB-TESTER} gfn2 pcem)
#add_test("GFN2-xTB_API_PCEM" ${XTB-TESTER} gfn2 pcem)
add_test("GFN1-xTB_SCC" ${XTB-TESTER} gfn1 scc)
add_test("GFN1-xTB_API" ${XTB-TESTER} gfn1 api)
add_test("GFN1-xTB_API_XB" ${XTB-TESTER} gfn1 xb)
Expand Down Expand Up @@ -162,7 +162,7 @@ set_tests_properties(EXE_Singlepoint
"GFN2-xTB_API"
"GFN2-xTB_API_GBSA"
"GFN2-xTB_API_GBSA_salt"
"GFN2-xTB_API_PCEM"
#"GFN2-xTB_API_PCEM"
"GFN1-xTB_SCC"
"GFN1-xTB_API"
"GFN1-xTB_API_XB"
Expand Down
60 changes: 51 additions & 9 deletions TESTSUITE/c_api_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ main (int argc, char **argv)
int const natoms = 7;
int const attyp[7] = {6,6,6,1,1,1,1};
double const charge = 0.0;
int const uhf = 0;
double const coord[3*7] =
{0.00000000000000, 0.00000000000000,-1.79755622305860,
0.00000000000000, 0.00000000000000, 0.95338756106749,
Expand All @@ -20,24 +21,65 @@ main (int argc, char **argv)
1.92825631079613, 0.00000000000000,-2.53624948351102,
0.00000000000000, 0.00000000000000, 5.23010455462158};

SCC_options const opt = (SCC_options){2, 0, 1.0, 300.0, true, false, true, 30, "none"};

xtb_TEnvironment env;
xtb_TMolecule mol;
xtb_TCalculator calc;
xtb_TResults res;
double energy;
double dipole[3];
double q[natoms];
double qp[6*natoms];
double wbo[natoms*natoms];

int stat = GFN2_calculation(&natoms, attyp, &charge, NULL, coord, &opt, "-",
&energy, NULL, dipole, q, NULL, qp, wbo);
env = xtb_newEnvironment();
calc = xtb_newCalculator();
res = xtb_newResults();
mol = xtb_newMolecule(env, &natoms, attyp, coord, NULL, NULL, NULL, NULL);
if (xtb_checkEnvironment(env)) {
xtb_showEnvironment(env, NULL);
return 1;
}

xtb_setVerbosity(env, XTB_VERBOSITY_FULL);
if (xtb_checkEnvironment(env)) {
xtb_showEnvironment(env, NULL);
return 2;
}

xtb_loadGFN2xTB(env, mol, calc, NULL);
if (xtb_checkEnvironment(env)) {
xtb_showEnvironment(env, NULL);
return 3;
}

xtb_singlepoint(env, mol, calc, res);
if (xtb_checkEnvironment(env)) {
xtb_showEnvironment(env, NULL);
return 4;
}

xtb_getEnergy(env, res, &energy);
xtb_getCharges(env, res, q);
xtb_getDipole(env, res, dipole);
xtb_getBondOrders(env, res, wbo);
if (xtb_checkEnvironment(env)) {
xtb_showEnvironment(env, NULL);
return 5;
}

assert(stat == 0);
assert(fabs(energy + 8.3824793849585) < 1.0e-9);
assert(fabs(q[5] - 0.05184019996829) < 1.0e-8);
assert(fabs(dipole[2] + 0.29832384492435) < 1.0e-6);
assert(fabs(qp[14] - 0.56386138525354) < 1.0e-6);
assert(fabs(dipole[2] + 0.298279305689518) < 1.0e-6);
assert(fabs(wbo[9] - 2.89823984265213) < 1.0e-8);

xtb_delResults(&res);
xtb_delCalculator(&calc);
xtb_delMolecule(&mol);
xtb_delEnvironment(&env);

assert(!res);
assert(!calc);
assert(!mol);
assert(!env);

return 0;
}

36 changes: 28 additions & 8 deletions TESTSUITE/gfn0.f90
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,15 @@ subroutine test_gfn0_api

use xtb_type_options
use xtb_type_molecule
use xtb_type_wavefunction
use xtb_type_data
use xtb_type_param
use xtb_type_environment

use xtb_pbc_tools

use xtb_calculators
use xtb_xtb_calculator, only : TxTBCalculator
use xtb_main_setup, only : newXTBCalculator, newWavefunction

implicit none

Expand All @@ -155,10 +158,13 @@ subroutine test_gfn0_api

type(TMolecule) :: mol
type(TEnvironment) :: env
type(TWavefunction) :: wfn
type(scc_results) :: res
type(TxTBCalculator) :: calc

real(wp) :: energy
real(wp) :: hl_gap
real(wp) :: dum(3,3)
real(wp) :: sigma(3,3)
real(wp),allocatable :: gradient(:,:)

! setup the environment variables
Expand All @@ -170,8 +176,12 @@ subroutine test_gfn0_api
energy = 0.0_wp
gradient = 0.0_wp

call gfn0_calculation &
(stdout,env,opt,mol,hl_gap,energy,gradient,dum,dum)
call newXTBCalculator(env, mol, calc, method=0)
call env%checkpoint("failed setup")
call newWavefunction(env, mol, calc, wfn)

call calc%singlepoint(env, mol, wfn, 2, .false., energy, gradient, sigma, &
& hl_gap, res)

call assert_close(hl_gap, 5.5384029314207_wp,thr)
call assert_close(energy,-8.6908532561691_wp,thr)
Expand All @@ -193,12 +203,15 @@ subroutine test_gfn0_api_srb

use xtb_type_options
use xtb_type_molecule
use xtb_type_data
use xtb_type_wavefunction
use xtb_type_param
use xtb_type_environment

use xtb_pbc_tools

use xtb_calculators
use xtb_xtb_calculator, only : TxTBCalculator
use xtb_main_setup, only : newXTBCalculator, newWavefunction

implicit none

Expand Down Expand Up @@ -237,10 +250,13 @@ subroutine test_gfn0_api_srb

type(TMolecule) :: mol
type(TEnvironment) :: env
type(TWavefunction) :: wfn
type(scc_results) :: res
type(TxTBCalculator) :: calc

real(wp) :: energy
real(wp) :: hl_gap
real(wp) :: dum(3,3)
real(wp) :: sigma(3,3)
real(wp),allocatable :: gradient(:,:)

! setup the environment variables
Expand All @@ -252,8 +268,12 @@ subroutine test_gfn0_api_srb
energy = 0.0_wp
gradient = 0.0_wp

call gfn0_calculation &
(stdout,env,opt,mol,hl_gap,energy,gradient,dum,dum)
call newXTBCalculator(env, mol, calc, method=0)
call env%checkpoint("failed setup")
call newWavefunction(env, mol, calc, wfn)

call calc%singlepoint(env, mol, wfn, 2, .false., energy, gradient, sigma, &
& hl_gap, res)

call assert_close(hl_gap, 3.1192454818777_wp,thr)
call assert_close(energy,-40.908850360158_wp,thr)
Expand Down
Loading

0 comments on commit 37ae399

Please sign in to comment.