Author: bugman Date: Tue Sep 18 16:15:01 2012 New Revision: 17489 URL: http://svn.gna.org/viewcvs/relax?rev=17489&view=rev Log: Created the new generic_fns.result_files for standardising the handling of results files. This fixes the bug where results files are repetitively added to the list. All of the code touching cdp.result_files now uses this module instead. Added: trunk/generic_fns/result_files.py Modified: trunk/generic_fns/__init__.py trunk/generic_fns/bmrb.py trunk/generic_fns/grace.py trunk/generic_fns/molmol.py trunk/generic_fns/pymol_control.py trunk/generic_fns/value.py Modified: trunk/generic_fns/__init__.py URL: http://svn.gna.org/viewcvs/relax/trunk/generic_fns/__init__.py?rev=17489&r1=17488&r2=17489&view=diff ============================================================================== --- trunk/generic_fns/__init__.py (original) +++ trunk/generic_fns/__init__.py Tue Sep 18 16:15:01 2012 @@ -49,6 +49,7 @@ 'relax_data', 'relax_re', 'reset', + 'result_files', 'results', 'script', 'selection', Modified: trunk/generic_fns/bmrb.py URL: http://svn.gna.org/viewcvs/relax/trunk/generic_fns/bmrb.py?rev=17489&r1=17488&r2=17489&view=diff ============================================================================== --- trunk/generic_fns/bmrb.py (original) +++ trunk/generic_fns/bmrb.py Tue Sep 18 16:15:01 2012 @@ -33,6 +33,7 @@ from generic_fns import exp_info from generic_fns.mol_res_spin import create_spin, generate_spin_id, return_residue, return_spin, set_spin_element, set_spin_isotope from generic_fns.pipes import cdp_name +from generic_fns.result_files import add_result_file from info import Info_box from relax_errors import RelaxError, RelaxFileError, RelaxFileOverwriteError, RelaxNoModuleInstallError, RelaxNoPipeError from relax_io import get_file_path, mkdir_nofail @@ -288,7 +289,4 @@ # Add the file to the results file list. if isinstance(file, str): - if not hasattr(cdp, 'result_files'): - cdp.result_files = [] - cdp.result_files.append(['text', 'BMRB', file]) - status.observers.result_file.notify() + add_result_file(type='text', label='BMRB', file=file) Modified: trunk/generic_fns/grace.py URL: http://svn.gna.org/viewcvs/relax/trunk/generic_fns/grace.py?rev=17489&r1=17488&r2=17489&view=diff ============================================================================== --- trunk/generic_fns/grace.py (original) +++ trunk/generic_fns/grace.py Tue Sep 18 16:15:01 2012 @@ -31,6 +31,7 @@ import generic_fns from generic_fns.mol_res_spin import count_molecules, count_residues, count_spins, exists_mol_res_spin_data, generate_spin_id, spin_loop from generic_fns import pipes +from generic_fns.result_files import add_result_file from relax_errors import RelaxError, RelaxNoSequenceError, RelaxNoSimError from relax_io import get_file_path, open_write_file, test_binary from relax_warnings import RelaxWarning @@ -421,11 +422,7 @@ file.close() # Add the file to the results file list. - if not hasattr(cdp, 'result_files'): - cdp.result_files = [] - cdp.result_files.append(['grace', 'Grace', file_path]) - status.observers.result_file.notify() - + add_result_file(type='grace', label='Grace', file=file_path) def write_xy_data(data, file=None, graph_type=None, norm=False): Modified: trunk/generic_fns/molmol.py URL: http://svn.gna.org/viewcvs/relax/trunk/generic_fns/molmol.py?rev=17489&r1=17488&r2=17489&view=diff ============================================================================== --- trunk/generic_fns/molmol.py (original) +++ trunk/generic_fns/molmol.py Tue Sep 18 16:15:01 2012 @@ -1,6 +1,6 @@ ############################################################################### # # -# Copyright (C) 2004-2011 Edward d'Auvergne # +# Copyright (C) 2004-2012 Edward d'Auvergne # # # # This file is part of the program relax (http://www.nmr-relax.com). # # # @@ -31,6 +31,7 @@ # relax module imports. from generic_fns.mol_res_spin import exists_mol_res_spin_data from generic_fns import pipes +from generic_fns.result_files import add_result_file from relax_errors import RelaxError, RelaxNoSequenceError from relax_io import get_file_path, open_read_file, open_write_file, test_binary from specific_fns.setup import get_specific_fn @@ -338,10 +339,7 @@ file.close() # Add the file to the results file list. - if not hasattr(cdp, 'result_files'): - cdp.result_files = [] - cdp.result_files.append(['molmol', 'Molmol', file_path]) - status.observers.result_file.notify() + add_result_file(type='molmol', label='Molmol', file=file_path) def ribbon(): Modified: trunk/generic_fns/pymol_control.py URL: http://svn.gna.org/viewcvs/relax/trunk/generic_fns/pymol_control.py?rev=17489&r1=17488&r2=17489&view=diff ============================================================================== --- trunk/generic_fns/pymol_control.py (original) +++ trunk/generic_fns/pymol_control.py Tue Sep 18 16:15:01 2012 @@ -1,6 +1,6 @@ ############################################################################### # # -# Copyright (C) 2006-2011 Edward d'Auvergne # +# Copyright (C) 2006-2012 Edward d'Auvergne # # # # This file is part of the program relax (http://www.nmr-relax.com). # # # @@ -38,6 +38,7 @@ # relax module imports. from generic_fns.mol_res_spin import exists_mol_res_spin_data from generic_fns import pipes +from generic_fns.result_files import add_result_file from maths_fns.rotation_matrix import euler_to_R_zyz, R_to_axis_angle from relax_errors import RelaxError, RelaxNoPdbError, RelaxNoSequenceError from relax_io import delete, file_root, get_file_path, open_read_file, open_write_file, test_binary @@ -512,10 +513,7 @@ file.close() # Add the file to the results file list. - if not hasattr(cdp, 'result_files'): - cdp.result_files = [] - cdp.result_files.append(['pymol', 'PyMOL', file_path]) - status.observers.result_file.notify() + add_result_file(type='pymol', label='PyMOL', file=file_path) def tensor_pdb(file=None): Added: trunk/generic_fns/result_files.py URL: http://svn.gna.org/viewcvs/relax/trunk/generic_fns/result_files.py?rev=17489&view=auto ============================================================================== --- trunk/generic_fns/result_files.py (added) +++ trunk/generic_fns/result_files.py Tue Sep 18 16:15:01 2012 @@ -1,0 +1,58 @@ +############################################################################### +# # +# Copyright (C) 2012 Edward d'Auvergne # +# # +# This file is part of the program relax (http://www.nmr-relax.com). # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see <http://www.gnu.org/licenses/>. # +# # +############################################################################### + +# Module docstring. +"""Module for handling result files.""" + +# relax module imports. +from status import Status; status = Status() + + +def add_result_file(type=None, label=None, file=None): + """Add a results file to the current data pipe. + + @keyword type: The mimetype of the result file, for example 'text', 'grace', 'molmol' or 'pymol'. + @type type: str + @keyword label: The label to attach to the file. For example a BMRB file can have the label 'BMRB' and type 'text'. + @type label: str + @keyword file: The path of the file. + @type file: str + """ + + # First check if the structure exists, creating it if needed. + if not hasattr(cdp, 'result_files'): + cdp.result_files = [] + + # Check if the file already exists. + for i in range(len(cdp.result_files)): + if cdp.result_files[i][2] == file: + # Overwrite the settings. + cdp.result_files[i][0] = type + cdp.result_files[i][1] = label + + # Nothing left to do. + return True + + # Add the file. + cdp.result_files.append([type, label, file]) + + # Notify all observers. + status.observers.result_file.notify() Modified: trunk/generic_fns/value.py URL: http://svn.gna.org/viewcvs/relax/trunk/generic_fns/value.py?rev=17489&r1=17488&r2=17489&view=diff ============================================================================== --- trunk/generic_fns/value.py (original) +++ trunk/generic_fns/value.py Tue Sep 18 16:15:01 2012 @@ -29,6 +29,7 @@ # relax module imports. from generic_fns import minimise, pipes from generic_fns.mol_res_spin import exists_mol_res_spin_data, generate_spin_id, generate_spin_id_data_array, return_spin, spin_loop +from generic_fns.result_files import add_result_file from relax_errors import RelaxError, RelaxNoSequenceError, RelaxNoSpinError, RelaxParamSetError, RelaxValueError from relax_io import get_file_path, open_write_file, read_spin_data, write_spin_data import specific_fns @@ -462,10 +463,7 @@ file.close() # Add the file to the results file list. - if not hasattr(cdp, 'result_files'): - cdp.result_files = [] - cdp.result_files.append(['text', 'Text', file_path]) - status.observers.result_file.notify() + add_result_file(type='text', label='Text', file=file_path) def write_data(param=None, file=None, bc=False, return_value=None):