pymatgen.analysis.local_env module¶

class
BrunnerNN_real
(tol=0.0001, cutoff=8.0)[source]¶ Bases:
pymatgen.analysis.local_env.NearNeighbors
Determine coordination number using Brunner’s algorithm which counts the atoms that are within the largest gap in differences in real space interatomic distances. This algorithm uses Brunner’s method of largest gap in interatomic distances.
Parameters:  tol (float) – tolerance parameter for bond determination (default: 1E4).
 cutoff (float) – cutoff radius in Angstrom to look for nearneighbor atoms. Defaults to 8.0.

get_nn_info
(structure, n)[source]¶ Get all nearneighbor sites as well as the associated image locations and weights of the site with index n.
Parameters:  structure (Structure) – input structure.
 n (integer) – index of site for which to determine nearneighbor information.
Returns:  each dictionary provides information
about a single near neighbor, where key ‘site’ gives access to the corresponding Site object, ‘image’ gives the image location, and ‘weight’ provides the weight that a given nearneighbor site contributes to the coordination number (1 or smaller), ‘site_index’ gives index of the corresponding site in the original structure.
Return type: siw (list of dicts)

class
BrunnerNN_reciprocal
(tol=0.0001, cutoff=8.0)[source]¶ Bases:
pymatgen.analysis.local_env.NearNeighbors
Determine coordination number using Brunner’s algorithm which counts the atoms that are within the largest gap in differences in real space interatomic distances. This algorithm uses Brunner’s method of largest reciprocal gap in interatomic distances.
Parameters:  tol (float) – tolerance parameter for bond determination (default: 1E4).
 cutoff (float) – cutoff radius in Angstrom to look for nearneighbor atoms. Defaults to 8.0.

get_nn_info
(structure, n)[source]¶ Get all nearneighbor sites as well as the associated image locations and weights of the site with index n.
Parameters:  structure (Structure) – input structure.
 n (integer) – index of site for which to determine nearneighbor information.
Returns:  each dictionary provides information
about a single near neighbor, where key ‘site’ gives access to the corresponding Site object, ‘image’ gives the image location, and ‘weight’ provides the weight that a given nearneighbor site contributes to the coordination number (1 or smaller), ‘site_index’ gives index of the corresponding site in the original structure.
Return type: siw (list of dicts)

class
BrunnerNN_relative
(tol=0.0001, cutoff=8.0)[source]¶ Bases:
pymatgen.analysis.local_env.NearNeighbors
Determine coordination number using Brunner’s algorithm which counts the atoms that are within the largest gap in differences in real space interatomic distances. This algorithm uses Brunner’s method of of largest relative gap in interatomic distances.
Parameters:  tol (float) – tolerance parameter for bond determination (default: 1E4).
 cutoff (float) – cutoff radius in Angstrom to look for nearneighbor atoms. Defaults to 8.0.

get_nn_info
(structure, n)[source]¶ Get all nearneighbor sites as well as the associated image locations and weights of the site with index n.
Parameters:  structure (Structure) – input structure.
 n (integer) – index of site for which to determine nearneighbor information.
Returns:  each dictionary provides information
about a single near neighbor, where key ‘site’ gives access to the corresponding Site object, ‘image’ gives the image location, and ‘weight’ provides the weight that a given nearneighbor site contributes to the coordination number (1 or smaller), ‘site_index’ gives index of the corresponding site in the original structure.
Return type: siw (list of dicts)

class
CovalentBondNN
(tol=0.2, order=True)[source]¶ Bases:
pymatgen.analysis.local_env.NearNeighbors
Determine nearneighbor sites and bond orders using builtin pymatgen.Molecule CovalentBond functionality.
NOTE: This strategy is only appropriate for molecules, and not for structures.
Parameters:  tol (float) – Tolerance for covalent bond checking.
 order (bool) – If True (default), this class will compute bond orders. If
 bond lengths will be computed (False,) –

get_bonded_structure
(structure, decorate=False)[source]¶ Obtain a MoleculeGraph object using this NearNeighbor class.
Parameters:  structure – Molecule object.
 decorate (bool) – whether to annotate site properties
 order parameters using neighbors determined by (with) –
 NearNeighbor class (this) –
Returns: a pymatgen.analysis.graphs.MoleculeGraph object

get_nn_info
(structure, n)[source]¶ Get all nearneighbor sites and weights (orders) of bonds for a given atom.
Parameters:  structure – input Molecule.
 n – index of site for which to determine near neighbors.
Returns: [dict] representing a neighboring site and the type of
bond present between site n and the neighboring site.

