-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add recipes for Python ctypes interface (#16)
- Loading branch information
Showing
11 changed files
with
927 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
Geometry = GenFormat { | ||
|
||
6 S | ||
Ti O | ||
1 1 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 | ||
2 1 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 | ||
3 2 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 | ||
4 2 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 | ||
5 2 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 | ||
6 2 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 | ||
0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 | ||
1.0000000000E+02 0.0000000000E+00 0.0000000000E+00 | ||
0.0000000000E+00 1.0000000000E+02 0.0000000000E+00 | ||
0.0000000000E+00 0.0000000000E+00 1.0000000000E+02 | ||
|
||
} | ||
|
||
Driver = {} | ||
|
||
Hamiltonian = DFTB { | ||
|
||
Scc = Yes | ||
MaxSccIterations = 100 | ||
SccTolerance = 1.00e-05 | ||
|
||
SlaterKosterFiles = Type2FileNames { | ||
Prefix = "../../slakos/mio-ext/" | ||
Separator = "-" | ||
Suffix = ".skf" | ||
} | ||
|
||
MaxAngularMomentum { | ||
Ti = "d" | ||
O = "p" | ||
} | ||
|
||
KPointsAndWeights = SupercellFolding { | ||
4 0 0 | ||
0 4 0 | ||
0 0 4 | ||
0.5 0.5 0.5 | ||
} | ||
|
||
} | ||
|
||
Analysis { | ||
CalculateForces = Yes | ||
} | ||
|
||
ParserOptions { | ||
ParserVersion = 8 | ||
} |
36 changes: 36 additions & 0 deletions
36
docs/_archives/recipes/interfaces/pyapi/extpot/dftb_in.hsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Geometry = GenFormat { | ||
3 C | ||
O H | ||
1 1 0.00000000000E+00 0.00000000000E+00 0.00000000000E+00 | ||
2 2 0.00000000000E+00 0.00000000000E+00 0.00000000000E+00 | ||
3 2 0.00000000000E+00 0.00000000000E+00 0.00000000000E+00 | ||
} | ||
|
||
Driver = {} | ||
|
||
Hamiltonian = DFTB { | ||
|
||
SCC = Yes | ||
SCCTolerance = 1.00E-012 | ||
MaxSCCIterations = 1000 | ||
|
||
MaxAngularMomentum = { | ||
O = "p" | ||
H = "s" | ||
} | ||
|
||
SlaterKosterFiles = Type2FileNames { | ||
Prefix = "../../../slakos/mio-ext/" | ||
Separator = "-" | ||
Suffix = ".skf" | ||
} | ||
|
||
} | ||
|
||
Analysis = { | ||
CalculateForces = Yes | ||
} | ||
|
||
ParserOptions = { | ||
ParserVersion = 8 | ||
} |
69 changes: 69 additions & 0 deletions
69
docs/_archives/recipes/interfaces/pyapi/extpot/pyapiExtpot.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import numpy as np | ||
import dftbplus | ||
|
||
|
||
LIB_PATH = '/home/user/libdftbplus' | ||
|
||
|
||
def main(): | ||
'''Main driver routine.''' | ||
|
||
# coordinates of H2O, in atomic units | ||
coords = np.array([ | ||
[0.000000000000000E+00, -0.188972598857892E+01, 0.000000000000000E+00], | ||
[0.000000000000000E+00, 0.000000000000000E+00, 0.147977639152057E+01], | ||
[0.000000000000000E+00, 0.000000000000000E+00, -0.147977639152057E+01]]) | ||
|
||
# the values of extpot and extpotgrad used here were | ||
# taken from file: test/api/mm/testers/test_extpot.f90 | ||
extpot = np.array([-0.025850198503435, | ||
-0.005996294763958, | ||
-0.022919371690684]) | ||
|
||
extpotgrad = np.array([ | ||
[0.035702717378527, 0.011677956375860, 0.009766745155626], | ||
[0.023243271928971, -0.000046945156575, 0.004850533043745], | ||
[0.016384005706180, 0.004608295375551, 0.005401080774962]]) | ||
|
||
cdftb = dftbplus.DftbPlus(libpath=LIB_PATH, | ||
hsdpath='dftb_in.hsd', | ||
logfile='log.log') | ||
|
||
# set geometry | ||
cdftb.set_geometry(coords, latvecs=None) | ||
|
||
# set external potential and its gradients | ||
cdftb.set_external_potential(extpot, extpotgrad=extpotgrad) | ||
|
||
# get number of atoms | ||
natoms = cdftb.get_nr_atoms() | ||
|
||
# calculate energy, forces and Gross charges | ||
merminen = cdftb.get_energy() | ||
gradients = cdftb.get_gradients() | ||
grosschgs = cdftb.get_gross_charges() | ||
|
||
# finalize DFTB+ and clean up | ||
cdftb.close() | ||
|
||
# print obtained nr. of atoms | ||
print('(H2O) Obtained nr. of atoms: {:d}'.format(natoms)) | ||
|
||
# print obtained mermin free energy | ||
print('(H2O) Obtained Mermin-energy: {:15.10f}'.format(merminen)) | ||
|
||
# print obtained gradients | ||
print('(H2O) Obtained gradient of atom 1: {:15.10f} {:15.10f} {:15.10f}' | ||
.format(*gradients[0])) | ||
print('(H2O) Obtained gradient of atom 2: {:15.10f} {:15.10f} {:15.10f}' | ||
.format(*gradients[1])) | ||
print('(H2O) Obtained gradient of atom 3: {:15.10f} {:15.10f} {:15.10f}' | ||
.format(*gradients[2])) | ||
|
||
# print obtained Gross charges | ||
print('(H2O) Obtained Gross charges: {:15.10f} {:15.10f}' | ||
.format(*grosschgs)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
set -e | ||
python3 ./pyapiExtpot.py > output | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import numpy as np | ||
import dftbplus | ||
|
||
|
||
LIB_PATH = '/home/user/libdftbplus' | ||
|
||
# DFTB+ conversion factors | ||
# (according to prog/dftb+/lib_common/constants.F90) | ||
BOHR__AA = 0.529177249 | ||
AA__BOHR = 1 / BOHR__AA | ||
|
||
|
||
def main(): | ||
'''Main driver routine.''' | ||
|
||
# coordinates of TiO2, in atomic units | ||
coords = np.array([ | ||
[-0.016726922839251, 0.016725329441158, -0.000003204152532], | ||
[-0.016726505918979, 1.920201169305565, -7.297102897292027], | ||
[ 0.017412997824265, -0.024318617967798, 2.005339137853385], | ||
[ 1.920770753428742, -0.024319922392223, -4.437737763954652], | ||
[ 0.024319174400169, -0.017404302527510, -2.005347277168561], | ||
[ 0.024317270342179, 1.886164739806594, -5.291732430733527]]) | ||
coords *= AA__BOHR | ||
|
||
# lattice vectors of TiO2, in atomic units | ||
latvecs = np.array([ | ||
[-1.903471721000000, 1.903471721000000, 4.864738245000000], | ||
[ 1.903471721000000, -1.903471721000000, 4.864738245000000], | ||
[ 1.903471721000000, 1.903471721000000, -4.864738245000000]]) | ||
latvecs *= AA__BOHR | ||
|
||
cdftb = dftbplus.DftbPlus(libpath=LIB_PATH, | ||
hsdpath='dftb_in.hsd', | ||
logfile='TiO2.log') | ||
|
||
# set geometry | ||
cdftb.set_geometry(coords, latvecs=latvecs) | ||
|
||
# get number of atoms | ||
natoms = cdftb.get_nr_atoms() | ||
|
||
# calculate energy, gradients and Gross charges | ||
merminen = cdftb.get_energy() | ||
gradients = cdftb.get_gradients() | ||
grosschgs = cdftb.get_gross_charges() | ||
|
||
# finalize DFTB+ and clean up | ||
cdftb.close() | ||
|
||
# print obtained nr. of atoms | ||
print('(TiO2) Obtained nr. of atoms: {:d}'.format(natoms)) | ||
|
||
# print obtained mermin free energy | ||
print('(TiO2) Obtained Mermin-energy: {:15.10f}'.format(merminen)) | ||
|
||
# print obtained gradients | ||
print('(TiO2) Obtained gradient of atom 1: {:15.10f} {:15.10f} {:15.10f}' | ||
.format(*gradients[0])) | ||
|
||
# print obtained Gross charges | ||
print('''(TiO2) Obtained Gross charges: {:15.10f} {:15.10f} | ||
{:15.10f} {:15.10f} {:15.10f} {:15.10f}'''.format(*grosschgs)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
55 changes: 55 additions & 0 deletions
55
docs/_archives/recipes/interfaces/pyapi/qdepextpot/dftb_in.hsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
Geometry = GenFormat { | ||
3 C | ||
O H | ||
1 1 0.00000000000E+00 -0.10000000000E+01 0.00000000000E+00 | ||
2 2 0.00000000000E+00 0.00000000000E+00 0.78306400000E+00 | ||
3 2 0.00000000000E+00 0.00000000000E+00 -0.78306400000E+00 | ||
} | ||
|
||
Driver {} | ||
|
||
Hamiltonian = DFTB { | ||
|
||
SCC = Yes | ||
SCCTolerance = 1.00E-10 | ||
MaxSCCIterations = 1000 | ||
|
||
Mixer = Broyden {} | ||
|
||
MaxAngularMomentum { | ||
O = "p" | ||
H = "s" | ||
} | ||
|
||
Filling = Fermi { | ||
Temperature [Kelvin] = 1.0E-8 | ||
} | ||
|
||
SlaterKosterFiles = Type2FileNames { | ||
Prefix = "../../../slakos/mio-ext/" | ||
Separator = "-" | ||
Suffix = ".skf" | ||
} | ||
|
||
# ElectricField { | ||
# | ||
# PointCharges { | ||
# | ||
# CoordsAndCharges { | ||
# -0.944863438887178 -9.44863438887178 1.70075418999692 2.5 | ||
# 4.34637181888102 -5.85815332110050 2.64561762888410 -1.9 | ||
# } | ||
# | ||
# } | ||
# | ||
# } | ||
|
||
} | ||
|
||
Analysis { | ||
CalculateForces = Yes | ||
} | ||
|
||
ParserOptions { | ||
ParserVersion = 6 | ||
} |
Oops, something went wrong.