pymatgen.electronic_structure.core module

This module provides core classes needed by all define electronic structure, such as the Spin, Orbital, etc.

class Magmom(moment, saxis=(0, 0, 1))[source]

Bases: MSONable

New class in active development. Use with caution, feedback is appreciated.

Class to handle magnetic moments. Defines the magnetic moment of a site or species relative to a spin quantization axis. Designed for use in electronic structure calculations.

  • For the general case, Magmom can be specified by a vector, e.g. m = Magmom([1.0, 1.0, 2.0]), and subscripts will work as expected, e.g. m[0] gives 1.0

  • For collinear calculations, Magmom can assumed to be scalar-like, e.g. m = Magmom(5.0) will work as expected, e.g. float(m) gives 5.0

Both of these cases should be safe and shouldn’t give any surprises, but more advanced functionality is available if required.

There also exist useful static methods for lists of magmoms:

  • Magmom.are_collinear(magmoms) - if true, a collinear electronic structure calculation can be safely initialized, with float(Magmom) giving the expected scalar magnetic moment value

  • Magmom.get_consistent_set_and_saxis(magmoms) - for non-collinear electronic structure calculations, a global, consistent spin axis has to be used. This method returns a list of Magmoms which all share a common spin axis, along with the global spin axis.

All methods that take lists of magmoms will accept magmoms either as Magmom objects or as scalars/lists and will automatically convert to a Magmom representation internally.

The following methods are also particularly useful in the context of VASP calculations:

  • Magmom.get_xyz_magmom_with_001_saxis()

  • Magmom.get_00t_magmom_with_xyz_saxis()

See VASP documentation for more information:

  • moment – magnetic moment, supplied as float or list/np.ndarray

  • saxis – spin axis, supplied as list/np.ndarray, parameter will be converted to unit vector (default is [0, 0, 1])


Magmom object

static are_collinear(magmoms) bool[source]

Method checks to see if a set of magnetic moments are collinear with each other. :param magmoms: list of magmoms (Magmoms, scalars or vectors) :return: bool

classmethod from_global_moment_and_saxis(global_moment, saxis)[source]

Convenience method to initialize Magmom from a given global magnetic moment, i.e. magnetic moment with saxis=(0,0,1), and provided saxis.

Method is useful if you do not know the components of your magnetic moment in frame of your desired saxis.

  • global_moment

  • saxis – desired saxis


classmethod from_moment_relative_to_crystal_axes(moment, lattice)[source]

Obtaining a Magmom object from a magnetic moment provided relative to crystal axes.

Used for obtaining moments from magCIF file. :param moment: list of floats specifying vector magmom :param lattice: Lattice :return: Magmom


For internal implementation reasons, in non-collinear calculations VASP prefers:

MAGMOM = 0 0 total_magnetic_moment SAXIS = x y z

to an equivalent:

MAGMOM = x y z SAXIS = 0 0 1

This method returns a Magmom object with magnetic moment [0, 0, t], where t is the total magnetic moment, and saxis rotated as required.

A consistent direction of saxis is applied such that t might be positive or negative depending on the direction of the initial moment. This is useful in the case of collinear structures, rather than constraining assuming t is always positive.



static get_consistent_set_and_saxis(magmoms, saxis=None)[source]

Method to ensure a list of magmoms use the same spin axis. Returns a tuple of a list of Magmoms and their global spin axis.

  • magmoms – list of magmoms (Magmoms, scalars or vectors)

  • saxis – can provide a specific global spin axis


(list of Magmoms, global spin axis) tuple

get_moment(saxis=(0, 0, 1))[source]

Get magnetic moment relative to a given spin quantization axis. If no axis is provided, moment will be given relative to the Magmom’s internal spin quantization axis, i.e. equivalent to Magmom.moment


saxis – (list/numpy array) spin quantization axis


np.ndarray of length 3


If scalar magmoms, moments will be given arbitrarily along z. Used for writing moments to magCIF file.


lattice – Lattice


vector as list of floats

static get_suggested_saxis(magmoms)[source]

This method returns a suggested spin axis for a set of magmoms, taking the largest magnetic moment as the reference. For calculations with collinear spins, this would give a sensible saxis for a ncl calculation.


magmoms – list of magmoms (Magmoms, scalars or vectors)


np.ndarray of length 3


Returns a Magmom in the default setting of saxis = [0, 0, 1] and the magnetic moment rotated as required.



property global_moment[source]

Get the magnetic moment defined in an arbitrary global reference frame.


np.ndarray of length 3

static have_consistent_saxis(magmoms)[source]

This method checks that all Magmom objects in a list have a consistent spin quantization axis. To write MAGMOM tags to a VASP INCAR, a global SAXIS value for all magmoms has to be used. If saxis are inconsistent, can create consistent set with: Magmom.get_consistent_set(magmoms)


magmoms – list of magmoms (Magmoms, scalars or vectors)



property projection[source]

Projects moment along spin quantisation axis. Useful for obtaining collinear approximation for slightly non-collinear magmoms.



class Orbital(value)[source]

Bases: Enum

Enum type for specific orbitals. The indices are basically the order in which the orbitals are reported in VASP and has no special meaning.

dx2 = 8[source]
dxy = 4[source]
dxz = 7[source]
dyz = 5[source]
dz2 = 6[source]
f0 = 12[source]
f1 = 13[source]
f2 = 14[source]
f3 = 15[source]
f_1 = 11[source]
f_2 = 10[source]
f_3 = 9[source]
property orbital_type[source]

Returns OrbitalType of an orbital.

px = 3[source]
py = 1[source]
pz = 2[source]
s = 0[source]
class OrbitalType(value)[source]

Bases: Enum

Enum type for orbital type. Indices are basically the azimuthal quantum number, l.

d = 2[source]
f = 3[source]
p = 1[source]
s = 0[source]
class Spin(value)[source]

Bases: Enum

Enum type for Spin. Only up and down. Usage: Spin.up, Spin.down.

down = -1[source]
up = 1[source]