Skip to content

Commit

Permalink
Merge pull request #591 from timcallow/ldos_default_units
Browse files Browse the repository at this point in the history
Change default units when reading from cube files
  • Loading branch information
RandomDefaultUser authored Oct 25, 2024
2 parents 7f52d06 + 063c01d commit 7c95e6b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 11 additions & 2 deletions mala/targets/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def from_numpy_array(cls, params, array, units="1/A^3"):
return return_dos

@classmethod
def from_cube_file(cls, params, path, units="1/A^3"):
def from_cube_file(cls, params, path, units="1/Bohr^3"):
"""
Create a Density calculator from a cube file.
Expand Down Expand Up @@ -391,7 +391,7 @@ def backconvert_units(array, out_units):
else:
raise Exception("Unsupported unit for density.")

def read_from_cube(self, path, units="1/A^3", **kwargs):
def read_from_cube(self, path, units="1/Bohr^3", **kwargs):
"""
Read the density data from a cube file.
Expand All @@ -404,6 +404,15 @@ def read_from_cube(self, path, units="1/A^3", **kwargs):
Units the density is saved in. Usually none.
"""
printout("Reading density from .cube file ", path, min_verbosity=0)
# automatically convert units if they are None since cube files take atomic units
if units is None:
units="1/Bohr^3"
if units != "1/Bohr^3":
printout(
"The expected units for the density from cube files are 1/Bohr^3\n"
f"Proceeding with specified units of {units}\n"
"We recommend to check and change the requested units"
)
data, meta = read_cube(path)
data *= self.convert_units(1, in_units=units)
self.density = data
Expand Down
13 changes: 11 additions & 2 deletions mala/targets/ldos.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def from_numpy_array(cls, params, array, units="1/(eV*A^3)"):

@classmethod
def from_cube_file(
cls, params, path_name_scheme, units="1/(eV*A^3)", use_memmap=None
cls, params, path_name_scheme, units="1/(Ry*Bohr^3)", use_memmap=None
):
"""
Create an LDOS calculator from multiple cube files.
Expand Down Expand Up @@ -463,7 +463,7 @@ def backconvert_units(array, out_units):
raise Exception("Unsupported unit for LDOS.")

def read_from_cube(
self, path_scheme, units="1/(eV*A^3)", use_memmap=None, **kwargs
self, path_scheme, units="1/(Ry*Bohr^3)", use_memmap=None, **kwargs
):
"""
Read the LDOS data from multiple cube files.
Expand Down Expand Up @@ -495,6 +495,15 @@ def read_from_cube(
# tmp.pp003ELEMENT_ldos.cube
# ...
# tmp.pp100ELEMENT_ldos.cube
# automatically convert units if they are None since cube files take atomic units
if units is None:
units = "1/(Ry*Bohr^3)"
if units != "1/(Ry*Bohr^3)":
printout(
"The expected units for the LDOS from cube files are 1/(Ry*Bohr^3)\n"
f"Proceeding with specified units of {units}\n"
"We recommend to check and change the requested units"
)
return self._read_from_qe_files(
path_scheme, units, use_memmap, ".cube", **kwargs
)
Expand Down

0 comments on commit 7c95e6b

Please sign in to comment.