Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ridme example and changes examples from deadtime to tmin #446

Merged
merged 7 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions examples/advanced/ex_comparing_uncertainties.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@
# Experimental parameters
tau1 = 0.3 # First inter-pulse delay, μs
tau2 = 4.0 # Second inter-pulse delay, μs
deadtime = 0.1 # Acquisition deadtime, μs
tmin = 0.1 # Start time, μs

# Load the experimental data
t,Vexp = dl.deerload(path + file)

# Pre-processing
Vexp = dl.correctphase(Vexp) # Phase correction
Vexp = Vexp/np.max(Vexp) # Rescaling (aesthetic)
t = t + deadtime # Account for deadtime
t = t - t[0] # Account for zerotime
t = t + tmin

# Distance vector
r = np.arange(2,6,0.05) # nm
Expand Down
6 changes: 3 additions & 3 deletions examples/advanced/ex_dipolarpathways_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
# Experimental parameters
tau1 = 0.5 # First inter-pulse delay, μs
tau2 = 3.5 # Second inter-pulse delay, μs
deadtime = 0.1 # Acquisition deadtime, μs
tmin = 0.1 # Start time, μs

# Load the experimental data
t,Vexp = dl.deerload(path + file)

# Pre-processing
Vexp = dl.correctphase(Vexp) # Phase correction
Vexp = Vexp/np.max(Vexp) # Rescaling (aesthetic)
t = t + deadtime # Account for deadtime

t = t - t[0] # Account for zerotime
t = t + tmin
# Construct the distance vector
r = np.arange(2,5,0.05)

Expand Down
5 changes: 3 additions & 2 deletions examples/advanced/ex_extracting_gauss_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
# Experimental parameters
tau1 = 0.3 # First inter-pulse delay, μs
tau2 = 4.0 # Second inter-pulse delay, μs
deadtime = 0.1 # Acquisition deadtime, μs
tmin = 0.1 # Start time, μs

# Load the experimental data
t,Vexp = dl.deerload(path + file)

# Pre-processing
Vexp = dl.correctphase(Vexp) # Phase correction
Vexp = Vexp/np.max(Vexp) # Rescaling (aesthetic)
t = t + deadtime # Account for deadtime
t = t - t[0] # Account for zerotime
t = t + tmin

# Construct the dipolar signal model
r = np.arange(2,6,0.02)
Expand Down
5 changes: 3 additions & 2 deletions examples/advanced/ex_forcefield_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ def forcefield_P(c0,c1,c2,c3):
# Experimental parameters
tau1 = 0.3 # First inter-pulse delay, μs
tau2 = 5.0 # Second inter-pulse delay, μs
deadtime = 0.1 # Acquisition deadtime, μs
tmin = 0.1 # Start time, μs

# Load the experimental data
t,Vexp = dl.deerload(path + file)

# Pre-processing
Vexp = dl.correctphase(Vexp) # Phase correction
Vexp = Vexp/np.max(Vexp) # Rescaling (aesthetic)
t = t + deadtime # Account for deadtime
t = t - t[0] # Account for zerotime
t = t + tmin

# Construct the energy and distance distribution models
forcefield_energymodel = dl.Model(forcefield_energy)
Expand Down
11 changes: 6 additions & 5 deletions examples/advanced/ex_global_twostates_parametric.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# Experimental parameters
tau1 = 0.4 # First inter-pulse delay, μs
tau2 = 4.5 # Second inter-pulse delay, μs
deadtime = 0.2 # Acquisition deadtime, μs
tmin = 0.2 # Start time, μs

Vmodels, ts, Vexps = [], [], []
for file in files:
Expand All @@ -39,10 +39,11 @@
t, Vexp = dl.deerload(path + file)

# Pre-processing
Vexp = dl.correctphase(Vexp) # Phase correction
Vexp = Vexp / np.max(Vexp) # Rescaling (aesthetic)
t = t + deadtime # Account for deadtime

