mailr27639 - in /trunk: lib/structure/internal/object.py 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 February 13, 2015 - 17:45:
Author: bugman
Date: Fri Feb 13 17:45:08 2015
New Revision: 27639

URL: http://svn.gna.org/viewcvs/relax?rev=27639&view=rev
Log:
Converted the structure.mean user function to the new 
pipe/model/molecule/atom_id design.

This allows the average structure calculation to work on atomic coordinates 
from different data
pipes, different structural models, and different molecules.  The user 
function backend uses the new
pipe_control.structure.main.assemble_structural_coordinates() function to 
assemble the common atom
coordinates, molecule names, residue names, residue numbers, atom names and 
elements.  All this
information is then used to construct a new molecule container for storing 
the average structure in
the internal structural object.

To allow for the averaged structural data to be stored, the internal 
structural object method
add_coordinates() has been created.  This is modelled on the PDB, Gaussian, 
and XYZ format loading
methods.  The internal structural object mean() method is no longer used, but 
remains for anyone who
might have interest in the future (though as it is untested, bit-rot will be 
a problem).


Modified:
    trunk/lib/structure/internal/object.py
    trunk/pipe_control/structure/main.py
    trunk/user_functions/structure.py

Modified: trunk/lib/structure/internal/object.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/lib/structure/internal/object.py?rev=27639&r1=27638&r2=27639&view=diff
==============================================================================
--- trunk/lib/structure/internal/object.py      (original)
+++ trunk/lib/structure/internal/object.py      Fri Feb 13 17:45:08 2015
@@ -1162,6 +1162,50 @@
 
             # Sort.
             mol._sort()
