DanPorter / Dans_Diffraction

Reads crystallographic cif files and simulates diffraction
Apache License 2.0
56 stars 13 forks source link

Incorrect Atom configuration for Hf4+ #20

Closed DanPorter closed 1 month ago

DanPorter commented 2 months ago

In the FDMNES gui, generating the input file for a compound such as HfO2, where Hf has a charge of Hf4+, the automatic atomic configuration is wrong, leading to FDMNES not running:

 Atom ! s=0,p=1,d=2,f=3, must be neutral, get d states right by moving e to 2s and 2p sites
 72 3  4 3 12.00  6 0 2.00  6 1 4.00 ! Hf4+ 4f12 6s2 6p4
  8 0 ! O 

FDMNES error:

 By default the code does not accept non-neutral molecule or unit-cell,
 because often it is a mistake in the use of "Atom" or "Atom_conf" keywords.

 If it is not a mistake, what is possible specially when working with molecule,
 use the keyword: "Chfree".
 The code will not stop anymore.

 Remark: avoid electronic configuration coresponding to the formal charges.
 They are usually "too much", specially for the s and p orbitals.
FDMNES Finished!

The correct atomic configuration for Hf4+ in the FDMNES input file should be:

 Atom ! s=0,p=1,d=2,f=3, must be neutral, get d states right by moving e to 2s and 2p sites
 72 3  5 2 0.00  6 0 0.00  6 1 4.00 ! Hf4+ 4f12 6s2 6p4
  8 0 ! O 
DanPorter commented 1 month ago

Notes on finding the problem

The fdmnes runfile is generated here: https://github.com/DanPorter/Dans_Diffraction/blob/02100e5d6d549fecdc8e1c7456782e8af83ed74f/Dans_Diffraction/classes_properties.py#L800-L805

The atomic configuration string is generated here: https://github.com/DanPorter/Dans_Diffraction/blob/02100e5d6d549fecdc8e1c7456782e8af83ed74f/Dans_Diffraction/classes_orbitals.py#L488-L499

The correct orbital configuration is generated for the charge here: https://github.com/DanPorter/Dans_Diffraction/blob/02100e5d6d549fecdc8e1c7456782e8af83ed74f/Dans_Diffraction/functions_crystallography.py#L1694-L1710

So, the error must be in the Atom fdmnes string generation: https://github.com/DanPorter/Dans_Diffraction/blob/02100e5d6d549fecdc8e1c7456782e8af83ed74f/Dans_Diffraction/classes_orbitals.py#L398-L407

DanPorter commented 1 month ago

The fix was to add the missing orbitals by comparing the orbital lists of the charged and neutral atoms: https://github.com/DanPorter/Dans_Diffraction/blob/d6d2cac958d43d2a11bd3a810f8b94e41bd28d33/Dans_Diffraction/classes_orbitals.py#L298-L326

The generated string for FDMNES then automatically spots the empty orbitals and removes electrons correcty:

from Dans_Diffraction.classes_orbitals import Atom
atom = Atom('Hf', 4)
print(atom)
# Atom:  72       Hf4+  1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p6 4d10 4f12 5s2 5p6 5d0 6s2
print(atom.generate_string_fdmnes())
# 72 4  4 3 12.00  5 2 0.00  6 0 2.00  6 1 4.00 ! Hf4+ 4f12 5d0 6s2 6p4