Trees | Indices | Help |
|
---|
|
1 ############################################################################### 2 # # 3 # Copyright (C) 2003-2004,2007-2009 Edward d'Auvergne # 4 # # 5 # This file is part of the program relax (http://www.nmr-relax.com). # 6 # # 7 # This program 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 3 of the License, or # 10 # (at your option) any later version. # 11 # # 12 # This program 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 this program. If not, see <http://www.gnu.org/licenses/>. # 19 # # 20 ############################################################################### 21 22 # Module docstring. 23 """Module for reading and writing the relax program state.""" 24 25 # relax module imports. 26 from data_store import Relax_data_store; ds = Relax_data_store() 27 from lib.errors import RelaxError 28 from lib.io import open_read_file, open_write_file 29 from pipe_control import interatomic, mol_res_spin, pipes 30 from pipe_control.reset import reset 31 from status import Status; status = Status() 32 3335 """Load the program state from the pickled file. 36 37 @param file: The file object containing the relax state. 38 @type file: file object 39 """ 40 41 # Unpickle the data class. 42 state = load(file) 43 44 # Close the file. 45 file.close() 46 47 # Black list of objects (all dict objects, non-modifiable objects, data store specific methods, and other special objects). 48 black_list = dir(dict) + ['__weakref__', '__dict__', '__module__', '__reset__', '_back_compat_hook', 'add', 'from_xml', 'is_empty', 'to_xml'] 49 50 # Loop over the objects in the saved state, and dump them into the relax data store. 51 for name in dir(state): 52 # Skip blacklisted objects. 53 if name in black_list: 54 continue 55 56 # Get the object. 57 obj = getattr(state, name) 58 59 # Place ALL objects into the singleton! 60 setattr(ds, name, obj) 61 62 # Loop over the keys of the dictionary. 63 for key in state: 64 # Shift the PipeContainer. 65 ds[key] = state[key] 66 67 # Delete the state object. 68 del state 69 70 # Success. 71 return True72 7375 """Function for loading a saved program state. 76 77 @keyword state: The saved state file. 78 @type state: str 79 @keyword dir: The path of the state file. 80 @type dir: str 81 @keyword verbosity: The verbosity level. 82 @type verbosity: int 83 @keyword force: If True, the relax data store will be reset prior to state loading. 84 @type force: bool 85 """ 86 87 # Open the file for reading. 88 file = open_read_file(file_name=state, dir=dir, verbosity=verbosity) 89 90 # Reset. 91 if force: 92 reset() 93 94 # Make sure that the data store is empty. 95 if not ds.is_empty(): 96 raise RelaxError("The relax data store is not empty.") 97 98 # Restore from the XML. 99 ds.from_xml(file) 100 101 # Update all of the required metadata structures. 102 for pipe, pipe_name in pipes.pipe_loop(name=True): 103 mol_res_spin.metadata_update(pipe=pipe_name) 104 interatomic.metadata_update(pipe=pipe_name) 105 106 # Signal a change in the current data pipe. 107 status.observers.pipe_alteration.notify() 108 109 # Signal the state loading 110 status.observers.state_load.notify()111 112114 """Function for saving the program state. 115 116 @keyword state: The saved state file. 117 @type state: str 118 @keyword dir: The path of the state file. 119 @type dir: str 120 @keyword verbosity: The verbosity level. 121 @type verbosity: int 122 @keyword force: Boolean argument which if True causes the file to be overwritten if it 123 already exists. 124 @type force: bool 125 @keyword compress_type: The compression type. The integer values correspond to the compression 126 type: 0, no compression; 1, Bzip2 compression; 2, Gzip compression. 127 @type compress_type: int 128 """ 129 130 # Open the file for writing. 131 file = open_write_file(file_name=state, dir=dir, verbosity=verbosity, force=force, compress_type=compress_type) 132 133 # Save as XML. 134 ds.to_xml(file) 135 136 # Close the file. 137 file.close()138
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sat Jun 8 10:45:13 2024 | http://epydoc.sourceforge.net |