Appendix: Creating initial density matrices¶

The density matrix used in DFT+U can be initialized by providing a file called n_mmp_mat. However, the format of this file is not very well suited to produce by hand. For this reason there are small utility functions to help with this step in the python masci-tools library. (https://pypi.org/project/masci-tools/)

The module masci_tools.io.io_nmmpmat provides three helper functions:

  • write_nmmpmat: Create a block for orbital l from a complex numpy array of shape 2l+1 x 2l+1
  • write_nmmpmat_from_states: Create a block for orbital l from the occupations of the diagonal elements
  • write_nmmpmat_from_orbitals: Create a block for orbital l from the occupations of the atomic orbitals

This is divided into two steps. The helper functions will create a list of strings in the right format for one block (meaning one orbital and one spin).

These can be stiched together and written out to a file.

Here we create a single block for a d-orbital with only the m=0 and m=+-1 occupied

In [ ]:
from masci_tools.io.io_nmmpmat import write_nmmpmat_from_states
from pprint import pprint

nmmp_lines = write_nmmpmat_from_states(orbital=2, state_occupations=[0,1,1,1,0])

pprint(nmmp_lines)

If we want to create a second block we just make another call to a helper function and extend the previous list with the result from this function

Here we occupy the dyz and dx^2-y^2 orbitals

The order of the orbitals in the list can be found by looking at the help for the write_nmmpmat_from_orbitals function.

In [ ]:
from masci_tools.io.io_nmmpmat import write_nmmpmat_from_orbitals

new_nmmp_lines = write_nmmpmat_from_orbitals(orbital=2, orbital_occupations=[0,1,0,1,0])

nmmp_lines.extend(new_nmmp_lines)
pprint(nmmp_lines)
In [ ]:
write_nmmpmat_from_orbitals?

To write out the produced density matrix we can write out the list one by one

In [ ]:
with open('n_mmp_mat', 'w') as file:
    for line in nmmp_lines:
        file.write(line+'\n')

All helper functions can also take two angles theta and phi to apply a d-wigner rotation matrix to the density matrix

In [ ]:
import numpy as np
rotated_nmmp_lines = write_nmmpmat_from_states(orbital=3, state_occupations=[1,1,1,0,0,0,0], theta=np.pi/2)
pprint(rotated_nmmp_lines)
In [ ]: