Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vatai committed Mar 21, 2024
1 parent 59093c5 commit d547cb3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
12 changes: 6 additions & 6 deletions radicalpy/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def semiclassical_mary(
sim: SemiclassicalSimulation,
num_samples: int,
init_state: State,
ts: NDArray[float],
ts: ArrayLike,
Bs: ArrayLike,
D: float,
J: float,
Expand All @@ -98,12 +98,12 @@ def semiclassical_mary(
M = 16 # number of spin states
trace = np.zeros((num_samples, len(ts)))
mary = np.zeros((len(ts), len(Bs)))
gen = sim.semiclassical_gen2(num_samples)
HHs = sim.semiclassical_HHs(num_samples)

for i, B0 in enumerate(tqdm(Bs)):
Hz = sim.zeeman_hamiltonian(B0)
for j, Hnuc in enumerate(gen):
Ht = Hz + Hnuc
for j, HH in enumerate(HHs):
Ht = Hz + HH
L = sim.convert(Ht)
sim.apply_liouville_hamiltonian_modifiers(L, kinetics + relaxations)
propagator = sp.sparse.linalg.expm(L * dt)
Expand Down Expand Up @@ -161,11 +161,11 @@ def semiclassical_kinetics_mary(
rho_triplet = np.zeros(len(ts), dtype=complex)
radical_pair_yield = np.zeros((1, len(ts)), dtype=complex)
triplet_yield = np.zeros((1, len(ts)), dtype=complex)
gen = sim.semiclassical_gen2(num_samples)
HHs = sim.semiclassical_HHs(num_samples)

for i, B0 in enumerate(tqdm(Bs)):
Hz = sim.zeeman_hamiltonian(B0)
for j, Hnuc in enumerate(gen):
for j, Hnuc in enumerate(HHs):
Ht = Hz + Hnuc
L = sim.convert(Ht)
kinetic_matrix[5:21, 5:21] -= L
Expand Down
27 changes: 6 additions & 21 deletions radicalpy/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,26 +1231,7 @@ def adjust_hamiltonian(self, H: np.ndarray):


class SemiclassicalSimulation(LiouvilleSimulation):
def semiclassical_gen(
self,
num_samples: int,
) -> np.ndarray:
num_particles = len(self.radicals)
spinops = [
[self.spin_operator(ri, ax) for ax in "xyz"] for ri in range(num_particles)
]
result = np.zeros((num_samples, 4, 4), dtype=complex)
for i in range(num_samples):
for ri, m in enumerate(self.molecules):
std = m.semiclassical_std
Is = np.random.normal(0, std, size=1)
gamma = m.radical.gamma_mT
for ax in range(3):
spinop = spinops[ri][ax]
result[i, :, :] += gamma * spinop * Is
return result

def semiclassical_gen2(
def semiclassical_HHs(
self,
num_samples: int,
) -> np.ndarray:
Expand All @@ -1260,7 +1241,11 @@ def semiclassical_gen2(

spinops = np.array([self.spin_operator(0, ax) for ax in "xyz"])
cov = np.diag([m.semiclassical_std for m in self.molecules])
samples = np.random.multivariate_normal([0, 0], cov, size=(num_samples, 3))
samples = np.random.multivariate_normal(
mean=[0, 0],
cov=cov,
size=(num_samples, 3),
)
result = np.einsum("nam,axy->nxy", samples, spinops)
return result * self.radicals[0].gamma_mT

Expand Down

0 comments on commit d547cb3

Please sign in to comment.