diff --git a/express/mixins.py b/express/mixins.py index 0ce3d92a..ac6360db 100644 --- a/express/mixins.py +++ b/express/mixins.py @@ -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() diff --git a/express/parsers/structure.py b/express/parsers/structure.py index 97a36743..f3848ef7 100644 --- a/express/parsers/structure.py +++ b/express/parsers/structure.py @@ -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): """ @@ -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, } } @@ -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) ], }