Changes

Jump to navigation Jump to search
Forced creation of a TOC - this will improve the formatting on the main page 'Did you know...' section.
__TOC__
 
== Data background ==
This is data recorded at 600 and 950 MHz.<br>
This should follow <code>relax-4.0.01.Darwin.dmg </code> installation on a macMac, only with GUI.
For each spectrometer frequency, the data is saved in <code>np.arrays</code>
# one for the residue number,
# one for the rates,
They can be retrieved also with scipy's loadmat command.
The experiments are on-resonance {{:R1rho}}, and the rates are already corrected for the (small) offset effect, using the experimentally determined {{:R1}}.
Specifically, the numpy shapes of the data is:
## errorbars_rate (61, 19)
## RFfields (1, 19)
 
'''For the 950 MHz, the 4000 Hz dispersion point is replicated.'''
== Create data files for relax ==
First prepare data, by running in python.Python:
<source lang="bash">
python 1_prepare_data.py
</source>
The script is: {{collapsible script| type =Python 2/3 script| title == The <code>1_prepare_data.py ===File: '''1_prepare_data</code> script.py'''<source | lang ="python">| script =
import os
import scipy as scimport from scipy.ioimport loadmat
import numpy as np
# Set path
#cwd = status.install_path+os.sep+'test_suite'+os.sep+'shared_data'+os.sep+'dispersion'+os.sep+'Paul_Schanda_2015_Nov'
cwd = os.getcwd()
outdir = cwd + os.sep
fields = [600, 950]
# Loop over the experiments, collect all data
for field in fields:
print ("\n%s"%field, field)
# Make a dic inside
# Construct the path to the data
path = cwd + os.sep + "Archive" + os.sep + "exp_%s"%field + os.sep + "matrices" + os.sep all_data['%s'%field]['path'] = path
# Collect all filename paths
for file_name in file_names:
# Create path name
file_name_path = path + "%s_%s.mat"%(field, file_name)
field_file_name_paths.append(file_name_path)
# Load the data
file_name_path_data = sc.io.loadmat(file_name_path)
# Extract as numpy
file_name_path_data_np = file_name_path_data[file_name]
all_data['%s'%field]['np_%s'%file_name] = file_name_path_data_np
print (file_name, file_name_path_data_np.shape)
# Collect residues
# Write a sequence file for relax
f = open(outdir + "residues.txt", "w")
f.write("# Residue_i\n")
for res in all_res_uniq:
f.close()
f_exp = open(outdir + "exp_settings.txt", "w")
f_exp.write("# sfrq_MHz RFfield_kHz file_name\n")
# Then write the files for the rates
k = 1
for field in all_data['fields']:
resis = all_data['%s'%field]['np_residues'][0]
RFfields = all_data['%s'%field]['np_RFfields'][0]
print ("\nfield: %3.3f"%field)
for i, RF_field_strength_kHz in enumerate(RFfields):
#print "RF_field_strength_kHz: %3.3f"%RF_field_strength_kHz
# Generate file name
f_name = outdir + "sfrq_%i_MHz_RFfield_%1.3f_kHz3f_kHz_%03d.in"%(field, RF_field_strength_kHz, k)
cur_file = open(f_name, "w")
cur_file.write("# resi rate rate_err\n")
exp_string = "%11.7f %11.7f %s\n"%(field, RF_field_strength_kHz, f_name)
print ("%s"%exp_string,)
f_exp.write(exp_string)
cur_file.close()
k += 1
f_exp.close()
</source>}}
== Run analysis in relax GUI ==
* Start relax
* Then click: "New {{button|new analysis (Cmd+}} or {{key press|cmd|n)}}* Then click icon for "{{button|Relaxation dispersion" -> }} {{next}} {{button|Next}}
* Just accept name for the pipe
* Open the interpreter: Cmd+{{key press|cmd|p}}
* Paste in
<source lang="python">
script(file='2_load_data.py')
</source>
* ( You can scroll through earlier commands with: Cmd+ Arrow {{key press|cmd|up}} )* Close the Grace <code>Results viewer</code> window* When this is doneClose the interpreter window Now save the current state! This saved state can now be loaded just before an analysis, and contain all setup and data.* {{menu|File|Save as (Shift+Ctrl+S)}} {{next}} Save as <code>before_analysis.bz2</code> Now '''Quit relax''', quit and start relaxagain.<br>* Then Go to convert all xmgrace files to png: {{menu|File|Open relax state (Ctrl+O)}} {{next}} Locate <code>before_analysis.bz2</code> In the GUI, select:* For models, only select: <code>No Rex</code> and <code>M61<source lang="bash"/code>cd gracepython grace2images* {{:R1}} parameter optimisation to False, as this '''on-resonance''' data does not use {{:R1}}.py* The number of Monte-Carlo simulations to <code>3</sourcecode>. (The minimum number before relax refuse to run).* Let other things be standard, and click execute
{{note|The number of Monte-Carlo simulations is set to '''3'''. This should give means that relax will do the analysis, and the images fitted parameters will be correct, but the standard error of the data<gallery widths=300px heights=240px >Disp 12 HNparameters will be wrong.png|Resi 12 at 600+950 MHz</gallery>}}
* Afterwards you can* start relax* Open The reason for this is, that the interpreter: Cmd+p* Paste in <source lang=data "naturally"? for some spins contains measurements which are "pythondoubtful">import os; os.chdir(os.getenv('HOME') + os.sep + 'Desktop' + os.sep + 'temp'); pwd()</sourcebr>* Close When relax is performing Monte-Carlo simulations, all the data is first copied x times to the interpreternumber of Monte-Carlo simulations, and each {{:R2eff}} point on the graph * File -> Open relax state -> "temp_stateis modified randomly by a gaussian noise with a width described by the associated errors.bz2"
'''Here comes an error message we have For spins which contains measurements which are "doubtful", relax will be spending "very long time" trying to investigatefit a meaningful model. <br>This "time" is poorly spend on "bad data". But this can just be closed?'''
Essentially Rather, one need should first try to de-select spin 51 before one select * analyse the data quickly* make the models for R1rho graphs* examine which spins should be deselected* and then start rerun the analysis.with a higher number of monte-carlo simulations
After this comes the part with global fit/clustered analysis.
* analyse the data again
* Select which spins should be included in a global fit/clustered analysis
* and then rerun with analysis
The script under it can be run by<source lang="bash">relax 2_load_data.py -t log.txt</source>=== 2_load_data.py =The script==File: '''2_load_data.py'''<source lang="python"># relax importfrom pipe_control.mol_res_spin import spin_loop
{{collapsible script
| type = relax script
| title = The <code>2_load_data.py</code> script.
| lang = python
| script =
###############################################################################
# #
# Copyright (C) 2015 Troels E. Linnet #
# #
# This file is part of the program relax (http://www.nmr-relax.com). #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
###############################################################################
# Test if running as script or through GUI.
is_script = False
# Minimum: Just read the sequence data, but this misses a lot of information.
sequence.read(file='residues.txt', res_num_col=1)
 
# Name the spins
for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
spin.name(name="HN", spin_id=spin_id)
# Manually force the model to be R2eff, so plotting can be performed later
cur_spin.model = "R2eff"
 
# Name the isotope for field strength scaling.
spin.isotope(isotope='15N')
 
# Open the settings file
#relax_disp.relax_time(spectrum_id=spec_id, time=time_sl)
 
# Name the isotope for field strength scaling.
spin.isotope(isotope='15N')
relax_disp.select_model(model='R2eff')
# Plot data
state.save("temp_state", force=True)
 
# Do it through script
#if False:
#if True:
#if is_script: # Deselect spin 51, due to weid data point deselect.spin(spin_id=":51@HN", change_all=False) 
import os
from auto_analyses import relax_disp as aa_relax_disp
GRID_INC = 21
# The number of Monte Carlo simulations to be used for error analysis at the end of the analysis.
MC_NUM = 5003
# Model selection technique.
MODSEL = 'AIC'
result_dir_name = os.getcwd()+ os.sep + "results"
# Which models to analyse ?
#MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE]
# Fit, instead of read
#r1_fit = True r1_fit = False  # Set the initial guess from the minimum R2eff point set_grid_r20=True  """ @keyword pipe_name: The name of the data pipe containing all of the data for the analysis. @type pipe_name: str @keyword pipe_bundle: The data pipe bundle to associate all spawned data pipes with. @type pipe_bundle: str @keyword results_dir: The directory where results files are saved. @type results_dir: str @keyword models: The list of relaxation dispersion models to optimise. @type models: list of str @keyword grid_inc: Number of grid search increments. If set to None, then the grid search will be turned off and the default parameter values will be used instead. @type grid_inc: int or None @keyword mc_sim_num: The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. @type mc_sim_num: int @keyword exp_mc_sim_num: The number of Monte Carlo simulations for the error analysis in the 'R2eff' model when exponential curves are fitted. This defaults to the value of the mc_sim_num argument when not given. When set to '-1', the R2eff errors are estimated from the Covariance matrix. For the 2-point fixed-time calculation for the 'R2eff' model, this argument is ignored. @type exp_mc_sim_num: int or None @keyword modsel: The model selection technique to use in the analysis to determine which model is the best for each spin cluster. This can currently be one of 'AIC', 'AICc', and 'BIC'. @type modsel: str @keyword pre_run_dir: The optional directory containing the dispersion auto-analysis results from a previous run. The optimised parameters from these previous results will be used as the starting point for optimisation rather than performing a grid search. This is essential for when large spin clusters are specified, as a grid search becomes prohibitively expensive with clusters of three or more spins. At some point a RelaxError will occur because the grid search is impossibly large. For the cluster specific parameters, i.e. the populations of the states and the exchange parameters, an average value will be used as the starting point. For all other parameters, the R20 values for each spin and magnetic field, as well as the parameters related to the chemical shift difference dw, the optimised values of the previous run will be directly copied. @type pre_run_dir: None or str @keyword optimise_r2eff: Flag to specify if the read previous R2eff results should be optimised. For R1rho models where the error of R2eff values are determined by Monte-Carlo simulations, it can be valuable to make an initial R2eff run with a high number of Monte-Carlo simulations. Any subsequent model analysis can then be based on these R2eff values, without optimising the R2eff values. @type optimise_r2eff: bool @keyword insignificance: The R2eff/R1rho value in rad/s by which to judge insignificance. If the maximum difference between two points on all dispersion curves for a spin is less than this value, that spin will be deselected. This does not affect the 'No Rex' model. Set this value to 0.0 to use all data. The value will be passed on to the relax_disp.insignificance user function. @type insignificance: float @keyword numeric_only: The class of models to use in the model selection. The default of False allows all dispersion models to be used in the analysis (no exchange, the analytic models and the numeric models). The value of True will activate a pure numeric solution - the analytic models will be optimised, as they are very useful for replacing the grid search for the numeric models, but the final model selection will not include them. @type numeric_only: bool @keyword mc_sim_all_models: A flag which if True will cause Monte Carlo simulations to be performed for each individual model. Otherwise Monte Carlo simulations will be reserved for the final model. @type mc_sim_all_models: bool @keyword eliminate: A flag which if True will enable the elimination of failed models and failed Monte Carlo simulations through the eliminate user function. @type eliminate: bool @keyword set_grid_r20: A flag which if True will set the grid R20 values from the minimum R2eff values through the r20_from_min_r2eff user function. This will speed up the grid search with a factor GRID_INC^(Nr_spec_freq). For a CPMG experiment with two fields and standard GRID_INC=21, the speed-up is a factor 441. @type set_grid_r20: bool @keyword r1_fit: A flag which if True will activate R1 parameter fitting via relax_disp.r1_fit for the models that support it. If False, then the relax_disp.r1_fit user function will not be called. """  
# Go
aa_relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, exp_mc_sim_num=None, modsel=MODSEL, pre_run_dir=None, optimise_r2eff=False, insignificance=0.0, numeric_only=False, mc_sim_all_models=False, eliminate=True, set_grid_r20=set_grid_r20, r1_fit=r1_fit)</source>}}
=== Run the same analysis in relax through terminal ===
The analysis can be performed by
<source lang="bash">
python 1_prepare_data.py
 
relax 2_load_data.py -t log.txt
# Or
mpirun -np 8 relax --multi='mpi4py' 2_load_data.py -t log.txt
</source>
== Following analysis Inspect and make graphs == * When this is done, quit relax* Then to convert all xmgrace files to png 
First make graphs
<source lang="bash">
cd grace
./grace2images.py -t EPS,PNG
 
cd ..
cd No_Rex/
./grace2images.py -t EPS,PNG
cat r1.out
cat r1rho_prime.out
cd M61
./grace2images.py -t PNG
cat r1rho_prime.out
cat kex.out
cat phi_ex.out
 
cat kex.out | grep "None 12"
cat phi_ex.out | grep "None 12"
</source>
 
This should give the images of the data
<gallery widths=300px heights=240px >
Disp 12 HN.png|Resi 12 at 600+950 MHz
</gallery>
For model [[M61]], spin 12 is:
[[<gallery widths=300px heights=240px >File:Disp 12 HN M61.png|thumb|Spin 61 model Resi 12 at 600+950 MHz for [[M61]]model. kex=25000, phi_ex=0.32</gallery>
== Further analysis steps ==
Load the final state * Inspect which residues should not be included in analysis
<source lang="bash">
desel_ids # Now simulate that all spins are first deselected, and then selected.deselect.all()sel_ids = [":49@N12",":52@N51",":53@N"]# De-select for analysis those spins who have bad datafor desel_spin sel_spin in desel_idssel_ids: print("Deselecting Selecting spin %s"%desel_spinsel_spin) deselectselect.spin(spin_id=desel_spinsel_spin, change_all=False)</source>
* # Inspect which residues should be analysed together for a clustered/global fit.<source lang="bash">cluster_ids = [":13@N",":15@N",":16@N",":25@N"]sel_ids
# Cluster spins
print("Adding spin %s to cluster"%curspin)
relax_disp.cluster('model_cluster', curspin)
 
# Show the pipe
print("\nPrinting all the available pipes.")
pipe.display()
 
# Get the selected models
print("\nChecking which model is stored per spin.")
for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False):
print("For spin_id '%s the model is '%s''"%(spin_id, curspin.model))
 
# Copy pipe and switch to it.
pipe.copy(pipe_from="final - relax_disp", pipe_to="relax_disp_cluster", bundle_to="relax_disp_cluster")
pipe.switch(pipe_name="relax_disp_cluster")
pipe.display()
 
# Go again with clustered spins.
relax_disp.Relax_disp(pipe_name="relax_disp_cluster", pipe_bundle="relax_disp_cluster", results_dir=outdir+sep+"cluster", models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, exp_mc_sim_num=None, modsel=MODSEL, pre_run_dir=None, optimise_r2eff=False, insignificance=0.0, numeric_only=False, mc_sim_all_models=False, eliminate=True, set_grid_r20=set_grid_r20, r1_fit=r1_fit)
 
# Get the clustered fitted values
print("\nChecking which value is stored per spin.")
kex = None
for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False):
if kex == None:
kex = curspin.kex
self.assertEqual(curspin.kex, kex)
print("For spin_id %s the kex is %.3f"%(spin_id, kex))
</source>
Trusted, Bureaucrats
4,223

edits

Navigation menu