Author: bugman Date: Sat Jun 9 16:56:21 2012 New Revision: 16802 URL: http://svn.gna.org/viewcvs/relax?rev=16802&view=rev Log: The bmrb.display user function is now operational. This user function never worked as pystarlib expects a file path as a string, but a modification of pystarlib fixes this. The bmrb.display simply now calls the write() function with STDOUT as the file. The write() function was modified to handle file handles. Modified: branches/uf_redesign/generic_fns/bmrb.py Modified: branches/uf_redesign/generic_fns/bmrb.py URL: http://svn.gna.org/viewcvs/relax/branches/uf_redesign/generic_fns/bmrb.py?rev=16802&r1=16801&r2=16802&view=diff ============================================================================== --- branches/uf_redesign/generic_fns/bmrb.py (original) +++ branches/uf_redesign/generic_fns/bmrb.py Sat Jun 9 16:56:21 2012 @@ -33,6 +33,7 @@ import dep_check from generic_fns import exp_info from generic_fns.mol_res_spin import create_spin, generate_spin_id, return_residue, return_spin +from generic_fns.pipes import cdp_name from info import Info_box from relax_errors import RelaxError, RelaxFileError, RelaxFileOverwriteError, RelaxNoModuleInstallError, RelaxNoPipeError from relax_io import get_file_path, mkdir_nofail @@ -42,21 +43,14 @@ def display(version='3.1'): - """Display the results in the BMRB NMR-STAR format.""" - - # Test if bmrblib is installed. - if not dep_check.bmrblib_module: - raise RelaxNoModuleInstallError('BMRB library', 'bmrblib') - - # Test if the current data pipe exists. - if not ds.current_pipe: - raise RelaxNoPipeError - - # Specific results writing function. - write_function = specific_fns.setup.get_specific_fn('bmrb_write', ds[ds.current_pipe].pipe_type, raise_error=False) - - # Write the results. - write_function(sys.stdout, version=version) + """Display the results in the BMRB NMR-STAR format. + + @keyword version: The NMR-STAR version to create. This can be either '2.1', '3.0', or '3.1'. + @type version: str + """ + + # Call the write() function with stdout. + write(file=sys.stdout, version=version) def generate_sequence(N=0, spin_ids=None, spin_nums=None, spin_names=None, res_nums=None, res_names=None, mol_names=None): @@ -210,11 +204,12 @@ raise RelaxNoModuleInstallError('BMRB library', 'bmrblib') # Test if the current data pipe exists. - if not ds.current_pipe: + pipe_name = cdp_name() + if not pipe_name: raise RelaxNoPipeError # Make sure that the data pipe is empty. - if not ds[ds.current_pipe].is_empty(): + if not ds[pipe_name].is_empty(): raise RelaxError("The current data pipe is not empty.") # Get the full file path. @@ -225,46 +220,59 @@ raise RelaxFileError(file_path) # Specific results reading function. - read_function = specific_fns.setup.get_specific_fn('bmrb_read', ds[ds.current_pipe].pipe_type) + read_function = specific_fns.setup.get_specific_fn('bmrb_read', ds[pipe_name].pipe_type) # Read the results. read_function(file_path, version=version, sample_conditions=sample_conditions) def write(file=None, dir=None, version='3.1', force=False): - """Create a BMRB NMR-STAR formatted file.""" + """Create a BMRB NMR-STAR formatted file. + + @keyword file: The name of the file to create or a file object. + @type file: str or file object + @keyword dir: The optional directory to place the file into. If set to 'pipe_name', then it will be placed in a directory with the same name as the current data pipe. + @type dir: str or None + @keyword version: The NMR-STAR version to create. This can be either '2.1', '3.0', or '3.1'. + @type version: str + @keyword force: A flag which if True will allow a currently existing file to be overwritten. + @type force: bool + """ # Test if bmrblib is installed. if not dep_check.bmrblib_module: raise RelaxNoModuleInstallError('BMRB library', 'bmrblib') # Test if the current data pipe exists. - if not ds.current_pipe: + pipe_name = cdp_name() + if not pipe_name: raise RelaxNoPipeError # Check the file name. if file == None: raise RelaxError("The file name must be specified.") - # The special data pipe name directory. - if dir == 'pipe_name': - dir = ds.current_pipe + # A file object. + if isinstance(file, str): + # The special data pipe name directory. + if dir == 'pipe_name': + dir = pipe_name + + # Get the full file path. + file = get_file_path(file, dir) + + # Fail if the file already exists and the force flag is False. + if access(file, F_OK) and not force: + raise RelaxFileOverwriteError(file, 'force flag') + + # Print out. + print("Opening the file '%s' for writing." % file) + + # Create the directories. + mkdir_nofail(dir, verbosity=0) # Specific results writing function. - write_function = specific_fns.setup.get_specific_fn('bmrb_write', ds[ds.current_pipe].pipe_type) - - # Get the full file path. - file_path = get_file_path(file, dir) - - # Fail if the file already exists and the force flag is False. - if access(file_path, F_OK) and not force: - raise RelaxFileOverwriteError(file_path, 'force flag') - - # Print out. - print("Opening the file '%s' for writing." % file_path) - - # Create the directories. - mkdir_nofail(dir, verbosity=0) + write_function = specific_fns.setup.get_specific_fn('bmrb_write', ds[pipe_name].pipe_type) # Get the info box. info = Info_box() @@ -281,10 +289,11 @@ cdp.exp_info.software_setup(name=exp_info.SOFTWARE['relax'].name, version=version_full(), vendor_name=exp_info.SOFTWARE['relax'].authors, url=exp_info.SOFTWARE['relax'].url, cite_ids=['relax_ref1', 'relax_ref2'], tasks=exp_info.SOFTWARE['relax'].tasks) # Execute the specific BMRB writing code. - write_function(file_path, version=version) + write_function(file, version=version) # Add the file to the results file list. - if not hasattr(cdp, 'result_files'): - cdp.result_files = [] - cdp.result_files.append(['text', 'BMRB', file_path]) - status.observers.result_file.notify() + 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()