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