Skip to content

Commit 51f84e7

Browse files
Merge pull request #143 from Exabyte-io/feature/SOF-7266-1-round-coordinates
feature/SOF-7266-1-round-coordinates
2 parents 8857e0f + 756af08 commit 51f84e7

File tree

6 files changed

+24
-13
lines changed

6 files changed

+24
-13
lines changed

express/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import warnings
22
import importlib
3+
import numpy as np
34

45
try:
56
from ._version import version as __version__

express/mixins.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import numpy as np
2+
from express import settings
3+
4+
5+
class RoundNumericValuesMixin(object):
6+
def _round(self, array):
7+
return np.round(array, settings.PRECISION).tolist()

express/parsers/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import os
22

3+
from express.mixins import RoundNumericValuesMixin
34

4-
class BaseParser(object):
5+
6+
class BaseParser(RoundNumericValuesMixin):
57
"""
68
Base Parser class.
79
"""

express/parsers/structure.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ def lattice_bravais(self):
7777
"""
7878
return {
7979
"type": self._lattice_type(),
80-
"a": self.structure.lattice.a,
81-
"b": self.structure.lattice.b,
82-
"c": self.structure.lattice.c,
83-
"alpha": self.structure.lattice.alpha,
84-
"beta": self.structure.lattice.beta,
85-
"gamma": self.structure.lattice.gamma,
80+
"a": self._round(self.structure.lattice.a),
81+
"b": self._round(self.structure.lattice.b),
82+
"c": self._round(self.structure.lattice.c),
83+
"alpha": self._round(self.structure.lattice.alpha),
84+
"beta": self._round(self.structure.lattice.beta),
85+
"gamma": self._round(self.structure.lattice.gamma),
8686
"units": {"length": "angstrom", "angle": "degree"},
8787
}
8888

@@ -159,7 +159,9 @@ def basis(self):
159159
return {
160160
"units": "crystal",
161161
"elements": [{"id": i, "value": v.species_string} for i, v in enumerate(self.structure.sites)],
162-
"coordinates": [{"id": i, "value": v.frac_coords.tolist()} for i, v in enumerate(self.structure.sites)],
162+
"coordinates": [
163+
{"id": i, "value": self._round(v.frac_coords.tolist())} for i, v in enumerate(self.structure.sites)
164+
],
163165
}
164166

165167
def space_group_symbol(self):

express/properties/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from mat3ra.esse import ESSE
22
from abc import abstractmethod
33

4+
from express.mixins import RoundNumericValuesMixin
45

5-
class BaseProperty(object):
6+
7+
class BaseProperty(RoundNumericValuesMixin):
68
"""
79
Base Property class.
810
@@ -35,6 +37,7 @@ def serialize_and_validate(self):
3537
dict
3638
"""
3739
instance = self._serialize()
40+
# TODO: consider rounding all numbers at this stage
3841
self.esse.validate(instance, self.schema)
3942
return instance
4043

express/properties/non_scalar/bandgaps.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import numpy as np
22
from typing import Tuple
33
from copy import deepcopy
4-
from express import settings
54
from express.properties.utils import eigenvalues
65
from express.properties.non_scalar import NonScalarProperty
76

@@ -184,6 +183,3 @@ def _eigenvalues(self) -> list:
184183
eigens_at_spin["energies"] = eigens_at_spin["energies"][start:end]
185184
eigens_at_spin["occupations"] = eigens_at_spin["occupations"][start:end]
186185
return eigens_at_kpoints
187-
188-
def _round(self, array):
189-
return np.round(array, settings.PRECISION).tolist()

0 commit comments

Comments
 (0)