mailr27122 - in /trunk: pipe_control/structure/main.py user_functions/structure.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on December 18, 2014 - 10:03:
Author: bugman
Date: Thu Dec 18 10:03:26 2014
New Revision: 27122

URL: http://svn.gna.org/viewcvs/relax?rev=27122&view=rev
Log:
Implemented the structure.atomic_fluctuations user function.

This is loosely based on the structure.web_of_motion user function and is 
related to it.  The user
function will write to file a correlation matrix of interatomic distance 
fluctuations.


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=27122&r1=27121&r2=27122&view=diff
==============================================================================
--- trunk/pipe_control/structure/main.py        (original)
+++ trunk/pipe_control/structure/main.py        Thu Dec 18 10:03:26 2014
@@ -21,7 +21,7 @@
 
 # Python module imports.
 from minfx.generic import generic_minimise
-from numpy import array, float64, zeros
+from numpy import array, float64, std, zeros
 from numpy.linalg import norm
 from os import F_OK, access, getcwd
 from re import search
@@ -224,6 +224,80 @@
 
     # Call the library method to do all of the work.
     return assemble_coord_array(objects=objects, object_names=object_names, 
molecules=molecules, models=models, atom_id=atom_id, 
seq_info_flag=seq_info_flag)
+
+
+def atomic_fluctuations(pipes=None, models=None, molecules=None, 
atom_id=None, file=None, format='text', dir=None, force=False):
+    """Write out a correlation matrix of pairwise interatomic distance 
fluctuations between different structures.
+
+    @keyword pipes:     The data pipes to generate the interatomic distance 
fluctuation correlation matrix for.
+    @type pipes:        None or list of str
+    @keyword models:    The list of models to generate the interatomic 
distance fluctuation correlation matrix for.  The number of elements must 
match the pipes argument.  If set to None, then all models will be used.
+    @type models:       None or list of lists of int
+    @keyword molecules: The list of molecules to generate the interatomic 
distance fluctuation correlation matrix for.  The number of elements must 
match the pipes argument.
+    @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.
+    @type file:         str
+    @keyword format:    The output format.  This is currently only "text" 
for text file output.
+    @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.
+    @type dir:          str or None
+    @keyword force:     The force flag which if True will cause the file to 
be overwritten.
+    @type force:        bool
+    """
+
+    # Checks.
+    check_pipe()
+    check_structure()
+    format_list = ['text']
+    if format not in format_list:
+        raise RelaxError("The format '%s' must be one of %s." % (format, 
format_list))
+
+    # Assemble the atomic coordinates.
+    coord, ids, mol_names, res_names, res_nums, atom_names, elements = 
assemble_coordinates(pipes=pipes, molecules=molecules, models=models, 
atom_id=atom_id, seq_info_flag=True)
+
+    # Check that more than one structure is present.
+    if not len(coord) > 1:
+        raise RelaxError("Two or more structures are required.")
+
+    # The output file.
+    file = open_write_file(file, dir=dir, force=force)
+
+    # The header line.
+    file.write('#')
+    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])
+
+        # Output the spin ID.
+        if i == 0:
+            file.write(" %18s" % id)
+        else:
+            file.write(" %20s" % id)
+    file.write('\n')
+
+    # Generate the pairwise matrix.
+    n = len(atom_names)
+    matrix = zeros((n, n), float64)
+    for i in range(n):
+        for j in range(n):
+            # The interatomic distances between each structure.
+            dist = []
+            for k in range(len(coord)):
+                dist.append(norm(coord[k, i] - coord[k, j]))
+
+            # Calculate and store the corrected sample standard deviation.
+            matrix[i, j] = std(array(dist, float64), ddof=1)
+
+            # Output the matrix.
+            if j == 0:
+                file.write("%20.15f" % matrix[i, j])
+            else:
+                file.write(" %20.15f" % matrix[i, j])
+
+        # End of the current line.
+        file.write('\n')
 
 
 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=27122&r1=27121&r2=27122&view=diff
==============================================================================
--- trunk/user_functions/structure.py   (original)
+++ trunk/user_functions/structure.py   Thu Dec 18 10:03:26 2014
@@ -256,6 +256,92 @@
 uf.wizard_apply_button = False
 uf.wizard_height_desc = 370
 uf.wizard_size = (1000, 750)
+uf.wizard_image = WIZARD_IMAGE_PATH + 'structure' + sep + '2JK4.png'
+
+
+# The structure.atomic_fluctuations user function.
+uf = uf_info.add_uf('structure.atomic_fluctuations')
+uf.title = "Create an interatomic distance fluctuation correlation matrix."
+uf.title_short = "Interatomic distance fluctuation correlation matrix."
+uf.add_keyarg(
+    name = "pipes",
+    py_type = "str_list",
+    desc_short = "data pipes",
+    desc = "The data pipes to generate the interatomic distance fluctuation 
correlation matrix for.",
+    wiz_combo_iter = pipe_names,
+    wiz_read_only = False,
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "models",
+    py_type = "int_list_of_lists",
+    desc_short = "model list for each data pipe",
+    desc = "The list of models for each data pipe to generate the 
interatomic distance fluctuation correlation matrix for.  The number of 
elements must match the pipes argument.  If no models are given, then all 
will be used.",
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "molecules",
+    py_type = "str_list_of_lists",
+    desc_short = "molecule list for each data pipe",
+    desc = "The list of molecules for each data pipe to generate the 
interatomic distance fluctuation correlation matrix for.  This allows 
differently named molecules in the same or different data pipes to be 
superimposed.  The number of elements must match the pipes argument.  If no 
molecules are given, then all will be used.",
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "atom_id",
+    py_type = "str",
+    desc_short = "atom identification string",
+    desc = "The atom identification string of the coordinates of interest.  
This can be used to restrict the correlation matrix to one atom per residue, 
for example.",
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "file",
+    py_type = "str_or_inst",
+    arg_type = "file sel",
+    desc_short = "file name",
+    desc = "The name of the text file.",
+    wiz_filesel_style = FD_SAVE
+)
+uf.add_keyarg(
+    name = "format",
+    py_type = "str",
+    default = "text",
+    desc_short = "output format",
+    desc = "The output format.",
+    wiz_element_type = "combo",
+    wiz_combo_choices = ["Text file"],
+    wiz_combo_data = ["text"]
+)
+uf.add_keyarg(
+    name = "dir",
+    py_type = "str",
+    arg_type = "dir",
+    desc_short = "directory name",
+    desc = "The directory to save the file to.",
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "force",
+    default = False,
+    py_type = "bool",
+    desc_short = "force flag",
+    desc = "A flag which if set to True will cause any pre-existing files to 
be overwritten."
+)
+# 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(paragraph_multi_struct)
+uf.desc[-1].add_paragraph(paragraph_atom_id)
+# Prompt examples.
+uf.desc.append(Desc_container("Prompt examples"))
+uf.desc[-1].add_paragraph("To create the interatomic distance fluctuation 
correlation matrix for the models 1, 3, and 5, type:")
+uf.desc[-1].add_prompt("relax> structure.atomic_fluctuations(models=[[1, 3, 
5]], file='atomic_fluctuation_matrix')")
+uf.desc[-1].add_paragraph("To create the interatomic distance fluctuation 
correlation matrix for the molecules 'A', 'B', 'C', and 'D', type:")
+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_size = (1000, 750)
+uf.wizard_apply_button = False
 uf.wizard_image = WIZARD_IMAGE_PATH + 'structure' + sep + '2JK4.png'
 
 




Related Messages


Powered by MHonArc, Updated Thu Dec 18 10:40:04 2014