The FleurXMLModifier class can be used if you want to change anything in a inp.xml file in an easy and robust way. It will validate all the changes you wish to do and apply all these changes to a given inp.xml and produce a new XML tree.


To modify an existing inp.xml, a FleurXMLModifier instance has to be initialised. After that, a user should register certain modifications which will be cached. They will be applied on a given inp.xml. However, the provided inp.xml will not be changed but only a modified XML tree is returned, which you can store in a new .xml file.

from masci_tools.io.fleurxmlmodifier import  FleurXMLModifier

fm = FleurXMLModifier()                                      # Initialise FleurXMLModifier class
fm.set_inpchanges({'dos' : True, 'Kmax': 3.9 })              # Add changes
new_xmltree, _ = fm.modify_xmlfile('/path/to/original/inp.xml') #Apply 

User Methods

General methods

Modification registration methods

The registration methods can be separated into two groups. First of all, there are XML methods that require deeper knowledge about the structure of an inp.xml file. All of them require an xpath input and start their method names start with xml_:

On the other hand, there are shortcut methods that already know some paths:

Modifying the density matrix for LDA+U calculations

The above mentioned FleurXMLModifier.set_nmmpmat(), FleurXMLModifier.rotate_nmmpmat() and FleurXMLModifier.align_nmmpmat_to_sqa() take a special role in the modification registration methods, as the modifications are not done on the inp.xml file but the density matrix file n_mmp_mat used by Fleur for LDA+U calculations. The resulting new n_mmp_mat file is returned next to the new inp.xml by the FleurXMLModifier.modify_xmlfile().

The code example below shows how to use this method to add a LDA+U procedure to an atom species and provide an initial guess for the density matrix.

from masci_tools.io.fleurxmlmodifier import FleurXMLModifier

fm = FleurXMLModifier()
# Add LDA+U procedure
fm.set_species('Nd-1', {'ldaU':{'l': 3, 'U': 6.76, 'J': 0.76, 'l_amf': 'F'}})
# Initialize n_mmp_mat file with the states m = -3 to m = 0 occupied for spin up
# spin down is initialized with 0 by default, since no n_mmp_mat file is provided
fm.set_nmmpmat('Nd-1', orbital=3, spin=1, state_occupations=[1,1,1,1,0,0,0])
new_xmltree, add_files = fm.modify_xmlfile('/path/to/original/inp.xml')


The n_mmp_mat file is a simple text file with no knowledge of which density matrix block corresponds to which LDA+U procedure. They are read in the same order as they appear in the inp.xml. For this reason the n_mmp_mat file can become invalid if one adds/removes a LDA+U procedure to the inp.xml after the n_mmp_mat file was initialized. Therefore any modifications to the n_mmp_mat file should be done after adding/removing or modifying the LDA+U configuration.