pymatgen.analysis.structure_analyzer module¶

class
JMolCoordFinder
(el_radius_updates=None)[source]¶ Bases:
object
Determine coordinated sites and coordination number using an emulation of JMol’s default autoBond() algorithm. This version of the algorithm does not take into account any information regarding known charge states.
Initialize coordination finder parameters (atomic radii)
Parameters: el_radius_updates – (dict) symbol>float to override default atomic radii table values 
get_coordinated_sites
(structure, n, tol=0.001)[source]¶ Get the coordinated sites for a site :param structure: (Structure) :param n: (int) index of site in the structure to analyze :param tol: (float) a numerical tolerance to extend search
Returns: ([sites]) a list of coordinated sites


class
OrderParameters
(types, parameters=None, cutoff=10.0)[source]¶ Bases:
object
This class permits the calculation of various types of local order parameters.
Create an OrderParameter analyzer instance.
Parameters:  types ([string]) –
List of strings representing the types of order parameters to be calculated. Note that multiple mentions of the same type may occur. Currently available types are “cn” (simple coordination number—normalized,
if desired), “lin” [Petersstyle OP recognizing linear coordination
 (Zimmermann & Jain, in progress, 2017)],
 “bent” [Petersstyle OP recognizing bent coordination
 (Zimmermann & Jain, in progress, 2017)],
 “tet” [Petersstyle OP recognizing tetrahedral
 coordination (Zimmermann et al., J. Am. Chem. Soc., 137, 1335213361, 2015)],
 “oct” [Petersstyle OP recognizing octahedral
 coordination (Zimmermann et al., J. Am. Chem. Soc., 137, 1335213361, 2015)],
 “bcc” [Petersstyle OP recognizing local
 bodycentered cubic environment (Peters, J. Chem. Phys., 131, 244103, 2009)],
“reg_tri” (OP recognizing coordination with a regular triangle), “sq” (OP recognizing square coordination), “sq_pyr” (OP recognizing square pyramidal coordination), “tri_bipyr” (OP recognizing trigonal bipyramidal coord.), “q2” [Bond orientational order parameter (BOOP)
of weight l=2 (Steinhardt et al., Phys. Rev. B, 28, 784805, 1983)],“q4” (BOOP of weight l=4), “q6” (BOOP of weight l=6).
 parameters ([[float]]) –
2D list of floating point numbers that store parameters associated with the different order parameters that are to be calculated (1st dimension = length of types tuple; any 2nd dimension may be zero, in which case default values are used). In the following, those order parameters q_i are listed that require further parameters for their computation (values in brackets denote default values):
“cn”: normalizing constant (1); “lin”: Gaussian width in fractions of pi (180 degrees)reflecting the “speed of penalizing” deviations away from 180 degrees of any individual neighbor1centerneighbor2 configuration (0.0667); “bent”: target angle in degrees (180);
 Gaussian width for penalizing deviations away from perfect target angle in fractions of pi (0.0667);
 “tet”: Gaussian width for penalizing deviations away
 perfecttetrahedral angle (0.0667);
 “oct”: threshold angle in degrees distinguishing a second
 neighbor to be either close to the south pole or close to the equator (160.0); Gaussian width for penalizing deviations away from south pole (0.0667); Gaussian width for penalizing deviations away from equator (0.0556); constant for shifting q_oct toward smaller values, which can be helpful when trying to fine tune the capabilities of distinguishing between different environments (e.g., tet vs oct) given a single mutual threshold q_thresh;
 “bcc”: southpole threshold angle as for “oct” (160.0);
 southpole Gaussian width as for “oct” (0.0667);
 “reg_tri”: Gaussian width for penalizing angles away from
 the expected angles, given the estimated heighttoside ratio of the trigonal pyramid in which the central atom is located at the tip (0.0222);
 “sq”: Gaussian width for penalizing angles away from
 the expected angles, given the estimated heighttodiagonal ratio of the pyramid in which the central atom is located at the tip (0.0333);
 “sq_pyr”: Gaussian width in fractions of pi
 for penalizing angles away from 90 degrees (0.0333); Gaussian width in Angstrom for penalizing variations in neighbor distances (0.1);
 “tri_bipyr”: threshold angle to identify close to
 South pole positions (160.0, cf., oct). Gaussian width for penalizing deviations away from south pole (0.0667); Gaussian width for penalizing deviations away from equator (0.0556).
 cutoff (float) – Cutoff radius to determine which nearest neighbors are supposed to contribute to the order parameters. If the value is negative the neighboring sites found by distance and cutoff radius are further pruned using the get_coordinated_sites method from the VoronoiCoordFinder class.

