mirror of
https://github.com/nqrduck/nqr-blochsimulator.git
synced 2024-09-29 08:30:35 +00:00
94 lines
3 KiB
Python
94 lines
3 KiB
Python
|
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,
|
||
|
):
|
||
|
"""
|
||
|
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
|
||
|
The resonant frequency of the sample.
|
||
|
gamma : float
|
||
|
The gamma value of the sample.
|
||
|
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
|
||
|
The spin-lattice relaxation time of the sample.
|
||
|
T2 : float
|
||
|
The spin-spin relaxation time of the sample.
|
||
|
T2_star : float
|
||
|
The effective spin-spin relaxation time of the sample.
|
||
|
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.
|
||
|
"""
|
||
|
self.name = name
|
||
|
self.density = density
|
||
|
self.molar_mass = molar_mass
|
||
|
self.resonant_frequency = resonant_frequency
|
||
|
self.gamma = gamma
|
||
|
self.nuclear_spin = nuclear_spin
|
||
|
self.spin_factor = spin_factor
|
||
|
self.powder_factor = powder_factor
|
||
|
self.filling_factor = filling_factor
|
||
|
self.T1 = T1
|
||
|
self.T2 = T2
|
||
|
self.T2_star = T2_star
|
||
|
self.atom_density = atom_density
|
||
|
self.sample_volume = sample_volume
|
||
|
self.calculate_atoms()
|
||
|
|
||
|
def calculate_atoms(self):
|
||
|
"""
|
||
|
Calculate the number of atoms in the sample per volume unit.
|
||
|
|
||
|
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 * 6 / 3)
|
||
|
)
|
||
|
else:
|
||
|
self.atoms = self.avogadro * self.density / self.molar_mass
|