Skip to content

Commit

Permalink
Replace functions returning constants in common_functions with their …
Browse files Browse the repository at this point in the history
…respective constants in util.constants

This results in very slight differences for the Ry to eV conversion in the 7th decimal place
  • Loading branch information
janssenhenning committed Feb 16, 2021
1 parent cf7984a commit c171563
Show file tree
Hide file tree
Showing 19 changed files with 113 additions and 124 deletions.
12 changes: 0 additions & 12 deletions masci_tools/io/common_functions.py
Expand Up @@ -61,18 +61,6 @@ def get_alat_from_bravais(bravais, is3D=True):
return np.sqrt(np.sum(bravais_tmp**2, axis=1)).max()


def get_Ang2aBohr():
return 1.8897261254578281


def get_aBohr2Ang():
return 1 / get_Ang2aBohr()


def get_Ry2eV():
return 13.605693009


def search_string(searchkey, txt):
iline = 0
for line in txt:
Expand Down
4 changes: 2 additions & 2 deletions masci_tools/io/kkr_params.py
Expand Up @@ -1503,7 +1503,7 @@ def read_keywords_from_inputcard(self, inputcard='inputcard'):
:note: converts '<RBLEFT>', '<RBRIGHT>', 'ZPERIODL', and 'ZPERIODR' automatically to Ang. units!
"""
from numpy import shape, array
from masci_tools.io.common_functions import get_aBohr2Ang
from masci_tools.util.constants import BOHR_A

# some print statements with debug info
debug = False
Expand Down Expand Up @@ -1700,7 +1700,7 @@ def read_keywords_from_inputcard(self, inputcard='inputcard'):
rbr = self.get_value('<RBRIGHT>')
zper_l = self.get_value('ZPERIODL')
zper_r = self.get_value('ZPERIODR')
alat2ang = self.get_value('ALATBASIS') * get_aBohr2Ang()
alat2ang = self.get_value('ALATBASIS') * BOHR_A
if rbl is not None:
self.set_value('<RBLEFT>', array(rbl) * alat2ang)
if rbr is not None:
Expand Down
10 changes: 5 additions & 5 deletions masci_tools/io/parsers/kkrimp_parser_functions.py
Expand Up @@ -14,9 +14,10 @@
Tools for the impurity caluclation plugin and its workflows
"""
from numpy import array, ndarray, loadtxt
from masci_tools.io.common_functions import search_string, open_general, get_version_info, get_Ry2eV, convert_to_pystd
from masci_tools.io.common_functions import search_string, open_general, get_version_info, convert_to_pystd
from masci_tools.io.parsers.kkrparser_functions import get_rms, find_warnings, get_charges_per_atom, get_core_states
import traceback
from masci_tools.util.constants import HTR_TO_EV

