pymatgen.analysis.magnetism.analyzer module

class CollinearMagneticStructureAnalyzer(structure: pymatgen.core.structure.Structure, overwrite_magmom_mode: Union[pymatgen.analysis.magnetism.analyzer.OverwriteMagmomMode, str] = 'none', round_magmoms: bool = False, detect_valences: bool = False, make_primitive: bool = True, default_magmoms: bool = None, set_net_positive: bool = True, threshold: float = 0.1)[source]

Bases: object

A class which provides a few helpful methods to analyze collinear magnetic structures.

If magnetic moments are not defined, moments will be taken either from default_magmoms.yaml (similar to the default magmoms in MPRelaxSet, with a few extra definitions) or from a specie:magmom dict provided by the default_magmoms kwarg.

Input magmoms can be replaced using the ‘overwrite_magmom_mode’ kwarg. This can be: * “none” to do nothing, * “respect_sign” which will overwrite existing magmoms with

those from default_magmoms but will keep sites with positive magmoms positive, negative magmoms negative and zero magmoms zero,

  • “respect_zeros”, which will give a ferromagnetic structure (all positive magmoms from default_magmoms) but still keep sites with zero magmoms as zero,

  • “replace_all” which will try to guess initial magmoms for all sites in the structure irrespective of input structure (this is most suitable for an initial DFT calculation),

  • “replace_all_if_undefined” is the same as “replace_all” but only if no magmoms are defined in input structure, otherwise it will respect existing magmoms.

  • “normalize” will normalize magmoms to unity, but will respect sign (used for comparing orderings), magmoms < theshold will be set to zero

  • structure – Structure object

  • (str) (overwrite_magmom_mode) – default “none”

  • (int or bool) (round_magmoms) – will round input magmoms to

specified number of decimal places if integer is supplied, if set to a float will try and group magmoms together using a kernel density estimator of provided width, and extracting peaks of the estimator :param detect_valences (bool): if True, will attempt to assign valences to input structure :param make_primitive (bool): if True, will transform to primitive magnetic cell :param default_magmoms (dict): (optional) dict specifying default magmoms :param set_net_positive (bool): if True, will change sign of magnetic moments such that the net magnetization is positive. Argument will be ignored if mode “respect_sign” is used. :param threshold (float): number (in Bohr magnetons) below which magmoms will be rounded to zero, default of 0.1 can probably be increased for many magnetic systems, depending on your application

get_exchange_group_info(symprec=0.01, angle_tolerance=5.0)[source]

Returns the information on the symmetry of the Hamiltonian describing the exchange energy of the system, taking into account relative direction of magnetic moments but not their absolute direction.

This is not strictly accurate (e.g. some/many atoms will have zero magnetic moments), but defining symmetry this way is a useful way of keeping track of distinct magnetic orderings within pymatgen.

  • symprec – same as SpacegroupAnalyzer

  • angle_tolerance – same as SpacegroupAnalyzer


spacegroup_symbol, international_number


Returns a Structure with all magnetic moments positive or zero. :param make_primitive (bool): Return a primitive structure, defaults to True. :return: Structure


Returns a Structure without magnetic moments defined. :param make_primitive (bool): Return a primitive structure, defaults to True. :return: Structure


Returns a Structure with only magnetic atoms present. :return: Structure


Returns a Structure with species decorated with spin values instead of using magmom site properties. :return: Structure


Convenience property, returns True if any non-zero magmoms present. :return:


Convenience property, returns magmoms as a numpy array. :return: np.array


Returns a dict of magnetic species and the magnitude of their associated magmoms. Will return a set if there are multiple magmoms per species.


dict of magnetic species and magmoms


Compares the magnetic orderings of one structure with another. :param other: Structure :return (bool):


Number of magnetic sites present in structure.


return (int)

number_of_unique_magnetic_sites(symprec=0.001, angle_tolerance=5)[source]
  • (float) (angle_tolerance) – same as in SpacegroupAnalyzer

  • (float) – same as in SpacegroupAnalyzer

Return (int)

Number of symmetrically-distinct magnetic sites present

in structure.


Applies heuristics to return a magnetic ordering for a collinear magnetic structure. Result is not guaranteed for correctness. :return: Ordering Enum (‘FiM’ is used as the abbreviation for ferrimagnetic)


Equivalent to Structure.types_of_specie but only returns magnetic species. :return: types of Specie

class MagneticStructureEnumerator(structure, default_magmoms=None, strategies=('ferromagnetic', 'antiferromagnetic'), automatic=True, truncate_by_symmetry=True, transformation_kwargs=None)[source]

Bases: object

Combines MagneticStructureAnalyzer and MagOrderingTransformation to automatically generate a set of transformations for a given structure and produce a list of plausible magnetic orderings.

This class will try generated different collinear magnetic orderings for a given input structure.

If the input structure has magnetic moments defined, it is possible to use these as a hint as to which elements are magnetic, otherwise magnetic elements will be guessed (this can be changed using default_magmoms kwarg).

  • structure – input structure

  • default_magmoms – (optional, defaults provided) dict of

magnetic elements to their initial magnetic moments in µB, generally these are chosen to be high-spin since they can relax to a low-spin configuration during a DFT electronic configuration

strategies: different ordering strategies to use, choose from:

ferromagnetic, antiferromagnetic, antiferromagnetic_by_motif, ferrimagnetic_by_motif and ferrimagnetic_by_species (here, “motif”, means to use a different ordering parameter for symmetry inequivalent sites)

automatic: if True, will automatically choose sensible strategies truncate_by_symmetry: if True, will remove very unsymmetrical

orderings that are likely physically implausible

transformation_kwargs: keyword arguments to pass to

MagOrderingTransformation, to change automatic cell size limits, etc.

available_strategies = ('ferromagnetic', 'antiferromagnetic', 'ferrimagnetic_by_motif', 'ferrimagnetic_by_species', 'antiferromagnetic_by_motif', 'nonmagnetic')
class Ordering[source]

Bases: enum.Enum

An enumeration.

FM = 'FM'
FiM = 'FiM'
NM = 'NM'
Unknown = 'Unknown'
class OverwriteMagmomMode[source]

Bases: enum.Enum

An enumeration.

none = 'none'
normalize = 'normalize'
replace_all = 'replace_all'
respect_sign = 'respect_sign'
respect_zero = 'respect_zeros'
magnetic_deformation(structure_A, structure_B)[source]

Calculates ‘magnetic deformation proxy’, a measure of deformation (norm of finite strain) between ‘non-magnetic’ (non-spin-polarized) and ferromagnetic structures.

Adapted from Bocarsly et al. 2017, doi: 10.1021/acs.chemmater.6b04729

  • structure_A – Structure

  • structure_B – Structure