def dropletmodel(t): #---------------------------------------------------------------------------------- # Dispersed-state component model Vdis_model = dl.dipolarmodel(t, r, Pmodel=dl.dd_gauss, Bmodel=dl.bg_exp, npathways=2) # Liquid-droplet-state component model Vld_model = dl.dipolarmodel(t, r, Pmodel=dl.dd_gauss, Bmodel=dl.bg_strexp, npathways=2) # Create a dipolar signal model that is a linear combination of both components Vmodel = dl.lincombine(Vdis_model, Vld_model, addweights=True) Vmodel = dl.link(Vmodel, reftime1=['reftime1_1', 'reftime1_2'], reftime2=['reftime2_1', 'reftime2_2'], lam1=['lam1_1', 'lam1_2'], lam2=['lam2_1', 'lam2_2']) # Make the second weight dependent on the first one Vmodel = dl.relate(Vmodel, weight_2=lambda weight_1: 1 - weight_1) return Vmodel, Vdis_model, Vld_model
# Construct the distance axis r = np.linspace(2.5, 4.5, 200) # Pre-allocate the empty lists of models Pmodels = [[]] * Nmax Vmodels = [[]] * Nmax # The basic model for the components (can be e.g. dl.dd_rice) basisModel = dl.dd_gauss # Model construction for n in range(Nmax): # Construct the n-Gaussian model Pmodels[n] = dl.lincombine(*[basisModel] * (n + 1)) # Construct the corresponding dipolar signal model Vmodels[n] = dl.dipolarmodel(t, r, Pmodel=Pmodels[n]) # Fit the models to the data fits = [[]] * Nmax for n in range(Nmax): fits[n] = dl.fit(Vmodels[n], Vexp, reg=False) #%% # Extract the values of the Akaike information criterion for each fit aic = np.array([fit.stats['aic'] for fit in fits]) # Compute the relative difference in AIC aic -= aic.min() # Plotting fig = plt.figure(figsize=[6, 6])
𝜏2 = 4.4 # μs 𝜏1 = 0.4 # μs # Load the experimental data t, Vexp = np.load('../data/example_data_#3.npy') # Construct the distance vector r = np.linspace(2, 6, 100) # 4-pulse DEER can have up to four different dipolar pathways Nmax = 4 # Create the 4-pulse DEER signal models with increasing number of pathways experiment = dl.ex_4pdeer(𝜏1, 𝜏2) Vmodels = [ dl.dipolarmodel(t, r, npathways=n + 1, experiment=experiment) for n in range(Nmax) ] # Fit the individual models to the data fits = [[]] * Nmax for n, Vmodel in enumerate(Vmodels): fits[n] = dl.fit(Vmodel, Vexp) #%% # Extract the values of the Akaike information criterion for each fit aic = np.array([fit.stats['aic'] for fit in fits]) # Compute the relative difference in AIC aic = aic - aic.min() + 1 # ...add plus one for log-scale
# Load the experimental data t1,Vexp1 = np.load('../data/example_4pdeer_#3.npy') t2,Vexp2 = np.load('../data/example_4pdeer_#4.npy') # Put the datasets into lists ts = [t1,t2] Vs = [Vexp1,Vexp2] # Normalize the datasets Vs = [V/np.max(V) for V in Vs] # Distance vector r = np.linspace(2,5,150) # nm # Construct the dipolar models for the individual signals V1model = dl.dipolarmodel(ts[0],r) V2model = dl.dipolarmodel(ts[1],r) # Make the global model by joining the individual models globalmodel = dl.merge(V1model,V2model) # Link the distance distribution into a global parameter globalmodel = dl.link(globalmodel,P=['P_1','P_2']) # Fit the model to the data fit = dl.fit(globalmodel,Vs) # %% plt.figure(figsize=[10,7]) violet = '#4550e6'
import deerlab as dl # %% # Load the experimental data t, Vexp = np.load('../data/example_data_#1.npy') # Pre-process Vexp = dl.correctphase(Vexp) Vexp = Vexp / np.max(Vexp) # Distance vector r = np.linspace(2, 5.5, 80) # Construct the 4-pulse DEER dipolar model Vmodel = dl.dipolarmodel(t, r) Vmodel.reftime.set(par0=0.5, lb=0.0, ub=1.0) # Fit the model to the data using covariane-based uncertainty fit_cm = dl.fit(Vmodel, Vexp) # Fit the model to the data using bootstrapped uncertainty fit_bs = dl.fit(Vmodel, Vexp, bootstrap=10) # Compute the covariance-based uncertainty bands of the distance distribution Pci50_cm = fit_cm.PUncert.ci(50) Pci95_cm = fit_cm.PUncert.ci(95) # Compute the bootstrapped uncertainty bands of the distance distribution Pci50_bs = fit_bs.PUncert.ci(50) Pci95_bs = fit_bs.PUncert.ci(95)
Vs = [V1, V2, V3, V4, V5] # Total ligand concentrations used in experiments L = [0.3, 3, 10, 30, 300] # µM # Distance vector r = np.linspace(1.5, 6, 90) # Construct a non-parametric distance distribution that is a # linear combination of two non-parametric distributions PAmodel = dl.freedist(r) PBmodel = dl.freedist(r) Pmodel = dl.lincombine(PAmodel, PBmodel, addweights=True) # Construct the dipolar models of the individual signals Vmodels = [dl.dipolarmodel(t, r, Pmodel) for t in ts] # Create the global model titrmodel = dl.merge(*Vmodels) # Make the two components of the distance distriution global titrmodel = dl.link(titrmodel, PA=['P_1_1', 'P_1_2', 'P_1_3', 'P_1_4', 'P_1_5'], PB=['P_2_1', 'P_2_2', 'P_2_3', 'P_2_4', 'P_2_5']) # Functionalize the chemical equilibrium model titrmodel.addnonlinear('Kdis', lb=3, ub=7, par0=5, description='Dissociation constant')
# %% # Import required packages import numpy as np import matplotlib.pyplot as plt import deerlab as dl # %% # Load the experimental data t, Vexp = np.load('../data/example_5pdeer_#1.npy') # Distance vector r = np.linspace(2, 5, 200) # nm # Construct dipolar model with two dipolar pathways Vmodel = dl.dipolarmodel(t, r, npathways=2) # The refocusing time of the second pathway can be well estimated by visual inspection Vmodel.reftime2.set(lb=3, ub=4, par0=3.5) # Fit the model to the data fit = dl.fit(Vmodel, Vexp) # %% # Extract fitted dipolar signal Vfit = fit.model Vci = fit.modelUncert.ci(95) # Extract fitted distance distribution Pfit = fit.P
#%% # Load the experimental 4-pulse and 5-pulse DEER datasets t4p, V4p = np.load('../data/example_4pdeer_#2.npy') t5p, V5p = np.load('../data/example_5pdeer_#2.npy') # Since they have different scales, normalize both datasets V4p = V4p / np.max(V4p) V5p = V5p / np.max(V5p) # Run fit r = np.linspace(2, 4.5, 100) # Construct the individual dipolar signal models V4pmodel = dl.dipolarmodel(t4p, r, npathways=1) V5pmodel = dl.dipolarmodel(t5p, r, npathways=2) V5pmodel.reftime2.set(lb=3, ub=3.5, par0=3.2) # Make the joint model with the distribution as a global parameters globalmodel = dl.merge(V4pmodel, V5pmodel) globalmodel = dl.link(globalmodel, P=['P_1', 'P_2']) # Fit the model to the data (with fixed regularization parameter) fit = dl.fit(globalmodel, [V4p, V5p], regparam=0.5) # %% plt.figure(figsize=[10, 7]) violet = '#4550e6'
Vexp = dl.correctphase(Vexp) Vexp /= max(Vexp) # Construct the energy and distance distribution models forcefield_energymodel = dl.Model(forcefield_energy) forcefield_Pmodel = dl.Model(forcefield_P) # Set boundaries and initial conditions forcefield_Pmodel.c1.set(lb=-1, ub=1, par0=0) forcefield_Pmodel.c2.set(lb=-1, ub=1, par0=0) forcefield_Pmodel.c3.set(lb=-1, ub=1, par0=0) forcefield_Pmodel.c0.set(lb=-1, ub=1, par0=0) # Construct the dipolar signal model Vmodel = dl.dipolarmodel(t, r, Pmodel=forcefield_Pmodel, Bmodel=dl.bg_homfractal) # Fit the model to the data fit = dl.fit(Vmodel, Vexp) fit.plot(axis=t) plt.ylabel('V(t)') plt.xlabel('Time $t$ (μs)') plt.show() #%% # Evaluate the models at the fitted parameters Pfit = forcefield_Pmodel(fit.c0, fit.c1, fit.c2, fit.c3) energy = forcefield_energymodel(fit.c0, fit.c1, fit.c2, fit.c3)
# Construct the model object Pmodel = dl.Model(Ptwostates) # Set the parameter boundaries and start values Pmodel.meanA.set(lb=2, ub=7, par0=5) Pmodel.meanB.set(lb=2, ub=7, par0=3) Pmodel.widthA.set(lb=0.05, ub=0.8, par0=0.1) Pmodel.widthB.set(lb=0.05, ub=0.8, par0=0.1) Pmodel.fracA.set(lb=0, ub=1, par0=0.5) # Generate the individual dipolar signal models Nsignals = len(Vexps) Vmodels = [[]] * Nsignals for n in range(Nsignals): Vmodels[n] = dl.dipolarmodel(ts[n], r, Pmodel) Vmodels[n].reftime.set(lb=0, ub=0.5, par0=0.2) # Combine the individual signal models into a single global models globalmodel = dl.merge(*Vmodels) # Link the global parameters toghether globalmodel = dl.link(globalmodel, meanA=['meanA_1', 'meanA_2', 'meanA_3'], meanB=['meanB_1', 'meanB_2', 'meanB_3'], widthA=['widthA_1', 'widthA_2', 'widthA_3'], widthB=['widthB_1', 'widthB_2', 'widthB_3']) # Fit the datasets to the model globally fit = dl.fit(globalmodel, Vexps) # Extract the fitted fractions