Skip to content

Commit

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

update: round materials coordinates, lattice params
  • Loading branch information
timurbazhirov authored Feb 21, 2024
2 parents 51f84e7 + 6bc9b64 commit dde6feb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 3 additions & 2 deletions express/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@


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

def _round(self, array, decimal_places=settings.PRECISION):
return np.round(array, decimal_places).tolist()
17 changes: 13 additions & 4 deletions express/parsers/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
"conventional": lambda s: mg.symmetry.analyzer.SpacegroupAnalyzer(s).get_conventional_standard_structure(),
}

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


class StructureParser(BaseParser, IonicDataMixin):
"""
Expand Down Expand Up @@ -61,9 +69,9 @@ def lattice_vectors(self):
"""
return {
"vectors": {
"a": self.structure.lattice.matrix.tolist()[0],
"b": self.structure.lattice.matrix.tolist()[1],
"c": self.structure.lattice.matrix.tolist()[2],
"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]),
"alat": 1.0,
}
}
Expand Down Expand Up @@ -160,7 +168,8 @@ def basis(self):
"units": "crystal",
"elements": [{"id": i, "value": v.species_string} 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)
{"id": i, "value": self._round(v.frac_coords.tolist(), PRECISION_MAP["coordinates_crystal"])}
for i, v in enumerate(self.structure.sites)
],
}

Expand Down

0 comments on commit dde6feb

Please sign in to comment.