Optical matrix elements

Run-time issues concerning Yambo that are not covered in the above forums.

Moderators: andrea marini, Daniele Varsano, myrta gruning, Conor Hogan

Post Reply
Bruno
Posts: 58
Joined: Tue Dec 08, 2020 11:16 am

Optical matrix elements

Post by Bruno » Fri Jan 22, 2021 2:09 pm

Hello!

I'm interested on the optical matrix elements and I've read here on the forum that is possible to extract this info from the dipoles database. I'm trying to do that using a script provided by Claudio in another post here on the forum but so far its not working(script1.py) so I suppose I must be using it wrong, just executing it as "python3 script1.py" is giving me the following error:

print "Dipole element <n{0:}|{3:}|n{1:}> at k{2:}: {4:}, module: {5:}".format(args.B1,args.B2,args.K,args.xyz,Dipole,abs(Dipole))
^
SyntaxError: invalid syntax


Also I tried using another script provided by Daniele and also no luck(script2.py), for this one I changed the "path" as instructed by I'm receiving the following error:

Traceback (most recent call last):
File "script.py", line 20, in <module>
dip_file = Dataset(path+"ndb.dipoles_fragment_1","r")
File "netCDF4/_netCDF4.pyx", line 2015, in netCDF4._netCDF4.Dataset.__init__
File "netCDF4/_netCDF4.pyx", line 1636, in netCDF4._netCDF4._ensure_nc_success
FileNotFoundError: [Errno 2] No such file or directory: b'/ccc/scratch/cont003/gen7682/cuccobru/final/SAVE/ndb.dipoles_fragment_1'


And in fact I don't have fragments of the nbd.dipoles on the Save folder, just the ndb.dipoles file. Any solutions for any of the scripts are very welcome! Thank you. (I'm using the Yambo 5.0.0)
script2.py.txt
script1.py.txt
Regards,
You do not have the required permissions to view the files attached to this post.
MSc. Bruno Cucco
PhD Candidate
CNRS Institut des Sciences Chimiques de Rennes, France
Université de Rennes 1
https://iscr.univ-rennes1.fr

User avatar
palful
Posts: 21
Joined: Tue Jan 26, 2016 11:23 am
Location: Rome and Milan

Re: Optical matrix elements

Post by palful » Fri Jan 22, 2021 6:14 pm

Ciao Bruno,

You can actually read the optical matrix elements ("dipoles") using yambopy, the python suite to manage advanced pre/postprocessing of yambo.
Below an example (also attached), followed by some explanation.

In order to read the dipoles your python script will be like (commented version attached):

Code: Select all

from yambopy import *
ylat = YamboLatticeDB.from_db(filename='./SAVE/ns.db1') 
ydip = YamboDipolesDB(ylat,save='./dbs',filename='./ndb.dipoles') 

print(ydip.dipoles[0,2,4,3])
print(ydip.dipoles[0,2,3,4])
First we import yambopy, then read the general lattice information (such as kpoint coordinates and symmetries) with YamboLatticeDB, for which you only need the ns.db1 file inside the yambo SAVE folder.

After that, we instance the class YamboDipolesDB where the argument 'save' is the path to the databases and 'filename' the database name.

Now, the numpy array

Code: Select all

ydip.dipoles
contains the dipole values. Its axes are as follows: [ kpoint in full Brillouin zone, cartesian direction, band 1, band 2 ]. Keep in mind that since the indexing starts from 0, ydip.dipoles[0,2,4,3] in the example contains the values at Gamma, with component along the z-axis, between the third and second bands of the system.

Using yambopy
- Follow the installation instructions here: http://www.yambo-code.org/wiki/index.ph ... in_Yambopy.
- If you have questions or run into problems, you can post about it in this subtopic on the yambo forum: viewforum.php?f=35

Let us know if it worked!

Hope this helps,
Fulvio
You do not have the required permissions to view the files attached to this post.
Fulvio Paleari
Istituto di Struttura della Materia (CNR)
Area della Ricerca Roma 1

Bruno
Posts: 58
Joined: Tue Dec 08, 2020 11:16 am

Re: Optical matrix elements

Post by Bruno » Wed Jan 27, 2021 1:18 pm

Hello!

I think thats indeed what I'm looking for! Can you tell me what are the output units?

Regards,
MSc. Bruno Cucco
PhD Candidate
CNRS Institut des Sciences Chimiques de Rennes, France
Université de Rennes 1
https://iscr.univ-rennes1.fr

User avatar
palful
Posts: 21
Joined: Tue Jan 26, 2016 11:23 am
Location: Rome and Milan

Re: Optical matrix elements

Post by palful » Mon Feb 01, 2021 2:45 pm

Hi,

The quantity saved in ndb.dipoles should be: i*R_nmk = i*<n k| r | m k> , with R_nmk in atomic units of length (bohr).

Fulvio
Fulvio Paleari
Istituto di Struttura della Materia (CNR)
Area della Ricerca Roma 1

Xiaoming Wang
Posts: 67
Joined: Fri Dec 18, 2020 7:14 am

Re: Optical matrix elements