__copyright__ = (u'Copyright (c), 2018, Forschungszentrum Jülich GmbH,' 'IAS-1/PGI-1, Germany. All rights reserved.')
__license__ = 'MIT license, see LICENSE.txt file'
Expand Down Expand Up @@ -357,7 +358,6 @@ def parse_kkrimp_outputfile(self, out_dict, file_dict, debug=False):
"""

Ry2eV = get_Ry2eV()
msg_list = []
files = file_dict

Expand Down Expand Up @@ -470,7 +470,7 @@ def parse_kkrimp_outputfile(self, out_dict, file_dict, debug=False):

try:
result = self._get_Etot(files['out_log'])
out_dict['energy'] = result[-1] * Ry2eV
out_dict['energy'] = result[-1] * HTR_TO_EV/2.0
out_dict['energy_unit'] = 'eV'
out_dict['total_energy_Ry'] = result[-1]
out_dict['total_energy_Ry_unit'] = 'Rydberg'
Expand Down Expand Up @@ -505,9 +505,9 @@ def parse_kkrimp_outputfile(self, out_dict, file_dict, debug=False):

try:
esp_at, etot_at = self._get_energies_atom(files['out_enersp_at'], files['out_enertot_at'], natom)
out_dict['single_particle_energies'] = esp_at * Ry2eV
out_dict['single_particle_energies'] = esp_at * HTR_TO_EV/2.0
out_dict['single_particle_energies_unit'] = 'eV'
out_dict['total_energies_atom'] = etot_at * Ry2eV
out_dict['total_energies_atom'] = etot_at * HTR_TO_EV/2.0
out_dict['total_energies_atom_unit'] = 'eV'
except:
msg = 'Error parsing output of KKRimp: single particle energies'
Expand Down
8 changes: 4 additions & 4 deletions masci_tools/io/parsers/kkrparser_functions.py
Expand Up @@ -16,9 +16,10 @@
parser file where parse_kkr_outputfile is called
"""
from numpy import ndarray, array, loadtxt, shape
from masci_tools.io.common_functions import (search_string, get_version_info, get_Ry2eV, angles_to_vec,
from masci_tools.io.common_functions import (search_string, get_version_info, angles_to_vec,
get_corestates_from_potential, get_highest_core_state, open_general,
convert_to_pystd)
from masci_tools.util.constants import HTR_TO_EV
import traceback

__copyright__ = (u'Copyright (c), 2017, Forschungszentrum Jülich GmbH,' 'IAS-1/PGI-1, Germany. All rights reserved.')
Expand Down Expand Up @@ -545,7 +546,6 @@ def parse_kkr_outputfile(out_dict,
Parser method for the kkr outfile. It returns a dictionary with results
"""
# scaling factors etc. defined globally
Ry2eV = get_Ry2eV()
doscalc = False

# collection of parsing error messages
Expand Down Expand Up @@ -840,7 +840,7 @@ def parse_kkr_outputfile(out_dict,

try:
result = get_Etot(outfile)
out_dict['energy'] = result[-1] * Ry2eV
out_dict['energy'] = result[-1] * HTR_TO_EV/2.0
out_dict['energy_unit'] = 'eV'
out_dict['total_energy_Ry'] = result[-1]
out_dict['total_energy_Ry_unit'] = 'Rydberg'
Expand All @@ -853,7 +853,7 @@ def parse_kkr_outputfile(out_dict,

try:
result = get_single_particle_energies(outfile_000)
out_dict['single_particle_energies'] = result * Ry2eV
out_dict['single_particle_energies'] = result * HTR_TO_EV/2.0
out_dict['single_particle_energies_unit'] = 'eV'
except:
if not doscalc:
Expand Down
5 changes: 3 additions & 2 deletions masci_tools/io/parsers/voroparser_functions.py
Expand Up @@ -14,9 +14,10 @@
Everything that is needed to parse the output of a voronoi calculation.
"""
from masci_tools.io.common_functions import (get_corestates_from_potential, get_highest_core_state, search_string,
get_version_info, get_Ry2eV, get_ef_from_potfile, open_general,
get_version_info, get_ef_from_potfile, open_general,
convert_to_pystd)
from masci_tools.io.parsers.kkrparser_functions import get_core_states
from masci_tools.util.constants import HTR_TO_EV
import numpy as np
import io
import sys
Expand Down Expand Up @@ -92,7 +93,7 @@ def parse_voronoi_output(out_dict, outfile, potfile, atominfo, radii, inputfile,
out_dict['emin_units'] = 'Ry'
diff_emin_ef = emin - get_ef_from_potfile(potfile)
out_dict['emin_minus_efermi_Ry'] = diff_emin_ef
out_dict['emin_minus_efermi'] = diff_emin_ef * get_Ry2eV()
out_dict['emin_minus_efermi'] = diff_emin_ef * HTR_TO_EV/2.0
out_dict['emin_minus_efermi_Ry_units'] = 'Ry'
out_dict['emin_minus_efermi_units'] = 'eV'
except:
Expand Down
54 changes: 27 additions & 27 deletions masci_tools/tests/test_kkrimp_tools/test_parse_outfiles_full.yml
Expand Up @@ -126,7 +126,7 @@ core_states_group:
- 5
- 5
- 5
energy: -585774.7465183247
energy: -585774.7514261826
energy_contour_group:
emin: -0.5
emin_unit: Rydberg
Expand Down Expand Up @@ -315,19 +315,19 @@ magnetism_group:
nspin: 1
number_of_atoms_in_unit_cell: 13
single_particle_energies:
- -444.3596464334259
- -444.35964643713214
- -444.35964643713214
- -444.35964643713214
- -444.35964643713214
- -444.35964643713214
- -444.35964643713214
- -444.35964643713214
- -444.35964643713214
- -444.35964643713214
- -444.35964643713214
- -444.35964643713214
- -444.35964643713214
- -444.3596501564508
- -444.359650160157
- -444.359650160157
- -444.359650160157
- -444.359650160157
- -444.359650160157
- -444.359650160157
- -444.359650160157
- -444.359650160157
- -444.359650160157
- -444.359650160157
- -444.359650160157
- -444.359650160157
single_particle_energies_unit: eV
timings_group:
Iteration number: 7.97079992294312
Expand All @@ -354,19 +354,19 @@ total_charge_per_atom:
- 28.999993
total_charge_per_atom_unit: electron charge
total_energies_atom:
- -350719.5210815695
- -350719.52108157217
- -350719.52108157217
- -350719.52108157217
- -350719.52108157217
- -350719.52108157217
- -350719.52108157217
- -350719.52108157217
- -350719.52108157217
- -350719.52108157217
- -350719.52108157217
- -350719.52108157217
- -350719.52108157217
- -350719.5240200395
- -350719.5240200422
- -350719.5240200422
- -350719.5240200422
- -350719.5240200422
- -350719.5240200422
- -350719.5240200422
- -350719.5240200422
- -350719.5240200422
- -350719.5240200422
- -350719.5240200422
- -350719.5240200422
- -350719.5240200422
total_energies_atom_unit: eV
total_energy_Ry: -43053.65012505
total_energy_Ry_unit: Rydberg
Expand Down
Expand Up @@ -126,7 +126,7 @@ core_states_group:
- 5
- 5
- 5
energy: -585774.7465183247
energy: -585774.7514261826
energy_contour_group:
emin: -0.5
emin_unit: Rydberg
Expand Down Expand Up @@ -315,19 +315,19 @@ magnetism_group:
nspin: 1
number_of_atoms_in_unit_cell: 13
single_particle_energies:
- -444.3596464334259
- -444.35964643713214
- -444.35964643713214
- -444.35964643713214
- -444.35964643713214
- -444.35964643713214
- -444.35964643713214
- -444.35964643713214
- -444.35964643713214
- -444.35964643713214
- -444.35964643713214
- -444.35964643713214
- -444.35964643713214
- -444.3596501564508
- -444.359650160157
- -444.359650160157
- -444.359650160157
- -444.359650160157
- -444.359650160157
- -444.359650160157
- -444.359650160157
- -444.359650160157
- -444.359650160157
- -444.359650160157
- -444.359650160157
- -444.359650160157
single_particle_energies_unit: eV
timings_group:
Iteration number: 7.97079992294312
Expand All @@ -354,19 +354,19 @@ total_charge_per_atom:
- 28.999993
total_charge_per_atom_unit: electron charge
total_energies_atom:
- -350719.5210815695
- -350719.52108157217
- -350719.52108157217
- -350719.52108157217
- -350719.52108157217
- -350719.52108157217
- -350719.52108157217
- -350719.52108157217
- -350719.52108157217
- -350719.52108157217
- -350719.52108157217
- -350719.52108157217
- -350719.52108157217
- -350719.5240200395
- -350719.5240200422
- -350719.5240200422
- -350719.5240200422
- -350719.5240200422
- -350719.5240200422
- -350719.5240200422
- -350719.5240200422
- -350719.5240200422
- -350719.5240200422
- -350719.5240200422
- -350719.5240200422
- -350719.5240200422
total_energies_atom_unit: eV
total_energy_Ry: -43053.65012505
total_energy_Ry_unit: Rydberg
Expand Down
4 changes: 2 additions & 2 deletions masci_tools/tests/test_kkrparams.py
Expand Up @@ -485,7 +485,7 @@ def test_read_unsorted_inputfile(self):

def test_read_slab(self):
from numpy import array
from masci_tools.io.common_functions import get_Ang2aBohr
from masci_tools.util.constants import BOHR_A
p = kkrparams(params_type='kkr')

# automatically read keywords from inpucard
Expand All @@ -495,7 +495,7 @@ def test_read_slab(self):
rbr = p.get_value('<RBRIGHT>')
zper_l = p.get_value('ZPERIODL')
zper_r = p.get_value('ZPERIODR')
ang2alat = get_Ang2aBohr() / p.get_value('ALATBASIS')
ang2alat = 1 / (p.get_value('ALATBASIS')*BOHR_A)
if rbl is not None:
p.set_value('<RBLEFT>', array(rbl) * ang2alat)
if rbr is not None:
Expand Down
Expand Up @@ -298,7 +298,7 @@ direct_bravais_matrix:
- 0.707107
direct_bravais_matrix_unit: alat
dos_at_fermi_energy: 15.032559
energy: -69143.0041551653
energy: -69143.00473447336
energy_contour_group:
emin: -0.6
emin_unit: Rydberg
Expand Down Expand Up @@ -454,12 +454,12 @@ reciprocal_bravais_matrix:
- 1.414214
reciprocal_bravais_matrix_unit: 2*pi / alat
single_particle_energies:
- 0.3301642569173711
- 1.5169676617833023
- 38.200748406400834
- 38.200748406400834
- 1.5169676617833023
- 0.3301642569173711
- 0.33016425968362084
- 1.5169676744930711
- 38.20074872646216
- 38.20074872646216
- 1.5169676744930711
- 0.33016425968362084
single_particle_energies_unit: eV
symmetries_group:
number_of_lattice_symmetries: 4
Expand Down
Expand Up @@ -298,7 +298,7 @@ direct_bravais_matrix:
- 0.707107
direct_bravais_matrix_unit: alat
dos_at_fermi_energy: 15.032559
energy: -69143.0041551653
energy: -69143.00473447336
energy_contour_group:
emin: -0.6
emin_unit: Rydberg
Expand Down Expand Up @@ -454,12 +454,12 @@ reciprocal_bravais_matrix:
- 1.414214
reciprocal_bravais_matrix_unit: 2*pi / alat
single_particle_energies:
- 0.3301642569173711
- 1.5169676617833023
- 38.200748406400834
- 38.200748406400834
- 1.5169676617833023
- 0.3301642569173711
- 0.33016425968362084
- 1.5169676744930711
- 38.20074872646216
- 38.20074872646216
- 1.5169676744930711
- 0.33016425968362084
single_particle_energies_unit: eV
symmetries_group:
number_of_lattice_symmetries: 4
Expand Down
Expand Up @@ -298,7 +298,7 @@ direct_bravais_matrix:
- 0.707107
direct_bravais_matrix_unit: alat
dos_at_fermi_energy: 9.013371
energy: -69143.56589518131
energy: -69143.56647449407
energy_contour_group:
emin: -0.6
emin_unit: Rydberg
Expand Down Expand Up @@ -454,12 +454,12 @@ reciprocal_bravais_matrix:
- 1.414214
reciprocal_bravais_matrix_unit: 2*pi / alat
single_particle_energies:
- 0.2097247970611916
- 1.2887334935546728
- 37.826589199624905
- 37.826589199624905
- 1.2887334935546728
- 0.2097247970611916
- 0.2097247988183508
- 1.2887335043522035
- 37.82658951655137
- 37.82658951655137
- 1.2887335043522035
- 0.2097247988183508
single_particle_energies_unit: eV
symmetries_group:
number_of_lattice_symmetries: 4
Expand Down

0 comments on commit c171563

Please sign in to comment.