Author Topic: Help in python code  (Read 7140 times)

0 Members and 1 Guest are viewing this topic.

Online Jahanzaib

  • QuantumATK Guru
  • ****
  • Posts: 103
  • Country: gb
  • Reputation: 3
    • View Profile
Help in python code
« on: December 6, 2023, 05:11 »
Dear Expert
My python code for DOS works perfectly fine but I need to adjust a bit which I already tried but I couldn't succeeded. Can anyone share some tips or tricks so I can get required DOS.

Please find the attached code - there are two part of code
1) # Plot DOS 1 in the first subplot
     Herein, I have stanene nanoribbons consist of Tin 120 and H 24 (total 144 atoms) - my code gives me DOS for complete system but I am interested in
                         - Only p-orbitals of Tin, I know about projection stuff but I don't know how to loop it over complete all Tin.

2) # Plot DOS 2 in the second subplot
    Herein, I adsorbed FeSn10 on stanene nanoribbon and I am interested in
                        - Both p - orbitals of Tin, and Fe (atom indices = 144 and d-orbitals)

Thank you

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: Help in python code
« Reply #1 on: December 9, 2023, 01:00 »
The plotting script is not helpful to answer the question, it's just plotting data once you have already extracted it. The question is really about how you computed the DOS, with which projections, and how to extract them. It's also a bit unclear what you want to plot, do you need multiple lines for the projected DOS of p-orbitals, one line for each atom, or just p for all atoms, one line? I guess my confusion is from the "loop", is it over atoms or projections? Seems like you should use ProjectOnShellsByElement, but I agree it's a bit hard to know from the manual how you use "evaluate" to get the individual data out. If you give me a bit more info, I can try to help.

Online Jahanzaib

  • QuantumATK Guru
  • ****
  • Posts: 103
  • Country: gb
  • Reputation: 3
    • View Profile
Re: Help in python code
« Reply #2 on: December 9, 2023, 04:35 »
Sorry Dr. Blom for inconveniences.

Please the find complete code for reference, and I have sent hdf5 file on email (quantumatk-support@synopsys.com) and I cannot share my results. Please have a look.
 1) DOS1
      Herein, I am only interested in p-orbitals of Tin. For "loop", I was trying to say that I have a long stanene nanoribbon (Tin=120 and H=24), is it the way to do to get the DOS for all 120 tin?
Projection(spin=Spin.Up, atoms=[Tin]) + Projection(spin=Spin.Down, atoms=[Tin]) - also i tried this but not worked for me.
then how to do angular_momenta=[1]????

2)DOS2
I think it's clear for you, just interested in Both p - orbitals of Tin, and Fe (atom indices = 144 and d-orbitals).

Thank you

Online Jahanzaib

  • QuantumATK Guru
  • ****
  • Posts: 103
  • Country: gb
  • Reputation: 3
    • View Profile
Re: Help in python code
« Reply #3 on: December 13, 2023, 02:17 »
Dear Dr Blom

For DOS1: I tried the projection and it works fine but I am interested in broadening=0.03 * eV which I think we cannot get through PDOS?

dos_Up = dos.evaluate(projection_list=ProjectionList(elements=[Tin], angular_momenta=[1]), spin=Spin.Up)
dos_Down = dos.evaluate(projection_list=ProjectionList(elements=[Tin], angular_momenta=[1]), spin=Spin.Down)


For DOS2, still trying.

Thank you
« Last Edit: December 18, 2023, 01:30 by Jahanzaib »

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: Help in python code
« Reply #4 on: January 19, 2024, 00:57 »
Sorry for the delay.

In general, I would avoid using DensityOfStates, as it's by now just a legacy object. PDOS really has all the same functionality, but is better supported and a LOT faster. And, you can use broadening in PDOS, but it's a bit hidden. Just set set spectrum_method=GaussianBroadening(broadening=0.03*eV).

So, for both DOS1 and DOS2, using ProjectOnShellsBySites in PDOS should give you the data you need, and then you can filter it down for plotting.

Online Jahanzaib

  • QuantumATK Guru
  • ****
  • Posts: 103
  • Country: gb
  • Reputation: 3
    • View Profile
Re: Help in python code
« Reply #5 on: January 19, 2024, 11:05 »
Thank you Dr Blom for you guidance.
I already got with PDOS but don't have an idea for broadening in PDOS - i will try that.


Online Jahanzaib

  • QuantumATK Guru
  • ****
  • Posts: 103
  • Country: gb
  • Reputation: 3
    • View Profile
