Skip to content

Commit

Permalink
Merge pull request #145 from Exabyte-io/feature/SOF-7266-1-round-coor…
Browse files Browse the repository at this point in the history
…dinates-update-precision-x2

feature/SOF-7266-1-round-coordinates-update-precision-x2
  • Loading branch information
timurbazhirov authored Feb 21, 2024
2 parents dde6feb + 964003c commit 10a3759
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
28 changes: 15 additions & 13 deletions express/parsers/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@

PRECISION_MAP = {
# decimal places
"coordinates_crystal": 6,
## Default values are used for the below
# "coordinates_crystal": 4,
# "angles": 4,
"coordinates_crystal": 9,
"coordinates_cartesian": 6,
"angles": 4,
}


Expand Down Expand Up @@ -67,11 +66,12 @@ def lattice_vectors(self):
Reference:
func: express.parsers.mixins.ionic.IonicDataMixin.lattice_vectors
"""
precision = PRECISION_MAP["coordinates_cartesian"]
return {
"vectors": {
"a": self._round(self.structure.lattice.matrix.tolist()[0]),
"b": self._round(self.structure.lattice.matrix.tolist()[1]),
"c": self._round(self.structure.lattice.matrix.tolist()[2]),
"a": self._round(self.structure.lattice.matrix.tolist()[0], precision),
"b": self._round(self.structure.lattice.matrix.tolist()[1], precision),
"c": self._round(self.structure.lattice.matrix.tolist()[2], precision),
"alat": 1.0,
}
}
Expand All @@ -83,14 +83,16 @@ def lattice_bravais(self):
Reference:
func: express.parsers.mixins.ionic.IonicDataMixin.lattice_bravais
"""
precision_coordinates = PRECISION_MAP["coordinates_cartesian"]
precision_angles = PRECISION_MAP["angles"]
return {
"type": self._lattice_type(),
"a": self._round(self.structure.lattice.a),
"b": self._round(self.structure.lattice.b),
"c": self._round(self.structure.lattice.c),
"alpha": self._round(self.structure.lattice.alpha),
"beta": self._round(self.structure.lattice.beta),
"gamma": self._round(self.structure.lattice.gamma),
"a": self._round(self.structure.lattice.a, precision_coordinates),
"b": self._round(self.structure.lattice.b, precision_coordinates),
"c": self._round(self.structure.lattice.c, precision_coordinates),
"alpha": self._round(self.structure.lattice.alpha, precision_angles),
"beta": self._round(self.structure.lattice.beta, precision_angles),
"gamma": self._round(self.structure.lattice.gamma, precision_angles),
"units": {"length": "angstrom", "angle": "degree"},
}

Expand Down
19 changes: 14 additions & 5 deletions express/properties/non_scalar/bandgaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
from express.properties.utils import eigenvalues
from express.properties.non_scalar import NonScalarProperty

PRECISION_MAP = {
# decimal places
"ibz_kpts": 4,
"eigenvalues": 4,
}


class BandGaps(NonScalarProperty):
"""
Expand Down Expand Up @@ -96,11 +102,13 @@ def compute_on_mesh(
# value for shifting back eigenvalues (see also _get_bands_info)
e_fermi = self.fermi_energy if absolute_eigenvalues else 0

precision = PRECISION_MAP["ibz_kpts"]

if k_val is not None and k_cond is not None:
result.update(
{
"kpointValence": self._round(self.ibz_k_points[k_val]),
"kpointConduction": self._round(self.ibz_k_points[k_cond]),
"kpointValence": self._round(self.ibz_k_points[k_val], precision),
"kpointConduction": self._round(self.ibz_k_points[k_cond], precision),
"eigenvalueValence": ev_k[k_val] + e_fermi,
"eigenvalueConduction": ec_k[k_cond] + e_fermi,
}
Expand Down Expand Up @@ -169,12 +177,13 @@ def _eigenvalues(self) -> list:
Returns:
dict
"""
precision = PRECISION_MAP["eigenvalues"]
eigens_at_kpoints = deepcopy(self.eigenvalues_at_kpoints)
for eigens_at_kpoint in eigens_at_kpoints:
eigens_at_kpoint["kpoint"] = self._round(eigens_at_kpoint["kpoint"])
eigens_at_kpoint["kpoint"] = self._round(eigens_at_kpoint["kpoint"], precision)
for eigens_at_spin in eigens_at_kpoint["eigenvalues"]:
eigens_at_spin["energies"] = self._round(eigens_at_spin["energies"])
eigens_at_spin["occupations"] = self._round(eigens_at_spin["occupations"])
eigens_at_spin["energies"] = self._round(eigens_at_spin["energies"], precision)
eigens_at_spin["occupations"] = self._round(eigens_at_spin["occupations"], precision)
# occupations are empty in case of QE GW, hence sending all values.
if len(eigens_at_spin["occupations"]) == 0:
continue
Expand Down
19 changes: 6 additions & 13 deletions express/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,10 @@
"average_potential_profile": {
"reference": "express.properties.non_scalar.two_dimensional_plot.average_potential_profile.AveragePotentialProfile" # noqa: E501
},
"dielectric_tensor": {
"reference": "express.properties.non_scalar.dielectric_tensor.DielectricTensor"
},
"hubbard_u": {
"reference": "express.properties.non_scalar.hubbard_u.HubbardU"
},
"hubbard_v": {
"reference": "express.properties.non_scalar.hubbard_v.HubbardV"
},
"hubbard_v_nn": {
"reference": "express.properties.non_scalar.hubbard_v_nn.HubbardV_NN"
}
"dielectric_tensor": {"reference": "express.properties.non_scalar.dielectric_tensor.DielectricTensor"},
"hubbard_u": {"reference": "express.properties.non_scalar.hubbard_u.HubbardU"},
"hubbard_v": {"reference": "express.properties.non_scalar.hubbard_v.HubbardV"},
"hubbard_v_nn": {"reference": "express.properties.non_scalar.hubbard_v_nn.HubbardV_NN"},
}

CONVERGENCE_PROPERTIES = {
Expand All @@ -81,4 +73,5 @@
"exabyteml": "express.parsers.exabyteml.ExabyteMLParser",
}

PRECISION = 4
# Used to round to zero by default
PRECISION = 9

0 comments on commit 10a3759

Please sign in to comment.