Commit 44083b0e authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Improved DOS tests.

parent 0f0549d0
Pipeline #77901 failed with stages
in 23 minutes and 20 seconds
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
##### Physical settings ################
xc pbe
RI_method LVL_fast
charge 0.0
spin none
# spin collinear
# default_initial_moment 1
# default_initial_moment hund
relativistic atomic_zora scalar
many_body_dispersion
# vdw_correction_hirshfeld
# mbd_eigensolver lapack
KS_method scalapack
basis_threshold 1.e-5
empty_states 8
##### SCF settings ################
sc_accuracy_forces 1E-4
sc_accuracy_rho 1E-5
sc_accuracy_eev 1E-3
sc_accuracy_etot 1E-6
sc_iter_limit 600
mixer pulay
n_max_pulay 6
charge_mix_param 0.08
occupation_type gaussian 0.01
# k-point grid
k_grid 10 10 10
##### Relaxation###################
# partition_type rho_r2
# relax_geometry bfgs 0.01
# relax_unit_cell full
# relax_unit_cell fixed_angles
##### Output options #############
# output mulliken
# output dipole
# DOS
dos_kgrid_factors 8 8 8
output dos -20 20 10000 0.1
output atom_proj_dos -20 10000 160 0.1
output species_proj_dos -20 20 10000 0.1
# note 0.02 in the DOS parameters is Gaussian broadening.
# output band structure
output band 0.5 0.5 0.5 0.0 0.0 0.0 50 L Gamma
output band 0.0 0.0 0.0 0.0 0.5 0.5 50 Gamma X
output band 0.0 0.5 0.5 0.25 0.5 0.75 50 X W
output band 0.25 0.5 0.75 0.375 0.375 0.75 50 W K
################################################################################
#
# FHI-aims code project
# VB, Fritz-Haber Institut, 2009
#
# Suggested "light" defaults for Si atom (to be pasted into control.in file)
# Be sure to double-check any results obtained with these settings for post-processing,
# e.g., with the "tight" defaults and larger basis sets.
#
################################################################################
species Si
# global species definitions
nucleus 14
mass 28.0855
#
l_hartree 6
#
cut_pot 4.0 2.0 1.0
basis_dep_cutoff 1e-4
#
radial_base 42 7.0
radial_multiplier 2
angular_grids specified
division 0.4121 50
division 0.7665 110
division 1.0603 194
division 1.2846 302
division 1.4125 434
# division 1.4810 590
# division 1.5529 770
# division 1.6284 974
# division 2.6016 1202
# outer_grid 974
outer_grid 434
################################################################################
#
# Definition of "minimal" basis
#
################################################################################
# valence basis states
valence 3 s 2.
valence 3 p 2.
# ion occupancy
ion_occ 3 s 1.
ion_occ 3 p 1.
################################################################################
#
# Suggested additional basis functions. For production calculations,
# uncomment them one after another (the most important basis functions are
# listed first).
#
# Constructed for dimers: 1.75 A, 2.0 A, 2.25 A, 2.75 A, 3.75 A
#
################################################################################
# "First tier" - improvements: -571.96 meV to -37.03 meV
hydro 3 d 4.2
hydro 2 p 1.4
hydro 4 f 6.2
ionic 3 s auto
# "Second tier" - improvements: -16.76 meV to -3.03 meV
hydro 3 d 9
hydro 5 g 9.4
# hydro 4 p 4
# hydro 1 s 0.65
# "Third tier" - improvements: -3.89 meV to -0.60 meV
# ionic 3 d auto
# hydro 3 s 2.6
# hydro 4 f 8.4
# hydro 3 d 3.4
# hydro 3 p 7.8
# "Fourth tier" - improvements: -0.33 meV to -0.11 meV
# hydro 2 p 1.6
# hydro 5 g 10.8
# hydro 5 f 11.2
# hydro 3 d 1
# hydro 4 s 4.5
# Further basis functions that fell out of the optimization - noise
# level... < -0.08 meV
# hydro 4 d 6.6
# hydro 5 g 16.4
# hydro 4 d 9
################################################################################
#
# For methods that use the localized form of the "resolution of identity" for
# the two-electron Coulomb operator (RI_method LVL), particularly Hartree-Fock and
# hybrid density functional calculations, the highest accuracy can be obtained by
# uncommenting the line beginning with "for_aux" below, thus adding an extra g radial
# function to the construction of the product basis set for the expansion.
# See Ref. New J. Phys. 17, 093020 (2015) for more information, particularly Figs. 1 and 6.
#
################################################################################
#
# for_aux hydro 5 g 6.0
# Diamond structure with lattice constant 5.431 AA.
lattice_vector 0.0000 2.7155 2.7155
lattice_vector 2.7155 0.0000 2.7155
lattice_vector 2.7155 2.7155 0.0000
atom_frac 0.0 0.0 0.0 Si
atom_frac 0.25 0.25 0.25 Si
......@@ -193,6 +193,33 @@ def bands_polarized_gap_indirect() -> Backend:
return backend
@pytest.fixture(scope='session')
def dos_si_vasp() -> Backend:
parser_name = "parsers/vasp"
filepath = "tests/data/normalizers/dos/dos_si_vasp/vasprun.xml.relax2.xz"
backend = parse_file((parser_name, filepath))
backend = run_normalize(backend)
return backend
@pytest.fixture(scope='session')
def dos_si_exciting() -> Backend:
parser_name = "parsers/exciting"
filepath = "tests/data/normalizers/dos/dos_si_exciting/INFO.OUT"
backend = parse_file((parser_name, filepath))
backend = run_normalize(backend)
return backend
@pytest.fixture(scope='session')
def dos_si_fhiaims() -> Backend:
parser_name = "parsers/fhi-aims"
filepath = "tests/data/normalizers/dos/dos_si_fhiaims/aims.log"
backend = parse_file((parser_name, filepath))
backend = run_normalize(backend)
return backend
@pytest.fixture(scope='session')
def dos_polarized_vasp() -> Backend:
parser_name = "parsers/vasp"
......
......@@ -13,39 +13,75 @@
# limitations under the License.
import numpy as np
# import matplotlib.pyplot as mpl
from tests.test_parsing import parse_file
from tests.normalizing.conftest import run_normalize
from nomad.parsing.legacy import Backend
from tests.normalizing.conftest import ( # pylint: disable=unused-import
dos_si_fhiaims,
dos_si_exciting,
dos_si_vasp,
)
from nomad_dos_fingerprints import DOSFingerprint, tanimoto_similarity
# from nomad_dos_fingerprints import DOSFingerprint, tanimoto_similarity
vasp_parser_dos = (
'parsers/vasp', 'tests/data/parsers/vasp/vasp_dos.xml')
# def test_fingerprint(dos_unpolarized_vasp):
# # Check if DOS fingerprint was created
# backend_dos_fingerprint = dos_unpolarized_vasp['section_dos_fingerprint'][0]
# dos_fingerprint = DOSFingerprint().from_dict(dict(
# bins=backend_dos_fingerprint.bins,
# indices=backend_dos_fingerprint.indices,
# grid_id=backend_dos_fingerprint.grid_id,
# stepsize=backend_dos_fingerprint.stepsize,
# filling_factor=backend_dos_fingerprint.filling_factor))
# assert tanimoto_similarity(dos_fingerprint, dos_fingerprint) == 1
# def test_dos_normalizer():
# """
# Ensure the DOS normalizer acted on the DOS values. We take a VASP example.
# """
# backend = parse_file(vasp_parser_dos)
# backend = run_normalize(backend)
# def plot_dos_energies(dos_si_vasp: Backend, dos_si_exciting: Backend, dos_si_fhiaims: Backend):
# """For debugging.
# """
# x_exciting = dos_si_exciting.get_value('dos_energies_normalized', 0)
# y_exciting = dos_si_exciting.get_value('dos_values_normalized', 0)
# x_vasp = dos_si_vasp.get_value('dos_energies_normalized', 0)
# y_vasp = dos_si_vasp.get_value('dos_values_normalized', 0)
# x_fhiaims = dos_si_fhiaims.get_value('dos_energies_normalized', 0)
# y_fhiaims = dos_si_fhiaims.get_value('dos_values_normalized', 0)
# mpl.plot(x_vasp, y_vasp[0], label="VAP")
# mpl.plot(x_exciting, y_exciting[0], label="exciting")
# mpl.plot(x_fhiaims, y_fhiaims[0], label="FHI-aims")
# mpl.legend()
# mpl.show()
# # Check if 'dos_values' were indeed normalized
# # 'dvn' stands for 'dos_values_normalized'
# backend_dvn = backend.get_value('dos_values_normalized', 0)
# last_value = backend_dvn[0, -1]
# expected = 1.7362195274239454e+47
# # Compare floats properly with numpy (delta tolerance involved)
# assert np.allclose(last_value, expected)
# # Check if DOS fingerprint was created
# backend_dos_fingerprint = backend['section_dos_fingerprint'][0]
# dos_fingerprint = DOSFingerprint().from_dict(dict(
# bins=backend_dos_fingerprint.bins,
# indices=backend_dos_fingerprint.indices,
# grid_id=backend_dos_fingerprint.grid_id,
# stepsize=backend_dos_fingerprint.stepsize,
# filling_factor=backend_dos_fingerprint.filling_factor))
def test_dos_magnitude(dos_si_vasp: Backend, dos_si_exciting: Backend, dos_si_fhiaims: Backend):
"""
Ensure the DOS normalizer acted on the DOS values. The order of magnitude
for normalized DOS values in VASP, exciting and FHIAims are currently
tested.
"""
dos_vasp = dos_si_vasp.get_value('dos_values_normalized', 0)
dos_exciting = dos_si_exciting.get_value('dos_values_normalized', 0)
dos_fhiaims = dos_si_fhiaims.get_value('dos_values_normalized', 0)
# assert tanimoto_similarity(dos_fingerprint, dos_fingerprint) == 1
dos_vasp_mean = mean_nonzero(dos_vasp)
dos_exciting_mean = mean_nonzero(dos_exciting)
dos_fhiaims_mean = mean_nonzero(dos_fhiaims)
assert is_same_magnitude(dos_vasp_mean, dos_exciting_mean, dos_fhiaims_mean)
def mean_nonzero(dos: np.array):
"""Returns the mean value of all nonzero elements in the given array.
"""
return dos[np.nonzero(dos)].mean()
def is_same_magnitude(*args):
"""Used to test that all given floating point numbers are of the expected
order of magnitude.
"""
correct_magnitude = 1e18
tolerance = 10
values = np.array(args)
values_normalized = values / correct_magnitude
return ((values_normalized <= tolerance) & (values_normalized >= 1 / tolerance)).all()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment