nqr-blochsimulator/src/nqr_blochsimulator/classes/sample.py

103 lines
3.6 KiB
Python
Raw Normal View History

2023-08-22 14:06:38 +00:00
from math import pi, sqrt
class Sample:
"""
A class to represent a sample for NQR (Nuclear Quadrupole Resonance) Bloch Simulation.
"""
avogadro = 6.022e23
def __init__(
self,
name,
density,
molar_mass,
resonant_frequency,
gamma,
nuclear_spin,
spin_factor,
powder_factor,
filling_factor,
T1,
T2,
T2_star,
atom_density=None,
sample_volume=None,
sample_length=None,
2023-08-23 14:47:41 +00:00
sample_diameter=None,
2023-08-22 14:06:38 +00:00
):
"""
Constructs all the necessary attributes for the sample object.
Parameters
----------
name : str
The name of the sample.
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).
resonant_frequency : float
2024-06-02 18:31:51 +00:00
The resonant frequency of the sample in MHz.
2023-08-22 14:06:38 +00:00
gamma : float
2024-06-02 18:31:51 +00:00
The gamma value of the sample in MHz/T.
2023-08-22 14:06:38 +00:00
nuclear_spin : float
The nuclear spin quantum number of the sample.
spin_factor : float
The spin factor of the sample.
powder_factor : float
The powder factor of the sample.
filling_factor : float
The filling factor of the sample.
T1 : float
2024-06-02 18:31:51 +00:00
The spin-lattice relaxation time of the sample in microseconds.
2023-08-22 14:06:38 +00:00
T2 : float
2024-06-02 18:31:51 +00:00
The spin-spin relaxation time of the sample in microseconds.
2023-08-22 14:06:38 +00:00
T2_star : float
2024-06-02 18:31:51 +00:00
The effective spin-spin relaxation time of the sample in microseconds.
2023-08-22 14:06:38 +00:00
atom_density : float, optional
The atom density of the sample (atoms per cm^3). By default None.
sample_volume : float, optional
The volume of the sample (m^3). By default None.
sample_length : float, optional
2024-06-02 18:31:51 +00:00
The length of the sample (mm). By default None.
sample_diameter : float, optional
2024-06-02 18:31:51 +00:00
The diameter of the sample m(m). By default None.
2023-08-22 14:06:38 +00:00
"""
self.name = name
self.density = density
self.molar_mass = molar_mass
2024-06-02 18:31:51 +00:00
self.resonant_frequency = resonant_frequency * 1e6
self.gamma = gamma * 1e6
2023-08-22 14:06:38 +00:00
self.nuclear_spin = nuclear_spin
self.spin_factor = spin_factor
self.powder_factor = powder_factor
self.filling_factor = filling_factor
2024-06-02 18:31:51 +00:00
self.T1 = T1 * 1e-6
self.T2 = T2 * 1e-6
self.T2_star = T2_star * 1e-6
2023-08-22 14:06:38 +00:00
self.atom_density = atom_density
self.sample_volume = sample_volume
self.sample_length = sample_length
self.sample_diameter = sample_diameter
2023-08-22 14:06:38 +00:00
self.calculate_atoms()
def calculate_atoms(self):
"""
Calculate the number of atoms in the sample per volume unit. This only works if the sample volume and atom density are provided.
Also the sample should be cylindrical.
2023-08-22 14:06:38 +00:00
If atom density and sample volume are provided, use these to calculate the number of atoms.
If not, use Avogadro's number, density, and molar mass to calculate the number of atoms.
"""
if self.atom_density and self.sample_volume:
self.atoms = (
self.atom_density
* self.sample_volume
/ 1e-6
/ (self.sample_volume * self.sample_length / self.sample_diameter)
2023-08-22 14:06:38 +00:00
)
else:
self.atoms = self.avogadro * self.density / self.molar_mass