compute_trigonometric_terms
(thetas, phis)[source]¶ ” Computes trigonometric terms that are required to calculate bond orientational order parameters.
Parameters:  thetas ([float]) – polar angles of all neighbors in radians.
 phis ([float]) – azimuth angles of all neighbors in radians. The list of azimuth angles is expected to have the same size as the list of polar angles; otherwise, a ValueError is raised. Also, the two lists of angles have to be coherent in order. That is, it is expected that the order in the list of azimuth angles corresponds to a distinct sequence of neighbors. And, this sequence has to equal the sequence of neighbors in the list of polar angles.

get_order_parameters
(structure, n, indeces_neighs=None, tol=0.0, target_spec=None)[source]¶ Compute all order parameters of site n.
Parameters:  structure (Structure) – input structure.
 n (int) – index of site in input structure, for which OPs are to be calculated. Note that we do not use the sites iterator here, but directly access sites via struct[index].
 indeces_neighs ([int]) – list of indeces of those neighbors in Structure object structure that are to be considered for OP computation. This optional argument overwrites the way neighbors are to be determined as defined in the constructor (i.e., Voronoi coordination finder via negative cutoff radius vs constant cutoff radius if cutoff was positive). We do not use information about the underlying structure lattice if the neighbor indeces are explicitly provided. This has two important consequences. First, the input Structure object can, in fact, be a simple list of Site objects. Second, no nearest images of neighbors are determined when providing an index list. Note furthermore that this neighbor determination type ignores the optional target_spec argument.
 tol (float) – threshold of weight (= solid angle / maximal solid angle) to determine if a particular pair is considered neighbors; this is relevant only in the case when Voronoi polyhedra are used to determine coordination
 target_spec (Specie) – target specie to be considered when calculating the order parameters of site n; None includes all species of input structure.
Returns: list of floats representing order parameters. Should it not be possible to compute a given OP for a conceptual reason, the corresponding entry is None instead of a float. For Steinhardt et al.’s bond orientational OPs and the other geometric OPs (“tet”, “oct”, “bcc”), this can happen if there is a single neighbor around site n in the structure because that, obviously, does not permit calculation of angles between multiple neighbors.

get_parameters
(index)[source]¶ Returns list of floats that represents the parameters associated with calculation of the order parameter that was defined at the index provided. Attention: the parameters do not need to equal those originally inputted because of processing out of efficiency reasons.
Parameters: index (int) – index of orderparameter for which associated parameters are to be returned

get_q2
(thetas=None, phis=None)[source]¶ Calculates the value of the bond orientational order parameter of weight l=2. If the function is called with nonempty lists of polar and azimuthal angles the corresponding trigonometric terms are computed afresh. Otherwise, it is expected that the compute_trigonometric_terms function has been just called.
Parameters:  thetas ([float]) – polar angles of all neighbors in radians.
 phis ([float]) – azimuth angles of all neighbors in radians.
Returns:  bond orientational order parameter of weight l=2
corresponding to the input angles thetas and phis.
Return type: q2 (float)

get_q4
(thetas=None, phis=None)[source]¶ Calculates the value of the bond orientational order parameter of weight l=4. If the function is called with nonempty lists of polar and azimuthal angles the corresponding trigonometric terms are computed afresh. Otherwise, it is expected that the compute_trigonometric_terms function has been just called.
Parameters:  thetas ([float]) – polar angles of all neighbors in radians.
 phis ([float]) – azimuth angles of all neighbors in radians.
Returns:  bond orientational order parameter of weight l=4
corresponding to the input angles thetas and phis.
Return type: q4 (float)

get_q6
(thetas=None, phis=None)[source]¶ Calculates the value of the bond orientational order parameter of weight l=6. If the function is called with nonempty lists of polar and azimuthal angles the corresponding trigonometric terms are computed afresh. Otherwise, it is expected that the compute_trigonometric_terms function has been just called.
Parameters:  thetas ([float]) – polar angles of all neighbors in radians.
 phis ([float]) – azimuth angles of all neighbors in radians.
Returns:  bond orientational order parameter of weight l=6
corresponding to the input angles thetas and phis.
Return type: q6 (float)

get_type
(index)[source]¶ Return type of orderparameter at the index provided and represented by a short string.
Parameters: index (int) – index of orderparameter for which type is to be returned

last_nneigh
¶ ” Returns the number of neighbors encountered during the most recent orderparameter calculation. A value of 1 indicates that no such calculation has yet been performed for this instance.

num_ops
¶ ” Returns the number of different order parameters that are targeted to be calculated.
 types ([string]) –