get_nn_shell_info
(structure, site_idx, shell)[source]¶ Get a certain nearest neighbor shell for a certain site.
Determines all nonbacktracking paths through the neighbor network computed by get_nn_info. The weight is determined by multiplying the weight of the neighbor at each hop through the network. For example, a 2ndnearestneighbor that has a weight of 1 from its 1stnearestneighbor and weight 0.5 from the original site will be assigned a weight of 0.5.
As this calculation may involve computing the nearest neighbors of atoms multiple times, the calculation starts by computing all of the neighbor info and then calling _get_nn_shell_info. If you are likely to call this method for more than one site, consider calling get_all_nn first and then calling this protected method yourself.
Parameters:  structure (Molecule) – Input structure
 site_idx (int) – index of site for which to determine neighbor information.
 shell (int) – Which neighbor shell to retrieve (1 == 1st NN shell)
Returns:  list of dictionaries. Each entry in the list is information about
a certain neighbor in the structure, in the same format as get_nn_info.

class
Critic2NN
[source]¶ Bases:
pymatgen.analysis.local_env.NearNeighbors
Performs a topological analysis using critic2 to obtain neighbor information, using a sum of atomic charge densities. If an actual charge density is available (e.g. from a VASP CHGCAR), see Critic2Caller directly instead.

get_bonded_structure
(structure, decorate=False)[source]¶ Obtain a StructureGraph object using this NearNeighbor class. Requires the optional dependency networkx (pip install networkx).
Parameters:  structure – Structure object.
 decorate (bool) – whether to annotate site properties
 order parameters using neighbors determined by (with) –
 NearNeighbor class (this) –
Returns: a pymatgen.analysis.graphs.BondedStructure object

get_nn_info
(structure, n)[source]¶ Get all nearneighbor sites as well as the associated image locations and weights of the site with index n.
Parameters:  structure (Structure) – input structure.
 n (integer) – index of site for which to determine nearneighbor information.
Returns:  each dictionary provides information
about a single near neighbor, where key ‘site’ gives access to the corresponding Site object, ‘image’ gives the image location, and ‘weight’ provides the weight that a given nearneighbor site contributes to the coordination number (1 or smaller), ‘site_index’ gives index of the corresponding site in the original structure.
Return type: siw (list of dicts)


class
CrystalNN
(weighted_cn=False, cation_anion=False, distance_cutoffs=(0.5, 1), x_diff_weight=3.0, porous_adjustment=True, search_cutoff=7, fingerprint_length=None)[source]¶ Bases:
pymatgen.analysis.local_env.NearNeighbors
This is custom near neighbor method intended for use in all kinds of periodic structures (metals, minerals, porous structures, etc). It is based on a Voronoi algorithm and uses the solid angle weights to determine the probability of various coordination environments. The algorithm can also modify probability using smooth distance cutoffs as well as Pauling electronegativity differences. The output can either be the most probable coordination environment or a weighted list of coordination environments.
Initialize CrystalNN with desired parameters. Default parameters assume “chemical bond” type behavior is desired. For geometric neighbor finding (e.g., structural framework), set (i) distance_cutoffs=None, (ii) x_diff_weight=0.0 and (optionally) (iii) porous_adjustment=False which will disregard the atomic identities and perform best for a purely geometric match.
Parameters:  weighted_cn – (bool) if set to True, will return fractional weights for each potential near neighbor.
 cation_anion – (bool) if set True, will restrict bonding targets to sites with opposite or zero charge. Requires an oxidation states on all sites in the structure.
 distance_cutoffs – ([float, float])  if not None, penalizes neighbor distances greater than sum of covalent radii plus distance_cutoffs[0]. Distances greater than covalent radii sum plus distance_cutoffs[1] are enforced to have zero weight.
 x_diff_weight – (float)  if multiple types of neighbor elements are possible, this sets preferences for targets with higher electronegativity difference.
 porous_adjustment – (bool)  if True, readjusts Voronoi weights to better describe layered / porous structures
 search_cutoff – (float) cutoff in Angstroms for initial neighbor search; this will be adjusted if needed internally
 fingerprint_length – (int) if a fixed_length CN “fingerprint” is desired from get_nn_data(), set this parameter

NNData
¶ alias of
nn_data

get_cn
(structure, n, use_weights=False)[source]¶ Get coordination number, CN, of site with index n in structure.
Parameters:  structure (Structure) – input structure.
 n (integer) – index of site for which to determine CN.
 use_weights (boolean) – flag indicating whether (True) to use weights for computing the coordination number or not (False, default: each coordinated site has equal weight).
