Author Topic: Access to Hamiltonian or Density Matrix  (Read 13885 times)

0 Members and 1 Guest are viewing this topic.

Offline NasiLemak

  • New QuantumATK user
  • *
  • Posts: 4
  • Country: cn
  • Reputation: 0
    • View Profile
Access to Hamiltonian or Density Matrix
« on: April 11, 2011, 07:48 »
I wonder if there is any method that the users of ATK can access or export Hamiltonian / Density Matrix so that they can do some other analysis of the system.
Hopefully ATK developer can give a positive answer.
Thank you so much.
« Last Edit: April 11, 2011, 07:58 by NasiLemak »

Offline Nordland

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 812
  • Reputation: 18
    • View Profile
Re: Access to Hamiltonian or Density Matrix
« Reply #1 on: April 11, 2011, 10:09 »
I should be able to help you, but first you must give me a little more information.

What kind of configurations is it for?

Offline NasiLemak

  • New QuantumATK user
  • *
  • Posts: 4
  • Country: cn
  • Reputation: 0
    • View Profile
Re: Access to Hamiltonian or Density Matrix
« Reply #2 on: April 12, 2011, 03:33 »
Thank you so much.
What I want to do is to extract the density matrix or Hamiltonian so that I can calculate some other physical properties.
First, I want to try a bulk configuration, and further more, if possible, I also want to try the scattering region of a device configuration.

Offline Nordland

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 812
  • Reputation: 18
    • View Profile
Re: Access to Hamiltonian or Density Matrix
« Reply #3 on: April 12, 2011, 12:00 »
I have cooked up a little code snippet that should get the job done for all your needs.
Code: python
def extractHamiltonianAndOverlap(configuration, kx=0.0, ky=0.0, kz=0.0):
    """
    Routine for getting the hamiltonian and overlap for a given k-point.
    """
    from NL.ComputerScienceUtilities.Functions import realMatrixToNumpy
    # Get the density matrix calculator.
    dmc = configuration.calculator()._densityMatrixCalculator()
    # Get the neighbourlist.
    nb = dmc.neighbourlist()
    # Calculate the phases for this k-point.
    phases = nb.calculatePhases(NLEngine.Cartesian3D(kx,ky,kz))
    # Get a reference for the sparse data structure.
    sparse_H = dmc.hamiltonian()
    sparse_S = dmc.overlap()
    # Perform the fourierTransform to get the dense representation.
    # Change to NLEngine.DOWNDOWN to get spin down.
    spin = NLEngine.UPUP
    denseS = NLEngine.fourierTransform(sparse_S.getSparseCSR(spin), phases)
    denseH = NLEngine.fourierTransform(sparse_H.getSparseCSR(spin), phases)
    # Convert to numpy for easy use in Python.
    real_numpy_S = realMatrixToNumpy(NLEngine.realPart(denseS))
    imag_numpy_S = realMatrixToNumpy(NLEngine.imaginaryPart(denseS))
    real_numpy_H = realMatrixToNumpy(NLEngine.realPart(denseH))
    imag_numpy_H = realMatrixToNumpy(NLEngine.imaginaryPart(denseH))
    # Construct complex numpy.
    H = real_numpy_H + complex(0.0,1.0)*imag_numpy_H
    S = real_numpy_S + complex(0.0,1.0)*imag_numpy_S
    # Return
    return H,S
It is not sure that this exacted snippet will work forever, but it is likely. An example of the usage:
Code: python
H, S = extractHamiltonianAndOverlap(bulk_configuration, kx=0.0, ky=0.5, kz=0.2)
print H
print S
I hope it helps your forward.
« Last Edit: April 26, 2011, 07:06 by Nordland »

Offline NasiLemak

  • New QuantumATK user
  • *
  • Posts: 4
  • Country: cn
  • Reputation: 0
    • View Profile
Re: Access to Hamiltonian or Density Matrix
« Reply #4 on: April 14, 2011, 05:39 »
Thank you so much. That is what I want. I will try that later.

Offline zhangguangping

  • QuantumATK Guru
  • ****
  • Posts: 193
  • Country: cn
  • Reputation: 2
    • View Profile
Re: Access to Hamiltonian or Density Matrix
« Reply #5 on: April 16, 2011, 04:54 »
I have cooked up a little code snippet that should get the job done for all your needs.
I hope it helps your forward.

Dear Nordland,
From your code. I see, you just move the interactions the unitcell with the neighborings into the unitcell with multiplying the phase,then we have a N*N dimension of H and S,where  N is the dimension of the unit cell. If we want to get the bandstructure, we should construct the H and S like this for every k points and then solve the equation ES{Φ}=H{Φ}? In which {Φ} is expanded in the basis orbits in the unit cell.