Vexp = dl.correctphase(Vexp) # Phase correction
Vexp = Vexp / np.max(Vexp) # Rescaling (aesthetic)
t = t - t[0] # Account for zerotime
t = t + tmin

# Put the datasets into lists
ts.append(t)
Vexps.append(Vexp)
Expand Down
5 changes: 3 additions & 2 deletions examples/advanced/ex_identifiability_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
# Experimental parameters
tau1 = 0.3 # First inter-pulse delay, μs
tau2 = 4.0 # Second inter-pulse delay, μs
deadtime = 0.1 # Acquisition deadtime, μs
tmin = 0.1 # Start time, μs

# Load the experimental data
t,Vexp = dl.deerload(path + file)

# Pre-processing
Vexp = dl.correctphase(Vexp) # Phase correction
Vexp = Vexp/np.max(Vexp) # Rescaling (aesthetic)
t = t + deadtime # Account for deadtime
t = t - t[0] # Account for zerotime
t = t + tmin

# Truncate the signal
Vexp_truncated = Vexp[t<=2]
Expand Down
4 changes: 2 additions & 2 deletions examples/advanced/ex_long_threespin_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
files = [f'../data/triradical_protein_deer_{dB}dB.DTA' for dB in [0,6,9]]

# Experiment information
t0 = 0.280 # Acquisition deadtime, μs
t0 = 0.280 # Start time, μs
tau1 = 0.40 # First interpulse delay, μs
tau2 = 9.00 # Second interpulse delay, μs

Expand All @@ -34,7 +34,7 @@
t,Vexp, descriptor = dl.deerload(file,full_output=True)
t = t[:-80]
Vexp = Vexp[:-80]
# Adjust the start time
# Adjust the Start time
t = t - t[0] + t0

# Pre-processing
Expand Down
9 changes: 5 additions & 4 deletions examples/advanced/ex_multigauss_fitting_4pdeer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@
# Experimental parameters
tau1 = 0.3 # First inter-pulse delay, μs
tau2 = 4.0 # Second inter-pulse delay, μs
deadtime = 0.1 # Acquisition deadtime, μs
tmin = 0.1 # Start time, μs

# Load the experimental data
t, Vexp = dl.deerload(path + file)

# Pre-processing
Vexp = dl.correctphase(Vexp) # Phase correction
Vexp = Vexp / np.max(Vexp) # Rescaling (aesthetic)
t = t + deadtime # Account for deadtime
Vexp = dl.correctphase(Vexp) # Phase correction
Vexp = Vexp / np.max(Vexp) # Rescaling (aesthetic)
t = t - t[0] # Account for zerotime
t = t + tmin

# Maximal number of Gaussians in the models
Nmax = 5
Expand Down
5 changes: 3 additions & 2 deletions examples/advanced/ex_profileanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
# Experimental parameters
tau1 = 0.3 # First inter-pulse delay, μs
tau2 = 4.0 # Second inter-pulse delay, μs
deadtime = 0.1 # Acquisition deadtime, μs
tmin = 0.1 # Start time, μs

# Load the experimental data
t,Vexp = dl.deerload(path + file)

# Pre-processing
Vexp = dl.correctphase(Vexp) # Phase correction
Vexp = Vexp/np.max(Vexp) # Rescaling (aesthetic)
t = t + deadtime # Account for deadtime
t = t - t[0] # Account for zerotime
t = t + tmin

# Distance vector
r = np.arange(2,5,0.05) # nm
Expand Down
5 changes: 3 additions & 2 deletions examples/basic/ex_bootstrapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@
# Experimental parameters
tau1 = 0.3 # First inter-pulse delay, μs
tau2 = 4.0 # Second inter-pulse delay, μs
deadtime = 0.1 # Acquisition deadtime, μs
tmin = 0.1 # Start time, μs

# Load the experimental data
t,Vexp = dl.deerload(path + file)