Returns: coordination number.
Return type: cn (integer or float)

get_cn_dict
(structure, n, use_weights=False)[source]¶ Get coordination number, CN, of each element bonded to site with index n in structure
Parameters:  structure (Structure) – input structure
 n (integer) – index of site for which to determine CN.
 use_weights (boolean) – flag indicating whether (True) to use weights for computing the coordination number or not (False, default: each coordinated site has equal weight).
Returns: dictionary of CN of each element bonded to site
Return type: cn (dict)

get_nn_data
(structure, n, length=None)[source]¶ The main logic of the method to compute near neighbor.
Parameters:  structure – (Structure) enclosing structure object
 n – (int) index of target site to get NN info for
 length – (int) if set, will return a fixed range of CN numbers
Returns:  all near neighbor sites with weights
 a dict of CN > weight
 a dict of CN > associated near neighbor sites
Return type: a namedtuple (NNData) object that contains

get_nn_info
(structure, n)[source]¶ Get all nearneighbor information. :param structure: (Structure) pymatgen Structure :param n: (int) index of target site
Returns:  each dictionary provides information
 about a single near neighbor, where key ‘site’ gives access to the corresponding Site object, ‘image’ gives the image location, and ‘weight’ provides the weight that a given nearneighbor site contributes to the coordination number (1 or smaller), ‘site_index’ gives index of the corresponding site in the original structure.
Return type: siw (list of dicts)

class
CutOffDictNN
(cut_off_dict=None)[source]¶ Bases:
pymatgen.analysis.local_env.NearNeighbors
A very basic NN class using a dictionary of fixed cutoff distances. Can also be used with no dictionary defined for a Null/Empty NN class.
Parameters:  cut_off_dict (Dict[str, float]) – a dictionary
 cutoff distances, e.g. { (of) – 2.0} for
 maximum FeO bond length of 2.0 Angstroms. (a) –
 that if your structure is oxidation state (Note) –
 the cutoff distances will have to (decorated,) –
 include the oxidation state, e.g. (explicitly) –
 { ('Fe2+', 'O2') – 2.0}

static
from_preset
(preset)[source]¶ Initialise a CutOffDictNN according to a preset set of cutoffs.
Parameters: preset (str) – A preset name. The list of supported presets are:
 ”vesta_2019”: The distance cutoffs used by the VESTA visualisation program.
Returns: A CutOffDictNN using the preset cutoff dictionary.

get_nn_info
(structure, n)[source]¶ Get all nearneighbor sites as well as the associated image locations and weights of the site with index n.
Parameters:  structure (Structure) – input structure.
 n (integer) – index of site for which to determine nearneighbor information.
Returns:  each dictionary provides information
about a single near neighbor, where key ‘site’ gives access to the corresponding Site object, ‘image’ gives the image location, and ‘weight’ provides the weight that a given nearneighbor site contributes to the coordination number (1 or smaller), ‘site_index’ gives index of the corresponding site in the original structure.
Return type: siw (list of dicts)

class
EconNN
(tol=0.0001, cutoff=10.0)[source]¶ Bases:
pymatgen.analysis.local_env.NearNeighbors
Determines the average effective coordination number for each cation in a given structure using Hoppe’s algorithm.
This method finds all cationcentered polyhedrals in the structure, calculates the bond weight for each peripheral ion in the polyhedral, and sums up the bond weights to obtain the effective coordination number for each polyhedral. It then averages the effective coordination of all polyhedrals with the same cation at the central site.
Parameters:  tol (float) – tolerance parameter for bond determination (default: 1e4).
 cutoff (float) – cutoff radius in Angstrom to look for nearneighbor atoms. Defaults to 10.0.

get_nn_info
(structure, n)[source]¶ Get all nearneighbor sites as well as the associated image locations and weights of the site with index n.
Parameters:  structure (Structure) – input structure.
 n (integer) – index of site for which to determine nearneighbor information.
Returns:  each dictionary provides information
about a single near neighbor, where key ‘site’ gives access to the corresponding Site object, ‘image’ gives the image location, and ‘weight’ provides the weight that a given nearneighbor site contributes to the coordination number (1 or smaller), ‘site_index’ gives index of the corresponding site in the original structure.
Return type: siw (list of dicts)

class
JmolNN
(tol=0.56, min_bond_distance=0.4, el_radius_updates=None)[source]¶ Bases:
pymatgen.analysis.local_env.NearNeighbors
Determine nearneighbor 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.
Parameters:  tol (float) – tolerance parameter for bond determination (default: 0.56).
 el_radius_updates – (dict) symbol>float to override default atomic radii table values

