Electronic structure of water molecule
Electronic structure of water molecule
Setup calculation
We start to ask a very simple calculation DFTB calculation from scratch :
DFTB
Specify the path to Slater Koster parameters :
PARAM PTYPE=NSC
∼/basis
Replace ∼/basis by your basis directory.
Enter a very simple geometry (non optimized) for water molecule with appropriate axis in XYZ coordinates :
GEOMETRY
O 0.0 0.0 0.0
H 0.0 0.75 0.0
H 0.0 0.0 0.75
Now, we have a complete input in deMon.inp that looks like :
DFTB
PARAM PTYPE=NSC
~/basis
GEOMETRY
O 0.0 0.0 0.0
H 0.0 0.75 0.0
H 0.0 0.0 0.75
Note: More details are available in tutorial-basic.ipynb.
A. Run simple calculation
Edit a new file tutorial_1.py. The first step is to declare the environment variables. As we saw in Tutorial 0, we reuse the global.json file, which contains all the relevant variables.
import deMonPy
deMonPy.configure_from_file("global.json")
Now, we declare the molecule with a list of atomic symbols and an array for the position.
import numpy as np
symbols = ["O", "H", "H"]
positions = np.array([[0.0, 0.0, 0.0], [0.0, 0.75, 0.0], [0.0, 0.0, 0.75]])
We define the parameters as in the deMon.inp but in the form of a python dictionary.
from deMonPy.deMonNano import deMonNano
WORKDIR = ".run/tutorial-1/A/"
parameters = {
"DEMON_EXECUTABLE": deMonPy.DEMON_EXECUTABLE,
"BASIS": {"PTYPE": "NSC", "SKFILE": deMonPy.DEMON_BASIS},
"DEMON_PARAMETERS": {
"ACTIVE": {
"DFTB": {},
},
},
}
We can break down each line of the parameters as follows:
The first entry gives the path to the deMonNano binary that runs the calculation.
"DEMON_EXECUTABLE": deMonPy.DEMON_EXECUTABLE,
That is the deMonNano executable.
The BASIS entry gives the Slater-Koster basis directory and selects the parameter set with PTYPE.
"BASIS": {"PTYPE": "NSC", "SKFILE": deMonPy.DEMON_BASIS},
That is the deMonNano basis directory which is PTYPE that could be NSC, BIO or MAT. The BIO and MAT keyword works with SCC-DFTB only.
The DEMON_PARAMETERS entry holds the deMonNano input keywords of the calculation, starting with the DFTB keyword that requests a simple DFTB calculation.
"DEMON_PARAMETERS": {
"ACTIVE": {
"DFTB": {},
},
},
This part starts with DEMON_PARAMETERS keyword and it follows by ACTIVE. Only these keywords will be interpreted.
Parameter DFTB asks for a simple DFTB calculation.
With the parameters ready, these two lines create the deMonNano calculator and run the simple DFTB calculation on the water geometry defined above.
dem = deMonNano(title="CALCULATION DEMONANO", workdir=WORKDIR, **parameters)
dem.calculate(symbols=symbols, positions=positions)
The first line defines the object deMonNano with a title, a work directory and the parameters. The second line starts calculation at the correct location.
This prints the total energy of the run, read from the results dictionary of the deMonNano object.
print(f"Total energy : {dem.results['energy']}")
In terminal, run the command :
$ python3 tutorial_1_A.py
We have plotted the energy output. The results of calculation is stored into a dictionary named results of deMonNano object.
B. SCC calculation
Perform a single point SCC calculation on the water molecule.
WARNING: Don’t forget the first few lines in a new *.py file. In future, we will no longer remind you to run script in new file.
from deMonPy.deMonNano import deMonNano
WORKDIR = ".run/tutorial-1/B/"
parameters = {
"DEMON_EXECUTABLE": deMonPy.DEMON_EXECUTABLE,
"BASIS": {"PTYPE": "MAT", "SKFILE": deMonPy.DEMON_BASIS},
"DEMON_PARAMETERS": {
"ACTIVE": {
"DFTB": {"SCC": True},
},
},
}
dem = deMonNano(title="CALCULATION DEMONANO", workdir=WORKDIR, **parameters)
dem.calculate(symbols=symbols, positions=positions)
print(f"Total energy : {dem.results['energy']}")
In terminal, run the command :
$ python3 tutorial_1_B.py
C. Geometry optimization
We add an optimization scheme with OPT keyword.
from deMonPy.deMonNano import deMonNano
WORKDIR = ".run/tutorial-1/C/"
parameters = {
"DEMON_EXECUTABLE": deMonPy.DEMON_EXECUTABLE,
"BASIS": {"PTYPE": "BIO", "SKFILE": deMonPy.DEMON_BASIS},
"DEMON_PARAMETERS": {
"ACTIVE": {
"DFTB": {"SCC": True},
},
},
"DEMON_MODULE": {"ACTIVE": {"OPT": {}}},
}
dem = deMonNano(title="CALCULATION DEMONANO", workdir=WORKDIR, **parameters)
dem.calculate(symbols=symbols, positions=positions)
This prints the final total energy and the optimized geometry, the latter being stored under the output_geometry key of the results dictionary.
print(f"Total energy : {dem.results['energy']}")
optimized_geometry = dem.results["output_geometry"]
print("Optimized geometry : ", optimized_geometry)
In terminal, run the command :
$ python3 tutorial_1_C.py
Note: In future, we will no longer remind you to run this command using the correct script name.
D. Debug command and outputs
This runs the SCC-DFTB calculation on the optimized geometry with PRINT DEBUG, which makes deMonNano write extra information (Hamiltonian, overlaps, density matrix) to the output file; extract_debug=True tells DeMonNanoPy to read and store these matrices in the results.
from deMonPy.deMonNano import deMonNano
WORKDIR = ".run/tutorial-1/D/"
parameters = {
"DEMON_EXECUTABLE": deMonPy.DEMON_EXECUTABLE,
"BASIS": {"PTYPE": "BIO", "SKFILE": deMonPy.DEMON_BASIS},
"DEMON_PARAMETERS": {
"ACTIVE": {"DFTB": {"SCC": True}, "PRINT": {"DEBUG": True}},
},
}
dem = deMonNano(title="CALCULATION DEMONANO", workdir=WORKDIR, **parameters)
dem.calculate(
symbols=optimized_geometry.symbols, positions=optimized_geometry.positions, extract_debug=True
)
dem.print_results()
This lists the keys of the results dictionary, which now also contains the matrices read from the debug section.
print(dem.results.keys())
Display of final matrix obtained from DEBUG keyword (all the steps are read and stored) :
print("Hamiltonian-0 : \n", dem.results["Ham0"][0])
print("Overlaps : \n", dem.results["Overlaps"][0])
print("Gamma : \n", dem.results["Gamma"])
The final step of the stored matrices — Hamiltonian, density and coefficients — is then displayed.
print("Hamiltonian final : \n", dem.results["Hamiltonian"][-1])
print("Density : \n", dem.results["Density"][-1])
print("Coefficients : \n", dem.results["Coefficients"][-1])
Next steps
Tutorial 2 — Molecular dynamics of Coronene
applies the same parameter dictionaries to a molecular-dynamics run on the
coronene molecule. The DFTB
keyword page documents the sub-keywords used here (such as SCC), and the
DeMonNanoPy Examples section shows short
standalone scripts, starting from the DFTB single point of water.