Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-janssen committed Sep 6, 2023
2 parents 3dfd157 + d971f02 commit beb9de5
Show file tree
Hide file tree
Showing 7 changed files with 444 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .ci_support/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ dependencies:
- scipy =1.11.2
- spglib =2.0.2
- sqsgenerator =0.2
- pyxtal =0.5.9
- pyxtal =0.6.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"symmetry": ['spglib==2.0.2'],
"surface": ['spglib==2.0.2', 'pymatgen==2023.8.10'],
"phonopy": ['phonopy==2.20.0', 'spglib==2.0.2'],
"pyxtal": ['pyxtal==0.5.9']
"pyxtal": ['pyxtal==0.6.0']
},
cmdclass=versioneer.get_cmdclass(),
)
211 changes: 207 additions & 4 deletions structuretoolkit/analyse/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import numpy as np

from structuretoolkit.analyse.distance import find_mic, get_distances_array
from structuretoolkit.analyse.neighbors import get_neighborhood, get_neighbors
from structuretoolkit.analyse.phonopy import get_equivalent_atoms
Expand Down Expand Up @@ -26,22 +28,223 @@ def get_symmetry(
structure, use_magmoms=False, use_elements=True, symprec=1e-5, angle_tolerance=-1.0
):
"""
Args:
structure (ase.atoms.Atoms): Atomistic Structure object
use_magmoms (bool): Whether to consider magnetic moments (cf. get_initial_magnetic_moments())
structure (Atoms): The structure to analyse.
use_magmoms (bool): Whether to consider magnetic moments (cf.
get_initial_magnetic_moments())
use_elements (bool): If False, chemical elements will be ignored
symprec (float): Symmetry search precision
angle_tolerance (float): Angle search tolerance
Returns:
symmetry (:class:`structuretoolkit.analyse.symmetry.Symmetry`): Symmetry class
"""
from structuretoolkit.analyse.symmetry import Symmetry

return Symmetry(
structure=structure,
use_magmoms=use_magmoms,
use_elements=use_elements,
symprec=symprec,
angle_tolerance=angle_tolerance,
)


def symmetrize_vectors(
structure,
vectors,
use_magmoms=False,
use_elements=True,
symprec=1e-5,
angle_tolerance=-1.0,
):
"""
Symmetrization of natom x 3 vectors according to box symmetries
Args:
structure (Atoms): The structure to analyse.
vectors (ndarray/list): natom x 3 array to symmetrize
use_magmoms (bool): Whether to consider magnetic moments (cf.
get_initial_magnetic_moments())
use_elements (bool): If False, chemical elements will be ignored
symprec (float): Symmetry search precision
angle_tolerance (float): Angle search tolerance
Returns:
(np.ndarray) symmetrized vectors
"""
from structuretoolkit.analyse.symmetry import Symmetry

return Symmetry(
structure=structure,
use_magmoms=use_magmoms,
use_elements=use_elements,
symprec=symprec,
angle_tolerance=angle_tolerance,
).symmetrize_vectors(vectors=vectors)


def group_points_by_symmetry(
structure,
points,
use_magmoms=False,
use_elements=True,
symprec=1e-5,
angle_tolerance=-1.0,
):
"""
This function classifies the points into groups according to the box symmetry given by
spglib.
Args:
structure (Atoms): The structure to analyse.
points: (np.array/list) nx3 array which contains positions
use_magmoms (bool): Whether to consider magnetic moments (cf.
get_initial_magnetic_moments())
use_elements (bool): If False, chemical elements will be ignored
symprec (float): Symmetry search precision
angle_tolerance (float): Angle search tolerance
Returns: list of arrays containing geometrically equivalent positions
It is possible that the original points are not found in the returned list, as the
positions outsie the box will be projected back to the box.
"""
from structuretoolkit.analyse.symmetry import Symmetry

return Symmetry(
structure=structure,
use_magmoms=use_magmoms,
use_elements=use_elements,
symprec=symprec,
angle_tolerance=angle_tolerance,
).get_arg_equivalent_sites(points)


def get_equivalent_points(
structure,
points,
use_magmoms=False,
use_elements=True,
symprec=1e-5,
angle_tolerance=-1.0,
):
"""
Args:
structure (Atoms): The structure to analyse.
points (list/ndarray): 3d vector
use_magmoms (bool): Whether to consider magnetic moments (cf.
get_initial_magnetic_moments())
use_elements (bool): If False, chemical elements will be ignored
symprec (float): Symmetry search precision
angle_tolerance (float): Angle search tolerance
Returns:
(ndarray): array of equivalent points with respect to box symmetries
"""
from structuretoolkit.analyse.symmetry import get_symmetry
from structuretoolkit.analyse.symmetry import Symmetry