get_max_bond_distance
(el1_sym, el2_sym)[source]¶ Use Jmol algorithm to determine bond length from atomic parameters :param el1_sym: (str) symbol of atom 1 :param el2_sym: (str) symbol of atom 2
Returns: (float) max bond length

get_nn_info
(structure, n)[source]¶ Get all nearneighbor sites as well as the associated image locations and weights of the site with index n using the bond identification algorithm underlying Jmol.
Parameters:  structure (Structure) – input structure.
 n (integer) – index of site for which to determine near neighbors.
Returns:  tuples, each one
of which represents a neighbor site, its image location, and its weight.
Return type: siw (list of tuples (Site, array, float))

class
LocalStructOrderParams
(types, parameters=None, cutoff=10.0)[source]¶ Bases:
object
This class permits the calculation of various types of local structure order parameters.
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 recognize following environments:
 ”cn”: simple coordination number—normalized
 if desired;
”sgl_bd”: single bonds; “bent”: bent (angular) coordinations
(Zimmermann & Jain, in progress, 2017);”T”: Tshape coordinations; “see_saw_rect”: see sawlike coordinations; “tet”: tetrahedra
(Zimmermann et al., submitted, 2017); ”oct”: octahedra
 (Zimmermann et al., submitted, 2017);
 ”bcc”: bodycentered cubic environments (Peters,
 Chem. Phys., 131, 244103, 2009);
”tri_plan”: trigonal planar environments; “sq_plan”: square planar environments; “pent_plan”: pentagonal planar environments; “tri_pyr”: trigonal pyramids (coordinated atom is in
the center of the basal plane);”sq_pyr”: square pyramids; “pent_pyr”: pentagonal pyramids; “hex_pyr”: hexagonal pyramids; “tri_bipyr”: trigonal bipyramids; “sq_bipyr”: square bipyramids; “pent_bipyr”: pentagonal bipyramids; “hex_bipyr”: hexagonal bipyramids; “cuboct”: cuboctahedra; “q2”: motifunspecific 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. “reg_tri”: regular triangle with varying height
to basal plane;”sq”: square coordination (cf., “reg_tri”); “oct_legacy”: original Petersstyle OP recognizing
octahedral coordination environments (Zimmermann et al., J. Am. Chem. Soc., 137, 1335213361, 2015) that can, however, produce small negative values sometimes.”sq_pyr_legacy”: square pyramids (legacy);
 parameters ([dict]) –
list of dictionaries that store floattype parameters associated with the definitions of the different order parameters (length of list = number of OPs). If an entry is None, default values are used that are read from the op_params.yaml file. With few exceptions, 9 different parameters are used across all OPs:
 ”norm”: normalizing constant (used in “cn”
 (default value: 1)).
 ”TA”: target angle (TA) in fraction of 180 degrees
 (“bent” (1), “tet” (0.6081734479693927), “tri_plan” (0.66666666667), “pent_plan” (0.6), “sq_pyr_legacy” (0.5)).
 ”IGW_TA”: inverse Gaussian width (IGW) for penalizing
 angles away from the target angle in inverse fractions of 180 degrees to (“bent” and “tet” (15), “tri_plan” (13.5), “pent_plan” (18), “sq_pyr_legacy” (30)).
 ”IGW_EP”: IGW for penalizing angles away from the
 equatorial plane (EP) at 90 degrees (“T”, “see_saw_rect”, “oct”, “sq_plan”, “tri_pyr”, “sq_pyr”, “pent_pyr”, “hex_pyr”, “tri_bipyr”, “sq_bipyr”, “pent_bipyr”, “hex_bipyr”, and “oct_legacy” (18)).
 ”fac_AA”: factor applied to azimuth angle (AA) in cosine
 term (“T”, “tri_plan”, and “sq_plan” (1), “tet”, “tri_pyr”, and “tri_bipyr” (1.5), “oct”, “sq_pyr”, “sq_bipyr”, and “oct_legacy” (2), “pent_pyr” and “pent_bipyr” (2.5), “hex_pyr” and “hex_bipyr” (3)).
 ”exp_cos_AA”: exponent applied to cosine term of AA
 (“T”, “tet”, “oct”, “tri_plan”, “sq_plan”, “tri_pyr”, “sq_pyr”, “pent_pyr”, “hex_pyr”, “tri_bipyr”, “sq_bipyr”, “pent_bipyr”, “hex_bipyr”, and “oct_legacy” (2)).
 ”min_SPP”: smallest angle (in radians) to consider
 a neighbor to be at South pole position (“see_saw_rect”, “oct”, “bcc”, “sq_plan”, “tri_bipyr”, “sq_bipyr”, “pent_bipyr”, “hex_bipyr”, “cuboct”, and “oct_legacy” (2.792526803190927)).
 ”IGW_SPP”: IGW for penalizing angles away from South
 pole position (“see_saw_rect”, “oct”, “bcc”, “sq_plan”, “tri_bipyr”, “sq_bipyr”, “pent_bipyr”, “hex_bipyr”, “cuboct”, and “oct_legacy” (15)).
 ”w_SPP”: weight for South pole position relative to
 equatorial positions (“see_saw_rect” and “sq_plan” (1), “cuboct” (1.8), “tri_bipyr” (2), “oct”, “sq_bipyr”, and “oct_legacy” (3), “pent_bipyr” (4), “hex_bipyr” (5), “bcc” (6)).
 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_nn method from the VoronoiNN class.

