#!/usr/bin/env python # coding: utf-8 # Back to the main [Index](index.ipynb) # ## The HIST.nc file # # 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 # In[1]: # Use this at the beginning of your script so that your code will be compatible with python3 from __future__ import print_function, division, unicode_literals 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 get_ipython().run_line_magic('matplotlib', 'inline') # Option available in jupyterlab. See https://github.com/matplotlib/jupyter-matplotlib #%matplotlib widget # In[2]: hist = abilab.abiopen(abidata.ref_file("sic_relax_HIST.nc")) print("Number of iterations performed:", hist.num_steps) # `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. # In[3]: for struct, etot in zip(hist.structures, hist.etotals): print("Volume:", struct.volume,", Etotal:", etot) # To get the last structure stored in the `HIST.nc` file: # In[4]: print(hist.final_structure) # To plot the evolution of the structural parameters with `matplotlib`: # In[5]: hist.plot(tight_layout=True); # To plot the total energies at the different iterations steps: # In[6]: hist.plot_energies(); # ## Converting to other formats # [[back to top](#top)] # # Use `to_xdatcar` to get a XDATCAR pymatgen object (useful to interface AbiPy with other pymatgen tools) # In[7]: # hist.write_xdatcar writes a XDATCAR file xdatcar = hist.to_xdatcar() print(xdatcar) # Back to the main [Index](index.ipynb)