Generating the Spin bath

Random bath

Documentation for the pycce.random_bath function, used to generate random bath.

random_bath(names, size, number=1000, density=None, types=None, density_units='cm-3', center=None, seed=None)

Generate random bath containing spins with names provided with argument name in the box of size size. By default generates coordinates in range (-size/2; +size/2) but this behavior can be changed by providing center keyword.

Examples

Generate 2000 \(^{13}\mathrm{C}\) nuclear spins in the cubic box with the side of 100 angstrom:

>>> atoms = random_bath('13C', 100, number=2000, seed=10)
>>> print(atoms.size)
2000
>>> print(round(atoms.x.min()), round(atoms.x.max()))
-50.0 50.0

Generate electron spin bath with density \(10^{17} \mathrm{cm}^{-3}\) in the cuboid box:

>>> electrons = random_bath('e', [1e3, 2e3, 3e3], density=1e17,
>>>                         density_units='cm-3', seed=10)
>>> print(electrons.size, round(electrons.x.min()), round(electrons.x.max()))
600 -494.0 500.0
>>> print(electrons.types)
SpinDict(e: (e, 0.5, -17608.59705))
Parameters
  • names (str or array-like with length n) – Name of the bath spin or array with the names of the bath spins,

  • size (float or ndarray with shape (3,)) – Size of the box. If float is given, assumes 3D cube with the edge = size. Otherwise the size specifies the dimensions of the box. Dimensionality is controlled by setting entries of the size array to 0.

  • number (int or array-like with length n) – Number of the bath spins in the box or array with the numbers of the bath spins. Has to have the same length as the name array.

  • density (float or array-like with length n) – Concentration of the bath spin or array with the concentrations. Has to have the same length as the name array.

  • types (SpinDict) – Dictionary with SpinTypes or input to create one.

  • density_units (str) –

    If number of spins provided as density, defines units. Values are accepted in the format m, or m^x or m-x where m is the length unit, x is dimensionality of the bath (e.g. x = 1 for 1D, 2 for 2D etc). If only m is provided the dimensions are inferred from size argument. Accepted length units:

    • m meters;

    • cm centimeters;

    • a angstroms.

  • center (ndarray with shape (3,)) – Coordinates of the (0, 0, 0) point of the final coordinate system in the initial coordinates. Default is size / 2 - center is in the middle of the box.

Returns

Array of the bath spins with random positions.

Return type

BathArray with shape (np.prod(number))

BathCell

Documentation for the pycce.BathCell - class for convenient generation of BathArray and the necessary helper functions.

class BathCell(a=None, b=None, c=None, alpha=None, beta=None, gamma=None, angle='rad', cell=None)

Generator of the bath spins positions from the unit cell of the material.

Parameters
  • a (float) – a parameter of the primitive cell.

  • b (float) – b parameter of the primitive cell.

  • c (float) – c parameter of the primitive cell.

  • alpha (float) – \(\alpha\) angle of the primitive cell.

  • beta (float) – \(\beta\) angle of the primitive cell.

  • gamma (float) – \(\gamma\) angle of the primitive cell.

  • angle (str) – units of the \(\alpha\), \(\beta\), \(\gamma\) angles. Can be either radians ('rad'), or degrees ('deg').

  • cell (ndarray with shape (3, 3)) –

    Parameters of the cell.

    cell is 3x3 matrix with columns of coordinates of crystallographic vectors in the cartesian reference frame. See cell attribute.

    If provided, overrides a, b, and c.

cell

Parameters of the cell. cell is 3x3 matrix with entries:

\[\begin{split}[&[a_x\ b_x\ c_x]\\ &[a_y\ b_y\ c_y]\\ &[a_z\ b_z\ c_z]]\end{split}\]

where a, b, c are crystallographic vectors and x, y, z are their coordinates in the cartesian reference frame.

Type

ndarray with shape (3, 3)

atoms

