Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python API #5

Merged
merged 3 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,9 @@ xtbopt.xyz
xtbopt.sdf
xtbopt.coord
xtbopt.log

# python build artefacts
__pycache__/
python/dist
python/build
*.egg-info
4 changes: 2 additions & 2 deletions TESTSUITE/cpp_api_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ main (int argc, char **argv)
1.92825631079613, 0.00000000000000,-2.53624948351102,
0.00000000000000, 0.00000000000000, 5.23010455462158};

const xtb::SCC_options opt {2, 0, 1.0, 300.0, true, false, 30, "none"};
const xtb::SCC_options opt {2, 0, 1.0, 300.0, true, false, true, 30, "none"};

double energy {0.0};
double dipole[3] {0.0};
double q[natoms] {0.0};
double qp[6*natoms] {0.0};
double wbo[natoms*natoms] {0.0};

int stat = xtb::GFN2_calculation(&natoms, attyp, &charge, coord, &opt, "-",
int stat = xtb::GFN2_calculation(&natoms, attyp, &charge, nullptr, coord, &opt, "-",
&energy, nullptr, dipole, q, nullptr, qp, wbo);

assert(stat == 0);
Expand Down
9 changes: 5 additions & 4 deletions TESTSUITE/gfn0.f90
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ subroutine test_gfn0_sp
mol%xyz = xyz
mol%chrg = 0.0_wp
call mol%set_nuclear_charge
call mol%calculate_distances
call mol%update

wfn%nel = idint(sum(mol%z))
wfn%nopen = 0
Expand Down Expand Up @@ -160,7 +160,7 @@ subroutine test_gfn0_api

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

! setup the environment variables
Expand All @@ -169,14 +169,15 @@ subroutine test_gfn0_api
call mol%allocate(nat)
mol%at = at
mol%xyz = xyz
call mol%calculate_distances
call mol%set_nuclear_charge
call mol%update

allocate(gradient(3,mol%n))
energy = 0.0_wp
gradient = 0.0_wp

call gfn0_calculation &
(istdout,env,opt,mol,gfn,hl_gap,energy,gradient)
(istdout,env,opt,mol,gfn,hl_gap,energy,gradient,dum,dum)

call assert_close(hl_gap, 5.5384029314207_wp,thr)
call assert_close(energy,-8.6908532561691_wp,thr)
Expand Down
31 changes: 21 additions & 10 deletions TESTSUITE/gfn1.f90
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ subroutine test_gfn1_scc
mol%xyz = xyz
mol%chrg = 0.0_wp
call mol%set_nuclear_charge
call mol%update

wfn%nel = idint(sum(mol%z))
wfn%nopen = 0

allocate( g(3,mol%n), source = 0.0_wp )

call use_parameterset('.param_gfn.xtb',globpar,okpar)
call assert(okpar)

Expand Down Expand Up @@ -124,6 +125,7 @@ subroutine test_gfn1_api
use tbdef_molecule
use tbdef_param
use tbdef_pcem
use tbdef_wavefunction

use tb_calculators

Expand All @@ -147,6 +149,7 @@ subroutine test_gfn1_api
type(tb_environment) :: env
type(gfn_parameter) :: gfn
type(tb_pcem) :: pcem
type(tb_wavefunction):: wfn

real(wp) :: energy
real(wp) :: hl_gap
Expand All @@ -158,14 +161,15 @@ subroutine test_gfn1_api
call mol%allocate(nat)
mol%at = at
mol%xyz = xyz
call mol%calculate_distances
call mol%set_nuclear_charge
call mol%update

allocate(gradient(3,mol%n))
energy = 0.0_wp
gradient = 0.0_wp

call gfn1_calculation &
(istdout,env,opt,mol,gfn,pcem,hl_gap,energy,gradient)
(istdout,env,opt,mol,gfn,pcem,wfn,hl_gap,energy,gradient)

call assert_close(hl_gap, 5.6067613075402_wp,thr)
call assert_close(energy,-8.4156335932985_wp,thr)
Expand All @@ -189,6 +193,7 @@ subroutine test_gfn1gbsa_api
use tbdef_molecule
use tbdef_param
use tbdef_pcem
use tbdef_wavefunction

use tb_calculators

Expand All @@ -214,6 +219,7 @@ subroutine test_gfn1gbsa_api
type(tb_environment) :: env
type(gfn_parameter) :: gfn
type(tb_pcem) :: pcem
type(tb_wavefunction):: wfn

real(wp) :: energy
real(wp) :: hl_gap
Expand All @@ -225,14 +231,15 @@ subroutine test_gfn1gbsa_api
call mol%allocate(nat)
mol%at = at
mol%xyz = xyz
call mol%calculate_distances
call mol%set_nuclear_charge
call mol%update

allocate(gradient(3,mol%n))
energy = 0.0_wp
gradient = 0.0_wp

call gfn1_calculation &
(istdout,env,opt,mol,gfn,pcem,hl_gap,energy,gradient)
(istdout,env,opt,mol,gfn,pcem,wfn,hl_gap,energy,gradient)

call assert_close(hl_gap, 6.641641300724_wp,1e-4_wp)
call assert_close(energy,-14.215790820910_wp,thr)
Expand All @@ -255,6 +262,7 @@ subroutine test_gfn1_pcem_api
use tbdef_molecule
use tbdef_param
use tbdef_pcem
use tbdef_wavefunction

use aoparam

Expand Down Expand Up @@ -288,6 +296,7 @@ subroutine test_gfn1_pcem_api
type(tb_environment) :: env
type(gfn_parameter) :: gfn
type(tb_pcem) :: pcem
type(tb_wavefunction):: wfn

real(wp) :: energy
real(wp) :: hl_gap
Expand All @@ -299,14 +308,15 @@ subroutine test_gfn1_pcem_api
call mol%allocate(nat)
mol%at = at
mol%xyz = xyz
call mol%calculate_distances
call mol%set_nuclear_charge
call mol%update

allocate(gradient(3,mol%n))
energy = 0.0_wp
gradient = 0.0_wp

call gfn1_calculation &
(istdout,env,opt,mol,gfn,pcem,hl_gap,energy,gradient)
(istdout,env,opt,mol,gfn,pcem,wfn,hl_gap,energy,gradient)

call assert_close(hl_gap, 9.0155275960407_wp,thr*10)
call assert_close(energy,-23.113490916186_wp,thr)
Expand All @@ -325,7 +335,8 @@ subroutine test_gfn1_pcem_api
call mol%allocate(nat2)
mol%at = at(:nat2)
mol%xyz = xyz(:,:nat2)
call mol%calculate_distances
call mol%set_nuclear_charge
call mol%update

call pcem%allocate(nat2)
pcem%xyz = xyz(:,nat2+1:)
Expand All @@ -335,7 +346,7 @@ subroutine test_gfn1_pcem_api
pcem%grd = 0.0_wp

call gfn1_calculation &
(istdout,env,opt,mol,gfn,pcem,hl_gap,energy,gradient)
(istdout,env,opt,mol,gfn,pcem,wfn,hl_gap,energy,gradient)

call assert_close(hl_gap, 8.7253450666347_wp,thr)
call assert_close(energy,-11.559896105984_wp,thr)
Expand All @@ -359,7 +370,7 @@ subroutine test_gfn1_pcem_api
pcem%gam = 999.0_wp ! point charges

call gfn1_calculation &
(istdout,env,opt,mol,gfn,pcem,hl_gap,energy,gradient)
(istdout,env,opt,mol,gfn,pcem,wfn,hl_gap,energy,gradient)

call assert_close(hl_gap, 8.9183046297437_wp,thr)
call assert_close(energy,-11.565012263827_wp,thr)
Expand Down
16 changes: 11 additions & 5 deletions TESTSUITE/gfn2.f90
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ subroutine test_gfn2_scc
mol%xyz = xyz
mol%chrg = 0.0_wp
call mol%set_nuclear_charge
call mol%update

wfn%nel = idint(sum(mol%z))
wfn%nopen = 0
Expand Down Expand Up @@ -167,7 +168,8 @@ subroutine test_gfn2_api
call mol%allocate(nat)
mol%at = at
mol%xyz = xyz
call mol%calculate_distances
call mol%set_nuclear_charge
call mol%update

allocate(gradient(3,mol%n))
energy = 0.0_wp
Expand Down Expand Up @@ -239,7 +241,8 @@ subroutine test_gfn2gbsa_api
call mol%allocate(nat)
mol%at = at
mol%xyz = xyz
call mol%calculate_distances
call mol%set_nuclear_charge
call mol%update

allocate(gradient(3,mol%n))
energy = 0.0_wp
Expand Down Expand Up @@ -309,7 +312,8 @@ subroutine test_gfn2salt_api
call mol%allocate(nat)
mol%at = at
mol%xyz = xyz
call mol%calculate_distances
call mol%set_nuclear_charge
call mol%update

allocate(gradient(3,mol%n))
energy = 0.0_wp
Expand Down Expand Up @@ -390,7 +394,8 @@ subroutine test_gfn2_pcem_api
call mol%allocate(nat)
mol%at = at
mol%xyz = xyz
call mol%calculate_distances
call mol%set_nuclear_charge
call mol%update

allocate(gradient(3,mol%n))
energy = 0.0_wp
Expand All @@ -416,7 +421,8 @@ subroutine test_gfn2_pcem_api
call mol%allocate(nat2)
mol%at = at(:nat2)
mol%xyz = xyz(:,:nat2)
call mol%calculate_distances
call mol%set_nuclear_charge
call mol%update

call pcem%allocate(nat2)
pcem%xyz = xyz(:,nat2+1:)
Expand Down
8 changes: 5 additions & 3 deletions TESTSUITE/peeq.f90
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ subroutine test_peeq_api
real(wp) :: energy
real(wp) :: hl_gap
real(wp) :: gradlatt(3,3)
real(wp) :: stress(3,3)
real(wp),allocatable :: gradient(:,:)

! setup the environment variables
Expand All @@ -217,7 +218,8 @@ subroutine test_peeq_api
call dlat_to_cell(lattice,mol%cellpar)
call dlat_to_rlat(lattice,mol%rec_lat)
call coord_trafo(nat,lattice,abc,mol%xyz)
call mol%calculate_distances
call mol%set_nuclear_charge
call mol%update

allocate(gradient(3,mol%n))
energy = 0.0_wp
Expand All @@ -226,8 +228,8 @@ subroutine test_peeq_api

call mctc_mute

call peeq_calculation &
(istdout,env,opt,mol,gfn,hl_gap,energy,gradient,gradlatt)
call gfn0_calculation &
(istdout,env,opt,mol,gfn,hl_gap,energy,gradient,stress,gradlatt)

call assert_close(hl_gap, 4.8620892163953_wp,thr)
call assert_close(energy,-8.4930019025474_wp,thr)
Expand Down
Loading