I have cooked up a little code snippet that should get the job done for all your needs.
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:
H, S = extractHamiltonianAndOverlap(bulk_configuration, kx=0.0, ky=0.5, kz=0.2)
print H
print S
I hope it helps your forward.
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
for i in range(X.shape[0]):
for j in range(X.shape[1]):
print X[i,j],
print
or simpler
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!