[1]:
# useful to autoreload the module without restarting the kernel
%load_ext autoreload
%autoreload 2
[2]:
from mppi import Parsers as P

Tutorial for the YamboParser class

This tutorial describes the usage of the YamboParser class that parse the o- file(s) produced by a yambo computation.

The class is designed to deal with the list of files produced as the output key of the run method of YamboCalculator.

Here we present some example:

[3]:
qp_output = ['YamboParser_test/qp_results/o-qp_test1.qp']
[4]:
qp_output_extendOut = ['YamboCalculator_test/qp_test_ExtendOut/o-qp_test_ExtendOut.qp']
[5]:
rt_output = ['YamboParser_test/rt_results/o-NETime_1000-dephase_0.01-freq_1.55-pol_circular.carriers',
        'YamboParser_test/rt_results/o-NETime_1000-dephase_0.01-freq_1.55-pol_circular.spin_magnetization',
        'YamboParser_test/rt_results/o-NETime_1000-dephase_0.01-freq_1.55-pol_circular.external_field',
        'YamboParser_test/rt_results/o-NETime_1000-dephase_0.01-freq_1.55-pol_circular.polarization']

When the list of files is passed to the parser the extendOut option used to run the computation has to be provided, otherwise the parser could perform a wrong assignement of the names of the variables.

[6]:
results = P.YamboParser(files=qp_output,extendOut=False)

results is a dictionary with the structure

[7]:
results
[7]:
{'qp': {'kpoint': array([1., 1., 1., 1., 1., 1., 1., 1., 2., 2., 2., 2., 2., 2., 2., 2.]),
  'band': array([1., 2., 3., 4., 5., 6., 7., 8., 1., 2., 3., 4., 5., 6., 7., 8.]),
  'e0': array([-1.190291e+01, -1.176000e-05, -1.176000e-05,  0.000000e+00,
          2.551225e+00,  2.551230e+00,  2.551230e+00,  3.152071e+00,
         -1.110872e+01, -3.914389e+00, -7.552550e-01, -7.552460e-01,
          1.962407e+00,  3.490390e+00,  3.490396e+00,  6.757975e+00]),
  'eme0': array([-1.50691 ,  0.7861  ,  0.7914  ,  0.7771  ,  1.884047,  1.907533,
          1.906476,  2.349819, -1.21027 ,  0.216875,  0.676644,  0.653277,
          1.799721,  2.065016,  2.084261,  2.726886]),
  'sce0': array([ 4.48108 ,  2.194   ,  2.201   ,  2.184061, -2.137494, -2.110904,
         -2.112035, -2.203245,  4.52994 ,  2.934759,  2.263484,  2.236098,
         -2.186759, -2.20382 , -2.182057, -2.267519])}}

For several usage it can be useful to access to the results with the object.attribute sintax.

In this case it is possible to use the AttributeDict class the perform this conversion

[8]:
from mppi import Utilities as U
[9]:
obj = U.AttributeDict(**results)

and we can access as

[10]:
obj.qp.e0
[10]:
array([-1.190291e+01, -1.176000e-05, -1.176000e-05,  0.000000e+00,
        2.551225e+00,  2.551230e+00,  2.551230e+00,  3.152071e+00,
       -1.110872e+01, -3.914389e+00, -7.552550e-01, -7.552460e-01,
        1.962407e+00,  3.490390e+00,  3.490396e+00,  6.757975e+00])

Test of a parsing with extendOut = True

[11]:
results = P.YamboParser(files=qp_output_extendOut,extendOut=True)

now all the variables are available, for instance

[12]:
results['qp']['z_Re']
[12]:
array([0.7587, 0.8448, 0.8449, 0.8443, 0.8378, 0.8386, 0.8387, 0.8421,
       0.8305, 0.8306, 0.8149, 0.8152, 0.7562, 0.828 , 0.8421, 0.8417,
       0.8403, 0.836 , 0.8367, 0.8331, 0.8293, 0.8282, 0.8112, 0.8115])

