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

Source Code for Module generic_fns.runs

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2004 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 = ['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 # Add the run and type. 48 self.relax.data.run_names.append(run) 49 self.relax.data.run_types.append(run_type)
50 51
52 - def delete(self, run=None):
53 """Function for deleting a run.""" 54 55 # Test if the run exists. 56 if run != None and not run in self.relax.data.run_names: 57 raise RelaxNoRunError, run 58 59 # Find out if any data in 'self.relax.data' is assigned to a run. 60 for name in dir(self.relax.data): 61 # Get the object. 62 object = getattr(self.relax.data, name) 63 64 # Skip to the next data structure if the object is not a dictionary. 65 if not hasattr(object, 'keys'): 66 continue 67 68 # Delete the data if the object contains the key 'run'. 69 if object.has_key(run): 70 del(object[run]) 71 72 # Clean up the runs, ie delete any runs for which there is no data left. 73 self.eliminate_unused_runs()
74 75
76 - def eliminate_unused_runs(self):
77 """Function for eliminating any runs for which there is no data.""" 78 79 # An array of runs to retain. 80 keep_runs = [] 81 82 # Find out if any data in 'self.relax.data' is assigned to a run. 83 for name in dir(self.relax.data): 84 # Skip to the next data structure if the object is not a dictionary. 85 object = getattr(self.relax.data, name) 86 if not hasattr(object, 'keys'): 87 continue 88 89 # Add the keys to 'keep_runs'. 90 for key in object.keys(): 91 if not key in keep_runs: 92 keep_runs.append(key) 93 94 # Delete the runs in 'self.relax.data.run_names' and 'self.relax.data.run_types' which are not in 'keep_runs'. 95 for run in self.relax.data.run_names: 96 if not run in keep_runs: 97 # Index. 98 index = self.relax.data.run_names.index(run) 99 100 # Remove from run_names. 101 self.relax.data.run_names.remove(run) 102 103 # Remove from run_types. 104 temp = self.relax.data.run_types.pop(index)
105 106
107 - def list_of_runs(self, run):
108 """Function for creating a list of runs.""" 109 110 # All runs. 111 if run == None: 112 runs = deepcopy(self.relax.data.run_names) 113 114 # Single run. 115 elif type(run) == str: 116 runs = [run] 117 118 # List of runs. 119 else: 120 runs = run 121 122 # Return the list. 123 return runs
124