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'