compute_trigonometric_terms
(thetas, phis)[source]¶ ” Computes trigonometric terms that are required to calculate bond orientational order parameters using internal variables.
Parameters:  thetas ([float]) – polar angles of all neighbors in radians.
 phis ([float]) – azimuth angles of all neighbors in radians. The list of 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, indices_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].
 indices_neighs ([int]) – list of indices 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 indices 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 species to be considered when calculating the order parameters of site n; None includes all species of input structure.
Returns: 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”, etc.), this can happen if there is a single neighbor around site n in the structure because that does not permit calculation of angles between multiple neighbors.
Return type: [floats]

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. Returns: parameters of a given OP. Return type: [float]

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: 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: 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: 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. Returns: OP type. Return type: str

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.
Return type: int

num_ops
¶ ” :returns:
 the number of different order parameters that are targeted
 to be calculated.
Return type: int
 types ([string]) –

class
MinimumDistanceNN
(tol=0.1, cutoff=10.0)[source]¶ Bases:
pymatgen.analysis.local_env.NearNeighbors
Determine nearneighbor sites and coordination number using the nearest neighbor(s) at distance, d_min, plus all neighbors within a distance (1 + delta) * d_min, where delta is a (relative) distance tolerance parameter.
Parameters:  tol (float) – tolerance parameter for neighbor identification (default: 0.1).
 cutoff (float) – cutoff radius in Angstrom to look for trial nearneighbor sites (default: 10.0).

get_nn_info
(structure, n)[source]¶ Get all nearneighbor sites as well as the associated image locations and weights of the site with index n using the closest neighbor distancebased method.
Parameters:  structure (Structure) – input structure.
 n (integer) – index of site for which to determine near neighbors.
Returns:  tuples, each one
of which represents a neighbor site, its image location, and its weight.
Return type: siw (list of tuples (Site, array, float))

class
MinimumOKeeffeNN
(tol=0.1, cutoff=10.0)[source]¶ Bases:
pymatgen.analysis.local_env.NearNeighbors
Determine nearneighbor sites and coordination number using the neighbor(s) at closest relative distance, d_min_OKeffee, plus some relative tolerance, where bond valence parameters from O’Keeffe’s bond valence method (J. Am. Chem. Soc. 1991, 32263229) are used to calculate relative distances.
Parameters:  tol (float) – tolerance parameter for neighbor identification (default: 0.1).
 cutoff (float) – cutoff radius in Angstrom to look for trial nearneighbor sites (default: 10.0).

get_nn_info
(structure, n)[source]¶ Get all nearneighbor sites as well as the associated image locations and weights of the site with index n using the closest relative neighbor distancebased method with O’Keeffe parameters.
Parameters:  structure (Structure) – input structure.
 n (integer) – index of site for which to determine near neighbors.
Returns:  tuples, each one
of which represents a neighbor site, its image location, and its weight.
Return type: siw (list of tuples (Site, array, float))

class
MinimumVIRENN
(tol=0.1, cutoff=10.0)[source]¶ Bases:
pymatgen.analysis.local_env.NearNeighbors
Determine nearneighbor sites and coordination number using the neighbor(s) at closest relative distance, d_min_VIRE, plus some relative tolerance, where atom radii from the ValenceIonicRadiusEvaluator (VIRE) are used to calculate relative distances.
Parameters:  tol (float) – tolerance parameter for neighbor identification (default: 0.1).
 cutoff (float) – cutoff radius in Angstrom to look for trial nearneighbor sites (default: 10.0).

get_nn_info
(structure, n)[source]¶ Get all nearneighbor sites as well as the associated image locations and weights of the site with index n using the closest relative neighbor distancebased method with VIRE atomic/ionic radii.
Parameters:  structure (Structure) – input structure.
 n (integer) – index of site for which to determine near neighbors.