Thanks for your answer in advance.

Offline Nordland

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 812
  • Reputation: 18
    • View Profile
Re: Access to Hamiltonian or Density Matrix
« Reply #6 on: April 16, 2011, 09:15 »
Exactly. Well spotted!

If you only are after calculating the band-structure, I would recommend that you use the build-in routine for it
since it will be done in native C++ rather than in Python.

Offline NasiLemak

  • New QuantumATK user
  • *
  • Posts: 4
  • Country: cn
  • Reputation: 0
    • View Profile
Re: Access to Hamiltonian or Density Matrix
« Reply #7 on: April 26, 2011, 05:30 »

I would like to point out one small typo in line 19. This line is for H but not S, thus the "sparse_S" should be "sparse_H"。
After correct this typo, the script can do the extraction of H and S exactly.

Thank you so much!

Offline Nordland

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 812
  • Reputation: 18
    • View Profile
Re: Access to Hamiltonian or Density Matrix
« Reply #8 on: April 26, 2011, 07:07 »
Good spotted.

I have updated the script above for future users.

Offline davalenciah

  • Heavy QuantumATK user
  • ***
  • Posts: 26
  • Reputation: 0
    • View Profile
Re: Access to Hamiltonian or Density Matrix
« Reply #9 on: August 17, 2011, 22:50 »
thanks for the code, but
when I used its
I got

Hamiltonian =
[[ -1.79177926e-01+0.j   4.31381157e-04+0.j   7.47164661e-04+0.j ...,
    1.58944871e-02+0.j   1.67094370e-06+0.j  -2.75295477e-02+0.j]
 [  0.00000000e+00+0.j   4.49252502e-03+0.j  -9.36283703e-04+0.j ...,
    2.22503996e-05+0.j  -4.14151484e-07+0.j   1.12248995e-05+0.j]
 [  0.00000000e+00+0.j   0.00000000e+00+0.j   3.41157733e-03+0.j ...,
    5.75047611e-07+0.j   9.49960993e-04+0.j  -2.47628152e-06+0.j]
 ...,
 [  0.00000000e+00+0.j   0.00000000e+00+0.j   0.00000000e+00+0.j ...,
    7.31291547e-01+0.j   1.20404864e-06+0.j   4.20901658e-03+0.j]
 [  0.00000000e+00+0.j   0.00000000e+00+0.j   0.00000000e+00+0.j ...,
    0.00000000e+00+0.j   9.79341845e-01+0.j  -1.15453173e-05+0.j]
 [  0.00000000e+00+0.j   0.00000000e+00+0.j   0.00000000e+00+0.j ...,
    0.00000000e+00+0.j   0.00000000e+00+0.j   7.29846714e-01+0.j]]

I would like to get the complete Hamiltonian and overlap not just a part.
How can I get the complete matrix

Thanks

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: Access to Hamiltonian or Density Matrix
« Reply #10 on: August 18, 2011, 04:17 »
The objects H and S do contain the full Hamiltonian/overlap matrices. It's only when numpy prints them, in the default format, to the terminal that it shortens the output, so you don't get 100,000 lines of text output.

Offline davalenciah

  • Heavy QuantumATK user
  • ***
  • Posts: 26
  • Reputation: 0
    • View Profile
Re: Access to Hamiltonian or Density Matrix
« Reply #11 on: August 18, 2011, 04:24 »
thanks

how could I change the default print i numpy to see
all elemnet of matrix H?

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: Access to Hamiltonian or Density Matrix
« Reply #12 on: August 18, 2011, 04:47 »
Hmm, you should keep in mind this is potentially a very large matrix. I'm not sure that printing it to the screen is very helpful. You can either do
Code: python
for i in range(X.shape[0]):
    for j in range(X.shape[1]):
        print X[i,j],
    print
or simpler
Code: python
numpy.set_printoptions(threshold='nan')
print X
However in this case you get the braces [ and ] too. And do pipe the output to a file!

Offline davalenciah

  • Heavy QuantumATK user
  • ***
  • Posts: 26
  • Reputation: 0
    • View Profile
Re: Access to Hamiltonian or Density Matrix
« Reply #13 on: August 20, 2011, 00:01 »
Thanks for all replies  ;)

I was wondering if the units of Hamiltonian elements
are eV, Hartree or another one?

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: Access to Hamiltonian or Density Matrix
« Reply #14 on: August 20, 2011, 00:04 »
All internal quantities in ATK are typically in Hartree and Bohr or combinations thereof.