def write(param=None, file=None, dir=None, scaling=1.0, return_value=None, return_data_desc=None, comment=None, bc=False, force=False): """Write data to a file. @keyword param: The name of the parameter to write to file. @type param: str @keyword file: The file to write the data to. @type file: str @keyword dir: The name of the directory to place the file into (defaults to the current directory). @type dir: str @keyword scaling: The value to scale the parameter by. @type scaling: float @keyword return_value: An optional function which if supplied will override the default value returning function. @type return_value: None or func @keyword return_data_desc: An optional function which if supplied will override the default parameter description returning function. @type return_data_desc: None or func @keyword comment: Text which will be added to the start of the file as comments. All lines will be prefixed by '# '. @type comment: str @keyword bc: A flag which if True will cause the back calculated values to be written. @type bc: bool @keyword force: A flag which if True will cause any pre-existing file to be overwritten. @type force: bool """ # Test if the current pipe exists. check_pipe() # Test if the sequence data is loaded. if not exists_mol_res_spin_data(): raise RelaxNoSequenceError # Open the file for writing. file_path = get_file_path(file, dir) file = open_write_file(file, dir, force) # Write the data. write_data(param=param, file=file, scaling=scaling, return_value=return_value, return_data_desc=return_data_desc, comment=comment, bc=bc) # Close the file. file.close() # Add the file to the results file list. add_result_file(type='text', label='Text', file=file_path)
def macro_write(data_type=None, style="classic", colour_start_name=None, colour_start_rgb=None, colour_end_name=None, colour_end_rgb=None, colour_list=None, file=None, dir=None, force=False): """Create a Molmol macro. @keyword data_type: The data type to map to the structure. @type data_type: str @keyword style: The style of the macro. @type style: str @keyword colour_start_name: The name of the starting colour of the linear gradient. @type colour_start_name: str @keyword colour_start_rgb: The RGB array starting colour of the linear gradient. @type colour_start_rgb: RBG colour array (len 3 with vals from 0 to 1) @keyword colour_end_name: The name of the ending colour of the linear gradient. @type colour_end_name: str @keyword colour_end_rgb: The RGB array ending colour of the linear gradient. @type colour_end_rgb: RBG colour array (len 3 with vals from 0 to 1) @keyword colour_list: The colour list to search for the colour names. Can be either 'molmol' or 'x11'. @type colour_list: str or None @keyword file: The name of the macro file to create. @type file: str @keyword dir: The name of the directory to place the macro file into. @type dir: str @keyword force: Flag which if set to True will cause any pre-existing file to be overwritten. @type force: bool """ # Test if the current data pipe exists. check_pipe() # Test if sequence data exists. if not exists_mol_res_spin_data(): raise RelaxNoSequenceError # Check the arguments. if colour_start_name != None and colour_start_rgb != None: raise RelaxError( "The starting colour name and RGB colour array cannot both be supplied." ) if colour_end_name != None and colour_end_rgb != None: raise RelaxError( "The ending colour name and RGB colour array cannot both be supplied." ) # Merge the colour args. if colour_start_name != None: colour_start = colour_start_name else: colour_start = colour_start_rgb if colour_end_name != None: colour_end = colour_end_name else: colour_end = colour_end_rgb # Create the macro. commands = create_macro(data_type=data_type, style=style, colour_start=colour_start, colour_end=colour_end, colour_list=colour_list) # File name. if file == None: file = data_type + '.mac' # Open the file for writing. file_path = get_file_path(file, dir) file = open_write_file(file, dir, force) # Loop over the commands and write them. for command in commands: file.write(command + "\n") # Close the file. file.close() # Add the file to the results file list. add_result_file(type='molmol', label='Molmol', file=file_path)
def write(file=None, dir=None, version='3.1', force=False): """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. 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.") # 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) # Get the info box. info = Info_box() # Add the relax citations. for id, key in zip(['relax_ref1', 'relax_ref2'], ['dAuvergneGooley08a', 'dAuvergneGooley08b']): # Alias the bib entry. bib = info.bib[key] # Add. exp_info.citation(cite_id=id, authors=bib.author2, doi=bib.doi, pubmed_id=bib.pubmed_id, full_citation=bib.cite_short(doi=False, url=False), title=bib.title, status=bib.status, type=bib.type, journal_abbrev=bib.journal, journal_full=bib.journal_full, volume=bib.volume, issue=bib.number, page_first=bib.page_first, page_last=bib.page_last, year=bib.year) # Add the relax software package. exp_info.software(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. api = return_api(pipe_name=pipe_name) api.bmrb_write(file, version=version) # Add the file to the results file list. if isinstance(file, str): add_result_file(type='text', label='BMRB', file=file)
def write(file=None, dir=None, version='3.1', force=False): """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. 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.") # 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_analyses.setup.get_specific_fn('bmrb_write', ds[pipe_name].pipe_type) # Get the info box. info = Info_box() # Add the relax citations. for id, key in zip(['relax_ref1', 'relax_ref2'], ['dAuvergneGooley08a', 'dAuvergneGooley08b']): # Alias the bib entry. bib = info.bib[key] # Add. exp_info.citation(cite_id=id, authors=bib.author2, doi=bib.doi, pubmed_id=bib.pubmed_id, full_citation=bib.cite_short(doi=False, url=False), title=bib.title, status=bib.status, type=bib.type, journal_abbrev=bib.journal, journal_full=bib.journal_full, volume=bib.volume, issue=bib.number, page_first=bib.page_first, page_last=bib.page_last, year=bib.year) # Add the relax software package. exp_info.software(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, version=version) # Add the file to the results file list. if isinstance(file, str): add_result_file(type='text', label='BMRB', file=file)
def macro_write(data_type=None, style="classic", colour_start_name=None, colour_start_rgb=None, colour_end_name=None, colour_end_rgb=None, colour_list=None, file=None, dir=None, force=False): """Create a PyMOL macro file. @keyword data_type: The data type to map to the structure. @type data_type: str @keyword style: The style of the macro. @type style: str @keyword colour_start_name: The name of the starting colour of the linear gradient. @type colour_start_name: str @keyword colour_start_rgb: The RGB array starting colour of the linear gradient. @type colour_start_rgb: RBG colour array (len 3 with vals from 0 to 1) @keyword colour_end_name: The name of the ending colour of the linear gradient. @type colour_end_name: str @keyword colour_end_rgb: The RGB array ending colour of the linear gradient. @type colour_end_rgb: RBG colour array (len 3 with vals from 0 to 1) @keyword colour_list: The colour list to search for the colour names. Can be either 'molmol' or 'x11'. @type colour_list: str or None @keyword file: The name of the macro file to create. @type file: str @keyword dir: The name of the directory to place the macro file into. @type dir: str @keyword force: Flag which if set to True will cause any pre-existing file to be overwritten. @type force: bool """ # Test if the current data pipe exists. pipes.test() # Test if sequence data exists. if not exists_mol_res_spin_data(): raise RelaxNoSequenceError # Check the arguments. if colour_start_name != None and colour_start_rgb != None: raise RelaxError("The starting colour name and RGB colour array cannot both be supplied.") if colour_end_name != None and colour_end_rgb != None: raise RelaxError("The ending colour name and RGB colour array cannot both be supplied.") # Merge the colour args. if colour_start_name != None: colour_start = colour_start_name else: colour_start = colour_start_rgb if colour_end_name != None: colour_end = colour_end_name else: colour_end = colour_end_rgb # Create the macro. commands = create_macro(data_type=data_type, style=style, colour_start=colour_start, colour_end=colour_end, colour_list=colour_list) # File name. if file == None: file = data_type + '.pml' # Open the file for writing. file_path = get_file_path(file, dir) file = open_write_file(file, dir, force) # Loop over the commands and write them. for command in commands: file.write(command + "\n") # Close the file. file.close() # Add the file to the results file list. add_result_file(type='pymol', label='PyMOL', file=file_path)
def write_xy(format='grace', x_data_type='res_num', y_data_type=None, spin_id=None, plot_data='value', norm_type='first', file=None, dir=None, force=False, norm=True): """Writing data to a file. @keyword format: The specific backend to use. The currently support backends are 'grace'. @type format: str @keyword x_data_type: The category of the X-axis data. @type x_data_type: str @keyword y_data_type: The category of the Y-axis data. @type y_data_type: str @keyword spin_id: The spin identification string. @type spin_id: str @keyword plot_data: The type of the plotted data, one of 'value', 'error', or 'sim'. @type plot_data: str @keyword norm_type: The point to normalise to 1. This can be 'first' or 'last'. @type norm_type: str @keyword file: The name of the Grace file to create. @type file: str @keyword dir: The optional directory to place the file into. @type dir: str @param force: Boolean argument which if True causes the file to be overwritten if it already exists. @type force: bool @keyword norm: The normalisation flag which if set to True will cause all graphs to be normalised to a starting value of 1. @type norm: bool """ # Checks. check_pipe() check_mol_res_spin_data() # Test if the plot_data argument is one of 'value', 'error', or 'sim'. if plot_data not in ['value', 'error', 'sim']: raise RelaxError("The plot data argument " + repr(plot_data) + " must be set to either 'value', 'error', 'sim'.") # Test if the simulations exist. if plot_data == 'sim' and not hasattr(cdp, 'sim_number'): raise RelaxNoSimError # Open the file for writing. file_path = get_file_path(file, dir) file = open_write_file(file, dir, force) # Get the data. data, set_names, graph_type = assemble_data(spin_id, x_data_name=x_data_type, y_data_name=y_data_type, plot_data=plot_data) # Convert the graph type. if graph_type == 'X,Y': graph_type = 'xy' elif graph_type == 'X,Y,dX': graph_type = 'xydx' elif graph_type == 'X,Y,dY': graph_type = 'xydy' elif graph_type == 'X,Y,dX,dY': graph_type = 'xydxdy' # No data, so close the empty file and exit. if not len(data) or not len(data[0]) or not len(data[0][0]): warn(RelaxWarning("No data could be found, creating an empty file.")) file.close() return # Get the axis information. data_type = [x_data_type, y_data_type] seq_type, axis_labels = axis_setup(data_type=data_type, norm=norm) # Write the header. write_xy_header(format=format, file=file, data_type=data_type, seq_type=seq_type, sets=[len(data[0])], set_names=[set_names], axis_labels=[axis_labels], norm=[norm]) # Write the data. write_xy_data(format=format, data=data, file=file, graph_type=graph_type, norm_type=norm_type, norm=[norm]) # Close the file. file.close() # Add the file to the results file list. label = None if format == 'grace': label = 'Grace' add_result_file(type=format, label='Grace', file=file_path)