1 #include <math.h>
2 #include <assert.h>
3 #include <stdio.h>
4
5 #include "xtb.h"
6
7 int
main(int argc,char ** argv)8 main (int argc, char **argv)
9 {
10 double const thr = 1.0e-10;
11 int const natoms = 7;
12 int const attyp[7] = {6,6,6,1,1,1,1};
13 double const charge = 0.0;
14 int const uhf = 0;
15 double const coord[3*7] =
16 {0.00000000000000, 0.00000000000000,-1.79755622305860,
17 0.00000000000000, 0.00000000000000, 0.95338756106749,
18 0.00000000000000, 0.00000000000000, 3.22281255790261,
19 -0.96412815539807,-1.66991895015711,-2.53624948351102,
20 -0.96412815539807, 1.66991895015711,-2.53624948351102,
21 1.92825631079613, 0.00000000000000,-2.53624948351102,
22 0.00000000000000, 0.00000000000000, 5.23010455462158};
23
24 xtb_TEnvironment env;
25 xtb_TMolecule mol;
26 xtb_TCalculator calc;
27 xtb_TResults res;
28 double energy;
29 double dipole[3];
30 double q[natoms];
31 double wbo[natoms*natoms];
32 int buffersize = 512;
33 char buffer[buffersize];
34 char solvent[] = "h2o";
35
36 assert(XTB_API_VERSION == xtb_getAPIVersion());
37
38 env = xtb_newEnvironment();
39 calc = xtb_newCalculator();
40 res = xtb_newResults();
41 mol = xtb_newMolecule(env, &natoms, attyp, coord, NULL, NULL, NULL, NULL);
42 if (xtb_checkEnvironment(env)) {
43 xtb_showEnvironment(env, NULL);
44 return 1;
45 }
46
47 xtb_getEnergy(env, res, &energy);
48 if (xtb_checkEnvironment(env)) {
49 xtb_getError(env, buffer, &buffersize);
50 printf("Error message is:\n%s\n", buffer);
51 }
52
53 xtb_setVerbosity(env, XTB_VERBOSITY_FULL);
54 if (xtb_checkEnvironment(env)) {
55 xtb_showEnvironment(env, NULL);
56 return 2;
57 }
58
59 xtb_loadGFN2xTB(env, mol, calc, NULL);
60 xtb_setAccuracy(env, calc, 1.0);
61 xtb_setElectronicTemp(env, calc, 300.0);
62 xtb_setMaxIter(env, calc, 30);
63 if (xtb_checkEnvironment(env)) {
64 xtb_showEnvironment(env, NULL);
65 return 3;
66 }
67
68 xtb_singlepoint(env, mol, calc, res);
69 if (xtb_checkEnvironment(env)) {
70 xtb_showEnvironment(env, NULL);
71 return 4;
72 }
73
74 xtb_getEnergy(env, res, &energy);
75 xtb_getCharges(env, res, q);
76 xtb_getDipole(env, res, dipole);
77 xtb_getBondOrders(env, res, wbo);
78 if (xtb_checkEnvironment(env)) {
79 xtb_showEnvironment(env, NULL);
80 return 5;
81 }
82
83 assert(fabs(energy + 8.3824793849585) < 1.0e-9);
84 assert(fabs(q[5] - 0.05184019996829) < 1.0e-8);
85 assert(fabs(dipole[2] + 0.298279305689518) < 1.0e-6);
86 assert(fabs(wbo[9] - 2.89823984265213) < 1.0e-8);
87
88 xtb_setSolvent(env, calc, solvent, NULL, NULL, NULL);
89 if (xtb_checkEnvironment(env)) {
90 xtb_showEnvironment(env, NULL);
91 return 6;
92 }
93
94 xtb_singlepoint(env, mol, calc, res);
95 if (xtb_checkEnvironment(env)) {
96 xtb_showEnvironment(env, NULL);
97 return 7;
98 }
99
100 xtb_getEnergy(env, res, &energy);
101 xtb_getCharges(env, res, q);
102 xtb_getDipole(env, res, dipole);
103 xtb_getBondOrders(env, res, wbo);
104 if (xtb_checkEnvironment(env)) {
105 xtb_showEnvironment(env, NULL);
106 return 8;
107 }
108
109 assert(fabs(energy + 8.38393864716134) < 1.0e-9);
110 assert(fabs(q[5] - 0.06090868805034) < 1.0e-8);
111 assert(fabs(dipole[2] + 0.35455233974705) < 1.0e-6);
112 assert(fabs(wbo[9] - 2.89453979224265) < 1.0e-8);
113
114 xtb_delResults(&res);
115 xtb_delCalculator(&calc);
116 xtb_delMolecule(&mol);
117 xtb_delEnvironment(&env);
118
119 assert(!res);
120 assert(!calc);
121 assert(!mol);
122 assert(!env);
123
124 return 0;
125 }
126