The HIST.nc file (relaxation/MD)

The HIST.nc file (relaxation/MD)#

The HIST.nc file contains the history of structural relaxations or molecular dynamics calculations. One can use the abiopen function provide by abilab to open the file and generate an instance of HistFile. Alteratively, one can use the abiopen.py script to open the file inside the shell with the syntax:

abiopen.py out_HIST.nc

This command will start the ipython interpreter so that one can interact directly with the HistFile object (named abifile inside ipython). To generate a jupyter notebook use:

abiopen.py out_HIST.nc -nb

For a quick visualization of the data, usei the --expose option:

abiopen.py out_HIST.nc -e
import warnings
warnings.filterwarnings("ignore")  # Ignore warnings

from abipy import abilab
abilab.enable_notebook() # This line tells AbiPy we are running inside a notebook
import abipy.data as abidata

# This line configures matplotlib to show figures embedded in the notebook.
# Replace `inline` with `notebook` in classic notebook
%matplotlib inline

# Option available in jupyterlab. See https://github.com/matplotlib/jupyter-matplotlib
#%matplotlib widget
hist = abilab.abiopen(abidata.ref_file("sic_relax_HIST.nc"))
print("Number of iterations performed:", hist.num_steps)
Number of iterations performed: 7

hist.structures is the list of structure objects at the different iteration steps. hist.etotals is a numpy array with the total energies in eV associated to the different steps.

for struct, etot in zip(hist.structures, hist.etotals):
    print("Volume:", struct.volume,", Etotal:", etot)
Volume: 20.35143854530183 , Etotal: -285.4877026791648
Volume: 20.409158480192932 , Etotal: -285.4890033793653
Volume: 20.38330515362838 , Etotal: -285.48909437448856
Volume: 20.356937162475436 , Etotal: -285.4891275969001
Volume: 20.356014964449688 , Etotal: -285.4891277808012
Volume: 20.35179280005498 , Etotal: -285.48912733506796
Volume: 20.355222239876444 , Etotal: -285.48912780562375

To get the last structure stored in the HIST.nc file:

print(hist.final_structure)
Full Formula (Si1 C1)
Reduced Formula: SiC
abc   :   3.064763   3.064763   3.064763
angles:  60.000000  60.000000  60.000000
pbc   :       True       True       True
Sites (2)
  #  SP        a     b      c  cartesian_forces
---  ----  -----  ----  -----  -----------------------
  0  C     -0     0     -0     [-0. -0. -0.] eV ang^-1
  1  Si     0.25  0.25   0.25  [-0. -0. -0.] eV ang^-1

To plot the evolution of the structural parameters with matplotlib:

hist.plot(tight_layout=True);
_images/452000e1dbae5ea961405a3220938b1d4a87612c053a3a6a509b851768081d0f.png
hist.plotly();

To plot the total energies at the different iterations steps:

hist.plot_energies();
_images/76d16b91a623741f76b9a4de95650d057667f581dce0fd2b30893af31928ee43.png
hist.plotly_energies();

Converting to other formats#

Use to_xdatcar to get a XDATCAR pymatgen object (useful to interface AbiPy with other pymatgen tools)

# hist.write_xdatcar writes a XDATCAR file
xdatcar = hist.to_xdatcar()
print(xdatcar)
Si1 C1
1.0
0.000000 2.166981 2.166981
2.166981 0.000000 2.166981
2.166981 2.166981 0.000000
C Si
1 1
Direct configuration=      1
0.00000000 0.00000000 0.00000000
0.25000000 0.25000000 0.25000000
Direct configuration=      2
-0.00000000 0.00000000 -0.00000000
0.25000000 0.25000000 0.25000000
Direct configuration=      3
-0.00000000 0.00000000 -0.00000000
0.25000000 0.25000000 0.25000000
Direct configuration=      4
-0.00000000 0.00000000 -0.00000000
0.25000000 0.25000000 0.25000000
Direct configuration=      5
-0.00000000 0.00000000 -0.00000000
0.25000000 0.25000000 0.25000000
Direct configuration=      6
-0.00000000 0.00000000 -0.00000000
0.25000000 0.25000000 0.25000000
Direct configuration=      7
-0.00000000 0.00000000 -0.00000000
0.25000000 0.25000000 0.25000000