Matplotlib example

From relax wiki
Revision as of 14:00, 15 October 2015 by Bugman (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Example

File: mat_example.py

# Get the OS path separator
from os import sep
# Find relax installation dir
from status import Status; status = Status()

# Import some tools to loop over the spins.
from pipe_control.mol_res_spin import return_spin, spin_loop

# Extra tools fo
import specific_analyses.relax_disp.disp_data as dtools

# Plotting facility.
import matplotlib.pyplot as plt

# Path to data
data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'relax_results'

# Load the state
state.load(data_path+sep+'final_state.bz2', force=True)

# Loop over the spins
for spin, spin_id in spin_loop(return_id=True):
    print spin, spin_id

# Get the available data for a spin.
print(dir(spin))

resi_data = []
kex_data = []
for resiob in cdp.mol[0].res:
    print resiob.name, resiob.num, resiob.spin[0].kex, resiob.spin[0].model
    resi_data.append(resiob.num), kex_data.append(resiob.spin[0].kex)

print(dir(resiob))

plt.plot(resi_data, kex_data, 'ro')
plt.show()

Example 2

File: mat_example.py

# Get the OS path separator
from os import sep
# Plotting facility.
import matplotlib.pyplot as plt

# Import some tools to loop over the spins.
from pipe_control.mol_res_spin import return_spin, spin_loop
 
# Load the state
#state.load('final_state.bz2', force=True)

outfile = open("test.txt", "w")

# Ini
spectrometer_frq = cdp.spectrometer_frq_list[0]
cpmg_frqs_list = cdp.cpmg_frqs_list
sel_point = cpmg_frqs_list[1]

resi_data = []
Rex_data = []
Model_data = []
for resiob in cdp.mol[0].res:
    cur_model = resiob.spin[0].model
    if cur_model == "TSMFK01" :
        r2dic=resiob.spin[0].r2a
        for key, value in r2dic.iteritems():
            r2a = value
    elif cur_model == "CR72 full":
        r2dic=resiob.spin[0].r2a
        for key, value in r2dic.iteritems():
            r2a = value
    else:
        r2dic=resiob.spin[0].r2
        for key, value in r2dic.iteritems():
            r2a = value

    r2effdic = resiob.spin[0].r2eff
    for key, value in r2effdic.iteritems():
        curcpmg = float(key.split("_")[-1])
        if curcpmg == sel_point:
            r2eff = value

    Rex = r2eff - r2a

    print(resiob.name, resiob.num, cur_model, r2a, r2eff, Rex)
    outfile.write("%s %s %s %s %s %s\n"%(resiob.name, resiob.num, cur_model.replace (" ", "_"), r2a, r2eff, Rex))

    resi_data.append(resiob.num)
    Rex_data.append(Rex)
    Model_data.append(cur_model)

outfile.close()

plt.plot(resi_data, Rex_data, 'ro')
for i in range(len(resi_data)):
    resi = resi_data[i]
    Rex = Rex_data[i]
    Model = Model_data[i]
    if Model == "No Rex":
        textcolor = 'k'
    elif Model == "TSMFK01":
        textcolor = 'r'
    else:
        textcolor = 'b'

    plt.annotate('%s'%(resi), xy=(resi,Rex), xytext=(resi, Rex), size=8, color=textcolor)
plt.plot([min(resi_data), max(resi_data)], [0, 0], 'k-', lw=2)

plt.show()

To run

relax mat_example.py

Or

$ relax
relax> script('mat_example.py')

See also