Skip to content

Commit

Permalink
FIX: cycling iterables
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentRDC committed Nov 6, 2018
1 parent 5fc8da5 commit dde2d30
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
22 changes: 10 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ crystals
:alt: Supported Python versions
:target: https://pypi.python.org/pypi/crystals

`crystals` is a library of data structure and algorithms to manipulate abstract crystals. `crystals` helps with reading crystallographic
``crystals`` is a library of data structure and algorithms to manipulate abstract crystals. ``crystals`` helps with reading crystallographic
files (like .cif and .pdb), provides access to atomic positions, and allows for space-group determination. Take a look at the `documentation <https://crystals.readthedocs.io/>`_
for more information.

Installation
============

`crystals` can be installed from source::
``crystals`` can be installed from source::

git clone https://github.com/LaurentRDC/crystals.git
cd crystals
python setup.py install

You can install the latest development version using `pip` as well::
You can install the latest development version using ``pip`` as well::

python -m pip install git+git://github.com/LaurentRDC/crystals.git

`crystals` is also available on the Python Package Index::
``crystals`` is also available on the Python Package Index::

pip install crystals

Expand All @@ -50,18 +50,17 @@ Citations
If you find this software useful, please consider citing the following publication:

.. [#] L. P. René de Cotret, M. R. Otto, M. J. Stern. and B. J. Siwick, *An open-source software ecosystem for the interactive
exploration of ultrafast electron scattering data*, Advanced Structural and Chemical Imaging 4:11 (2018) DOI: 10.1186/s40679-018-0060-y
exploration of ultrafast electron scattering data*, Advanced Structural and Chemical Imaging **4**:11 (2018) DOI: 10.1186/s40679-018-0060-y
Support / Report Issues
-----------------------

All support requests and issue reports should be
`filed on Github as an issue <https://github.com/LaurentRDC/crystals/issues>`_.
All support requests and issue reports should be `filed on Github as an issue <https://github.com/LaurentRDC/crystals/issues>`_.

License
-------

`crystals` is made available under the BSD 3-clause license. For more details, see `LICENSE.txt <https://github.com/LaurentRDC/crystals/blob/master/LICENSE.txt>`_.
``crystals`` is made available under the BSD 3-clause license. For more details, see `LICENSE.txt <https://github.com/LaurentRDC/crystals/blob/master/LICENSE.txt>`_.

Development
===========
Expand All @@ -75,9 +74,8 @@ Some optional tests might be skipped if dependencies are not installed, e.g. `AS
Related projects
----------------

Streaming operations on NumPy arrays are available in the `npstreams package <https://pypi.org/pypi/npstreams>`_.
- Streaming operations on NumPy arrays are available in the `npstreams package <https://pypi.org/pypi/npstreams>`_.

Interactive exploration of ultrafast electron diffraction data with the `iris-ued package <https://pypi.org/project/iris-ued/>`_.
- Interactive exploration of ultrafast electron diffraction data with the `iris-ued package <https://pypi.org/project/iris-ued/>`_.

A graphical user interface for the dual-tree complex wavelet transform baseline-removal routine is available as a
`separate package <https://pypi.org/pypi/dtgui>`_.
- Data structures and algorithms to handle ultrafast electron scattering data in the `scikit-ued package <https://pypi.org/project/scikit-ued>`_.
2 changes: 1 addition & 1 deletion crystals/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
__author__ = 'Laurent P. René de Cotret'
__email__ = 'laurent.renedecotret@mail.mcgill.ca'
__license__ = 'MIT'
__version__ = '0.0.1'
__version__ = '0.0.2'

from .atom import Atom, real_coords, frac_coords
from .atom_data import ELEM_TO_MAGMOM, ELEM_TO_MASS, ELEM_TO_NAME, ELEM_TO_NUM, NUM_TO_ELEM
Expand Down
16 changes: 13 additions & 3 deletions crystals/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
import numpy as np
from numpy.linalg import norm

from npstreams import cyclic

from .affine import change_basis_mesh, transform
from .base import Base


class LatticeSystem(Enum):
"""
Lattice system enumeration.
Expand Down Expand Up @@ -360,3 +357,16 @@ def _two_equal(iterable, atol):
if sum(isclose(i, l, abs_tol = atol) for l in iterable) == 2:
return True
return False

def cyclic(iterable):
"""
Yields cyclic permutations of an iterable.
Examples
--------
>>> list(cyclic((1,2,3)))
[(1,2,3), (2,3,1), (3,1,2)]
"""
iterable = tuple(iterable)
n = len(iterable)
yield from (tuple(iterable[i - j] for i in range(n)) for j in range(n))

0 comments on commit dde2d30

Please sign in to comment.