Utilities
Physical Constants
SimOS provides a series of physical constants that are commonly required in spin dynamics simulations.
- c = 299792458
Speed of light (CODATA 2018)
- elementary_charge = 1.602176634e-19
Elementary charge (CODATA 2018)
- ge = 2.00231930436256
g factor electron (CODATA 2018)
- hbar = 1.054571817e-34
Planck’s constant (CODATA 2018)
- kB = 1.380649e-23
Boltzman constant (CODATA 2018)
- magic_angle = np.float64(0.9553166181245092)
Magic angle in radians
- me = 9.1093837015e-31
electron mass (CODATA 2018)
- mub = 9.2740100783e-24
Bohr magneton (CODATA 2018)
- munuc = 5.0507837461e-27
Nuclear magneton (CODATA 2018)
- u = 1.6605390666e-27
Atomic mass u (CODATA 2018)
- yH1_H20 = 267515315.1
Gyromagn. ratio 1H in H20 (CODATA 2018)
- ye = -176085963023.0
Electron gyromagn. ratio (CODATA 2018)
Gyromagnetic Ratios
We offer a complete list of gyromagnetic ratios (any nucleus that is reasonably stable is included). Our list can also be accessed on a separate webpage.
Trivial Conversion Functions
SimOS further provides a series of trivial conversion functions that can help in making your code more readable.
- cart2spher(*args, rad=True)[source]
Transforms cartesian into spherical coordinates.
- Parameters:
*args –
A single or multiple sets of cartesian x, y, z coordinates. Coordinates can be provided as a single argument, i.e. [x, y, z] or [[x1,y1,z1], [x2,y2,z2]] or as three separate arguments, i.e. x, y, z or [x1, x2], [y1, y2], [z1, z2]
- Returns:
The corresponding spherical coordinates.
- deg2rad(angle)[source]
Takes an angle in degrees and returns it in radians.
- Parameters:
angle – A single angle or a list, tuple or numpy array of angles in degrees.
- Returns:
The angle in radians.
- efield(*args, eps_rel=1, mode='cart')[source]
Calculates the electric field of individual charges as well as total electric field in [V/m] Vectorized.
- f2w(freq)[source]
Takes a frequency and returns the corresponding angular frequency.
- Parameters:
freq – A single frequency or a list, tuple or a numpy array of frequencies.
- Returns:
The corresponding angular frequency.
- flatten(S)[source]
Flattens a nested list of lists, i.e. makes a single list out of it.
- Parameters:
S (list) – A nested list of lists.
- Returns:
The flattened list.
- fuse_dictionaries(*args)[source]
Fuses dictionaries into a single dictionary.
- Parameters:
*args –
A list of dictionaries or a series of dictionary arguments:
- Returns:
A single, fused dictionary.
- mafm(T_in, f)[source]
Takes a given time and rounds the value to the multiples of the period of a given frequency
:param T_in : Time, scalar or array :param f: Frequency (cycles) to take for the rounding
- parse_state_string(s)[source]
Parse a string which desribes a state of a given system into a dictionary of spin name (key) and projected spin value (value). :param str s: A string which describes the state. :returns: The parsed dictionary.
- rad2deg(angle)[source]
Takes an angle in radians and returns it in degrees.
- Parameters:
angle – A single angle or a list, tuple or numpy array of angles in radians.
- Returns:
The angle in degrees.
- rotate_matrix(mat, *args, inverse=False, **kwargs)[source]
Rotates a matrix by applying a “sandwich product” with a rotation matrix. The rotation matrix can be specified using a scipy Rotation object, a sympy Quaternion object or three euler angles.
Do not use this routine for quantum objects. Use .transform() or rotate_operator() instead.
- Parameters:
mat – Input matrix.
*args –
Rotation descripton: * Scipy Rotation object (scipy.spatial.transform.Rotation) * 3 euler angles. If euler angles are provided, the keyword argument convention=… must be given (e.g. convention=”zyx”). * sympy Quaternion object (sympy.quaternion.Quaternion)
- Keyword Arguments:
- inverse (‘’bool’’) – If True, rotation is inverted.
convention (‘’bool’’) – e.g. “zyz” or “zxy”, only required if euler angles are provided, axes convention.
- Example:
>>> rotate_matrix([[0,0,0],[1,0,0],[0,0,0]], np.pi/2, 0, 0, convention = "zxy") >>> R = Rotation.from_euler("zxy", [np.pi/2, 0, 0]) >>> rotate_matrix([[0,0,0],[1,0,0],[0,0,0]], R)
- Returns:
The rotated matrix.
- spher2cart(*args, rad=True)[source]
Transforms spherical into cartesian coordinates.
- Parameters:
*args –
A single or multiple sets of spherical coordinates r, theta, phi. Coordinates can be provided as a single argument, i.e. [r, theta, phi] or [[r1,theta1,phi1], [r2,theta2,phi2]] or as three separate arguments, i.e. r, theta, phi or [r1, r2], [theta1, theta2], [phi1 , phi2].
- Returns:
The corresponding cartesian coordinates.
- totalflatten(S)[source]
Flattens nestest lists and tuples into a single, flat list.
- Parameters:
S (list) – A nested list or tuples of lists and/or tuples.
- Returns:
The flattened list.