Returns:  tuples, each one
of which represents a neighbor site, its image location, and its weight.
Return type: siw (list of tuples (Site, array, float))

class
NearNeighbors
[source]¶ Bases:
object
Base class to determine near neighbors that typically include nearest neighbors and others that are within some tolerable distance.

get_all_nn_info
(structure)[source]¶ Get a listing of all neighbors for all sites in a structure
Parameters: structure (Structure) – Input structure Returns:  List of NN site information for each site in the structure. Each
 entry has the same format as get_nn_info

get_bonded_structure
(structure, decorate=False)[source]¶ Obtain a StructureGraph object using this NearNeighbor class. Requires the optional dependency networkx (pip install networkx).
Parameters:  structure – Structure object.
 decorate (bool) – whether to annotate site properties
 order parameters using neighbors determined by (with) –
 NearNeighbor class (this) –
Returns: a pymatgen.analysis.graphs.BondedStructure object

get_cn
(structure, n, use_weights=False)[source]¶ Get coordination number, CN, of site with index n in structure.
Parameters:  structure (Structure) – input structure.
 n (integer) – index of site for which to determine CN.
 use_weights (boolean) – flag indicating whether (True) to use weights for computing the coordination number or not (False, default: each coordinated site has equal weight).
Returns: coordination number.
Return type: cn (integer or float)

get_cn_dict
(structure, n, use_weights=False)[source]¶ Get coordination number, CN, of each element bonded to site with index n in structure
Parameters:  structure (Structure) – input structure
 n (integer) – index of site for which to determine CN.
 use_weights (boolean) – flag indicating whether (True) to use weights for computing the coordination number or not (False, default: each coordinated site has equal weight).
Returns: dictionary of CN of each element bonded to site
Return type: cn (dict)

get_local_order_parameters
(structure, n)[source]¶ Calculate those local structure order parameters for the given site whose ideal CN corresponds to the underlying motif (e.g., CN=4, then calculate the square planar, tetrahedral, seesawlike, rectangular seesawlike order paramters).
Parameters:  structure – Structure object
 n (int) – site index.
 Returns (Dict[str, float]):
 A dict of order parameters (values) and the underlying motif type (keys; for example, tetrahedral).

get_nn
(structure, n)[source]¶ Get near neighbors of site with index n in structure.
Parameters:  structure (Structure) – input structure.
 n (integer) – index of site in structure for which to determine neighbors.
Returns: near neighbors.
Return type: sites (list of Site objects)

get_nn_images
(structure, n)[source]¶ Get image location of all near neighbors of site with index n in structure.
Parameters:  structure (Structure) – input structure.
 n (integer) – index of site for which to determine the image location of near neighbors.
Returns:  image locations of
near neighbors.
Return type: images (list of 3D integer array)

get_nn_info
(structure, n)[source]¶ Get all nearneighbor sites as well as the associated image locations and weights of the site with index n.
Parameters:  structure (Structure) – input structure.
 n (integer) – index of site for which to determine nearneighbor information.
Returns:  each dictionary provides information
about a single near neighbor, where key ‘site’ gives access to the corresponding Site object, ‘image’ gives the image location, and ‘weight’ provides the weight that a given nearneighbor site contributes to the coordination number (1 or smaller), ‘site_index’ gives index of the corresponding site in the original structure.
Return type: siw (list of dicts)

get_nn_shell_info
(structure, site_idx, shell)[source]¶ Get a certain nearest neighbor shell for a certain site.
Determines all nonbacktracking paths through the neighbor network computed by get_nn_info. The weight is determined by multiplying the weight of the neighbor at each hop through the network. For example, a 2ndnearestneighbor that has a weight of 1 from its 1stnearestneighbor and weight 0.5 from the original site will be assigned a weight of 0.5.
As this calculation may involve computing the nearest neighbors of atoms multiple times, the calculation starts by computing all of the neighbor info and then calling _get_nn_shell_info. If you are likely to call this method for more than one site, consider calling get_all_nn first and then calling this protected method yourself.
Parameters:  structure (Structure) – Input structure
 site_idx (int) – index of site for which to determine neighbor information.
 shell (int) – Which neighbor shell to retrieve (1 == 1st NN shell)
Returns:  list of dictionaries. Each entry in the list is information about
a certain neighbor in the structure, in the same format as get_nn_info.

get_weights_of_nn_sites
(structure, n)[source]¶ Get weight associated with each near neighbor of site with index n in structure.
Parameters:  structure (Structure) – input structure.
 n (integer) – index of site for which to determine the weights.
