# pymatgen.analysis.structure_analyzer module¶

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” [Peters-style OP recognizing linear coordination (Zimmermann & Jain, in progress, 2017)], “bent” [Peters-style OP recognizing bent coordination (Zimmermann & Jain, in progress, 2017)], “tet” [Peters-style OP recognizing tetrahedral coordination (Zimmermann et al., J. Am. Chem. Soc., 137, 13352-13361, 2015)], “oct” [Peters-style OP recognizing octahedral coordination (Zimmermann et al., J. Am. Chem. Soc., 137, 13352-13361, 2015)], “bcc” [Peters-style OP recognizing local body-centered 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), “q2” [Bond orientational order parameter (BOOP) of weight l=2 (Steinhardt et al., Phys. Rev. B, 28, 784-805, 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 neighbor1-center-neighbor2 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”: south-pole threshold angle as for “oct” (160.0); south-pole Gaussian width as for “oct” (0.0667); “reg_tri”: Gaussian width for penalizing angles away from the expected angles, given the estimated height-to-side 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 height-to-diagonal 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). 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. 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 order-parameter 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 non-empty 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. bond orientational order parameter of weight l=2 corresponding to the input angles thetas and phis. 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 non-empty 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. bond orientational order parameter of weight l=4 corresponding to the input angles thetas and phis. 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 non-empty 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. bond orientational order parameter of weight l=6 corresponding to the input angles thetas and phis. q6 (float)
get_type(index)[source]

Return type of order-parameter at the index provided and represented by a short string.

Parameters: index (int) – index of order-parameter for which type is to be returned
last_nneigh

” Returns the number of neighbors encountered during the most recent order-parameter 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.

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. 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: initial_structure (Structure) – Initial input structure to calculation. final_structure (Structure) – Final output structure from calculation.
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. 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.
get_percentage_lattice_parameter_changes()[source]

Returns the percentage lattice parameter changes.

Returns: A dict of the percentage change in lattice parameter, e.g., {‘a’: 0.012, ‘b’: 0.021, ‘c’: -0.031} implies a change of 1.2%, 2.1% and -3.1% in the a, b and c lattice parameters respectively.
get_percentage_volume_change()[source]

Returns the percentage volume change.

Returns: Volume change in percentage, e.g., 0.055 implies a 5.5% increase.
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 Wigner-Seitz cells. For distorted-crystals, liquids or amorphous structures, rather than one-type, there is a statistical distribution of polyhedra. See ref: Microstructure and its relaxation in Fe-B amorphous system simulated by molecular dynamics,

Stepanyuk et al., J. Non-cryst. Solids (1993), 159, 80-87.
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 where c_i denotes number of facets with i vertices. 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. A list of tuples in the form (voronoi_index,frequency)
static plot_vor_analysis(voronoi_ensemble)[source]
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 connectivity
get_connections()[source]

Returns a list of site pairs that are Voronoi Neighbors, along with their real-space 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 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, 772-775

Parameters: n (int) – Site index 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. Boolean indicating if structure contains a peroxide anion.
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?
solid_angle(center, coords)[source]

Helper method to calculate the solid angle of a set of coords from the center.

Parameters: center (3x1 array) – Center to measure solid angle from. coords (Nx3 array) – List of coords to determine solid angle. The solid angle.
sulfide_type(structure)[source]

Determines if a structure is a sulfide/polysulfide

Parameters: structure (Structure) – Input structure. (str) sulfide/polysulfide/sulfate