Post by Xiaoming Wang » Mon Aug 09, 2021 4:09 pm

Hi,

Is the yambopy updated in alignment with the newest yambo version? For Yambo-5.0.3, DIP_iR in ndb.dipoles has six indexes. Is it spin, kpts, vb, cb, catesian direction, imag or real?

Best,
Xiaoming
Xiaoming Wang
The University of Toledo

User avatar
palful
Posts: 21
Joined: Tue Jan 26, 2016 11:23 am
Location: Rome and Milan

Re: Optical matrix elements

Post by palful » Wed Aug 11, 2021 10:56 am

Dear Xiaoming,

Are you doing a spin-polarised calculation? Can you attach an example ndb.dipoles file?

Thanks,
Fulvio
Fulvio Paleari
Istituto di Struttura della Materia (CNR)
Area della Ricerca Roma 1

Xiaoming Wang
Posts: 67
Joined: Fri Dec 18, 2020 7:14 am

Re: Optical matrix elements

Post by Xiaoming Wang » Wed Aug 11, 2021 10:03 pm

Dear Fulvio,

No, I'm not doing a spin-polarized calculation. The database is too large to be uploaded. Here I attach some information from ncdump.

Code: Select all

netcdf ndb {
dimensions:
        D_0000000003 = 3 ;
        D_0000000001 = 1 ;
        D_0000000002 = 2 ;
        D_0000000004 = 4 ;
        D_0000000011 = 11 ;
        D_0000000100 = 100 ;
        D_0000000032 = 32 ;
        D_0000000008 = 8 ;
        D_0000000576 = 576 ;
variables:
        float HEAD_VERSION(D_0000000003) ;
        float HEAD_REVISION(D_0000000001) ;
        float SERIAL_NUMBER(D_0000000001) ;
        float SPIN_VARS(D_0000000002) ;
        float HEAD_R_LATT(D_0000000004) ;
        float HEAD_WF(D_0000000001) ;
        float FRAGMENTED(D_0000000001) ;
        float TEMPERATURES(D_0000000002) ;
        float PARS(D_0000000011) ;
        char APPROACH(D_0000000001, D_0000000100) ;
        char KINDS(D_0000000001, D_0000000100) ;
        char WAVE_FUNC_XC(D_0000000001, D_0000000100) ;
        float DIP_iR(D_0000000001, D_0000000576, D_0000000008, D_0000000032, D_0000000003, D_0000000002) ;
        float DIP_P(D_0000000001, D_0000000576, D_0000000008, D_0000000032, D_0000000003, D_0000000002) ;
        float DIP_v(D_0000000001, D_0000000576, D_0000000008, D_0000000032, D_0000000003, D_0000000002) ;
data:

 HEAD_VERSION = 5, 0, 3 ;

 HEAD_REVISION = 19584 ;

 SERIAL_NUMBER = 2115 ;

 SPIN_VARS = 1, 1 ;

 HEAD_R_LATT = 576, 576, 576, 576 ;

 HEAD_WF = 4077 ;

 FRAGMENTED = 1 ;

 TEMPERATURES = 0, 0 ;

 PARS = 1, 40, 8, 9, -0.03674933, -0.03674933, 4077, 1, 1, 0, _ ;

 APPROACH =
  "G-space v                                                                                           " ;

 KINDS =
  "R V P                                                                                               " ;

 WAVE_FUNC_XC =
  "Perdew, Burke & Ernzerhof(X)+Perdew, Burke & Ernzerhof(C)                                           " ;

 DIP_iR =
  -3.661782e-08, -3.201844e-08,
  3.6709e-10, 1.779211e-08,
  2.095814e-10, 8.769372e-09,
  -7.588392e-10, 2.204259e-10,
  -7.021913e-11, -3.309342e-10,
  7.4839e-09, 1.125398e-09,
  -0.01041611, 0.0005428896,
.....
You can see the shape of DIP_iR from above.

Best,
Xiaoming
Xiaoming Wang
The University of Toledo

User avatar
palful
Posts: 21
Joined: Tue Jan 26, 2016 11:23 am
Location: Rome and Milan

Re: Optical matrix elements

Post by palful » Mon Nov 08, 2021 5:58 pm

Dear Xiaoming,

My deepest apologies for never coming back to this. I just missed the post somehow.

The problem you had should be related to a new format for the dipoles database that was introduced in a recent version of yambo.
Yambopy was not supporting this new format, however now it is patched and it does (to be tested in the spin-polarised case).

This is a simple testing script for the new version (to be downloaded from the yambo page). In case you find additional issues, don't hesitate to reply.

Code: Select all

from yambopy import *

# Generic indices for testing
ik,ir,ic,iv = [3,1,6,2]

# Read lattice info
ylat = YamboLatticeDB.from_db(filename='ns.db1')

# Read dipole matrix element
ydip = YamboDipolesDB(ylat,save='dbs',filename='ndb.dipoles')
print(ydip.dipoles.shape)
print(ydip.dipoles[ik,ir,ic,iv])
Cheers,
Fulvio
Fulvio Paleari
Istituto di Struttura della Materia (CNR)
Area della Ricerca Roma 1

Post Reply