diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e2d4449..3a78ef2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,11 @@ What's new .. currentmodule:: crystals +Release 1.6.1 +------------- + +* Fixed an issue where writing some crystal structures to CIF did not work correctly (#13). + Release 1.6.0 ------------- diff --git a/crystals/__init__.py b/crystals/__init__.py index 9b6410a..8b538ed 100644 --- a/crystals/__init__.py +++ b/crystals/__init__.py @@ -5,7 +5,7 @@ __author__ = "Laurent P. René de Cotret" __email__ = "laurent.renedecotret@mail.mcgill.ca" __license__ = "GPLv3" -__version__ = "1.6.0" +__version__ = "1.6.1" from .atom import Atom from .atom import Element diff --git a/crystals/tests/test_writers.py b/crystals/tests/test_writers.py index 09d803b..345de02 100644 --- a/crystals/tests/test_writers.py +++ b/crystals/tests/test_writers.py @@ -3,11 +3,11 @@ import tempfile from itertools import islice from pathlib import Path -from random import choice, randint - import numpy as np +from tempfile import TemporaryDirectory + import pytest -from crystals import Crystal +from crystals import Crystal, Atom try: import ase @@ -53,6 +53,26 @@ def test_cif_writer_idempotence(name): assert cryst == cryst2 +def test_supercell_preserved_in_cif(): + """See issue #13.""" + a = np.asfarray([3, 0.2, 0]) + b = np.asfarray([0.4, 8, 0]) + c = np.asfarray([0, 0, 9]) + + dimer = Crystal( + unitcell=[Atom("C", coords=(0.5, 0, 0)), Atom("C", coords=(0, 0, 0))], + lattice_vectors=[a * 2, b, c], + ) + with TemporaryDirectory() as tmpdir: + + dimer.to_cif(Path(tmpdir) / "dimer.cif") + from_file = Crystal.from_cif(Path(tmpdir) / "dimer.cif") + + assert set(tuple(atm.coords_fractional) for atm in dimer.unitcell) == set( + tuple(atm.coords_fractional) for atm in from_file.unitcell + ) + + @pytest.mark.parametrize("name", Crystal.builtins) def test_vasp_writer_idempotence(name): """Test that conversion to VASP of a structure loaded from VASP is idempotent."""