User Tools

Site Tools


exercises:2019_conexs_newcastle:ex4

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
exercises:2019_conexs_newcastle:ex4 [2019/09/11 03:38] – [Part 2: MD of liquid water] abussyexercises:2019_conexs_newcastle:ex4 [2020/08/21 10:15] (current) – external edit 127.0.0.1
Line 298: Line 298:
 &END TOPOLOGY &END TOPOLOGY
 </code> </code>
-where we specify the filename, format, and that we should not divide our atoms into molecules. When you have finished running the above input, try to use the following python script to convolve your spectra with Gaussian functions. Note that you might have to change the parameters at the top of the file to get pleasing results. If a new window with the plot does not open, it is also saved in the current directory as "pdos.png".+where we specify the filename, format, and that we should not divide our atoms into molecules. When you have finished running the above input, try to use the following python script to convolve your spectra with Gaussian functions. You do this by first loading Python3 by typing  
 +<code> 
 +module load Anaconda3/5.0.1 
 +</code> 
 +and then typing 
 +<code> 
 +python pdos_conv.py 
 +</code> 
 +Note that you might have to change the parameters at the top of the file to get pleasing results. If a new window with the plot does not open, it is also saved in the current directory as "pdos.png".
 <code - pdos_conv.py> <code - pdos_conv.py>
 import numpy as np import numpy as np
-import matplotlib.pyplot as plt 
 import os import os
 +import matplotlib as mpl
 +mpl.use('Agg')
 +import matplotlib.pyplot as plt
  
 # Parameters # Parameters
Line 380: Line 390:
 <code> <code>
 &MOTION &MOTION
-&MD+  &MD
     ENSEMBLE NVT     ENSEMBLE NVT
     STEPS 15     STEPS 15
Line 395: Line 405:
 &END MOTION &END MOTION
 </code> </code>
-The parameters in the MD section has been selected to finish in a few minut, but feel free to experiment with different values. To not print too much, also modify the &PDOS section to+The parameters in the MD section has been selected to finish in a few minutes, but feel free to experiment with different values and get a feel for how they work. To not print too much, also modify the &PDOS section to
 <code> <code>
 &PDOS &PDOS
Line 404: Line 414:
   &END   &END
 &END PDOS &END PDOS
-which means that we only print the PDOS every third step, as well as appending the specta instead of overwriting them.+</code> 
 +which means that we only print the PDOS every third step, as well as appending the spectra instead of overwriting them.
  
-When you have finished the calculation, you should have +When you have finished the calculation, you should have created some new files, including 
 +    * liquid_water-1.ener - containing information about energies, temperature, and timings 
 +    * liquid_water-pos-1.xyz - containing your trajectory 
 +Examine liquid_water-1.ener and make sure that the temperature and total energy remains reasonably stable during the run. As a final exercise, use a slightly modified python code from Part 1 to see how the PDOS spectrum changes with time. 
 +<code - pdos_conv_md.py> 
 +import numpy as np 
 +import os 
 +import matplotlib as mpl 
 +mpl.use('Agg'
 +import matplotlib.pyplot as plt 
 + 
 +# Parameters 
 +FWHM = 0.4   # Full width half maximum 
 +Emin=-16.    # Starting energy 
 +Emax= 4.     # ----- 
 +DE = 0.01    # Energy intervals 
 +dE=np.arange(Emin,Emax,DE) 
 +E_shift = 0 
 +filename = 'liquid_water-k1-1.pdos' 
 + 
 +def plot_pdos(txtfile): 
 + 
 +    if not os.path.isfile(txtfile): 
 +        print("Warning: File does not exist!"
 +        return np.zeros(np.shape(dE)[0]) 
 +         
 +    PDOS = np.asarray(open(txtfile).read().split()) 
 + 
 +    if 'f' in PDOS: 
 +        start = 26 
 +        Norb = 4+3 
 +    elif 'd' in PDOS: 
 +        start = 25 
 +        Norb = 3+3 
 +    elif 'p' in PDOS: 
 +        start = 24 
 +        Norb = 2+3 
 +    else: 
 +        start = 23 
 +        Norb = 1+3 
 +         
 +    L = int(PDOS[-Norb]) 
 +    N = np.where(PDOS=='Projected')[0]-1 
 +     
 +    for i in range(N.shape[0]-1): 
 +        pdos = PDOS[N[i]:N[i+1]] 
 +        pdos = pdos[start:
 +        pdos = np.asarray(np.split(pdos,L)) 
 +        E = pdos[:,1].astype(np.float)*27.2114 #a.u. -> eV 
 +        pdos = pdos[:,3:].astype(float) 
 +         
 +        if i == 0: 
 +            pdos_tot = np.zeros((pdos.shape)) 
 +        pdos_tot += pdos / N.shape[0] 
 +         
 +        s, p = convolve(E,pdos) 
 +        if i == 0: 
 +            yshift = np.max(np.append(s,p)) 
 +        plt.plot(dE+E_shift,s-i*yshift, c='blue',linestyle='-',linewidth=2.,alpha=0.7) 
 +        plt.plot(dE+E_shift,p-i*yshift, c='red',linestyle='-',linewidth=2.,alpha=0.7) 
 +         
 +    s, p = convolve(E,pdos_tot) 
 +    plt.text(-14,-(i+1.5)*yshift,'Sum'
 +    plt.plot(dE+E_shift,s-(i+2)*yshift, c='blue',linestyle='-',linewidth=2.,alpha=0.7) 
 +    plt.plot(dE+E_shift,p-(i+2)*yshift, c='red',linestyle='-',linewidth=2.,alpha=0.7) 
 +  
 +    plt.yticks([])                                                                                               
 +    plt.ylabel('PDOS (arbitrary units)'
 +    plt.xlabel('Binding energy (eV)'
 +    plt.xticks(np.arange(-15,5,5),-np.arange(-15,5,5)) 
 +    plt.xlim([-16,3]) 
 +    plt.title('FWHM = ' + str(FWHM) + ' eV') 
 + 
 +    plt.plot([100,101],[0,0], c='blue',linestyle='-',linewidth=2., label='O s') 
 +    plt.plot([100,101],[0,0], c='red',linestyle='-',linewidth=2., label = 'O p') 
 +    plt.legend(loc=1) 
 + 
 +    plt.savefig('pdos.png'
 +    plt.show()     
 +             
 +def convolve(E,PDOS): 
 +     
 +    sigma = 1 / (2 * np.sqrt(2 * np.log(2) ) ) * FWHM 
 +                 
 +    conv = np.zeros((len(dE),2)) 
 +    for j in range(conv.shape[1]): 
 +        W = PDOS[:,j] 
 +        for i,e in enumerate(E): 
 +            conv[:,j] += np.exp(-(dE-e)**2 / (2 * sigma**2))*W[i] 
 +    return conv[:,0], conv[:,1] 
 + 
 +plot_pdos(filename)  
 +</code>
exercises/2019_conexs_newcastle/ex4.1568173089.txt.gz · Last modified: 2020/08/21 10:15 (external edit)