Author: bugman Date: Thu Dec 18 12:13:07 2014 New Revision: 27129 URL: http://svn.gna.org/viewcvs/relax?rev=27129&view=rev Log: Enabled the gnuplot format for the structure.atomic_fluctuations user function. This uses the plotting API correlation_matrix() function for visualisation. The change allows the Structure.test_atomic_fluctuations_gnuplot system test to pass. Modified: trunk/pipe_control/structure/main.py trunk/user_functions/structure.py Modified: trunk/pipe_control/structure/main.py URL: http://svn.gna.org/viewcvs/relax/trunk/pipe_control/structure/main.py?rev=27129&r1=27128&r2=27129&view=diff ============================================================================== --- trunk/pipe_control/structure/main.py (original) +++ trunk/pipe_control/structure/main.py Thu Dec 18 12:13:07 2014 @@ -32,6 +32,7 @@ from lib.check_types import is_float from lib.errors import RelaxError, RelaxFileError from lib.io import get_file_path, open_write_file, write_data +from lib.plotting.api import correlation_matrix from lib.selection import tokenise from lib.sequence import write_spin_data from lib.structure.internal.coordinates import assemble_coord_array, loop_coord_structures @@ -237,11 +238,11 @@ @type molecules: None or list of lists of str @keyword atom_id: The atom identification string of the coordinates of interest. This matches the spin ID string format. @type atom_id: str or None - @keyword file: The name of the PDB file to write. + @keyword file: The name of the file to write. @type file: str - @keyword format: The output format. This is currently only "text" for text file output. + @keyword format: The output format. This can be set to "text" for text file output, or "gnuplot" for creating a gnuplot script. @type format: str - @keyword dir: The directory where the PDB file will be placed. If set to None, then the file will be placed in the current directory. + @keyword dir: The directory where the file will be placed. If set to None, then the file will be placed in the current directory. @type dir: str or None @keyword force: The force flag which if True will cause the file to be overwritten. @type force: bool @@ -250,7 +251,7 @@ # Checks. check_pipe() check_structure() - format_list = ['text'] + format_list = ['text', 'gnuplot'] if format not in format_list: raise RelaxError("The format '%s' must be one of %s." % (format, format_list)) @@ -262,20 +263,21 @@ raise RelaxError("Two or more structures are required.") # The output file. - file = open_write_file(file, dir=dir, force=force) + output = open_write_file(file, dir=dir, force=force) # The header line. - file.write('#') + output.write('#') + labels = [] for i in range(len(atom_names)): # The spin identification string. - id = generate_spin_id_unique(mol_name=mol_names[i], res_num=res_nums[i], res_name=res_names[i], spin_name=atom_names[i]) + labels.append(generate_spin_id_unique(mol_name=mol_names[i], res_num=res_nums[i], res_name=res_names[i], spin_name=atom_names[i])) # Output the spin ID. if i == 0: - file.write(" %18s" % id) + output.write(" %18s" % labels[i]) else: - file.write(" %20s" % id) - file.write('\n') + output.write(" %20s" % labels[i]) + output.write('\n') # Generate the pairwise matrix. n = len(atom_names) @@ -292,12 +294,20 @@ # Output the matrix. if j == 0: - file.write("%20.15f" % matrix[i, j]) + output.write("%20.15f" % matrix[i, j]) else: - file.write(" %20.15f" % matrix[i, j]) + output.write(" %20.15f" % matrix[i, j]) # End of the current line. - file.write('\n') + output.write('\n') + + # Close the file. + output.close() + + # The gnuplot script. + if format == 'gnuplot': + # Call the plotting API. + correlation_matrix(format=format, matrix=matrix, labels=labels, file=file, dir=dir, force=force) def connect_atom(index1=None, index2=None): Modified: trunk/user_functions/structure.py URL: http://svn.gna.org/viewcvs/relax/trunk/user_functions/structure.py?rev=27129&r1=27128&r2=27129&view=diff ============================================================================== --- trunk/user_functions/structure.py (original) +++ trunk/user_functions/structure.py Thu Dec 18 12:13:07 2014 @@ -298,7 +298,7 @@ py_type = "str_or_inst", arg_type = "file sel", desc_short = "file name", - desc = "The name of the text file.", + desc = "The name of the text file to create.", wiz_filesel_style = FD_SAVE ) uf.add_keyarg( @@ -306,10 +306,10 @@ py_type = "str", default = "text", desc_short = "output format", - desc = "The output format.", + desc = "The output format. For all formats other than the text file, a second file will be created with the same name as the text file but with the appropriate file extension added.", wiz_element_type = "combo", - wiz_combo_choices = ["Text file"], - wiz_combo_data = ["text"] + wiz_combo_choices = ["Text file", "Gnuplot script"], + wiz_combo_data = ["text", "gnuplot"] ) uf.add_keyarg( name = "dir", @@ -329,6 +329,9 @@ # Description. uf.desc.append(Desc_container()) uf.desc[-1].add_paragraph("This is used to visualise the interatomic distance fluctuations between different structures. The corrected sample standard deviation (SD) is calculated for the distances between all atom pairs, resulting in a pairwise matrix of SD values. The matrix will be output into a text file.") +uf.desc[-1].add_paragraph("In addition to creating the text file, a second file will be created if the format argument is set to anything other than the text file. It will have the same name as the text file, however the file extension will be changed to match the format. The currently supported formats are:") +uf.desc[-1].add_item_list_element("'text'", "This is the default value and will result in a single text file being created.") +uf.desc[-1].add_item_list_element("'gnuplot'", "This will create a script for visualising the correlation matrix using gnuplot.") uf.desc[-1].add_paragraph(paragraph_multi_struct) uf.desc[-1].add_paragraph(paragraph_atom_id) # Prompt examples. @@ -339,7 +342,7 @@ uf.desc[-1].add_prompt("relax> structure.atomic_fluctuations(molecules=[['A', 'B', 'C', 'D']], file='atomic_fluctuation_matrix')") uf.backend = pipe_control.structure.main.atomic_fluctuations uf.menu_text = "&atomic_fluctuations" -uf.wizard_height_desc = 450 +uf.wizard_height_desc = 400 uf.wizard_size = (1000, 750) uf.wizard_apply_button = False uf.wizard_image = WIZARD_IMAGE_PATH + 'structure' + sep + '2JK4.png'