Skip to content

Commit

Permalink
update: round materials coordinates, lattice params x 2
Browse files Browse the repository at this point in the history
  • Loading branch information
VsevolodX committed Feb 21, 2024
1 parent 756af08 commit 6bc9b64
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 6bc9b64

Please sign in to comment.