# Pre-processing
Vexp = dl.correctphase(Vexp) # Phase correction
Vexp = Vexp/np.max(Vexp) # Rescaling (aesthetic)
t = t + deadtime # Account for deadtime
t = t - t[0] # Account for zerotime
t = t + tmin

# Distance vector
r = np.linspace(2,5,100) # nm
Expand Down
6 changes: 3 additions & 3 deletions examples/basic/ex_fitting_4pdeer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
# Experimental parameters
tau1 = 0.3 # First inter-pulse delay, μs
tau2 = 4.0 # Second inter-pulse delay, μs
deadtime = 0.1 # Acquisition deadtime, μs
tmin = 0.1 # Start time, μs

# Load the experimental data
t,Vexp = dl.deerload(path + file)

# Pre-processing
Vexp = dl.correctphase(Vexp) # Phase correction
Vexp = Vexp/np.max(Vexp) # Rescaling (aesthetic)
t = t + deadtime # Account for deadtime

t = t - t[0] # Account for zerotime
t = t + tmin
# Distance vector
r = np.arange(2.5,5,0.01) # nm

Expand Down
5 changes: 3 additions & 2 deletions examples/basic/ex_fitting_4pdeer_compactness.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
# Experimental parameters
tau1 = 0.3 # First inter-pulse delay, μs
tau2 = 4.0 # Second inter-pulse delay, μs
deadtime = 0.1 # Acquisition deadtime, μs
tmin = 0.1 # Start time, μs

# Load the experimental data
t,Vexp = dl.deerload(path + file)

# Pre-processing
Vexp = dl.correctphase(Vexp) # Phase correction
Vexp = Vexp/np.max(Vexp) # Rescaling (aesthetic)
t = t + deadtime # Account for deadtime
t = t - t[0] # Account for zerotime
t = t + tmin

# Distance vector
r = np.arange(2,5,0.025) # nm
Expand Down
5 changes: 3 additions & 2 deletions examples/basic/ex_fitting_4pdeer_gauss.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
# Experimental parameters
tau1 = 0.3 # First inter-pulse delay, μs
tau2 = 4.0 # Second inter-pulse delay, μs
deadtime = 0.1 # Acquisition deadtime, μs
tmin = 0.1 # Start time, μs

# Load the experimental data
t,Vexp = dl.deerload(path + file)

# Pre-processing
Vexp = dl.correctphase(Vexp) # Phase correction
Vexp = Vexp/np.max(Vexp) # Rescaling (aesthetic)
t = t + deadtime # Account for deadtime
t = t - t[0] # Account for zerotime
t = t + tmin

# Distance vector
r = np.arange(1.5,6,0.01) # nm
Expand Down
13 changes: 7 additions & 6 deletions examples/basic/ex_fitting_5pdeer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@
file = 'example_5pdeer_1.DTA'

# Experimental parameters (reversed 5pDEER)
tau1 = 3.9 # First inter-pulse delay, μs
tau2 = 3.7 # Second inter-pulse delay, μs
tau3 = 0.5 # Third inter-pulse delay, μs
deadtime = 0.3 # Acquisition deadtime, μs
tau1 = 3.9 # First inter-pulse delay, μs
tau2 = 3.7 # Second inter-pulse delay, μs
tau3 = 0.5 # Third inter-pulse delay, μs
tmin = 0.3 # Start time, μs

# Load the experimental data
t,Vexp = dl.deerload(path + file)
Vexp = dl.correctphase(Vexp) # Phase correction
Vexp = Vexp/np.max(Vexp) # Rescaling (aesthetic)
t = t + deadtime # Account for deadtime
Vexp = Vexp/np.max(Vexp) # Rescaling (aesthetic)
t = t - t[0] # Account for zerotime
t = t + tmin