Let’s see a further example by parsing the typical files of a real-time computation

[13]:
results = P.YamboParser(rt_output)

In this case we have several files, so the dictionary has more than one key

[14]:
results.keys()
[14]:
dict_keys(['carriers', 'spin_magnetization', 'external_field', 'polarization'])

We can easily perform some plots

[15]:
import matplotlib.pyplot as plt
[16]:
time = results['carriers']['time']
elec = results['carriers']['dne']
field_int = results['external_field']['Intensity']
pol = results['polarization']['Pol_x']

ratio = max(field_int)/max(elec)

plt.plot(time,ratio*elec,label='dne')
plt.plot(time,field_int,label='field_int')
plt.legend()
plt.show()

plt.plot(time,pol,label='Pol_x')
plt.legend()
../_images/tutorials_Tutorial_YamboParser_26_0.png
[16]:
<matplotlib.legend.Legend at 0x7f3692d7c400>
../_images/tutorials_Tutorial_YamboParser_26_2.png

Again we can access to the results using the attribute syntax. For instance if we are intersted to the spin_magnetization part of the resutls we can set

[17]:
spin_results = U.AttributeDict(**results['spin_magnetization'])
[18]:
plt.plot(spin_results.time,spin_results.Mc_z)
plt.plot(spin_results.time,spin_results.Mv_z)
[18]:
[<matplotlib.lines.Line2D at 0x7f3656bb2898>]
../_images/tutorials_Tutorial_YamboParser_29_1.png

Parsing of a ypp computation

We test the functionality of the Parser to deal with the output of a ypp -s b computation for plotting the bands structure along a path

[19]:
bands_output = ['YamboCalculator_test/bands_test1/o-bands_test1.bands_interpolated']
[20]:
results = P.YamboParser(bands_output)

For instance

[21]:
results['bands_interpolated']['col0'] # kpath
[21]:
array([0.       , 0.022969 , 0.045938 , 0.068908 , 0.091877 , 0.1148459,
       0.1378151, 0.1607843, 0.1837534, 0.2067226, 0.2296918, 0.252661 ,
       0.2756301, 0.2985993, 0.3215685, 0.3445377, 0.3675069, 0.3904761,
       0.4134453, 0.436415 , 0.459384 , 0.482353 , 0.50532  , 0.52829  ,
       0.55088  , 0.573478 , 0.596071 , 0.6186643, 0.6412575, 0.6638508,
       0.686444 , 0.7090373, 0.7316306, 0.7542238, 0.7768171, 0.7994103,
       0.8220036, 0.8445969, 0.8671901, 0.8897834, 0.9123766, 0.9349699,
       0.9575632, 0.9801564, 1.0027497, 1.0253429, 1.0479362, 1.0705295,
       1.0931227, 1.115716 , 1.1383092, 1.1617714, 1.1852336, 1.2086958,
       1.2321579, 1.2556201, 1.2790824, 1.3025446, 1.3260068, 1.3494689,
       1.3729311, 1.3963933, 1.4198556, 1.4433178, 1.4660518, 1.4887859,
       1.5115199, 1.534254 , 1.556988 , 1.579722 , 1.6024561, 1.6251901,
       1.6479242, 1.6706582, 1.6933923, 1.7161263, 1.7388604, 1.7615944,
       1.7843285, 1.8070625, 1.8297966, 1.8525306, 1.8752646, 1.8979987,
       1.9207327, 1.9434668, 1.9662008, 1.9889349, 2.0116689, 2.0344031,
       2.057137 , 2.079871 , 2.10261  , 2.1253   ])
