Skip to content

Commit

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

feature/SOF-7266-1-round-coordinates
  • Loading branch information
timurbazhirov committed Feb 21, 2024
2 parents 8857e0f + 756af08 commit 51f84e7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions express/__init__.py
@@ -1,5 +1,6 @@
import warnings
import importlib
import numpy as np

try:
from ._version import version as __version__
Expand Down
7 changes: 7 additions & 0 deletions express/mixins.py
@@ -0,0 +1,7 @@
import numpy as np
from express import settings


class RoundNumericValuesMixin(object):
def _round(self, array):
return np.round(array, settings.PRECISION).tolist()
4 changes: 3 additions & 1 deletion express/parsers/__init__.py
@@ -1,7 +1,9 @@
import os

from express.mixins import RoundNumericValuesMixin

class BaseParser(object):

class BaseParser(RoundNumericValuesMixin):
"""
Base Parser class.
"""
Expand Down
16 changes: 9 additions & 7 deletions express/parsers/structure.py
Expand Up @@ -77,12 +77,12 @@ def lattice_bravais(self):
"""
return {
"type": self._lattice_type(),
"a": self.structure.lattice.a,
"b": self.structure.lattice.b,
"c": self.structure.lattice.c,
"alpha": self.structure.lattice.alpha,
"beta": self.structure.lattice.beta,
"gamma": self.structure.lattice.gamma,
"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),
"units": {"length": "angstrom", "angle": "degree"},
}

Expand Down Expand Up @@ -159,7 +159,9 @@ def basis(self):
return {
"units": "crystal",
"elements": [{"id": i, "value": v.species_string} for i, v in enumerate(self.structure.sites)],
"coordinates": [{"id": i, "value": v.frac_coords.tolist()} for i, v in enumerate(self.structure.sites)],
"coordinates": [
{"id": i, "value": self._round(v.frac_coords.tolist())} for i, v in enumerate(self.structure.sites)
],
}

def space_group_symbol(self):
Expand Down
5 changes: 4 additions & 1 deletion express/properties/__init__.py
@@ -1,8 +1,10 @@
from mat3ra.esse import ESSE
from abc import abstractmethod

from express.mixins import RoundNumericValuesMixin

class BaseProperty(object):

class BaseProperty(RoundNumericValuesMixin):
"""
Base Property class.
Expand Down Expand Up @@ -35,6 +37,7 @@ def serialize_and_validate(self):
dict
"""
instance = self._serialize()
# TODO: consider rounding all numbers at this stage
self.esse.validate(instance, self.schema)
return instance

Expand Down
4 changes: 0 additions & 4 deletions express/properties/non_scalar/bandgaps.py
@@ -1,7 +1,6 @@
import numpy as np
from typing import Tuple
from copy import deepcopy
from express import settings
from express.properties.utils import eigenvalues
from express.properties.non_scalar import NonScalarProperty

Expand Down Expand Up @@ -184,6 +183,3 @@ def _eigenvalues(self) -> list:
eigens_at_spin["energies"] = eigens_at_spin["energies"][start:end]
eigens_at_spin["occupations"] = eigens_at_spin["occupations"][start:end]
return eigens_at_kpoints

def _round(self, array):
return np.round(array, settings.PRECISION).tolist()

0 comments on commit 51f84e7

Please sign in to comment.