return get_symmetry(
return Symmetry(
structure=structure,
use_magmoms=use_magmoms,
use_elements=use_elements,
symprec=symprec,
angle_tolerance=angle_tolerance,
).get_arg_equivalent_sites(points)


def get_symmetry_dataset(structure, symprec=1e-5, angle_tolerance=-1.0):
"""
Args:
structure (Atoms): The structure to analyse.
symprec (float): Symmetry search precision
angle_tolerance (float): Angle search tolerance
Returns:
https://atztogo.github.io/spglib/python-spglib.html
"""
from structuretoolkit.analyse.symmetry import Symmetry

return Symmetry(
structure=structure,
symprec=symprec,
angle_tolerance=angle_tolerance,
).info


def get_spacegroup(structure, symprec=1e-5, angle_tolerance=-1.0):
"""
Args:
structure (Atoms): The structure to analyse.
symprec (float): Symmetry search precision
angle_tolerance (float): Angle search tolerance
Returns:
https://atztogo.github.io/spglib/python-spglib.html
"""
from structuretoolkit.analyse.symmetry import Symmetry

return Symmetry(
structure=structure,
symprec=symprec,
angle_tolerance=angle_tolerance,
).spacegroup


def get_primitive_cell(structure, symprec=1e-5, angle_tolerance=-1.0):
"""
Args:
structure (Atoms): The structure to analyse.
symprec (float): Symmetry search precision
angle_tolerance (float): Angle search tolerance
Returns:
"""
from structuretoolkit.analyse.symmetry import Symmetry

return Symmetry(
structure=structure,
symprec=symprec,
angle_tolerance=angle_tolerance,
).get_primitive_cell(standardize=False)


def get_ir_reciprocal_mesh(
structure,
mesh,
is_shift=np.zeros(3, dtype="intc"),
is_time_reversal=True,
symprec=1e-5,
):
"""
Args:
structure (Atoms): The structure to analyse.
mesh:
is_shift:
is_time_reversal:
symprec (float): Symmetry search precision
Returns:
"""
from structuretoolkit.analyse.symmetry import Symmetry

return Symmetry(
structure=structure,
symprec=symprec,
).get_ir_reciprocal_mesh(
mesh=mesh,
is_shift=is_shift,
is_time_reversal=is_time_reversal,
)
26 changes: 0 additions & 26 deletions structuretoolkit/analyse/symmetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,29 +383,3 @@ def get_ir_reciprocal_mesh(
if mesh is None:
raise SymmetryError(spglib.spglib.spglib_error.message)
return mesh


def get_symmetry(
structure, use_magmoms=False, use_elements=True, symprec=1e-5, angle_tolerance=-1.0
):
"""
Args:
use_magmoms (bool): Whether to consider magnetic moments (cf.
get_initial_magnetic_moments())
use_elements (bool): If False, chemical elements will be ignored
symprec (float): Symmetry search precision
angle_tolerance (float): Angle search tolerance
Returns:
symmetry (:class:`structuretoolkit.analyse.symmetry.Symmetry`): Symmetry class
"""
return Symmetry(
structure=structure,
use_magmoms=use_magmoms,
use_elements=use_elements,
symprec=symprec,
angle_tolerance=angle_tolerance,
)
1 change: 1 addition & 0 deletions structuretoolkit/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
pymatgen_to_ase,
)
from structuretoolkit.common.pyscal import ase_to_pyscal
from structuretoolkit.common.phonopy import phonopy_to_atoms, atoms_to_phonopy
36 changes: 36 additions & 0 deletions structuretoolkit/common/phonopy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
def phonopy_to_atoms(ph_atoms):
"""
Convert Phonopy Atoms to ASE-like Atoms
Args:
ph_atoms: Phonopy Atoms object
Returns: ASE-like Atoms object
"""
from ase.atoms import Atoms

return Atoms(
symbols=list(ph_atoms.get_chemical_symbols()),
positions=list(ph_atoms.get_positions()),
cell=list(ph_atoms.get_cell()),
pbc=True,
)


def atoms_to_phonopy(atom):
"""
Convert ASE-like Atoms to Phonopy Atoms
Args:
atom: ASE-like Atoms
Returns:
Phonopy Atoms
"""
from phonopy.structure.atoms import PhonopyAtoms

return PhonopyAtoms(
symbols=list(atom.get_chemical_symbols()),
scaled_positions=list(atom.get_scaled_positions()),
cell=list(atom.get_cell()),
)
Loading

0 comments on commit beb9de5

Please sign in to comment.