pychemia.crystal package¶
Module with classes for pure periodic systems (Crystals) There are three main classes on this module: KPoints for describing a grid, list or path of points in reciprocal space. Lattice for storing a manipulating cell vectors and computing the reciprocal lattice. CrystalSymmetry for computing spacegroups, finding primitives and refining cells.
Subpackages¶
Submodules¶
pychemia.crystal.kpoints module¶
-
class
pychemia.crystal.kpoints.
KPoints
(kmode='gamma', kpoints_list=None, weights=None, shifts=None, grid=None, kvertices=None, intermediates=None)[source]¶ Bases:
pychemia.utils.serializer.PyChemiaJsonable
Defines an object that contains information about kpoints mesh There are two mutually exclusive options:
Explicit array of kpoints with associated weights OR a specification of a grid with an optional set of shifts.
The default is one single kpoint in gamma
-
add_kpt
(kpoint, weight=1)[source]¶ Add one extra kpoint to the kpoints_list in the case of kmode ‘cartesian’ or ‘reduced’
Parameters: - kpoint – (list, numpy.array) The kpoint to be added
- weight – (int, float) the weight associated to that point
-
static
max_kpoints
(structure, kpoints_per_atom=1000)[source]¶ Returns the maximal grid of kpoints allowed during the kpoints convergence test. Based on the routine used in pymatgen.
Parameters: - structure – (pychemia.Structure) The structure to compute the maximal grid
- kpoints_per_atom – (int) number of kpoints per atom
Returns:
-
nkpt
¶ Number of kpoints For a grid the value is the product of the number of kpoints on each direction.
-
number_of_kpoints
¶
-
classmethod
optimized_grid
(lattice, kp_density=100000.0, nkpoints=None, force_odd=False)[source]¶ - Returns a KPoints object with kmode=’gamma’ with a grid optimized for a given
- density or number of kpoints. If force_odd is True the grid will be such that there are odd numbers on each direction such that ‘gamma’ is always included on the grid.
Parameters: - lattice – (pychemia.Lattice) A PyChemia Lattice object, if the argument is a pychemia.Structure object, its lattice will be used instead.
- kp_density – (float) A density of kpoints (default: 1E5)
- nkpoints – (int) Aproximate number of kpoints to use, if this argument is present the kp_density will be ignored
- force_odd – (bool) If True, force the grid to be odd for the three directions.
-
set_grid
(grid, shifts=None)[source]¶ Set a grid of kpoints with a proper check of correct arguments
Parameters: - grid – Number of kpoints on each direction (Only for ‘gamma’ and ‘monkhorst-pack’)
- shifts – Shift applied to the grid (Only for ‘gamma’ and ‘monkhorst-pack’)
-
set_kpoints_list
(kpoints_list, weights=None)[source]¶ Set an explicit list of kpoints with a proper check of correct arguments
Parameters: - kpoints_list – Explicit list of k-points (Only for ‘cartesian’ and ‘reduced’)
- weights – List of weights associated to each k-point (Only for ‘cartesian’ and ‘reduced’)
-
to_dict
¶
-
pychemia.crystal.lattice module¶
-
class
pychemia.crystal.lattice.
Lattice
(cell=None, periodicity=True)[source]¶ Bases:
object
Routines to create and manipulate the lattice The lattice is sufficiently general to account for periodicity in 1, 2 or 3 directions. However many routines are only implemented for 3 directions The lattice contains 1, 2 or 3 vectors
-
a
¶
-
alpha
¶
-
angles
¶
-
b
¶
-
beta
¶
-
c
¶
-
cell
¶ Return the cell as a numpy array
Returns:
-
distances_in_sphere
(x1, x2, radius, option='reduced', exclude_out_sphere=True, sort_by_distance=True)[source]¶ Returns all the distances between two positions x1 and x2 taking into account the periodicity of the cell
Parameters: - sort_by_distance –
- exclude_out_sphere –
- x1 –
- x2 –
- radius –
- option –
Returns:
-
static
from_parameters_to_cell
(a, b, c, alpha, beta, gamma)[source]¶ Create a Lattice using parameters a, b and c as box lengths and corresponging angles alpha, beta, gamma
Parameters: - a – (float): a lattice length.
- b – (float): b lattice length.
- c – (float): c lattice length.
- alpha – (float): alpha angle in degrees.
- beta – (float): beta angle in degrees.
- gamma – (float): gamma angle in degrees.
:rtype : (Lattice) object
-
gamma
¶
-
get_wigner_seitz_container
()[source]¶ Compute the corners of the box that contains the Wigner-Seitz cell
Returns: dict : dictionary with values numpy arrays
-
inverse
¶
-
lengths
¶ Return the 3 lenghts of the lattice in the same order as the lattice vectors
:rtype : list
-
metric
¶
-
minimal_distances
(reduced1, reduced2)[source]¶ Computes a matrix with the minimal distances between two sets of points represented as reciprocal coordinates
Parameters: - reduced1 – List or array of reduced coordinates for the first set of points
- reduced2 – Second set of points
Example: >>> import numpy as np >>> lattice = Lattice.random_cell(‘C2’) >>> r1 = np.random.rand(4, 3) >>> r2 = np.random.rand(4, 3) >>> dist, close_imgs = lattice.minimal_distances(r1, r2)
>>> solution = np.zeros((len(r1), len(r2)))
>>> for i in range(len(r1)): ... for j in range(len(r2)): ... reduced1 = r1[i] ... reduced2 = r2[j]+close_imgs[i, j] ... cartesian1 = lattice.reduced2cartesian(reduced1) ... cartesian2 = lattice.reduced2cartesian(reduced2) ... diff_vector = cartesian2 - cartesian1 ... solution[i, j] = np.linalg.norm(diff_vector)
>>> solution - dist < 1E-5 array([[ True, True, True, True], [ True, True, True, True], [ True, True, True, True], [ True, True, True, True]], dtype=bool)
-
periodic_dimensions
¶ Return the number of periodic dimensions
Returns: int
-
volume
¶ Computes the volume of the cell (3D), area (2D) or generalized volume for N dimensions
:rtype : float
-
pychemia.crystal.symmetry module¶
-
class
pychemia.crystal.symmetry.
CrystalSymmetry
(structure)[source]¶ Bases:
object
Takes a pychemia.Structure object and creates an object with methods to identify symmetry groups and other symmetry related operations. Uses spglib to perform various symmetry finding operations.
-
refine_cell
(symprec=1e-05)[source]¶ Refine a pychemia Structure using the tolerances and return a new structure in a Bravais lattice
Parameters: symprec – (float) Tolerance of distance between atomic positions and between lengths of lattice vectors to be tolerated in the symmetry finding. Returns: A new pychemia Structure in a Bravais lattice :rtype : (pychemia.Structure)
Example: >>> import pychemia >>> a = 4.05 >>> b = a/2 >>> fcc = pychemia.Structure(symbols=[‘Au’], ... cell=[[0, b+1E-5, b-1E-5], [b+1E-5, 0, b-1E-5], [b+1E-5, b-1E-5, 0]], periodicity=True) >>> symm = pychemia.crystal.CrystalSymmetry(fcc) >>> symm.number() 2 >>> symm.symbol() == u’P-1’ True >>> fcc2 = symm.refine_cell(symprec=1E-3) >>> symm2 = pychemia.crystal.CrystalSymmetry(fcc2) >>> symm2.number() 225 >>> symm2.symbol() == u’Fm-3m’ True
-
spglib_cell
¶
-