class
OxideType
(structure, relative_cutoff=1.1)[source]¶ Bases:
object
Separate class for determining oxide type.
Parameters:  structure – Input structure.
 relative_cutoff – Relative_cutoff * act. cutoff stipulates the max. distance two O atoms must be from each other. Default value is 1.1. At most 1.1 is recommended, nothing larger, otherwise the script cannot distinguish between superoxides and peroxides.

parse_oxide
()[source]¶ Determines if an oxide is a peroxide/superoxide/ozonide/normal oxide.
Returns: Type of oxide ozonide/peroxide/superoxide/hydroxide/None. nbonds (int): Number of peroxide/superoxide/hydroxide bonds in structure. Return type: oxide_type (str)

class
RelaxationAnalyzer
(initial_structure, final_structure)[source]¶ Bases:
object
This class analyzes the relaxation in a calculation.
Please note that the input and final structures should have the same ordering of sites. This is typically the case for most computational codes.
Parameters: 
get_percentage_bond_dist_changes
(max_radius=3.0)[source]¶ Returns the percentage bond distance changes for each site up to a maximum radius for nearest neighbors.
Parameters: max_radius (float) – Maximum radius to search for nearest neighbors. This radius is applied to the initial structure, not the final structure. Returns: Bond distance changes as a dict of dicts. E.g., {index1: {index2: 0.011, ...}}. For economy of representation, the index1 is always less than index2, i.e., since bonding between site1 and siten is the same as bonding between siten and site1, there is no reason to duplicate the information or computation.


class
VoronoiAnalyzer
(cutoff=5.0, qhull_options='Qbb Qc Qz')[source]¶ Bases:
object
Performs a statistical analysis of Voronoi polyhedra around each site. Each Voronoi polyhedron is described using Schaefli notation. That is a set of indices {c_i} where c_i is the number of faces with i number of vertices. E.g. for a bcc crystal, there is only one polyhedron notation of which is [0,6,0,8,0,0,...]. In perfect crystals, these also corresponds to the WignerSeitz cells. For distortedcrystals, liquids or amorphous structures, rather than onetype, there is a statistical distribution of polyhedra. See ref: Microstructure and its relaxation in FeB amorphous system simulated by molecular dynamics,
Stepanyuk et al., J. Noncryst. Solids (1993), 159, 8087.Parameters:  cutoff (float) – cutoff distance to search for neighbors of a given atom (default = 5.0)
 qhull_options (str) – options to pass to qhull (optional)

analyze
(structure, n=0)[source]¶ Performs Voronoi analysis and returns the polyhedra around atom n in Schlaefli notation.
Parameters:  structure (Structure) – structure to analyze
 n (int) – index of the center atom in structure
Returns:  <c3,c4,c6,c6,c7,c8,c9,c10>
where c_i denotes number of facets with i vertices.
Return type: voronoi index of n

