# Calculate momentum matrix element

Hi developers,
I want to calculate momentum matrix elements, as I read in References, we can obtain the PMAT.OUT by putting “taskname=pmat” in gw calculations and
<momentummatrix

fastpmat=“true”

I am trying to use output file but it’s not readable. Is there any way to make it readable?

On the other hand I need to change the source file to compute in different way, and in exciting book I read in source part in “genpmat.f90” I will find the subroutine related the calculating momentum matrix elements, I guess this book is related to previous version of exciting, cause I didn’t find the “genpmat.f90”, but Can you guide me please which subroutine produced result for momentum matrix element, maybe by some changes, I can make it readable and do necessary changes for desired result??
Best Regards,
Nasrin

Dear nasrin93,

There is no option to save the momentum matrix elements in a readable file within the gw part but there is an option in the excited state part (xs) that allows for writing the momentum matrix elements to an hdf5 file. Here is an example how you can do it:

``````<!-- define here the ground state-->
<xs
xstype="BSE"
rgkmax="8.0"
vkloff="0.05 0.15 0.25"
ngridk="2 2 2"
nempty="20">

<qpointset>
<qpoint>0.0 0.0 0.0</qpoint>
</qpointset>

<plan>
</plan>
</xs>

``````

You can define the ground state parameters with the attributes of the `xs` element. Also have a look at the input reference.

You find the momentum matrix elements in the file `bse_output.h5` in the group `pmat` and it is structured as follows:

``````GROUP "pmat" {
GROUP "00000001" {
DATASET "pmat" {
DATATYPE  H5T_IEEE_F64LE
DATASPACE  SIMPLE { ( 25, 25, 3, 2 ) / ( 25, 25, 3, 2 ) }
}
}
GROUP "00000002" {
DATASET "pmat" {
DATATYPE  H5T_IEEE_F64LE
DATASPACE  SIMPLE { ( 25, 25, 3, 2 ) / ( 25, 25, 3, 2 ) }
}
}
...
}
``````

The name of the sub groups indicates the index of the k-point for which the momentum matrix was computed. Each of these groups hold a dataset `pmat` which holds the momentum matrix elements. This dataset is a double array of dimensions `N_states x N_states x 3 x 2`. The dimension of the third rank reflects the three directions of space (p_x, p_y, p_z) and the last ranks dimension is for the real and the imaginary part.