QuantumATK Forum

QuantumATK => General Questions and Answers => Topic started by: Tufan on September 28, 2015, 15:15

Title: Hamiltonian Calculation
Post by: Tufan 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'
Title: Re: Hamiltonian Calculation
Post by: Anders Blom on September 28, 2015, 15:46
In 2014, use Cartesian3DDouble instead
Title: Re: Hamiltonian Calculation
Post by: kstokbro 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/