3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-27 06:43:40 +01:00
dft_tools/doc/reference/plotting_protocols/hdf5/tut_ex2.rst
tayral edd1ff4529 Restructuring documentation.
A first general restructuration of the doc according to the pattern [tour|tutorial|reference].
In the reference part, objects are documented per topic.
In each topic, [definition|c++|python|hdf5] (not yet implemented)
2014-10-18 12:21:08 +01:00

69 lines
2.2 KiB
ReStructuredText

.. _hdf5_tut_ex2:
Example 2: A Green function
----------------------------------------------
What about more complex objects ?
The good news is that **hdf-compliant** objects can be stored easily as well.
We can store a Green function in an hdf5 file:
.. runblock:: python
from pytriqs.archive import HDFArchive
from pytriqs.gf.local import GfImFreq
# Define a Green function
G = GfImFreq ( indices = [1], beta = 10, n_points = 1000)
# Opens the file myfile.h5, in read/write mode
R = HDFArchive('myfile.h5', 'w')
# Store the object G under the name 'g1' and mu
R['g1'] = G
R['mu'] = 1.29
del R # closing the files (optional: file is closed when the R reference is deleted)
Of course, we can retrieve G as easily:
.. runblock:: python
from pytriqs.archive import HDFArchive
from pytriqs.gf.local import GfImFreq
R = HDFArchive('myfile.h5', 'r') # Opens the file myfile.h5 in readonly mode
G = R['g1'] # Retrieve the object named g1 in the file as G
# ... ok now I can work with G
The structure of the HDF file is this time ::
MAC:~>h5ls -r myfile.h5
/ Group
/g1 Group
/g1/Data Dataset {2, 2, 1000}
/g1/Indices Dataset {2}
/g1/Mesh Group
/g1/Mesh/Beta Dataset {SCALAR}
/g1/Mesh/Statistic Dataset {SCALAR}
/g1/Mesh/TypeGF Dataset {SCALAR}
/g1/Mesh/array Dataset {1000}
/g1/Name Dataset {SCALAR}
/g1/Note Dataset {SCALAR}
/g1/Tail Group
/g1/Tail/Indices Dataset {2}
/g1/Tail/OrderMax Dataset {SCALAR}
/g1/Tail/OrderMaxMAX Dataset {SCALAR}
/g1/Tail/OrderMinMIN Dataset {SCALAR}
/g1/Tail/array Dataset {13, 2, 2}
/mu Dataset {SCALAR}
.. hint:: How does this work ?
The Green function implements (as detailed in :ref:`HDF_Protocol`)
* a method :func:`__reduce_to_dict__` that reduces to the Green function to a dictionary containing a mesh (Mesh), a tail (Tail), the data (Data), the indices (Indices) and so on.
* a classmethod :func:`__factory_from_dict__` that reconstructs the Green function from this dictionary.