## no image shown in output *.xsf file

Post here any question you encounter when running the scripts of the yambo-py suite. Post here problem strictly to the python interface as problem coming from the yambo runs should go in the appropriate subforum.

Moderators: amolina, miranda.henrique

### no image shown in output *.xsf file

Dear developers,

I want to plot the excitonic spectrum for 2D black phosphorus, as well as the orbital component for each energy level in spectrum with yambo-py code. I refer to this website
http://www.yambo-code.org/wiki/index.php?title=How_to_analyse_excitons. Firstly, after getting two files named 'o-bse_y.exc_E_sorted' and 'o-bse_y.exc_I_sorted', I run my code based on yambopy as following,
Code: Select all
import sysfrom yambopy import *a = YamboBSEAbsorptionSpectra(job_string='bse_y',path='.')excitons = a.get_excitons(min_intensity=0.01,max_energy=3.5,Degen_Step=0.01)print( "nexcitons: %d"%len(excitons) )print( "excitons:" )print( "  Energy  Intensity Index")for exciton in excitons:    print( "%8.4lf %8.4lf %5d"%tuple(exciton) )a.get_wavefunctions(Degen_Step=0.01,repx=range(-1,2),repy=range(1),repz=range(-1,2),Cells=[1,1,1],Hole=[0,24.45,7.80], FFTGvecs=10,wf=True, Direction='13')a.write_json()
to get .json file.
Secondly, I use my code to read .json file to plot orbital figures for energy level. But the .xsf file I got shows nothing, only blank. This part I use the code as following,
Code: Select all
import matplotlibmatplotlib.use('Agg') # prevents crashes if no X server presentfrom yambopy import *from qepy import *import jsonimport matplotlib.pyplot as pltimport numpy as npfrom math import sqrt, ceilimport argparse as argsdef get_var(dictionary,variables):    for var in variables:        if var in dictionary:            return dictionary[var]    raise ValueError( 'Could not find the variables %s in the output file'%str(variables) )f = open('absorptionspectra.json')data = json.load(f)f.close()print 'JSON file loaded.'print 'Absorption spectra ...'plt.plot(get_var(data,['E/ev','E/ev[1]']), get_var(data,['EPS-Im[2]' ]),label='BSE',lw=3)nexcitons = len(data['excitons'])print 'Number of excitons: ', nexcitonsfor n,exciton in enumerate(data['excitons']):    plt.axvline(exciton['energy'])plt.xlabel('$\omega$ (eV)')plt.ylabel('Intensity (arb. units)')plt.ylim(0.0,30.0,5.0)plt.legend()plt.savefig('excitonE_abs.png', bbox_inches='tight')print 'excitonE_abs.png'### Lattice : necessary to determine bounds of exciton weights plotprint 'Reciprocal lattice ...'lat = np.array(data['lattice'])rlat = rec_lat(lat)x,y,z = np.array(rlat )cut=0.2  ##default value setted by tslixmin,ymin,_ = -(x+y)*cutxmax,ymax,_ = +(x+y)*cutprint 'Excitons weights ...'nx = int(ceil(sqrt(nexcitons)))ny = int(ceil(nexcitons*1.0/nx))print "cols:",nxprint "rows:",nycmap = plt.get_cmap("gist_heat_r")fig = plt.figure(figsize=(nx*4,ny*4))sorted_excitons = sorted(data['excitons'],key=lambda x: x['energy'])for n,exciton in enumerate(sorted_excitons):    w   = np.array(exciton['weights'])    qpt = np.array(exciton['qpts'])    ax = plt.subplot(ny,nx,n+1)    ax.scatter(qpt[:,0], qpt[:,1], s=20, c=w, marker='H', cmap=cmap, lw=1, label="e: %lf"%exciton['energy'])    plt.xlim([-cut,cut])    plt.ylim([-cut,cut])    plt.gca().yaxis.set_major_locator(plt.NullLocator())    plt.gca().xaxis.set_major_locator(plt.NullLocator())    ax.set_aspect('equal')plt.savefig('mono_ex.png', bbox_inches='tight', dpi=1500)print 'mono_ex.png'print 'Done.'

I'm not sure is this error related to selected hole position or some other problems in my code. I'm sorry maybe this question is a little troublesome. Thank you for you help and patience.

Best regards,
Tianshu Li,
Jilin University, China
Tianshu

Posts: 27
Joined: Wed Sep 20, 2017 8:36 am

### Re: no image shown in output *.xsf file

Hi Tianshu,

The issue might be related to the position of the hole.
Here is a list of steps you might take to find the source of the problem:

1. Check if you are representing the density in your visualization software.
I personally have used Vesta and Xcrysden and in both of them, you might have to select some options to visualize the density in the XSF file.
Are the positions of the atoms represented?
I also take the opportunity to suggest you this online tool I developed:
http://henriquemiranda.github.io/excitonwebsite/
I appreciate any feedback and if you find any troubles please let me know.
This tool should play well with yambopy.

2. Check if the position of the hole makes sense.
You should fix the position of the hole in a point in space where there is some electronic density otherwise the probability of finding the electron (what is represented) will be very small.
Even though the code normalizes to the maximum of this probability it might be that you just get numerical noise.
A good rule of thumb is to put the hole near one of the atoms but not on top of it.
Depending on the type of orbital (s,p,d,...) that you want to choose you might want to put the hole in a different point in space around the atom.

3. Choose a good value to represent the isosurface.
If the electronic probability is very localized at some point in space it might be that you don't see it as it might be too close to the atom.

Best regards,
Henrique
Institute of Condensed Matter and Nanosciences
http://henriquemiranda.github.io/
UNIVERSITÉ CATHOLIQUE DE LOUVAIN
miranda.henrique

Posts: 16
Joined: Thu Jul 23, 2015 2:34 pm