structure#

Tools for structural manipulation and analysis

Functions

deform_lattice

Deform lattice vectors in structure.

get_displacement_vectors

Get vectors in cartesian coords of site displacements w.r.t.

get_distance_vector

Get distance vector between two sites assuming periodic boundary conditions.

get_furthest_neighbors

Get the indexes of atomic sites that are furthest away from the target site and maximally spaced apart from each other, considering periodic boundary conditions.

is_site_in_structure

Check if Site is part of the Structure list.

is_site_in_structure_coords

Check if a site's coordinates are present in a structure, using periodic boundary conditions.

rattle_atoms

Change randomly atomic positions.

remove_oxidation_state_from_site

Remove pymatgen oxidation state decoration from Site.

sort_sites_to_ref_coords

Sort Sites of one structure to match the order of coordinates in a reference structure.

view_structures_with_ase

Visualize a Structure object or a list of Structure objects with the ASE.

write_extxyz_file

Write extxyz format.

write_xdatcar_from_structures

Write XDATCAR file from a list of structures.

deform_lattice(structure, stdev=0.03)[source]#

Deform lattice vectors in structure. Also changes the angles of lattice vectors (off diagonal components). The function “apply_strain” from the Structure class only changes the base vectors’ size but not the angles.

Parameters:
  • structure (Structure) – Structure object.

  • stdev (float) – Standard deviation.

Returns:

structure – Structure with deformed lattice.

Return type:

Structure

get_displacement_vectors(structures)[source]#

Get vectors in cartesian coords of site displacements w.r.t. the first structure.

Parameters:

structures (list) – list of Pymatgen Structure objects.

Returns:

displacements – Displacement vectors in cartesian coordinates.

Return type:

np.array

get_distance_vector(site1, site2, jimage=None)[source]#

Get distance vector between two sites assuming periodic boundary conditions. Same as pymatgen.core.sites.Site.distance but returns a vector instead of norm.

Parameters:
  • 1 (site) – PeriodicSite object

  • 2 (site) – PeriodicSite object

  • jimage (np.array) – Specific periodic image in terms of lattice translations, e.g., [1,0,0] implies to take periodic image that is one a-lattice vector away. If jimage is None, the image that is nearest to the site is found.

Returns:

distance – Distance between the two sites in A°.

Return type:

float

get_furthest_neighbors(structure, target_site, species)[source]#

Get the indexes of atomic sites that are furthest away from the target site and maximally spaced apart from each other, considering periodic boundary conditions.

Parameters:
  • structure (Structure)

  • target_site ((int or PeriodicSite)) – PeriodicSite object or index of the target site in the structure

  • species (list) – List of species to find.

Returns:

selected_indices – List of indices corresponding to the furthest sites of the given species

Return type:

list

is_site_in_structure(site, structure, tol=0.001)[source]#

Check if Site is part of the Structure list. This function is needed because sometimes doing a simple check (“site in structure”) doesn’t work. This function performes a check on the coordinates and the element on the site. Therefore it is more reliable.

Parameters:
  • site (Site) – PeriodicSite or Site object.

  • structure (Structure) – Structure object.

  • tol (float) – Tolerance for fractional coordinates. The default is 1e-03.

Returns:

  • is_site_in_structure (bool)

  • index ((int)) – Index of site in structure in case site is_site_in_structure returns True If False index will be None.

is_site_in_structure_coords(site, structure, tol=0.001, return_distance=False)[source]#

Check if a site’s coordinates are present in a structure, using periodic boundary conditions.

Parameters:
  • site (Site) – PeriodicSite or Site object.

  • structure (Structure) – Structure object.

  • tol (float,) – Tolerance for site comparison, normalized with respect to lattice size.

  • return_distance (bool) – Return distance btw site coords and closest site in reference structure.

Returns:

  • is_site_in_structure_coords (bool) – Whether the site exists in the structure within tolerance.

  • index (int or None) – Index of matching site in structure if found, otherwise None.

  • distance (float) – Distance btw site coords and closest site in reference structure. Returned if return_distance is set to True.

rattle_atoms(structure, stdev=0.05, seed=None)[source]#

Change randomly atomic positions. Uses the ASE. Similar to the method “perturb” from the Structure class.

Parameters:
  • structure (Structure) – Structure object.

  • stdev (float) – Standard deviation.

  • seed (int) – Seed for random number generation passed to the Atoms.rattle method.

Returns:

structure – Structure with rattled atoms.

Return type:

Structure

remove_oxidation_state_from_site(site)[source]#

Remove pymatgen oxidation state decoration from Site.

sort_sites_to_ref_coords(structure, structure_ref, extra_sites=[], tol=0.001, get_indexes=False)[source]#

Sort Sites of one structure to match the order of coordinates in a reference structure.

Parameters:
  • structure (Structure) – Structure to sort.

  • structure_ref (Structure) – Reference Structure.

  • extra_sites (list) – Sites to append at the end of the structure.

  • tol (float) – Tolerance for site comparison. The distance between sites in target and reference stucture is used, periodicity is accounted for. The tolerance is normalized with respect to lattice vector size.

  • get_indexes (bool) – Get list of mapping indexes for target structure sites in reference structure.

Returns:

  • new_structure (Structure) – Sorted Structure.

  • indexes (list) – If get_indexes is True a tuple is returned. List of mapping indexes for target structure sites in reference structure.

view_structures_with_ase(structures)[source]#

Visualize a Structure object or a list of Structure objects with the ASE. First the Structure objects are converted into an ase Atom object, then “view” is used to visualize them.

write_extxyz_file(file, structure, structure_ref=None, displacements=False)[source]#

Write extxyz format. Displacements can be included for visualization.

Parameters:
  • file (str) – Path to save extxyz file to.

  • structure (Structure) – Structure to visualize.

  • structure_ref (Structure) – Reference Structure if needed.

  • displacements (bool) – Include displacement vectors.

write_xdatcar_from_structures(structures, file='XDATCAR')[source]#

Write XDATCAR file from a list of structures. The first structure determines the reference for the Trajectory object.

Parameters:
  • structures (list) – List of Structure objects.

  • file (str) – Path to write XDATCAR to.