-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
193 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from __future__ import annotations | ||
|
||
from math import sqrt | ||
|
||
import moyopy | ||
|
||
if __name__ == "__main__": | ||
# https://next-gen.materialsproject.org/materials/mp-560588 | ||
a = 3.81 | ||
c = 6.24 | ||
basis = [ | ||
[a, 0.0, 0.0], | ||
[-a / 2.0, a * sqrt(3.0) / 2.0, 0.0], | ||
[0.0, 0.0, c], | ||
] | ||
z1_2b = 0.00014 | ||
z2_2b = 0.37486 | ||
positions = [ | ||
# 2b | ||
[1 / 3, 2 / 3, z1_2b], | ||
[2 / 3, 1 / 3, z1_2b + 0.5], | ||
# 2b | ||
[1 / 3, 2 / 3, z2_2b], | ||
[2 / 3, 1 / 3, z2_2b + 0.5], | ||
] | ||
numbers = [0, 0, 1, 1] | ||
cell = moyopy.Cell(basis, positions, numbers) | ||
|
||
dataset = moyopy.MoyoDataset(cell, symprec=1e-5, angle_tolerance=None, setting=None) | ||
assert dataset.number == 186 | ||
assert dataset.hall_number == 480 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
from __future__ import annotations | ||
|
||
import numpy as np | ||
from pymatgen.core import Element, Structure | ||
|
||
import moyopy | ||
|
||
|
||
class MoyoAdapter: | ||
@staticmethod | ||
def get_structure(cell: moyopy.Cell) -> Structure: | ||
species = [Element.from_Z(number) for number in cell.numbers] | ||
return Structure(lattice=cell.basis, species=species, coords=cell.positions) | ||
|
||
@staticmethod | ||
def get_moyo_cell(structure: Structure) -> moyopy.Cell: | ||
basis = structure.lattice.matrix | ||
positions = structure.frac_coords | ||
numbers = [site.specie.Z for site in structure] | ||
|
||
return moyopy.Cell( | ||
basis=basis.tolist(), | ||
positions=positions.tolist(), | ||
numbers=numbers, | ||
) | ||
|
||
|
||
class MoyoSpacegroupAnalyzer: | ||
def __init__( | ||
self, | ||
structure: Structure, | ||
symprec: float = 1e-5, | ||
angle_tolerance: float | None = None, | ||
setting: moyopy.Setting | None = None, | ||
): | ||
self._cell = MoyoAdapter.get_moyo_cell(structure) | ||
self._dataset = moyopy.MoyoDataset( | ||
cell=self._cell, | ||
symprec=symprec, | ||
angle_tolerance=angle_tolerance, | ||
setting=setting, | ||
) | ||
|
||
@property | ||
def number(self) -> int: | ||
return self._dataset.number | ||
|
||
@property | ||
def hall_number(self) -> int: | ||
return self._dataset.hall_number | ||
|
||
@property | ||
def rotations(self) -> np.ndarray: | ||
return np.array(self._dataset.operations.rotations) | ||
|
||
@property | ||
def translations(self) -> np.ndarray: | ||
return np.array(self._dataset.operations.translations) | ||
|
||
@property | ||
def orbits(self) -> list[int]: | ||
return self._dataset.orbits | ||
|
||
@property | ||
def wyckoffs(self) -> list[str]: | ||
return self._dataset.wyckoffs | ||
|
||
@property | ||
def site_symmetry_symbols(self) -> list[str]: | ||
return self._dataset.site_symmetry_symbols | ||
|
||
@property | ||
def std_structure(self) -> Structure: | ||
return MoyoAdapter.get_structure(self._dataset.std_cell) | ||
|
||
@property | ||
def std_linear(self) -> np.ndarray: | ||
return np.array(self._dataset.std_linear) | ||
|
||
@property | ||
def std_origin_shift(self) -> np.ndarray: | ||
return np.array(self._dataset.std_origin_shift) | ||
|
||
@property | ||
def std_rotation_matrix(self) -> np.ndarray: | ||
return np.array(self._dataset.std_rotation_matrix) | ||
|
||
@property | ||
def prim_std_structure(self) -> Structure: | ||
return MoyoAdapter.get_structure(self._dataset.prim_std_cell) | ||
|
||
@property | ||
def prim_std_linear(self) -> np.ndarray: | ||
return np.array(self._dataset.prim_std_linear) | ||
|
||
@property | ||
def prim_std_origin_shift(self) -> np.ndarray: | ||
return np.array(self._dataset.prim_std_origin_shift) | ||
|
||
@property | ||
def mapping_std_prim(self) -> list[int]: | ||
return self._dataset.mapping_std_prim | ||
|
||
@property | ||
def symprec(self) -> float: | ||
return self._dataset.symprec | ||
|
||
@property | ||
def angle_tolerance(self) -> float | None: | ||
return self._dataset.angle_tolerance | ||
|
||
|
||
if __name__ == "__main__": | ||
a = 4.0 | ||
structure = Structure( | ||
lattice=np.eye(3) * a, | ||
species=["Al"] * 4, | ||
coords=np.array( | ||
[ | ||
[0.0, 0.0, 0.0], | ||
[0.0, 0.5, 0.5], | ||
[0.5, 0.0, 0.5], | ||
[0.5, 0.5, 0.0], | ||
] | ||
), | ||
) | ||
msa = MoyoSpacegroupAnalyzer(structure) | ||
assert msa.number == 225 | ||
assert msa.rotations.shape == (48 * 4, 3, 3) | ||
assert msa.orbits == [0, 0, 0, 0] | ||
assert msa.prim_std_structure.num_sites == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pymatgen |