Dictionary containing coordinates and occupancy of each lattice site:

{atom_1: [array([x1, y1, z1]), array([x2, y2, z2])],
 atom_2: [array([x3, y3, z3]), ...]}
Type

dict

isotopes

Dictionary containing spin types and their concentration for each lattice site type:

{atom_1: {spin_1: concentration, spin_2: concentration},
 atom_2: {spin_3: concentration ...}}

where atom_i are lattice site types, and spin_i are spin types.

Type

dict

property zdir

z-direction of the reference cartesian coordinate frame in cell coordinates.

Type

ndarray

rotate(rotation_matrix)

Rotate the BathCell using the rotation matrix provided.

Parameters

rotation_matrix (ndarray with shape (3,)) – Rotation matrix R which rotates the old basis of the cartesian reference frame to the new basis.

set_zdir(direction, type='cell')

Set z-direction of the cell.

Parameters
  • direction (ndarray with shape (3,)) – Direction of the z axis.

  • type (str) – How coordinates in direction are stored. If type="cell", assumes crystallographic coordinates. If type="angstrom" assumes that z direction is given in the cartresian reference frame.

add_atoms(*args, type='cell')

Add coordinates of the lattice sites to the unit cell.

Parameters
  • *args (tuple) – List of tuples, each containing the type of atom N (str), and the xyz coordinates in the format (float, float, float): (N, [x, y, z]).

  • type (str) –

    Type of coordinates. Can take values of ['cell', 'angstrom'].

    If type="cell", assumes crystallographic coordinates.

    If type="angstrom" assumes that coordinates are given in the cartresian reference frame.

Returns

View of cell.atoms dictionary, where each key is the type of lattice site, and each value is the list of coordinates in crystallographic frame.

Return type

dict

Examples

>>> cell = BathCell(10)
>>> cell.add_atoms(('C', [0, 0, 0]), ('C', [5, 5, 5]), type='angstrom')
>>> cell.add_atoms(('Si', [0, 0.5, 0.]), type='cell')
>>> print(cell.atoms)
{'C': [array([0., 0., 0.]), array([0.5, 0.5, 0.5])], 'Si': [array([0. , 0.5, 0. ])]}
add_isotopes(*args)

Add spins that can populate each lattice site type.

Parameters

*args (tuple or list of tuples) –