Returns: nearneighbor weights.
Return type: weights (list of floats)


class
OpenBabelNN
(order=True)[source]¶ Bases:
pymatgen.analysis.local_env.NearNeighbors
Determine nearneighbor sites and bond orders using OpenBabel API.
NOTE: This strategy is only appropriate for molecules, and not for structures.
Parameters:  order (bool) – True if bond order should be returned as a weight, False
 bond length should be used as a weight. (if) –

get_bonded_structure
(structure, decorate=False)[source]¶ Obtain a MoleculeGraph object using this NearNeighbor class. Requires the optional dependency networkx (pip install networkx).
Parameters:  structure – Molecule object.
 decorate (bool) – whether to annotate site properties
 order parameters using neighbors determined by (with) –
 NearNeighbor class (this) –
Returns: a pymatgen.analysis.graphs.MoleculeGraph object

get_nn_info
(structure, n)[source]¶ Get all nearneighbor sites and weights (orders) of bonds for a given atom.
Parameters:  molecule – input Molecule.
 n – index of site for which to determine near neighbors.
Returns: [dict] representing a neighboring site and the type of
bond present between site n and the neighboring site.

get_nn_shell_info
(structure, site_idx, shell)[source]¶ Get a certain nearest neighbor shell for a certain site.
Determines all nonbacktracking paths through the neighbor network computed by get_nn_info. The weight is determined by multiplying the weight of the neighbor at each hop through the network. For example, a 2ndnearestneighbor that has a weight of 1 from its 1stnearestneighbor and weight 0.5 from the original site will be assigned a weight of 0.5.
As this calculation may involve computing the nearest neighbors of atoms multiple times, the calculation starts by computing all of the neighbor info and then calling _get_nn_shell_info. If you are likely to call this method for more than one site, consider calling get_all_nn first and then calling this protected method yourself.
Parameters:  structure (Molecule) – Input structure
 site_idx (int) – index of site for which to determine neighbor information.
 shell (int) – Which neighbor shell to retrieve (1 == 1st NN shell)
Returns:  list of dictionaries. Each entry in the list is information about
a certain neighbor in the structure, in the same format as get_nn_info.

class
ValenceIonicRadiusEvaluator
(structure)[source]¶ Bases:
object
Computes site valences and ionic radii for a structure using bond valence analyzer
Parameters: structure – pymatgen.core.structure.Structure 
radii
¶ List of ionic radii of elements in the order of sites.

structure
¶ Returns oxidation state decorated structure.

valences
¶ List of oxidation states of elements in the order of sites.


class
VoronoiNN
(tol=0, targets=None, cutoff=13.0, allow_pathological=False, weight='solid_angle', extra_nn_info=True, compute_adj_neighbors=True)[source]¶ Bases:
pymatgen.analysis.local_env.NearNeighbors
Uses a Voronoi algorithm to determine near neighbors for each site in a structure.
Parameters:  tol (float) – tolerance parameter for nearneighbor finding. Faces that are smaller than tol fraction of the largest face are not included in the tessellation. (default: 0).
 targets (Element or list of Elements) – target element(s).
 cutoff (float) – cutoff radius in Angstrom to look for nearneighbor atoms. Defaults to 13.0.
 allow_pathological (bool) – whether to allow infinite vertices in determination of Voronoi coordination.
 weight (string) – available in get_voronoi_polyhedra)
 extra_nn_info (bool) –
 compute_adj_neighbors (bool) – for faster performance

get_all_nn_info
(structure)[source]¶ Get a listing of all neighbors for all sites in a structure
Parameters: structure (Structure) – Input structure Returns:  List of NN site information for each site in the structure. Each
 entry has the same format as get_nn_info

get_all_voronoi_polyhedra
(structure)[source]¶ Get the Voronoi polyhedra for all site in a simulation cell
Parameters: structure (Structure) – Structure to be evaluated Returns: A dict of sites sharing a common Voronoi facet with the site n mapped to a directory containing statistics about the facet:  solid_angle  Solid angle subtended by face
 angle_normalized  Solid angle normalized such that the
 faces with the largest
 area  Area of the facet
 face_dist  Distance between site n and the facet
 volume  Volume of Voronoi cell for this face
 n_verts  Number of vertices on the facet

get_nn_info
(structure, n)[source]¶ ” Get all nearneighbor sites as well as the associated image locations and weights of the site with index n in structure using Voronoi decomposition.
Parameters:  structure (Structure) – input structure.
 n (integer) – index of site for which to determine nearneighbor sites.
