Coverage for icet/core/orbit.py: 87%
68 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-12-26 04:12 +0000
« prev ^ index » next coverage.py v7.5.0, created at 2024-12-26 04:12 +0000
1"""
2This module provides the Orbit class.
3"""
5from _icet import Orbit
6from numpy.typing import NDArray
7__all__ = ['Orbit']
10def __str__(self) -> str:
11 """ String representation. """
12 s = f'Order: {self.order}\n'
13 s += f'Multiplicity: {len(self)}\n'
14 s += f'Radius: {self.radius:.4f}\n'
16 # Representative cluster
17 s += 'Representative cluster:\n'
18 for site, off, pos in zip(self.sites, self.site_offsets, self.positions):
19 offset = ''.join([f'{x:3}' for x in off])
20 position = ''.join([f' {x:6.2f}' for x in pos])
21 s += f'\tSite: {site},\tOffset: {offset},\tPosition:{position}\n'
23 return s
26def __repr__(self) -> str:
27 """ Representation. """
28 s = type(self).__name__ + '('
29 s += f'order={self.order}'
30 s += f', multiplicity={len(self)}'
31 s += f', radius={self.radius:.4f}'
32 s += f', sites={self.sites}'
33 s += ')'
34 return s
37def _repr_html_(self) -> str:
38 """ HTML representation. Used, e.g., in jupyter notebooks. """
39 s = ['<h4>Orbit</h4>']
40 s += ['<table border="1" class="dataframe">']
41 s += ['<thead><tr><th style="text-align: left;">Field</th><th>Value</th></tr></thead>']
42 s += ['<tbody>']
43 s += [f'<tr><td style="text-align: left;">Order</td><td>{self.order}</td></tr>']
44 s += [f'<tr><td style="text-align: left;">Multiplicity</td><td>{len(self)}</td></tr>']
45 s += [f'<tr><td style="text-align: left;">Radius</td><td>{self.radius:.4f}</td></tr>']
46 s += [f'<tr><td style="text-align: left;">Sites</td><td>{self.sites}</td></tr>']
47 s += ['</tbody>']
48 s += ['</table>']
49 return ''.join(s)
52@property
53def distances(self) -> list[float]:
54 """ Distances between all sites in the representative cluster. """
55 return self.representative_cluster.distances
58@property
59def sites(self) -> list[int]:
60 """ The indices of all sites in the representative cluster."""
61 return [site.index for site in self.representative_cluster.lattice_sites]
64@property
65def site_offsets(self) -> list[NDArray[int]]:
66 """ Unit cell offsets of all sites in the representative cluster. """
67 return [site.unitcell_offset.astype(int)
68 for site in self.representative_cluster.lattice_sites]
71@property
72def positions(self) -> list[NDArray[float]]:
73 """ Positions of all sites in the representative cluster. """
74 return self.representative_cluster.positions
77@property
78def all_distances(self) -> list[list[float]]:
79 """ Distances between all sites in all clusters. """
80 return [cluster.distances for cluster in self.clusters]
83@property
84def all_sites(self) -> list[list[int]]:
85 """ The site indices of all sites in all clusters."""
86 return [[site.index for site in cluster.lattice_sites]
87 for cluster in self.clusters]
90@property
91def all_site_offsets(self) -> list[list[NDArray[int]]]:
92 """ Unit cell offsets of all sites in all clusters. """
93 return [[site.unitcell_offset.astype(int) for site in cluster.lattice_sites]
94 for cluster in self.clusters]
97@property
98def all_positions(self) -> list[list[NDArray[float]]]:
99 """ Positions of all sites in all clusters. """
100 return [cluster.positions for cluster in self.clusters]
103Orbit.__str__ = __str__
104Orbit.__repr__ = __repr__
105Orbit._repr_html_ = _repr_html_
107Orbit.distances = distances
108Orbit.sites = sites
109Orbit.site_offsets = site_offsets
110Orbit.positions = positions
112Orbit.all_distances = all_distances
113Orbit.all_sites = all_sites
114Orbit.all_site_offsets = all_site_offsets
115Orbit.all_positions = all_positions