Package specific_analyses :: Package relax_disp :: Module uf
[hide private]
[frames] | no frames]

Source Code for Module specific_analyses.relax_disp.uf

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2008,2013-2014 Edward d'Auvergne                         # 
  4  # Copyright (C) 2006 Chris MacRaild                                           # 
  5  # Copyright (C) 2008-2009 Sebastien Morin                                     # 
  6  # Copyright (C) 2014 Troels E. Linnet                                         # 
  7  #                                                                             # 
  8  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  9  #                                                                             # 
 10  # This program is free software: you can redistribute it and/or modify        # 
 11  # it under the terms of the GNU General Public License as published by        # 
 12  # the Free Software Foundation, either version 3 of the License, or           # 
 13  # (at your option) any later version.                                         # 
 14  #                                                                             # 
 15  # This program is distributed in the hope that it will be useful,             # 
 16  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 17  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 18  # GNU General Public License for more details.                                # 
 19  #                                                                             # 
 20  # You should have received a copy of the GNU General Public License           # 
 21  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 22  #                                                                             # 
 23  ############################################################################### 
 24   
 25  # Module docstring. 
 26  """The relaxation dispersion API object.""" 
 27   
 28  # Python module imports. 
 29  from copy import deepcopy 
 30   
 31  # relax module imports. 
 32  from lib.dispersion.variables import MODEL_DESC, MODEL_LIST_FULL, MODEL_PARAMS, MODEL_R2EFF 
 33  from lib.errors import RelaxError 
 34  from pipe_control.mol_res_spin import check_mol_res_spin_data, spin_loop 
 35  from pipe_control.pipes import check_pipe 
 36  from specific_analyses.relax_disp.api import Relax_disp 
 37  from specific_analyses.relax_disp.checks import check_c_modules, check_exp_type, check_pipe_type 
 38  from specific_analyses.relax_disp.data import get_curve_type 
 39   
 40   
 41  # The API object. 
 42  api_relax_disp = Relax_disp() 
 43   
 44   
45 -def cluster(cluster_id=None, spin_id=None):
46 """Define spin clustering. 47 48 @keyword cluster_id: The cluster ID string. 49 @type cluster_id: str 50 @keyword spin_id: The spin ID string for the spin or group of spins to add to the cluster. 51 @type spin_id: str 52 """ 53 54 # Initialise. 55 if not hasattr(cdp, 'clustering'): 56 # Create the dictionary. 57 cdp.clustering = {} 58 cdp.clustering['free spins'] = [] 59 60 # Add all spin IDs to the cluster. 61 for spin, id in spin_loop(return_id=True): 62 cdp.clustering['free spins'].append(id) 63 64 # Add the key. 65 if cluster_id not in cdp.clustering: 66 cdp.clustering[cluster_id] = [] 67 68 # Loop over the spins to add to the cluster. 69 for spin, id in spin_loop(selection=spin_id, return_id=True): 70 # First remove the ID from all clusters. 71 for key in cdp.clustering: 72 if id in cdp.clustering[key]: 73 cdp.clustering[key].pop(cdp.clustering[key].index(id)) 74 75 # Then add the ID to the cluster. 76 cdp.clustering[cluster_id].append(id) 77 78 # Clean up - delete any empty clusters (except the free spins). 79 clean = [] 80 for key in cdp.clustering: 81 if key == 'free spins': 82 continue 83 if cdp.clustering[key] == []: 84 clean.append(key) 85 for key in clean: 86 cdp.clustering.pop(key)
87 88
89 -def cluster_ids():
90 """Return the current list of cluster ID strings. 91 92 @return: The list of cluster IDs. 93 @rtype: list of str 94 """ 95 96 # Initialise. 97 ids = ['free spins'] 98 99 # Add the defined IDs. 100 if hasattr(cdp, 'clustering'): 101 for key in cdp.clustering: 102 if key not in ids: 103 ids.append(key) 104 105 # Return the IDs. 106 return ids
107 108
109 -def model_setup(model, params):
110 """Update various model specific data structures. 111 112 @param model: The relaxation dispersion curve type. 113 @type model: str 114 @param params: A list consisting of the model parameters. 115 @type params: list of str 116 """ 117 118 # The model group. 119 if model == MODEL_R2EFF: 120 cdp.model_type = 'R2eff' 121 else: 122 cdp.model_type = 'disp' 123 124 # Loop over the sequence. 125 for spin, spin_id in spin_loop(skip_desel=True, return_id=True): 126 # The model and parameter names. 127 spin.model = model 128 spin.params = params 129 130 # Initialise the data structures (if needed). 131 api_relax_disp.data_init(spin_id)
132 133
134 -def r1_fit(fit=True):
135 """Set the R1 optimisation flag. 136 137 @keyword fit: The R1 optimisation flag. 138 @type fit: bool 139 """ 140 141 # Simply store the value for later use. 142 cdp.r1_fit = fit
143 144
145 -def select_model(model=MODEL_R2EFF):
146 """Set up the model for the relaxation dispersion analysis. 147 148 @keyword model: The relaxation dispersion analysis type. 149 @type model: str 150 """ 151 152 # Data checks. 153 check_pipe() 154 check_pipe_type() 155 check_mol_res_spin_data() 156 check_exp_type() 157 158 # The curve type. 159 curve_type = get_curve_type() 160 if model == MODEL_R2EFF and curve_type == 'exponential': 161 check_c_modules() 162 163 # Invalid model. 164 if model not in MODEL_DESC: 165 raise RelaxError("The model '%s' must be one of %s." % (model, MODEL_LIST_FULL)) 166 167 # R2eff/R1rho model. 168 if model == MODEL_R2EFF: 169 if curve_type == 'exponential': 170 params = ['r2eff', 'i0'] 171 else: 172 params = ['r2eff'] 173 174 # All other models. 175 else: 176 params = deepcopy(MODEL_PARAMS[model]) 177 178 # Printout. 179 print(MODEL_DESC[model]) 180 181 # Set up the model. 182 model_setup(model, params)
183