Re: Help in python code
« Reply #6 on: August 7, 2024, 23:09 »
Dear Members, I hope you are doing well.
Below is my code: I got error

# Read DOS object from file
dos = nlread('/home/hartree/jem/wolf6252/N-P/With-hyd/Fe/DOS/DOS.hdf5', DensityOfStates)[0]

# Get the actual energy values from the DOS object
energies = dos.energies()

# Set the spectrum method to Gaussian broadening with a broadening width of 0.03 eV
spectrum_method=GaussianBroadening(broadening=0.03*eV)

# Calculate the DOS spectrum with spin up using Gaussian broadening
dos_Up = dos.evaluate(projection_list=ProjectionList(atoms=[144], elements=[Iron], angular_momenta=[2]), spin=Spin.Up)

# Calculate the DOS spectrum with spin down using Gaussian broadening
dos_Down = dos.evaluate(projection_list=ProjectionList(atoms=[144], elements=[Iron], angular_momenta=[2]), spin=Spin.Down)

# Plot the spectra using pylab
import pylab
pylab.figure(figsize=(5, 10))
pylab.plot(dos_Up.inUnitsOf(eV**-1), energies.inUnitsOf(eV), color='darkblue', label='Spin Up')
pylab.plot(dos_Down.inUnitsOf(eV**-1), energies.inUnitsOf(eV), color='darkblue', linestyle='--', label='Spin Down')

# Add a dotted line at E-EF=0
pylab.axhline(y=0, linestyle='dotted', color='gray')

pylab.xlim(0,10)
pylab.ylim(-3,3)

# Save the figure as a high-resolution PNG image
pylab.savefig('Fe-PDOS.png', dpi=300, bbox_inches='tight')

# Add the legend in the upper right corner
pylab.legend(loc='upper right')

pylab.xlabel("PDOS (1/eV)")
pylab.ylabel("E-E$_{f}$/eV")
pylab.legend()
pylab.show()

I want add broadening and I got the following error:
      9 energies = dos.energies()
     10
---> 11 spectrum_method=GaussianBroadening(broadening=0.03*eV)
     12
     13 # Calculate the DOS spectrum with spin up using Gaussian broadening

TypeError: 'PhysicalQuantity' object is not callable.

Any one please help me how to solve this issue - I have tired but couldn't got solve it.

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: Help in python code
« Reply #7 on: August 7, 2024, 23:51 »
This should work, provided you are using a recent version, at least.

The only reason for this error I can imaging is that somewhere else in your script, GaussianBroadening was redefined, like if you by mistake did
GaussianBroadening=0.03*eV

If so, restart the atkpython interactive mode.

Online Jahanzaib

  • QuantumATK Guru
  • ****
  • Posts: 103
  • Country: gb
  • Reputation: 3
    • View Profile
Re: Help in python code
« Reply #8 on: August 8, 2024, 00:02 »
Thank you Dr. Blom for your response.

I am using 2022,
                  - if i use "spectrum_method=GaussianBroadening(broadening=0.03*eV)" then I got the following error i-e; 'PhysicalQuantity' object is not callable.
                  - if i use GaussianBroadening=0.03*eV, then it will have no effect on broadening.
Even, I restarted the atkpython interactive mode still got the same issue.



Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: Help in python code
« Reply #9 on: August 8, 2024, 19:36 »
GaussianBroadening=0.03*eV is distinctly wrong, you "destroy" the class.

spectrum_method=GaussianBroadening(broadening=0.03*eV) works as far back as the 2020 version so something is odd in your system.

Can you show us a screenshot like below, where you just start atkpython and execute the one single line
spectrum_method=GaussianBroadening(broadening=0.03*eV)




Online Jahanzaib

  • QuantumATK Guru
  • ****
  • Posts: 103
  • Country: gb
  • Reputation: 3
    • View Profile
Re: Help in python code
« Reply #10 on: August 11, 2024, 01:40 »
Many thanks to Dr. Blom for providing detailed information to the students. I really appreciate it.

In my case, I made a slight modification to the code. I was executing spectrum_method=GaussianBroadening(broadening=0.03*eV) separately, which prevented me from getting the desired broadening effect. After carefully reviewing the documentation, I tried a few different approaches, and finally, I achieved the correct result with:

gaussianSpectrum(energies=None, spin=None, broadening=None, projection_list=None).



Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: Help in python code
« Reply #11 on: August 12, 2024, 20:49 »
Yes, that works for the DensityOfStates class, but not for ProjectedDensityOfStates (which generally contains more features and is faster and uses less memory) which I thought you were using, based on the fact that you attempted to use the GaussianBroadening class.