Each tuple can have any of the following formats:

  • Name of the lattice site N (str), name of the spin X (str), concentration c (float, in decimal): (N, X, c).

  • Isotope name X and concentration `c: (X, c).

    In this case, the name of the isotope is given in the format "{}{}".format(digits, atom_name) where digits is any set of digits 0-9, atom_name is the name of the corresponding lattice site. Convenient when generating nuclear spin bath.

Returns

View of cell.isotopes dictionary which contains information about lattice site types, spin types, and their concentrations:

{atom_1: {spin_1: concentration, spin_2: concentration},
 atom_2: {spin_3: concentration ...}}

Return type

dict

Examples

>>> cell = BathCell(10)
>>> cell.add_atoms(('C', [0, 0, 0]), ('C', [5, 5, 5]), type='angstrom')
>>> cell.add_isotopes(('C', 'X', 0.001), ('13C', 0.0107))
>>> print(cell.isotopes)
{'C': {'X': 0.001, '13C': 0.0107}}
gen_supercell(size, add=None, remove=None, seed=None)

Generate supercell populated with spins.

Note

If isotopes were not provided, assumes the natural concentration of nuclear spin isotopes for each lattice site type. However, if any isotope concentration is provided, then uses only user-defined ones.

Parameters
  • size (float) – Approximate linear size of the supercell. The generated supercell will have minimal distance between opposite sides larger than this parameter.

  • add (tuple or list of tuples) – Tuple or list of tuples containing common_isotopes to add as a defect. Each tuple contains name of the new isotope and its coordinates in the cell basis: (isotope_name, x_cell, y_cell, z_cell).

  • remove (tuple or list of tuples) – Tuple or list of tuples containing bath to remove in the defect. Each tuple contains name of the atom to remove and its coordinates in the cell basis: (atom_name, x_cell, y_cell, z_cell).

  • seed (int) – Seed for random number generator.

Note

While add takes the spin name as an argument, remove takes the lattice site name.

Returns

Array of the spins in the given supercell.

Return type

BathArray

to_cartesian(coord)

Transform coordinates from crystallographic basis to the cartesian reference frame.

Parameters

coord (ndarray with shape (3,) or (n, 3)) – Coordinates in crystallographic basis or array of coordinates.

Returns

Cartesian coordinates in angstrom.

Return type

ndarray with shape (3,) or (n, 3)

to_cell(coord)

Transform coordinates from the cartesian coordinates of the reference frame to the cell coordinates.

Parameters

coord (ndarray with shape (3,) or (n, 3)) – Cartesian coordinates in angstrom or array of coordinates.

Returns

Coordinates in the cell basis.

Return type

ndarray with shape (3,) or (n, 3)

classmethod from_ase(atoms_object)

Generate BathCell instance from ase.Atoms object of Atomic Simulations Environment (ASE) package.

Parameters

atoms_object (Atoms) – Atoms object, used to generate new BathCell instance.

Returns

New instance of the BathCell with atoms read from ase.Atoms.

Return type

BathCell

defect(cell, atoms, add=None, remove=None)

Generate a defect in the given supercell.

The defect will be located in the unit cell, located roughly in the middle of the supercell, generated by BathCell, such that (0, 0, 0) of cartesian reference frame is located at (0, 0, 0) position of this unit cell.

Parameters
  • cell (ndarray with shape (3, 3)) – parameters of the unit cell.

  • atoms (BathArray) – Array of spins in the supercell.

  • add (tuple or list of tuples) – Add spin type(s) to the supercell at specified positions to create point defect. Each tuple contains name of the new isotope and its coordinates in the cell basis: (isotope_name, x_cell, y_cell, z_cell).

  • remove (tuple or list of tuples) – Remove lattice site from the supercell at specified position to create point defect. Each tuple contains name of the atom to remove and its coordinates in the cell basis: (atom_name, x_cell, y_cell, z_cell).

Returns

Array of spins with the defect added.

Return type

BathArray

BathArray

Documentation for the pycce.BathArray - central class, containing properties of the bath spins.

class BathArray(shape=None, array=None, names=None, hyperfines=None, quadrupoles=None, types=None, imap=None, ca=None, sn=None, hf=None, q=None, efg=None)

Subclass of ndarray containing information about the bath spins.

The subclass has fixed structured datatype:

_dtype_bath = np.dtype([('N', np.unicode_, 16),
                        ('xyz', np.float64, (3,)),
                        ('A', np.float64, (3, 3)),
                        ('Q', np.float64, (3, 3))])

Accessing different fields results in the ndarray view.

Each of the fields can be accessed as the attribute of the BathArray instance and modified accordingly. In addition to the name fields, the information of the bath spin types is stored in the types attribute. All of the items in types can be accessed as attributes of the BathArray itself.

Examples

Generate empty BathArray instance.

>>> ba = BathArray((3,))
>>> print(ba)
[('', [0., 0., 0.], [[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]], [[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]])
 ('', [0., 0., 0.], [[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]], [[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]])
 ('', [0., 0., 0.], [[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]], [[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]])]

Generate BathArray from the set of arrays:

>>> import numpy as np
>>> ca = np.random.random((3, 3))
>>> sn = ['1H', '2H', '3H']
>>> hf = np.random.random((3, 3, 3))
>>> ba = BathArray(ca=ca, hf=hf, sn=sn)
>>> print(ba.N, ba.types)
['1H' '2H' '3H'] SpinDict(1H: (1H, 0.5, 26.7519), 2H: (2H, 1, 4.1066, 0.00286), 3H: (3H, 0.5, 28.535))

Warning

Due to how structured arrays work, if one uses a boolean array to access an subarray, and then access the name field, the initial array will not change.

Example:

>>> ba = BathArray((10,), sn='1H')
>>> print(ba.N)
['1H' '1H' '1H' '1H' '1H' '1H' '1H' '1H' '1H' '1H']
>>> bool_mask = np.arange(10) % 2 == 0
>>> ba[bool_mask]['N'] = 'e'
>>> print(ba.N)
['1H' '1H' '1H' '1H' '1H' '1H' '1H' '1H' '1H' '1H']

To achieve the desired result, one should first access the name field and only then apply the boolean mask:

>>> ba['N'][bool_mask] = 'e'
>>> print(ba.N)
['e' '1H' 'e' '1H' 'e' '1H' 'e' '1H' 'e' '1H']
Parameters
  • shape (tuple) – Shape of the array.

  • array (array-like) – Either an unstructured array with shape (n, 3) containing coordinates of bath spins as rows OR structured ndarray with the same fields as the datatype of the bath.

  • name (array-like) – Array of the bath spin name.

  • hyperfines (array-like) – Array of the hyperfine tensors with shape (n, 3, 3).

  • quadrupoles (array-like) – Array of the quadrupole tensors with shape (n, 3, 3).

  • efg (array-like) – Array of the electric field gradients with shape (n, 3, 3) for each bath spin. Used to compute Quadrupole tensors for spins >= 1. Requires the spin types either be found in common_isotopes or specified with types argument.

  • types (SpinDict) – SpinDict or input to create one. Contains either SpinTypes of the bath spins or tuples which will initialize those. See pycce.bath.SpinDict documentation for details.

  • imap (InteractionMap) – Instance of InteractionMap containing user defined interaction tensors between bath spins stored in the array.

  • ca (array-like) – Shorthand notation for array argument.

  • sn (array-like) – Shorthand notation for name argument.

  • hf (array-like) – Shorthand notation for hyperfines argument.

  • q (array-like) – Shorthand notation for quadrupoles argument.

sort(axis=- 1, kind=None, order=None)

Sort array in-place. Is implemented only when imap is None. Otherwise use np.sort.

property name

Array of the name attribute for each spin in the array from types dictionary.

Note

While the value of this attribute should be the same as the N field of the BathArray instance, .name should not be used for production as it creates a new array from types dictionary.

Type

ndarray

property s

Array of the spin (spin value) attribute for each spin in the array from types dictionary.

Type

ndarray

property dim

Array of the dim (dimensions of the spin) attribute for each spin in the array from types dictionary.

Type

ndarray

property gyro

Array of the gyro (gyromagnetic ratio) attribute for each spin in the array from types dictionary.

Type

ndarray

property q

Array of the q (quadrupole moment) attribute for each spin in the array from types dictionary.

Type

ndarray

property detuning

Array of the detuning attribute for each spin in the array from types dictionary.

Type

ndarray

property x

Array of x coordinates for each spin in the array (bath['xyz'][:, 0]).

Type

ndarray

property y

Array of y coordinates for each spin in the array (bath['xyz'][:, 1]).

Type

ndarray

property z

Array of z coordinates for each spin in the array (bath['xyz'][:, 2]).

Type

ndarray

property N

Array of name for each spin in the array (bath['N']).

Type

ndarray

property xyz

Array of coordinates for each spin in the array (bath['xyz']).

Type

ndarray

property A

Array of hyperfine tensors for each spin in the array (bath['A']).

Type

ndarray

property Q

Array of quadrupole tensors for each spin in the array (bath['Q']).

Type

ndarray

add_type(*args, **kwargs)

Add spin type to the types dictionary.

Parameters
  • *args – Any number of positional inputs to create SpinDict entries. E.g. the tuples of form (name str, spin float, gyro float, q float).

  • **kwargs – Any number of keyword inputs to create SpinDict entries. E.g. name = (spin, gyro, q).

For details and allowed inputs see SpinDict documentation.

Returns

A view of self.types instance.

Return type

SpinDict

add_interaction(i, j, tensor)

Add interactions tensor between bath spins with indexes i and j.

Note

If called from the subarray this method does not change the tensors of the total BathArray.

Parameters
  • i (int or ndarray (n,)) – Index of the first spin in the pair or array of the indexes of the first spins in n pairs.

  • j (int or ndarray with shape (n,)) – Index of the second spin in the pair or array of the indexes of the second spins in n pairs.

  • tensor (ndarray with shape (3,3) or (n, 3,3)) – Interaction tensor between the spins i and j or array of tensors.

update(ext_bath, error_range=0.2, ignore_isotopes=True, inplace=True)

Update the properties of the spins in the array using data from other BathArray instance. For each spin in ext_bath check whether there is such spin in the array that has the same position within allowed error range given by error_range and has the same name. If such spins is found in the array, then it’s coordinates, hyperfine tensor and quadrupole tensor are updated using the values of the spin in the ext_bath object.

If ignore_isotopes is true, then the name check ignores numbers in the name of the spins.

Parameters
  • ext_bath (BathArray) – Array of the new spins.

  • error_range (float) – +- distance in Angstrom within which two positions are considered to be the same. Default is 0.2 A.

  • ignore_isotopes (bool) – True if ignore numbers in the name of the spins. Default True.

  • inplace (bool) – True if changes parameters of the array in place. If False, returns copy of the array.

Returns

updated BathArray instance.

Return type

BathArray

from_point_dipole(position, gyro_e=- 17608.59705, inplace=True)

Generate hyperfine couplings, assuming that bath spins interaction with central spin is the same as the one between two magnetic point dipoles.

Parameters
  • position (ndarray with shape (3,)) – position of the central spin

  • gyro_e (float or ndarray with shape (3,3)) –

    gyromagnetic ratio of the central spin

    OR

    tensor corresponding to interaction between magnetic field and central spin.

  • inplace (bool) – True if changes parameters of the array in place. If False, returns copy of the array.

Returns

updated BathArray instance with changed hyperfine couplings.

Return type

BathArray

from_cube(cube, gyro_e=- 17608.59705, inplace=True)

Generate hyperfine couplings, assuming that bath spins interaction with central spin can be approximated as a point dipole, interacting with given spin density distribution.

Parameters
  • cube (Cube) – An instance of Cube object, which contains spatial distribution of spin density. For details see documentation of Cube class.

  • gyro_e (float) – Gyromagnetic ratio of the central spin.

  • inplace (bool) – True if changes parameters of the array in place. If False, returns copy of the array.

Returns

Updated BathArray instance with changed hyperfine couplings.

Return type

BathArray

from_func(func, gyro_e=- 17608.59705, vectorized=False, inplace=True)

Generate hyperfine couplings from user-defined function.

Parameters
  • func (func) –

    Callable with signature:

    func(coord, gyro, central_gyro)
    

    where coord is array of the bath spin coordinate, gyro is the gyromagnetic ratio of bath spin, central_gyro is the gyromagnetic ratio of the central bath spin.

  • gyro_e (float) – gyromagnetic ratio of the central spin to be used in the function.

  • vectorized (bool) – If True, assume that func takes arrays of all bath spin coordinates and array of gyromagnetic ratios as arguments.

  • inplace (bool) – True if changes parameters of the array in place. If False, returns copy of the array.

Returns

Updated BathArray instance with changed hyperfine couplings.

Return type

BathArray

from_efg(efg, inplace=True)

Generate quadrupole splittings from electric field gradient tensors for spins >= 1.

Parameters
  • efg (array-like) – Array of the electric field gradients for each bath spin. The data for spins-1/2 should be included but can be any value.

  • inplace (bool) – True if changes parameters of the array in place. If False, returns copy of the array.

Returns

Updated BathArray instance with changed quadrupole tensors.

Return type

BathArray

dist(position=None)

Compute the distance of the bath spins from the given position.

Parameters

position (ndarray with shape (3,)) – Cartesian coordinates of the position from which to compute the distance. Default is (0, 0, 0).

Returns

Array of distances of each bath spin from the given position in angstrom.

Return type

ndarray with shape (n,)

savetxt(filename, fmt='%18.8f', strip_isotopes=False, **kwargs)

Save name of the isotopes and their coordinates to the txt file of xyz format.

Parameters
  • filename (str or file) – Filename or file handle.

  • fmt (str) – Format of the coordinate entry.

  • strip_isotopes (bool) – True if remove numbers from the name of bath spins. Default False.

  • **kwargs – Additional keywords of the numpy.savetxt function.

sort(a, *args, **kwargs)

Return a indexes of an sorted array. Overrides numpy.argsort function.

same_bath_indexes(barray_1, barray_2, error_range=0.2, ignore_isotopes=True)

Find indexes of the same array elements in two BathArray instances.

Parameters
  • barray_1 (BathArray) – First array.

  • barray_2 (BathArray) – Second array.

  • error_range (float) – If distance between positions in two arrays is smaller than error_range they are assumed to be the same.

  • ignore_isotopes (bool) – True if ignore numbers in the name of the spins. Default True.

Returns

tuple containing:

  • ndarray: Indexes of the elements in the first array found in the second.

  • ndarray: Indexes of the elements in the second array found in the first.

Return type

tuple

utilities.rotmatrix(final_vector)

Generate 3D rotation matrix which applied on initial vector will produce vector, aligned with final vector.

Examples

>>> R = rotmatrix([0,0,1], [1,1,1])
>>> R @ np.array([0,0,1])
array([0.577, 0.577, 0.577])
Parameters
  • initial_vector (ndarray with shape(3, )) – Initial vector.

  • final_vector (ndarray with shape (3, )) – Final vector.

Returns

Rotation matrix.

Return type

ndarray with shape (3, 3)

InteractionMap

class InteractionMap(rows=None, columns=None, tensors=None)

Dict-like object containing information about tensor interactions between two spins.

Each key is a tuple of two bath spin indexes.

Parameters
  • rows (array-like with shape (n,)) – Indexes of the bath spins, appearing on the left in the pairwise interaction.

  • columns (array-like with shape (n,)) – Indexes of the bath spins, appearing on the right in the pairwise interaction.

  • tensors (array-like with shape (n, 3, 3)) – Tensors of pairwise interactions between two spins with the indexes in rows and columns.

mapping

Actual dictionary storing the data.

Type

dict

property indexes

Array with the indexes of pairs of bath spins, for which the tensors are stored.

Type

ndarray with shape (n, 2)

shift(start, inplace=True)

Add an offset start to the indexes. If inplace is False, returns the copy of InteractionMap.

Parameters
  • start (int) – Offset in indexes.

  • inplace (bool) – If True, makes changes inplace. Otherwise returns copy of the map.

Returns

Map with shifted indexes.

Return type

InteractionMap

keys()a set-like object providing a view on D’s keys
items()a set-like object providing a view on D’s items
subspace(array)

Get new InteractionMap with indexes readressed from array. Within the subspace indexes are renumbered.

Examples

The subspace of [3,4,7] indexes will contain InteractionMap only within [3,4,7] elements with new indexes [0, 1, 2].

>>> import numpy as np
>>> im = InteractionMap()
>>> im[0, 3] = np.eye(3)
>>> im[3, 7] = np.ones(3)
>>> for k in im: print(k, '\n', im[k],)
(0, 3)
[[1. 0. 0.]
 [0. 1. 0.]
 [0. 0. 1.]]
(3, 7)
 [[1. 1. 1.]
  [1. 1. 1.]
  [1. 1. 1.]]
>>> array = [3, 4, 7]
>>> sim = im.subspace(array)
>>> for k in sim: print(k, '\n', sim[k])
(0, 2)
[[1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]]
Parameters

array (ndarray) – Either bool array containing True for elements within the subspace or array of indexes presented in the subspace.

Returns

The map for the subspace.

Return type

InteractionMap

classmethod from_dict(dictionary, presorted=False)

Generate InteractionMap from the dictionary. :param dictionary: Dictionary with tensors. :type dictionary: dict :param presorted: If true, assumes that the keys in the dictionary were already presorted. :type presorted: bool

Returns

New instance generated from the dictionary.

Return type

InteractionMap

Cube

class Cube(filename)

Class to process the .cube datafiles with spin polarization.

Parameters

filename (str) – Name of the .cube file.

comments

First two lines of the .cube file.

Type

str

origin

Coordinates of the origin in angstrom.

Type

ndarray with shape (3,)

voxel

Parameters of the voxel - unit of the 3D grid in angstrom.

Type

ndarray with shape (3,3)

size

Size of the cube.

Type

ndarray with shape (3,)

atoms

Array of atoms in the cube.

Type

BathArray with shape (n)

data

Data stored in cube.

Type

ndarray with shape (size[0], size[1], size[2]

grid

Coordinates of the points at which data is computed.

Type

ndarray with shape (size[0], size[1], size[2], 3

integral

Data integrated over cube.

Type

float

spin

integral / 2 - total spin.

Type

float

transform(rotmatrix=None, shift=None)

Changes coordinates of the grid. DOES NOT ASSUME PERIODICITY.

Parameters
  • rotmatrix (ndarray with shape (3, 3)) –

    Rotation matrix R:

    \[\begin{split}R = &[n_1^{(1)} n_1^{(2)} n_1^{(3)}]\\ &[n_2^{(1)} n_2^{(2)} n_2^{(3)}]\\ &[n_3^{(1)} n_3^{(2)} n_3^{(3)}]\end{split}\]

    where \(n_i^{(j)}\) corresponds to the coefficient of initial basis vector \(i\) for \(j\) new basis vector:

    \[e'_j = n_1^{(j)} \vec{e}_1 + n_2^{(j)} \vec{e}_2 + n_3^{(j)} \vec{e}_3\]

    In other words, columns of R are coordinates of the new basis in the old basis.

    Given vector in initial basis v = [v1, v2, v3], vector in new basis is given as v’ = R.T @ v.

  • shift (ndarray with shape (3,)) – Shift in the origin of coordinates (in the old basis).

integrate(position, gyro_n, gyro_e=- 17608.59705, spin=None)

Integrate over polarization data, stored in Cube object, to obtain hyperfine dipolar-dipolar tensor.

Parameters
  • position (ndarray with shape (3,) or (n, 3)) – Position of the bath spin at which to compute hyperfine tensor or array of positions.

  • gyro_n (float or ndarray with shape (n,)) – Gyromagnetic ratio of the bath spin or array of the ratios.

  • gyro_e (float) – Gyromagnetic ratio of central spin.

  • spin (float) – Total spin of the central spin. If not given, taken from the integral of the polarization.

Returns

Hyperfine tensor or array of hyperfine tensors.

Return type

ndarray with shape (3, 3) or (n, 3, 3)

SpinDict and SpinType

Documentation for the SpinDict - dict-like class which describes the properties of the different types of the spins in the bath.

class SpinDict(*args, **kwargs)

Wrapper class for dictionary tailored for containing properties of the spin types. Can take np.void or BathArray instances as keys. Every entry is instance of the SpinType.

Each entry of the SpinDict can be initianlized as follows:

  • As a Tuple containing name (optional), spin, gyromagnetic ratio, quadrupole constant (optional) and detuning (optional).

  • As a SpinType instance.

Examples

>>> types = SpinDict()
>>> types['1H'] = ('1H', 1 / 2, 26.7519)
>>> types['2H'] = 1, 4.1066, 0.00286
>>> types['3H'] = SpinType('3H', 1 / 2, 28.535, 0)
>>> print(types)
SpinDict({'1H': (1H, 0.5, 26.7519, 0.0), '2H': (2H, 1, 4.1066, 0.00286), '3H': (3H, 0.5, 28.535, 0)})

If SpinType of the given bath spin is not provided, when requested SpinDict will try to find information about the bath spins in the common_isotopes.

If found, adds an entry to the given SpinDict instance and returns it. Otherwise KeyError is raised.

To initiallize several SpinType entries one can use add_types method.

Parameters
  • *args – Any numbers of arguments which could initialize SpinType instances.

  • **kwargs – Any numbers of keyword arguments which could initialize SpinType instances. For details see SpinDict.add_type method.

add_type(*args, **kwargs)

Add one or several spin types to the spin dictionary.

Parameters
  • *args

    Any numbers of arguments which could initialize SpinType instances. Accepted arguments:

    • Tuple containing name, spin, gyromagnetic ratio, quadrupole constant (optional) and detuning (optional).

    • SpinType instance.

    Can also initialize one instance of SpinType if each argument corresponds to each positional argument necessary to initiallize.

  • **kwargs – Any numbers of keyword arguments which could initialize SpinType instances. Usefull as an alternative for updating the dictionary. for each keyword argument adds an entry to the SpinDict with the same name as keyword.

Examples

>>> types = SpinDict()
>>> types.add_type('1H', 1 / 2, 26.7519)
>>> types.add_type(('1H_det', 1 / 2, 26.7519, 10), ('2H', 1, 4.1066, 0.00286),
>>>                 SpinType('3H', 1 / 2, 28.535, 0), e=(1 / 2, 6.7283, 0))
>>> print(types)
SpinDict(1H: (1H, 0.5, 26.7519), 1H_det: (1H_det, 0.5, 26.7519, 10),
2H: (2H, 1, 4.1066, 0.00286), 3H: (3H, 0.5, 28.535), e: (e, 0.5, 6.7283))
class SpinType(name, s=0.0, gyro=0.0, q=0.0, detuning=0.0)

Class which contains properties of each spin type in the bath.

Parameters
  • name (str) – Name of the bath spin.

  • s (float) –

    Total spin of the bath spin.

    Default 0.

  • gyro (float) –

    Gyromagnetic ratio in rad * kHz / G.

    Default 0.

  • q (float) –

    Quadrupole moment in barn (for s > 1/2).

    Default 0.

  • detuning (float) –

    Energy detuning from the zeeman splitting in kHz, included as an extra \(+\omega \hat S_z\) term in the Hamiltonian, where \(\omega\) is the detuning.

    Default 0.

name

Name of the bath spin.

Type

str

s

Total spin of the bath spin.

Type

float

dim

Spin dimensionality = 2s + 1.

Type

int

gyro

Gyromagnetic ratio in rad/(ms * G).

Type

float

q

Quadrupole moment in barn (for s > 1/2).

Type

float

detuning

Energy detuning from the zeeman splitting in kHz.

Type

float

common_isotopes = SpinDict(1H: (0.5, 26.7522), 2H: (1.0, 4.1066, 0.0029), 3He: (0.5, -20.3789), ...)

An instance of the SpinDict dictionary, containing properties for the most of the common isotopes with nonzero spin. The isotope is considered common if it is stable and has nonzero concentration in nature.

Type

SpinDict

common_concentrations = {element ('H', 'He',...) : { isotope ('1H', '2H', ..) : concentration}}

Nested dict containing natural concentrations of the stable nuclear isotopes.

Type

dict