Returns:  tuples, each one
of which represents a coordinated site, its image location, and its weight.
Return type: siw (list of tuples (Site, array, float))

get_voronoi_polyhedra
(structure, n)[source]¶ Gives a weighted polyhedra around a site.
See ref: A Proposed Rigorous Definition of Coordination Number, M. O’Keeffe, Acta Cryst. (1979). A35, 772775
Parameters:  structure (Structure) – structure for which to evaluate the coordination environment.
 n (integer) – site index.
Returns: A dict of sites sharing a common Voronoi facet with the site n mapped to a directory containing statistics about the facet:
 solid_angle  Solid angle subtended by face
 angle_normalized  Solid angle normalized such that the
 faces with the largest
 area  Area of the facet
 face_dist  Distance between site n and the facet
 volume  Volume of Voronoi cell for this face
 n_verts  Number of vertices on the facet

calculate_weighted_avg
(bonds)[source]¶ Returns the weighted average bond length given by Hoppe’s effective coordination number formula.
Parameters:  bonds (list) – list of floats that are the
 distances between a cation and its (bond) –
 ions (peripheral) –

get_neighbors_of_site_with_index
(struct, n, approach='min_dist', delta=0.1, cutoff=10.0)[source]¶ Returns the neighbors of a given site using a specific neighborfinding method.
Parameters:  struct (Structure) – input structure.
 n (int) – index of site in Structure object for which motif type is to be determined.
 approach (str) – type of neighborfinding approach, where “min_dist” will use the MinimumDistanceNN class, “voronoi” the VoronoiNN class, “min_OKeeffe” the MinimumOKeeffe class, and “min_VIRE” the MinimumVIRENN class.
 delta (float) – tolerance involved in neighbor finding.
 cutoff (float) – (large) radius to find tentative neighbors.
Returns: neighbor sites.

get_okeeffe_distance_prediction
(el1, el2)[source]¶ Returns an estimate of the bond valence parameter (bond length) using the derived parameters from ‘Atoms Sizes and Bond Lengths in Molecules and Crystals’ (O’Keeffe & Brese, 1991). The estimate is based on two experimental parameters: r and c. The value for r is based off radius, while c is (usually) the AllredRochow electronegativity. Values used are not generated from pymatgen, and are found in ‘okeeffe_params.json’.
Parameters: el2 (el1,) – two Element objects Returns: a float value of the predicted bond length

get_okeeffe_params
(el_symbol)[source]¶ Returns the elemental parameters related to atom size and electronegativity which are used for estimating bondvalence parameters (bond length) of pairs of atoms on the basis of data provided in ‘Atoms Sizes and Bond Lengths in Molecules and Crystals’ (O’Keeffe & Brese, 1991).
Parameters: el_symbol (str) – element symbol. Returns:  atomsize (‘r’) and electronegativityrelated (‘c’)
 parameter.
Return type: (dict)

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

site_is_of_motif_type
(struct, n, approach='min_dist', delta=0.1, cutoff=10.0, thresh=None)[source]¶ Returns the motif type of the site with index n in structure struct; currently featuring “tetrahedral”, “octahedral”, “bcc”, and “cp” (closepacked: fcc and hcp) as well as “square pyramidal” and “trigonal bipyramidal”. If the site is not recognized, “unrecognized” is returned. If a site should be assigned to two different motifs, “multiple assignments” is returned.
Parameters:  struct (Structure) – input structure.
 n (int) – index of site in Structure object for which motif type is to be determined.
 approach (str) – type of neighborfinding approach, where “min_dist” will use the MinimumDistanceNN class, “voronoi” the VoronoiNN class, “min_OKeeffe” the MinimumOKeeffe class, and “min_VIRE” the MinimumVIRENN class.
 delta (float) – tolerance involved in neighbor finding.
 cutoff (float) – (large) radius to find tentative neighbors.
 thresh (dict) – thresholds for motif criteria (currently, required keys and their default values are “qtet”: 0.5, “qoct”: 0.5, “qbcc”: 0.5, “q6”: 0.4).
Returns: motif type (str).

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.
Returns: The solid angle.

vol_tetra
(vt1, vt2, vt3, vt4)[source]¶ Calculate the volume of a tetrahedron, given the four vertices of vt1, vt2, vt3 and vt4. :param vt1: coordinates of vertex 1. :type vt1: arraylike :param vt2: coordinates of vertex 2. :type vt2: arraylike :param vt3: coordinates of vertex 3. :type vt3: arraylike :param vt4: coordinates of vertex 4. :type vt4: arraylike
Returns: volume of the tetrahedron. Return type: (float)