# Distance vector
r = np.arange(3,5,0.025) # nm
Expand Down
86 changes: 86 additions & 0 deletions examples/basic/ex_fitting_ridme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# %% [markdown]
"""
Basic analysis of a RIDME signal
-------------------------------------------------------------------------

Fit a simple RIDME signal with a model with a non-parametric
distribution and a stretched exponetial background, using Tikhonov regularization.
"""

import numpy as np
import matplotlib.pyplot as plt
import deerlab as dl


# %%

# File location
path = '../data/'
file = 'example_ridme_1.DTA'

# Experimental parameters
tau1 = 0.4 # First inter-pulse delay, μs
tau2 = 4.2 # Second inter-pulse delay, μs
tmin = 0.28 # Start time, μs

# Load the experimental data
t,Vexp = dl.deerload(path + file)

# Pre-processing
Vexp = dl.correctphase(Vexp) # Phase correction
Vexp = Vexp/np.max(Vexp) # Rescaling (aesthetic)
t = t - t[0] # Account for zerotime
t = t + tmin

# Distance vector
r = np.linspace(1.5,6,50) # nm

# Construct the model
experimentmodel = dl.ex_ridme(tau1,tau2, pathways=[1])
Vmodel = dl.dipolarmodel(t,r,Bmodel=dl.bg_strexp, experiment =experimentmodel)

# Fit the model to the data
results = dl.fit(Vmodel,Vexp)

# Print results summary
print(results)

#%%

# Extract fitted dipolar signal
Vfit = results.model

# Extract fitted distance distribution
Pfit = results.P
Pci95 = results.PUncert.ci(95)
Pci50 = results.PUncert.ci(50)

# Extract the unmodulated contribution
Bfcn = lambda mod,decay,stretch,reftime: results.P_scale*(1-mod)*dl.bg_strexp(t-reftime,decay,stretch)
Bfit = results.evaluate(Bfcn)
Bci = results.propagate(Bfcn).ci(95)

plt.figure(figsize=[6,7])
violet = '#4550e6'
plt.subplot(211)
# Plot experimental and fitted data
plt.plot(t,Vexp,'.',color='grey',label='Data')
plt.plot(t,Vfit,linewidth=3,color=violet,label='Fit')
plt.plot(t,Bfit,'--',linewidth=3,color=violet,label='Unmodulated contribution')
plt.fill_between(t,Bci[:,0],Bci[:,1],color=violet,alpha=0.3)
plt.legend(frameon=False,loc='best')
plt.xlabel('Time $t$ (μs)')
plt.ylabel('$V(t)$ (arb.u.)')
# Plot the distance distribution
plt.subplot(212)
plt.plot(r,Pfit,color=violet,linewidth=3,label='Fit')
plt.fill_between(r,Pci95[:,0],Pci95[:,1],alpha=0.3,color=violet,label='95%-Conf. Inter.',linewidth=0)
plt.fill_between(r,Pci50[:,0],Pci50[:,1],alpha=0.5,color=violet,label='50%-Conf. Inter.',linewidth=0)
plt.legend(frameon=False,loc='best')
plt.autoscale(enable=True, axis='both', tight=True)
plt.xlabel('Distance $r$ (nm)')
plt.ylabel('$P(r)$ (nm$^{-1}$)')
plt.tight_layout()
plt.show()

# %%
4 changes: 2 additions & 2 deletions examples/basic/ex_restraints_4pdeer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
# Experimental parameters
tau1 = 0.3 # First inter-pulse delay, μs
tau2 = 4.0 # Second inter-pulse delay, μs
deadtime = 0.1 # Acquisition deadtime, μs
tmin = 0.1 # Start time, μs

# Load the experimental data
t,Vexp = dl.deerload(path + file)

# Pre-processing
Vexp = dl.correctphase(Vexp) # Phase correction
Vexp = Vexp/np.max(Vexp) # Rescaling (aesthetic)
t = t + deadtime # Account for deadtime
t = t + tmin # Account for zerotime

# Distance vector
r = np.arange(2,6,0.05) # nm
Expand Down
Loading