Author Topic: Hamiltonian Calculation  (Read 4082 times)

0 Members and 1 Guest are viewing this topic.

Offline Tufan

  • Regular QuantumATK user
  • **
  • Posts: 21
  • Country: in
  • Reputation: 0
    • View Profile
Hamiltonian Calculation
« on: September 28, 2015, 15:15 »


Trying to run the code to extract H and S matrices in QuantumWise 2014.3.
from NanoLanguage import *
import os

bulk_configuration = nlread("phosphorene.nc", BulkConfiguration)[0]

   
# --- BEGIN CODE -----------------------------------------------------
   
def complexMatrixToNumpy(m):
    """
    Function for converting a ComplexMatrix object to a numpy matrix.
    """
    rows = m.numberOfRows()
    columns = m.numberOfColumns()

    result = numpy.zeros((rows,columns), dtype=complex)

    for r in range(rows):
        for c in range(columns):
            result[r,c] = NLEngine.complexp_value(m(r,c))

    return result

def denseHS(bulk_configuration, ka=0.0, kb=0.0, kc=0.0, spin=Spin.Up):
    """
    For given bulk_configuration (which must have been calculated)
    returns the dense Hamiltonian and overlap matrices for a given K-point
    (given in fractional coordinates) and spin
    """
    import NLEngine
    # Get the density matrix.
    dmc = bulk_configuration.calculator()._densityMatrixCalculator()

    # Get the k-point.
    K = NLEngine.Cartesian3D(ka,kb,kc)

    # Neighbour list.
    nb = dmc.neighbourlist()

    # Phases.
    phases = nb.calculatePhases(K)

    # Get the hamiltonian.
    H = dmc.hamiltonian()
    S = dmc.overlap()

    # Perform the FFT.
    denseH = complexMatrixToNumpy(NLEngine.fourierTransform(H.getSparseCSR(spin._backengine()), phases))
    denseS = complexMatrixToNumpy(NLEngine.fourierTransform(S.getSparseCSR(spin._backengine()), phases))

    # Return the dense folded Hamiltonian and overlap.
    return denseH, denseS

# --- END CODE -------------------------------------------------------
   
# And here is how you use it
H,S = denseHS(bulk_configuration, ka=0., kb=0.0, kc=0.0, spin=Spin.Up)
numpy.set_printoptions(threshold=numpy.nan)
print H
print S



I am getting the following error:
Traceback (most recent call last):
  File "c:\users\arnab\appdata\local\temp\5603809391882558.py", line 61, in <module>
    H,S = denseHS(bulk_configuration, ka=0., kb=0.0, kc=0.0, spin=Spin.Up)
  File "c:\users\arnab\appdata\local\temp\5603809391882558.py", line 39, in denseHS
    K = NLEngine.Cartesian3D(ka,kb,kc)
AttributeError: 'module' object has no attribute 'Cartesian3D'

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5573
  • Country: dk
  • Reputation: 95
    • View Profile
    • QuantumATK at Synopsys
Re: Hamiltonian Calculation
« Reply #1 on: September 28, 2015, 15:46 »
In 2014, use Cartesian3DDouble instead

Offline kstokbro

  • Supreme QuantumATK Wizard
  • *****
  • Posts: 392
  • Reputation: 13
    • View Profile
    • QuantumWise
Re: Hamiltonian Calculation
« Reply #2 on: September 28, 2015, 22:46 »
In ATK-2014 there are build in functions for getting H and S, this is much simpler:
 see the tutorial
http://www.quantumwise.com/documents/tutorials/latest/LowLevelEntities/index.html/