Matplotlib DPL94 R1rho R2eff
Jump to navigation
Jump to search
Contents
About
Code
File: r1rhor2eff.py
### python imports
import sys
import os
from math import cos, sin
### plotting facility.
import matplotlib.pyplot as plt
### relax modules
# Import some tools to loop over the spins.
from pipe_control.mol_res_spin import return_spin, spin_loop
# Import method to calculate the R1rho offset data
from specific_analyses.relax_disp.disp_data import calc_rotating_frame_params, generate_r20_key, loop_exp_frq
###############
# You have to provide a DPL94 results state file
res_folder = "resultsR1"
res_state = os.path.join(res_folder, "DPL94", "results")
spin_inte = ":52@N"
spin_inte_rep = spin_inte.replace('#', '_').replace(':', '_').replace('@', '_')
# Load the state
state.load(res_state, force=True)
# Show pipes
pipe.display()
pipe.current()
# Get the spin of interest and save it in cdp, to access it after execution of script.
cdp.myspin = return_spin(spin_inte)
# Calculate the offset data
theta_spin_dic, Domega_spin_dic, w_eff_spin_dic, dic_key_list = calc_rotating_frame_params(spin=cdp.myspin, spin_id=spin_inte, verbosity=1)
# Save the data in cdp to access it after execution of script.
cdp.myspin.theta_spin_dic = theta_spin_dic
cdp.myspin.w_eff_spin_dic = w_eff_spin_dic
cdp.myspin.dic_key_list = dic_key_list
# Create spin.r2 keys
r2keys = []
for exp_type, frq in loop_exp_frq():
r2keys.append(generate_r20_key(exp_type=exp_type, frq=frq) )
# Save the keys
cdp.r2keys = r2keys
x_w_eff = []
x_theta = []
y = []
for dic_key in cdp.myspin.dic_key_list:
R1_rho_prime = cdp.myspin.r2[cdp.r2keys[0]]
R1 = cdp.myspin.ri_data['R1']
R1_rho = cdp.myspin.r2eff[dic_key]
# Get w_eff
w_eff = cdp.myspin.w_eff_spin_dic[dic_key]
x_w_eff.append(w_eff)
# Get theta
theta = cdp.myspin.theta_spin_dic[dic_key]
x_theta.append(theta)
# Calculate y value
R1rho_R2eff = (R1_rho - R1*cos(theta)*cos(theta)) / (sin(theta) * sin(theta))
y.append(R1rho_R2eff)
# Modify data
w_eff_div = 10**4
rem_points = 2
x_w_eff_mod = [x/w_eff_div for x in x_w_eff[:-rem_points]]
y_mod = y[:-rem_points]
# Plot R1rho_R2eff as function of w_eff
plt.figure()
plotlabel = 'R1rho_R2eff'
plt.plot(x_w_eff_mod, y_mod, 'o', label='R1rho_R2eff')
xlabel = 'Effective field in rotating frame [%s rad.s^-1]'%(str(w_eff_div))
plt.xlabel(xlabel)
ylabel = 'R1rho_R2eff [rad.s^-1]'
plt.ylabel(ylabel)
plt.legend(loc='best')
plt.grid(True)
plt.ylim([0,16])
plt.title("%s \n %s as function of %s"%(spin_inte,ylabel, xlabel))
plt.savefig("matplotlib_%s_%s_w_eff.png"%(spin_inte_rep, plotlabel) )
# Plot R1rho_R2eff as function of w_eff
plt.figure()
plotlabel = 'R1rho_R2eff'
plt.plot(x_theta, y, 'o', label='R1rho_R2eff')
xlabel = 'Rotating frame tilt angle [rad]'
plt.xlabel(xlabel)
ylabel = 'R1rho_R2eff [rad.s^-1]'
plt.ylabel(ylabel)
plt.legend(loc='best')
plt.grid(True)
plt.ylim([0,16])
plt.title("%s \n %s as function of %s"%(spin_inte,ylabel, xlabel))
plt.savefig("matplotlib_%s_%s_theta.png"%(spin_inte_rep, plotlabel) )
plt.show()
To run
relax -p r1rhor2eff.py