Methods

All the methods below are available directly under pylada.crystal.

Vector transformations

pylada.crystal.cppwrappers.zero_centered(a, cell, invcell=None) → [numpy.array(..),...]

Returns Folds vector back to origin.

This may not be the vector with the smallest possible norm if the cell is very skewed.

Parameters:
  • a – A 3d-vector to fold back into the cell. Can also be any numpy array where its last dimension if of length 3, ie. a.shape[-1] == 3.
  • cell – The cell matrix defining the periodicity.
  • invcell – Optional. The inverse of the cell defining the periodicity. It is computed if not given on input.
pylada.crystal.cppwrappers.into_voronoi(a, cell, invcell=None) → [numpy.array(..),...]

Returns Folds vector into first Brillouin zone of the input cell.

This returns the periodic image with the smallest possible norm.

Parameters:
  • a – The 3d-vector to fold back into the cell. Can also be any numpy array where its last dimension if of length 3, ie. a.shape[-1] == 3.
  • cell – The cell matrix defining the periodicity.
  • invcell – Optional. The inverse of the cell defining the periodicity. It is computed if not given on input.
pylada.crystal.cppwrappers.into_cell(a, cell, invcell=None) → [numpy.array(..),...]

Returns Folds vector into periodic the input cell.

Parameters:
  • a – The 3d-vector to fold back into the cell. Can also be any numpy array where its last dimension if of length 3, ie. a.shape[-1] == 3.
  • cell – The cell matrix defining the periodicity.
  • invcell – Optional. The inverse of the cell defining the periodicity. It is computed if not given on input.

Structure transformations

pylada.crystal.cppwrappers.supercell(lattice, cell) → Structure

Creates a supercell of an input lattice.

Parameters:
  • latticeStructure from which to create the supercell. Cannot be empty. Must be deepcopiable.
  • cell – Cell in cartesian coordinates of the supercell.
Returns:

A Structure representing the supercell. If lattice contains an attribute name, then the result’s is set to “supercell of ...”. All other attributes of the lattice are deep-copied to the supercell. The atoms within the result contain an attribute index which is an index to the equivalent site within lattice. Otherwise, the atoms are deep copies of the lattice sites.

pylada.crystal.cppwrappers.primitive(supercell, tolerance=1e-8) → Structure

Returns the primitive unit-cell lattice of an input lattice.

Parameters:
  • latticeStructure for which to get primitive unit-cell lattice. Cannot be empty. Must be deepcopiable.
  • tolerance – Optional. Tolerance when comparing positions. Defaults to 1e-8.
Returns:

A new Structure representing the primitive lattice.

pylada.crystal.cppwrappers.transform(structure, operation) → Structure

Returns a copy of the structure transformed according to affine operation.

Parameters:
  • structure – The Structure instance to transform.
  • operation – The rotation (applied first) is contained in the first three row and the translation (applied second) in the last row.
pylada.crystal.vasp_ordered(structure)[source]

Returns a structure with correct VASP order of ions.

Parameters:structureStructure for which to reorder atoms.

Structure and Geometry Analysis

pylada.crystal.cppwrappers.is_primitive(supercell, tolerance=1e-8) → Boolean

Returns True if the lattice is primitive.

Parameters:
  • latticeStructure for which to get primitive unit-cell lattice. Cannot be empty. Must be deepcopiable.
  • tolerance – Optional. Tolerance when comparing positions. Defaults to 1e-8.
pylada.crystal.cppwrappers.space_group(structure, tolerance=1e-8) → Structure

Finds and stores point group operations.

Implementation taken from ENUM.

Parameters:
  • structure – The Structure instance for which to find the point group.
  • tolerance – acceptable tolerance when determining symmetries. Defaults to 1e-8.
Returns:

python list of affine symmetry operations for the given structure. Each element is a 4x3 numpy array, with the first 3 rows forming the rotation, and the last row is the translation. The affine transform is applied as rotation * vector + translation.

Raises ValueError:
 

if the input structure is not primitive.

pylada.crystal.cppwrappers.map_sites(mapper, mappee, cmp=None, tolerance=1e-8) → Boolean

Map sites from a lattice onto a structure.

This function finds out which atomic sites in a supercell refer to the sites in a parent lattice. site attribute are added to the atoms in the mappee structure. These attributes hold an index to the relevant sites in the mapper. If a particular atom could not be mapped, then site is None.

Parameters:
  • mapperStructure instance acting as the parent lattice.
  • mappeeStructure instance acting as the supercell.
  • cmp – Can be set to a callable which shall take two atoms as input and return True if their occupation (and other attributes) are equivalent.
  • tolerance – Tolerance criteria when comparing distances.
Returns:

True if all sites in mappee where mapped to mapper.

pylada.crystal.cppwrappers.neighbors(structure, nmax, center, tolerance=1e-8) → [(Atom, numpy.array, float), ...]

Returns list of neighbors to input position

Creates a list referencing neighbors of a given position in a structure. In order to make this function well defined, it may return more atoms that actually requested. For instance, in an fcc structure with center at the origin, if asked for the 6 first neighbors, actually the first twelve are returned since they are equidistant. The input tolerance is the judge of equidistance.

Parameters:
  • structureStructure from which to determine neighbors.
  • nmax – Integer number of first neighbors to search for.
  • center – Position for which to determine first neighbors.
  • tolerance – Tolerance criteria for judging equidistance.
Returns:

A list of 3-tuples. The first item is a refence to the neighboring atom, the second is the position of its relevant periodic image relative to the center, the third is its distance from the center.

