Package generic_fns :: Module runs
[hide private]
[frames] | no frames]

Source Code for Module generic_fns.runs

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2004, 2006 Edward d'Auvergne                                  # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax is free software; you can redistribute it and/or modify               # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation; either version 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax is distributed in the hope that it will be useful,                    # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  from copy import deepcopy 
 24   
 25   
26 -class Runs:
27 - def __init__(self, relax):
28 """Class containing the function for creating a run.""" 29 30 self.relax = relax
31 32
33 - def create(self, run=None, run_type=None):
34 """Function for creating a run.""" 35 36 # Test if the run already exists. 37 if run in self.relax.data.run_names: 38 raise RelaxRunError, run 39 40 # List of valid run types. 41 valid = ['ct', 'jw', 'mf', 'noe', 'relax_fit', 'srls'] 42 43 # Test if run_type is valid. 44 if not run_type in valid: 45 raise RelaxError, "The run type name " + `run_type` + " is invalid and must be one of the strings in the list " + `valid` + "." 46 47 # Test that the C modules have been loaded. 48 if run_type == 'relax_fit' and not C_module_exp_fn: 49 raise RelaxError, "Relaxation curve fitting is not availible. Try compiling the C modules on your platform." 50 51 # Add the run and type. 52 self.relax.data.run_names.append(run) 53 self.relax.data.run_types.append(run_type)
54 55
56 - def delete(self, run=None):
57 """Function for deleting a run.""" 58 59 # Test if the run exists. 60 if run != None and not run in self.relax.data.run_names: 61 raise RelaxNoRunError, run 62 63 # Find out if any data in 'self.relax.data' is assigned to a run. 64 for name in dir(self.relax.data): 65 # Get the object. 66 object = getattr(self.relax.data, name) 67 68 # Skip to the next data structure if the object is not a dictionary. 69 if not hasattr(object, 'keys'): 70 continue 71 72 # Delete the data if the object contains the key 'run'. 73 if object.has_key(run): 74 del(object[run]) 75 76 # Clean up the runs, ie delete any runs for which there is no data left. 77 self.eliminate_unused_runs()
78 79
80 - def eliminate_unused_runs(self):
81 """Function for eliminating any runs for which there is no data.""" 82 83 # An array of runs to retain. 84 keep_runs = [] 85 86 # Find out if any data in 'self.relax.data' is assigned to a run. 87 for name in dir(self.relax.data): 88 # Skip to the next data structure if the object is not a dictionary. 89 object = getattr(self.relax.data, name) 90 if not hasattr(object, 'keys'): 91 continue 92 93 # Add the keys to 'keep_runs'. 94 for key in object.keys(): 95 if not key in keep_runs: 96 keep_runs.append(key) 97 98 # Delete the runs in 'self.relax.data.run_names' and 'self.relax.data.run_types' which are not in 'keep_runs'. 99 for run in self.relax.data.run_names: 100 if not run in keep_runs: 101 # Index. 102 index = self.relax.data.run_names.index(run) 103 104 # Remove from run_names. 105 self.relax.data.run_names.remove(run) 106 107 # Remove from run_types. 108 temp = self.relax.data.run_types.pop(index)
109 110
111 - def list_of_runs(self, run):
112 """Function for creating a list of runs.""" 113 114 # All runs. 115 if run == None: 116 runs = deepcopy(self.relax.data.run_names) 117 118 # Single run. 119 elif type(run) == str: 120 runs = [run] 121 122 # List of runs. 123 else: 124 runs = run 125 126 # Return the list. 127 return runs
128