Changed the way the nuclear spin is defined.

This commit is contained in:
jupfi 2024-06-04 16:25:50 +02:00
parent 83a4889748
commit f0ce8840b7
3 changed files with 25 additions and 12 deletions

View file

@ -13,17 +13,18 @@ class Sample:
def __init__( def __init__(
self, self,
name : str, name : str,
density : float, atoms : float,
molar_mass : float,
resonant_frequency : float, resonant_frequency : float,
gamma : float, gamma : float,
nuclear_spin : float, nuclear_spin : str,
spin_factor : float, spin_factor : float,
powder_factor : float, powder_factor : float,
filling_factor : float, filling_factor : float,
T1 : float, T1 : float,
T2 : float, T2 : float,
T2_star : float, T2_star : float,
density : float,
molar_mass : float,
atom_density=None, atom_density=None,
sample_volume=None, sample_volume=None,
sample_length=None, sample_length=None,
@ -36,16 +37,14 @@ class Sample:
---------- ----------
name : str name : str
The name of the sample. The name of the sample.
density : float atoms : float
The density of the sample (g/m^3 or kg/m^3). The number of atoms in the sample.
molar_mass : float
The molar mass of the sample (g/mol or kg/mol).
resonant_frequency : float resonant_frequency : float
The resonant frequency of the sample in MHz. The resonant frequency of the sample in MHz.
gamma : float gamma : float
The gamma value of the sample in MHz/T. The gamma value of the sample in MHz/T.
nuclear_spin : float nuclear_spin : string
The nuclear spin quantum number of the sample. The nuclear spin quantum number of the sample. Can be half-integer spin.
spin_factor : float spin_factor : float
The spin transition factor of the sample. The spin transition factor of the sample.
powder_factor : float powder_factor : float
@ -58,6 +57,10 @@ class Sample:
The spin-spin relaxation time of the sample in microseconds. The spin-spin relaxation time of the sample in microseconds.
T2_star : float T2_star : float
The effective spin-spin relaxation time of the sample in microseconds. The effective spin-spin relaxation time of the sample in microseconds.
density : float
The density of the sample (g/m^3 or kg/m^3).
molar_mass : float
The molar mass of the sample (g/mol or kg/mol).
atom_density : float, optional atom_density : float, optional
The atom density of the sample (atoms per cm^3). By default None. The atom density of the sample (atoms per cm^3). By default None.
sample_volume : float, optional sample_volume : float, optional
@ -68,6 +71,7 @@ class Sample:
The diameter of the sample m(m). By default None. The diameter of the sample m(m). By default None.
""" """
self.name = name self.name = name
self.atoms = atoms
self.density = density self.density = density
self.molar_mass = molar_mass self.molar_mass = molar_mass
self.resonant_frequency = resonant_frequency * 1e6 self.resonant_frequency = resonant_frequency * 1e6
@ -83,7 +87,10 @@ class Sample:
self.sample_volume = sample_volume self.sample_volume = sample_volume
self.sample_length = sample_length self.sample_length = sample_length
self.sample_diameter = sample_diameter self.sample_diameter = sample_diameter
self.calculate_atoms() if self.atoms == 0:
self.calculate_atoms()
# These are helper methods that are used to calculate different parameters of the sample.
def calculate_atoms(self): def calculate_atoms(self):
""" """
@ -103,6 +110,8 @@ class Sample:
else: else:
self.atoms = self.avogadro * self.density / self.molar_mass self.atoms = self.avogadro * self.density / self.molar_mass
logger.debug(f"Number of atoms in the sample: {self.atoms}")
def pauli_spin_matrices(self, spin): def pauli_spin_matrices(self, spin):
""" """
Generate the spin matrices for a given spin value. Generate the spin matrices for a given spin value.

View file

@ -313,10 +313,13 @@ class Simulation:
""" """
u = 4 * np.pi * 1e-7 # permeability of free space u = 4 * np.pi * 1e-7 # permeability of free space
num, den = self.sample.nuclear_spin.split("/")
nuclear_spin = float(num) / float(den)
magnetization = ( magnetization = (
( (
(self.sample.gamma * 2 * self.sample.atoms) (self.sample.gamma * 2 * self.sample.atoms)
/ (2 * self.sample.nuclear_spin + 1) / (2 * nuclear_spin + 1)
) )
* (h**2 * self.sample.resonant_frequency) * (h**2 * self.sample.resonant_frequency)
/ (Boltzmann * self.temperature) / (Boltzmann * self.temperature)

View file

@ -13,11 +13,12 @@ class TestSimulation(unittest.TestCase):
def setUp(self): def setUp(self):
self.sample = Sample( self.sample = Sample(
"BiPh3", "BiPh3",
atoms=0,
density=1.585e6, # g/m^3 density=1.585e6, # g/m^3
molar_mass=440.3, # g/mol molar_mass=440.3, # g/mol
resonant_frequency=83.56e6, # Hz resonant_frequency=83.56e6, # Hz
gamma=43.42, # MHz/T gamma=43.42, # MHz/T
nuclear_spin= 9 / 2, nuclear_spin= "9/2",
spin_factor=1.94 spin_factor=1.94
powder_factor=0.75, powder_factor=0.75,
filling_factor=0.7, filling_factor=0.7,