pylada.crystal.cppwrappers.coordination_shells(structure, nshells, center, tolerance=1e-8, natoms=0) → [ [(Atom, numpy.array, float), ...], ...]

Creates list of coordination shells up to given order.

Parameters:
  • structureStructure from which to determine neighbors.
  • nshells – Integer number of shells to compute.
  • center – Position for which to determine first neighbors.
  • tolerance – Tolerance criteria for judging equidistance.
  • natoms – Integer number of neighbors to consider. Defaults to fcc + some security.
Returns:

A list of lists of tuples. The outer list is over coordination shells. The inner list references the atoms in a shell. Each innermost tuple contains a reference to the atom in question, a vector from the center to the relevant periodic image of the atom, and finally, the associated distance.

pylada.crystal.cppwrappers.periodic_dnc(structure, overlap, mesh=None, nperbox=None, tolerance=1e-8) → [ [(Atom, numpy.array, bool), ...], ...]

Creates periodic divide-and-conquer boxes.

Creates a list of divide-and-conquer boxes for a periodic system. Takes into account periodic images. In order to make sure that a box contains all atoms relevant for a given calculation, it allows for an overlap, so that atoms which are close (say close enough to form a bond) which are not nominally within the are also referenced. In other words, the boxes have fuzzy limits. The return clearly indicates whether an atom is truly within a box or merely sitting close by.

Parameters:
  • structure – The Structure instance to transform.
  • overlap – Size in units of the structure’s scale attribute which determine atoms which are close but not quite within a box.
  • mesh – 3d-vector defining the mesh parameters from which to determine box. Give either this or nperbox, but not both.
  • nperbox – Integer number of atoms per box. Defaults to 20. Give either this or mesh, but not both.
  • return_mesh – If True, returns mesh as first item of a two-tuple.
Returns:

If return_mesh is false, returns a list of lists of 3-tuples (atom, translation, insmallbox). Each inner list represents a single divide-and-conquer box (+overlapping atoms). Each item within that box contains a reference to an atom, a possible translation to push the atom from its current position to its periodic image within the box, and boolean which is true if the atom truly inside the box as opposed to sitting just outside within the specified overlap. If return_mesh is true, then returns a two-tuple consisting of the mesh and the list of lists previously described.

pylada.crystal.cppwrappers.splitconfigs(structure, center, nmax, configurations=None, tolerance=1e-8) → [ ( (Atom, numpy.array), ...), float), ...]

Creates a split-configuration for a given structure and atomic origin.

Split-configurations are a symmetry-agnostic atom-centered description of a chemical environment [ABMZ].

Parameters:
  • structureStructure for which to create split-configurations.
  • centerAtom at the origin of the configuration.
  • nmax – Integer number of atoms (cutoff) to consider for inclusion in the split-configuration.
  • configurations – Defaults to None. Object where configurations should be stored, eg a list of previously returned configurations. There is no error checking, so do not mix and match.
  • tolerance – Tolerance criteria when comparing distances.
Returns:

A list of splitted configuration. Each item in this list is itself a view, e.g. a list with two inner items. The first inner item is an ordered list of references to atoms. The second inner item is the weight for that configuration. The references to the atoms are each a 2-tuple consisting of an actual reference to an atom, as well as the coordinates of that atom in the current view.

[ABMZ]d’Avezac, Botts, Mohlenkamp, Zunger, SIAM J. Comput. 30 (2011)
pylada.crystal.specieset(structure)[source]

Returns ordered set of species.

Especially usefull with VASP since we are sure what the list of species is always ordered the same way.

Iterators

Reading and Writing

pylada.crystal.read.poscar(path='POSCAR', types=None)[source]

Tries to read a VASP POSCAR file.

param path:Path to the POSCAR file. Can also be an object with file-like behavior.
type path:str or file object
param types:Species in the POSCAR.
type types:None or sequence of str
Returns:pylada.crystal.Structure instance.
pylada.crystal.read.castep(file)[source]

Tries to read a castep structure file.

pylada.crystal.write.poscar(structure, file='POSCAR', vasp5=None, substitute=None)[source]

Writes a poscar to file.

Parameters:
  • structure (Structure) – The structure to print out.
  • file (str, stream, or None.) – Object with a ‘’write’’ method. If a string, then a file object is opened with that filename. The file is overwritten. If None, then writes to POSCAR in current working directory.
  • vasp5 (bool) – If true, include species in poscar, vasp-5 style. Otherwise, looks for is_vasp_4 global config variable. Defaults to False, in which case, does not print specie types.
  • substitute (dict or None) – If present, will substitute the atom type in the structure. Can be incomplete. Only works with vasp5 = True (or is_vasp_4 = True).
>>> with open("POSCAR", "w") as file: write.poscar(structure, file, vasp5=True)

Species in structures can be substituted for others (when using vasp5 format). Below, aluminum atoms are replaced by cadmium atoms. Other atoms are left unchanged.

>>> with open("POSCAR", "w") as file:
>>>   write.poscar(structure, file, vasp5=True, substitute={"Al":"Cd"})

Selective dynamics are added to the POSCAR file if an atom in the structure has a freeze attribute (of non-zero length). It is expected that this attribute is a string and that it contains one of “x”, “y”, “z”, corresponding to freezing the first, second, or third fractional coordinates. Combinations of these are also allowed.

pylada.crystal.write.castep(structure, file=None)[source]

Writes castep input.

Table Of Contents

Previous topic

Atom, Structure, and HFTransform

Next topic

Predefined Lattices

This Page