[22]:
results['bands_interpolated']['col1'] # energies of the first band included in the computation
[22]:
array([-6.9219413e+00, -6.8940660e+00, -6.8085430e+00, -6.6620450e+00,
       -6.4545340e+00, -6.1918492e+00, -5.8844337e+00, -5.5441275e+00,
       -5.1817107e+00, -4.8061004e+00, -4.4246202e+00, -4.0431900e+00,
       -3.6652303e+00, -3.2892687e+00, -2.9078989e+00, -2.5116823e+00,
       -2.0972719e+00, -1.6731431e+00, -1.2571059e+00, -8.6869100e-01,
       -5.2580200e-01, -2.4899600e-01, -6.5040000e-02,  4.3244000e-06,
       -6.2932000e-02, -2.3642800e-01, -4.8253200e-01, -7.5852300e-01,
       -1.0327194e+00, -1.2913052e+00, -1.5373757e+00, -1.7856199e+00,
       -2.0538857e+00, -2.3532255e+00, -2.6814742e+00, -3.0252931e+00,
       -3.3692219e+00, -3.7041819e+00, -4.0295515e+00, -4.3500915e+00,
       -4.6728029e+00, -5.0056581e+00, -5.3559804e+00, -5.7269859e+00,
       -6.1147633e+00, -6.5082169e+00, -6.8906918e+00, -7.2399797e+00,
       -7.5270734e+00, -7.7186036e+00, -7.7862172e+00, -7.7605839e+00,
       -7.6950994e+00, -7.6177669e+00, -7.5589328e+00, -7.5380111e+00,
       -7.5569811e+00, -7.6014857e+00, -7.6482453e+00, -7.6763530e+00,
       -7.6773896e+00, -7.6584306e+00, -7.6362071e+00, -7.6266656e+00,
       -7.5948839e+00, -7.5105047e+00, -7.3746767e+00, -7.1930261e+00,
       -6.9738584e+00, -6.7258620e+00, -6.4578810e+00, -6.1798000e+00,
       -5.9016418e+00, -5.6306071e+00, -5.3687224e+00, -5.1128516e+00,
       -4.8563991e+00, -4.5915818e+00, -4.3120995e+00, -4.0155549e+00,
       -3.7040555e+00, -3.3825510e+00, -3.0564950e+00, -2.7303798e+00,
       -2.4069378e+00, -2.0864594e+00, -1.7668935e+00, -1.4455550e+00,
       -1.1219864e+00, -8.0136440e-01, -4.9847700e-01, -2.4046800e-01,
       -6.3440000e-02,  4.3244000e-06])

The parser cannot determine the names of the columns because the number of colums depend on the number of bands considered. The meaning of the columns can be identified by knowing the input used to perform the post processing.

[46]:
r = results['bands_interpolated']
kpath = r['col0']
band3 = r['col1']
band4 = r['col2']
band5 = r['col3']
band6 = r['col4']
[47]:
plt.plot(kpath,band3,label='band3')
plt.plot(kpath,band4,label='band4')
plt.plot(kpath,band5,label='band5')
plt.plot(kpath,band6,label='band6')
plt.legend()
[47]:
<matplotlib.legend.Legend at 0x7f3ea04b3358>
../_images/tutorials_Tutorial_YamboParser_39_1.png

Build a nice band plot

[48]:
G = [0.,0.,0.]
X = [1.,0.,0.]
L = [0.5,0.5,0.5]
W = [1.0,0.5,0.]
fcc_high_sym = {'X':X,'L':L,'G':G,'W':W}
[24]:
band_range = [3,6]
[25]:
data = results['bands_interpolated']
#data
[26]:
len(band_range)
[26]:
2
[31]:
def get_kp_coord_path(data,band_range):
    """
    Return a list with the coordinates of the kpoints
    ordered along the path. The coordinates are expressed in the same
    units provided by the output of the ypp computation.
    """
    num_bands = band_range[1]-band_range[0]+1
    index_first_col = 1 + num_bands
    len_kpath = len(data['col1'])
    kp_coord = []
    for ind in range(len_kpath):
        kp_coord.append([data['col'+str(index_first_col)][ind] for i in [0,1,2]])
    return kp_coord
[32]:
get_kp_coord_path(data,band_range)
[32]:
[[0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.0, 0.0, 0.0],
 [0.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