analyze_structures
(structures, step_freq=10, most_frequent_polyhedra=15)[source]¶ Perform Voronoi analysis on a list of Structures. Note that this might take a significant amount of time depending on the size and number of structures.
Parameters:  structures (list) – list of Structures
 (float (cutoff) – cutoff distance around an atom to search for neighbors
 step_freq (int) – perform analysis every step_freq steps
 qhull_options (str) – options to pass to qhull
 most_frequent_polyhedra (int) – this many unique polyhedra with highest frequences is stored.
Returns: A list of tuples in the form (voronoi_index,frequency)

class
VoronoiConnectivity
(structure, cutoff=10)[source]¶ Bases:
object
Computes the solid angles swept out by the shared face of the voronoi polyhedron between two sites.
Parameters:  structure (Structure) – Input structure
 cutoff (float) –

connectivity_array
¶ Provides connectivity array.
Returns: An array of shape [atomi, atomj, imagej]. atomi is the index of the atom in the input structure. Since the second atom can be outside of the unit cell, it must be described by both an atom index and an image index. Array data is the solid angle of polygon between atomi and imagej of atomj Return type: connectivity

get_connections
()[source]¶ Returns a list of site pairs that are Voronoi Neighbors, along with their realspace distances.

get_sitej
(site_index, image_index)[source]¶ Assuming there is some value in the connectivity array at indices (1, 3, 12). sitei can be obtained directly from the input structure (structure[1]). sitej can be obtained by passing 3, 12 to this function
Parameters:  site_index (int) – index of the site (3 in the example)
 image_index (int) – index of the image (12 in the example)

max_connectivity
¶ returns the 2d array [sitei, sitej] that represents the maximum connectivity of site i to any periodic image of site j

class
VoronoiCoordFinder
(structure, target=None, cutoff=10.0, allow_pathological=False)[source]¶ Bases:
object
Uses a Voronoi algorithm to determine the coordination for each site in a structure.
Parameters:  structure (Structure) – Input structure
 target ([Element/Specie]) – A list of target species to determine coordination for.
 cutoff (float) – Radius in Angstrom cutoff to look for coordinating atoms. Defaults to 10.0.
 allow_pathological (bool) – whether to allow infinite vertices in determination of Voronoi coordination

get_coordinated_sites
(n, tol=0, target=None)[source]¶ Returns the sites that are in the coordination radius of site with index n.
Parameters:  n (int) – Site index.
 tol (float) – Weight tolerance to determine if a particular pair is considered a neighbor.
 target (Element) – Target element
Returns: Sites coordinating input site.

get_coordination_number
(n)[source]¶ Returns the coordination number of site with index n.
Parameters: n (int) – Site index

get_voronoi_polyhedra
(n)[source]¶ Gives a weighted polyhedra around a site. This uses the voronoi construction with solid angle weights. See ref: A Proposed Rigorous Definition of Coordination Number, M. O’Keeffe, Acta Cryst. (1979). A35, 772775
Parameters: n (int) – Site index Returns: A dict of sites sharing a common Voronoi facet with the site n and their solid angle weights

average_coordination_number
(structures, freq=10)[source]¶ Calculates the ensemble averaged Voronoi coordination numbers of a list of Structures using VoronoiCoordFinder. Typically used for analyzing the output of a Molecular Dynamics run. :param structures: list of Structures. :type structures: list :param freq: sampling frequency of coordination number [every freq steps]. :type freq: int
Returns: Dictionary of elements as keys and average coordination numbers as values.

contains_peroxide
(structure, relative_cutoff=1.1)[source]¶ Determines if a structure contains peroxide anions.
Parameters:  structure (Structure) – Input structure.
 relative_cutoff – The peroxide bond distance is 1.49 Angstrom. Relative_cutoff * 1.49 stipulates the maximum distance two O atoms must be to each other to be considered a peroxide.
Returns: Boolean indicating if structure contains a peroxide anion.

get_dimensionality
(structure, max_hkl=2, el_radius_updates=None, min_slab_size=5, min_vacuum_size=5, standardize=True, bonds=None)[source]¶ This method returns whether a structure is 3D, 2D (layered), or 1D (linear chains or molecules) according to the algorithm published in Gorai, P., Toberer, E. & Stevanovic, V. Computational Identification of Promising Thermoelectric Materials Among Known Quasi2D Binary Compounds. J. Mater. Chem. A 2, 4136 (2016).
Note that a 1D structure detection might indicate problems in the bonding algorithm, particularly for ionic crystals (e.g., NaCl)
Users can change the behavior of bonds detection by passing either el_radius_updates to update atomic radii for autodetection of max bond distances, or bonds to explicitly specify max bond distances for atom pairs. Note that if you pass both, el_radius_updates are ignored.
Parameters:  structure – (Structure) structure to analyze dimensionality for
 max_hkl – (int) max index of planes to look for layers
 el_radius_updates – (dict) symbol>float to update atomic radii
 min_slab_size – (float) internal surface construction parameter
 min_vacuum_size – (float) internal surface construction parameter
 standardize (bool) – whether to standardize the structure before analysis. Set to False only if you already have the structure in a convention where layers / chains will be along low <hkl> indexes.
 bonds ({(specie1, specie2) – max_bond_dist}: bonds are specified as a dict of tuples: float of specie1, specie2 and the max bonding distance. For example, PO4 groups may be defined as {(“P”, “O”): 3}.
 Returns: (int) the dimensionality of the structure  1 (molecules/chains),
 2 (layered), or 3 (3D)

get_max_bond_lengths
(structure, el_radius_updates=None)[source]¶ Provides max bond length estimates for a structure based on the JMol table and algorithms.
Parameters:  structure – (structure)
 el_radius_updates – (dict) symbol>float to update atomic radii
 Returns: (dict)  (Element1, Element2) > float. The two elements are
 ordered by Z.

gramschmidt
(vin, uin)[source]¶ Returns that part of the first input vector that is orthogonal to the second input vector. The output vector is not normalized.
Parameters:  vin (numpy array) – first input vector
 uin (numpy array) – second input vector

oxide_type
(structure, relative_cutoff=1.1, return_nbonds=False)[source]¶ Determines if an oxide is a peroxide/superoxide/ozonide/normal oxide
Parameters:  structure (Structure) – Input structure.
 relative_cutoff (float) – Relative_cutoff * act. cutoff stipulates the max distance two O atoms must be from each other.
 return_nbonds (bool) – Should number of bonds be requested?