+
+
+    def add_coordinates(self, coord=None, mol_names=None, res_names=None, 
res_nums=None, atom_names=None, elements=None, set_mol_name=None, 
set_model_num=None):
+        """Add a set of coordinates to the structural object.
+
+        @keyword coord:         The array of atomic coordinates (first 
dimension is the atoms and the second are the coordinates).
+        @type coord:            numpy rank-2 float64 array
+        @keyword mol_names:     The list of molecule names corresponding to 
the first dimension of the coordinate array.
+        @type mol_names:        list of str
+        @keyword res_names:     The list of residue names corresponding to 
the first dimension of the coordinate array.
+        @type res_names:        list of str
+        @keyword res_nums:      The list of residue numbers corresponding to 
the first dimension of the coordinate array.
+        @type res_nums:         list of str
+        @keyword atom_names:    The list of atom names corresponding to the 
first dimension of the coordinate array.
+        @type atom_names:       list of str
+        @keyword elements:      The list of elements corresponding to the 
first dimension of the coordinate array.
+        @type elements:         list of str
+        @keyword set_mol_name:  Set the names of the molecules which are 
loaded.  If set to None, then all molecule names must be identical and the 
new molecule will have the same name.
+        @type set_mol_name:     None or str
+        @keyword set_model_num: Set the model number for the coordinates.
+        @type set_model_num:    None or int
+        """
+
+        # The new molecule name.
+        if not set_mol_name:
+            set_mol_name = mol_names[0]
+            for name in mol_names:
+                if set_mol_name != name:
+                    raise RelaxError("No unique molecule name can be found 
in the list %s for storing the new molecule structure.")
+
+        # No model set, so delete all current data.
+        if set_mol_name == None and set_model_num == None:
+            print("Deleting all structural data so that only the new 
molecule will be present.")
+            self.delete(verbosity=0)
+
+        # Generate a molecule container for the new data.
+        mol = MolContainer()
+
+        # Add the data.
+        for i in range(len(coord)):
+            mol.atom_add(atom_name=atom_names[i], res_name=res_names[i], 
res_num=res_nums[i], pos=coord[i], element=elements[i])
+
+        # Create the structural data data structures.
+        self.pack_structs([[mol]], orig_model_num=[None], 
set_model_num=[set_model_num], orig_mol_num=[None], 
set_mol_name=[set_mol_name])
 
 
     def add_model(self, model=None, coords_from=None):

Modified: trunk/pipe_control/structure/main.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/pipe_control/structure/main.py?rev=27639&r1=27638&r2=27639&view=diff
==============================================================================
--- trunk/pipe_control/structure/main.py        (original)
+++ trunk/pipe_control/structure/main.py        Fri Feb 13 17:45:08 2015
@@ -21,7 +21,7 @@
 
 # Python module imports.
 from minfx.generic import generic_minimise
-from numpy import array, average, dot, float64, std, zeros
+from numpy import array, average, dot, float64, mean, std, zeros
 from numpy.linalg import norm
 from os import F_OK, access, getcwd
 from re import search
@@ -368,6 +368,36 @@
     correlation_matrix(format=format, matrix=matrix, labels=labels, 
file=file, dir=dir, force=force)
 
 
+def average_structure(pipes=None, models=None, molecules=None, atom_id=None, 
set_mol_name=None, set_model_num=None):
+    """Calculate a mean structure.
+
+    @keyword pipes:         The data pipes containing structures to average.
+    @type pipes:            None or list of str
+    @keyword models:        The list of models for each data pipe.  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 for each data pipe.  The 
number of elements must match the pipes argument.
+    @type molecules:        None or list of lists of str
+    @keyword atom_id:       The molecule, residue, and atom identifier 
string.  This matches the spin ID string format.
+    @type atom_id:          str or None
+    @keyword set_mol_name:  The molecule name for the averaged molecule.
+    @type set_mol_name:     None or str
+    @keyword set_model_num: The model number for the averaged molecule.
+    @type set_model_num:    None or int
+    """
+
+    # Checks.
+    check_pipe()
+
+    # Assemble the structural coordinates.
+    coord, ids, mol_names, res_names, res_nums, atom_names, elements = 
assemble_structural_coordinates(pipes=pipes, models=models, 
molecules=molecules, atom_id=atom_id)
+
+    # Calculate the mean structure.
+    struct = mean(coord, axis=0)
+
+    # Store the data.
+    cdp.structure.add_coordinates(coord=struct, mol_names=mol_names, 
res_names=res_names, res_nums=res_nums, atom_names=atom_names, 
elements=elements, set_mol_name=set_mol_name, set_model_num=set_model_num)
+
+
 def connect_atom(index1=None, index2=None):
     """Connect two atoms.
 
@@ -964,17 +994,6 @@
 
     # Set the number of states for use in the specific analyses.
     cdp.N = len(from_mols)
-
-
-def mean():
-    """Calculate the mean structure from all models in the structural data 
object."""
-
-    # Checks.
-    check_pipe()
-    check_structure()
-
-    # Call the specific code.
-    cdp.structure.mean()
 
 
 def read_gaussian(file=None, dir=None, set_mol_name=None, 
set_model_num=None, verbosity=1, fail=True):

Modified: trunk/user_functions/structure.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/user_functions/structure.py?rev=27639&r1=27638&r2=27639&view=diff
==============================================================================
--- trunk/user_functions/structure.py   (original)
+++ trunk/user_functions/structure.py   Fri Feb 13 17:45:08 2015
@@ -812,13 +812,57 @@
 uf = uf_info.add_uf('structure.mean')
 uf.title = "Calculate the mean structure from all loaded models."
 uf.title_short = "Mean structure."
-# Description.
-uf.desc.append(Desc_container())
-uf.desc[-1].add_paragraph("This will calculate the mean structure from all 
loaded models.  The mean structure will replace all the models in the 
internal structural object.  This is provided as a structural aid, 
specifically for superimposition purposes.")
-uf.backend = pipe_control.structure.main.mean
+uf.add_keyarg(
+    name = "pipes",
+    py_type = "str_list",
+    desc_short = "data pipes",
+    desc = "The data pipes containing structures to average.",
+    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 containing structures to 
average.  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 average.  This 
allows differently named molecules in the same or different data pipes to be 
averaged.  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 averaged structure to one atom per residue, 
for example.",
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "set_mol_name",
+    py_type = "str",
+    desc_short = "averaged molecule name",
+    desc = "Set the optional name of the averaged molecule.",
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "set_model_num",
+    py_type = "int",
+    desc_short = "averaged model number",
+    desc = "Set the optional model number of the averaged molecule.",
+    can_be_none = True
+)
+# Description.
+uf.desc.append(Desc_container())
+uf.desc[-1].add_paragraph("This will calculate and store the mean structure 
from a collection of related molecules.  If a new molecule name or model 
number is not supplied, the mean structure will replace all the models in the 
internal structural object.  This is provided as a structural aid, 
specifically for superimposition purposes.")
+uf.backend = pipe_control.structure.main.average_structure
 uf.menu_text = "&mean"
 uf.gui_icon = "oxygen.categories.applications-education"
-uf.wizard_size = (700, 400)
+uf.wizard_size = (800, 600)
 uf.wizard_image = WIZARD_IMAGE_PATH + 'structure' + sep + '2JK4.png'
 
 




Related Messages


Powered by MHonArc, Updated Fri Feb 13 18:40:02 2015