mailr11206 - in /1.3: generic_fns/pcs.py generic_fns/rdc.py prompt/pcs.py prompt/rdc.py specific_fns/n_state_model.py


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

Header


Content

Posted by edward on May 19, 2010 - 10:49:
Author: bugman
Date: Wed May 19 10:49:53 2010
New Revision: 11206

URL: http://svn.gna.org/viewcvs/relax?rev=11206&view=rev
Log:
Created the rdc.corr_plot() and pcs_corr_plot() user functions.

These are for creating correlation plots of measured vs. back-calculated RDCs 
and PCSs.

A couple of N-state model methods (return_grace_string() and return_units()) 
were added to allow the
user functions to work.


Modified:
    1.3/generic_fns/pcs.py
    1.3/generic_fns/rdc.py
    1.3/prompt/pcs.py
    1.3/prompt/rdc.py
    1.3/specific_fns/n_state_model.py

Modified: 1.3/generic_fns/pcs.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/generic_fns/pcs.py?rev=11206&r1=11205&r2=11206&view=diff
==============================================================================
--- 1.3/generic_fns/pcs.py (original)
+++ 1.3/generic_fns/pcs.py Wed May 19 10:49:53 2010
@@ -30,8 +30,8 @@
 from warnings import warn
 
 # relax module imports.
+from generic_fns import grace, pipes
 from generic_fns.mol_res_spin import exists_mol_res_spin_data, return_spin, 
spin_loop
-from generic_fns import pipes
 from relax_errors import RelaxError, RelaxNoPdbError, RelaxNoSequenceError, 
RelaxNoSpinError
 from relax_io import open_write_file, read_spin_data, write_spin_data
 from relax_warnings import RelaxWarning
@@ -124,6 +124,69 @@
         if verbosity:
             print("\nUsing all paramagnetic positions.")
         cdp.paramagnetic_centre = full_pos_list
+
+
+def corr_plot(format=None, file=None, dir=None, force=False):
+    """Generate a correlation plot of the measured vs. back-calculated PCSs.
+
+    @keyword format:    The format for the plot file.  The following values 
are accepted: 'grace', a Grace plot; None, a plain text file.
+    @type format:       str or None
+    @keyword file:      The file name or object to write to.
+    @type file:         str or file object
+    @keyword dir:       The name of the directory to place the file into 
(defaults to the current directory).
+    @type dir:          str
+    @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.
+    pipes.test()
+
+    # Test if the sequence data is loaded.
+    if not exists_mol_res_spin_data():
+        raise RelaxNoSequenceError
+
+    # Does PCS data exist?
+    if not hasattr(cdp, 'pcs_ids') or not cdp.pcs_ids:
+        warn(RelaxWarning("No PCS data exists, skipping file creation."))
+        return
+
+    # Open the file for writing.
+    file = open_write_file(file, dir, force)
+
+    # Init.
+    data = []
+
+    # The diagonal.
+    data.append([[-100, -100], [100, 100]])
+
+    # Loop over the PCS data.
+    for align_id in cdp.pcs_ids:
+        # Append a new list for this alignment.
+        data.append([])
+
+        # Loop over the spins.
+        for spin, spin_id in spin_loop(return_id=True):
+            # Skip if data is missing.
+            if not hasattr(spin, 'pcs') or not hasattr(spin, 'pcs_bc') or 
not align_id in spin.pcs.keys() or not align_id in spin.pcs_bc.keys():
+                continue
+
+            # Append the data.
+            data[-1].append([spin.pcs[align_id], spin.pcs_bc[align_id], 
spin_id])
+
+    # The data size.
+    size = len(data)
+
+    # Only one data set.
+    data = [data]
+
+    # Grace file.
+    if format == 'grace':
+        # The header.
+        grace.write_xy_header(file=file, title="PCS correlation plot", 
sets=size, set_names=[None]+cdp.pcs_ids, linestyle=[2]+[0]*size, 
data_type=['pcs', 'pcs_bc'], axis_min=[-0.5, -0.5], axis_max=[0.5, 0.5], 
legend_pos=[1, 0.5])
+
+        # The main data.
+        grace.write_xy_data(data=data, file=file, graph_type='xy')
 
 
 def display(align_id=None):
@@ -300,7 +363,7 @@
         errors.append(error)
 
     # Print out.
-    write_spin_data(file=sys.stdout, spin_ids=spin_ids, data=values, 
data_name='RDCs', error=errors, error_name='RDC_error')
+    write_spin_data(file=sys.stdout, spin_ids=spin_ids, data=values, 
data_name='PCSs', error=errors, error_name='PCS_error')
 
 
     # Global (non-spin specific) data.

Modified: 1.3/generic_fns/rdc.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/generic_fns/rdc.py?rev=11206&r1=11205&r2=11206&view=diff
==============================================================================
--- 1.3/generic_fns/rdc.py (original)
+++ 1.3/generic_fns/rdc.py Wed May 19 10:49:53 2010
@@ -31,8 +31,8 @@
 from warnings import warn
 
 # relax module imports.
+from generic_fns import grace, pipes
 from generic_fns.mol_res_spin import exists_mol_res_spin_data, return_spin, 
spin_loop
-from generic_fns import pipes
 from maths_fns.rdc import ave_rdc_tensor
 from physical_constants import dipolar_constant, return_gyromagnetic_ratio
 from relax_errors import RelaxError, RelaxNoRDCError, RelaxNoSequenceError, 
RelaxNoSpinError
@@ -80,6 +80,69 @@
 
             # Calculate the RDC.
             spin.rdc_bc = ave_rdc_tensor(dj, unit_vect, cdp.N, 
cdp.align_tensors[i].A, weights=weights)
+
+
+def corr_plot(format=None, file=None, dir=None, force=False):
+    """Generate a correlation plot of the measured vs. back-calculated RDCs.
+
+    @keyword format:    The format for the plot file.  The following values 
are accepted: 'grace', a Grace plot; None, a plain text file.
+    @type format:       str or None
+    @keyword file:      The file name or object to write to.
+    @type file:         str or file object
+    @keyword dir:       The name of the directory to place the file into 
(defaults to the current directory).
+    @type dir:          str
+    @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.
+    pipes.test()
+
+    # Test if the sequence data is loaded.
+    if not exists_mol_res_spin_data():
+        raise RelaxNoSequenceError
+
+    # Does RDC data exist?
+    if not hasattr(cdp, 'rdc_ids') or not cdp.rdc_ids:
+        warn(RelaxWarning("No RDC data exists, skipping file creation."))
+        return
+
+    # Open the file for writing.
+    file = open_write_file(file, dir, force)
+
+    # Init.
+    data = []
+
+    # The diagonal.
+    data.append([[-100, -100], [100, 100]])
+
+    # Loop over the RDC data.
+    for align_id in cdp.rdc_ids:
+        # Append a new list for this alignment.
+        data.append([])
+
+        # Loop over the spins.
+        for spin, spin_id in spin_loop(return_id=True):
+            # Skip if data is missing.
+            if not hasattr(spin, 'rdc') or not hasattr(spin, 'rdc_bc') or 
not align_id in spin.rdc.keys() or not align_id in spin.rdc_bc.keys():
+                continue
+
+            # Append the data.
+            data[-1].append([spin.rdc[align_id], spin.rdc_bc[align_id], 
spin_id])
+
+    # The data size.
+    size = len(data)
+
+    # Only one data set.
+    data = [data]
+
+    # Grace file.
+    if format == 'grace':
+        # The header.
+        grace.write_xy_header(file=file, title="RDC correlation plot", 
sets=size, set_names=[None]+cdp.rdc_ids, linestyle=[2]+[0]*size, 
data_type=['rdc', 'rdc_bc'], axis_min=[-10, -10], axis_max=[10, 10], 
legend_pos=[1, 0.5])
+
+        # The main data.
+        grace.write_xy_data(data=data, file=file, graph_type='xy')
 
 
 def display(align_id=None):

Modified: 1.3/prompt/pcs.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/prompt/pcs.py?rev=11206&r1=11205&r2=11206&view=diff
==============================================================================
--- 1.3/prompt/pcs.py (original)
+++ 1.3/prompt/pcs.py Wed May 19 10:49:53 2010
@@ -75,7 +75,7 @@
         Examples
         ~~~~~~~~
 
-        To calculate the RDC Q-factor for only the spins '@H26', '@H27', and 
'@H28', type one of:
+        To calculate the PCS Q-factor for only the spins '@H26', '@H27', and 
'@H28', type one of:
 
         relax> pcs.calc_q_factors('@H26 & @H27 & @H28')
         relax> pcs.calc_q_factors(spin_id='@H26 & @H27 & @H28')
@@ -231,6 +231,62 @@
         pcs.copy(pipe_from=pipe_from, pipe_to=pipe_to, align_id=align_id)
 
 
+    def corr_plot(self, format='grace', file='pcs_corr_plot.agr', dir=None, 
force=False):
+        """Generate a correlation plot of the measured vs. the 
back-calculated PCSs.
+
+        Keyword Arguments
+        ~~~~~~~~~~~~~~~~~
+
+        format:  The format of the plot data.
+
+        file:  The name of the file.
+
+        dir:  The directory name.
+
+        force:  A flag which if True will cause the file to be overwritten.
+
+
+        Description
+        ~~~~~~~~~~~
+
+        Two formats are currently supported.  If format is set to 'grace', 
then a Grace plot file
+        will be created.  If the format arg is set to None, then a plain 
text list of the measured
+        and back-calculated data will be created.
+
+
+        Examples
+        ~~~~~~~~
+
+        To create a Grace plot of the data, type:
+
+        relax> pcs.corr_plot()
+
+
+        To create a plain text list of the measured and back-calculated 
data, type one of:
+
+        relax> pcs.corr_plot(None)
+        relax> pcs.corr_plot(format=None)
+        """
+
+        # Function intro text.
+        if self._exec_info.intro:
+            text = self._exec_info.ps3 + "pcs.corr_plot("
+            text = text + "format=" + repr(format)
+            text = text + ", file=" + repr(file)
+            text = text + ", dir=" + repr(dir)
+            text = text + ", force=" + repr(force) + ")"
+            print(text)
+
+        # The argument checks.
+        arg_check.is_str(format, 'format', can_be_none=True)
+        arg_check.is_str(file, 'file name')
+        arg_check.is_str(dir, 'directory name', can_be_none=True)
+        arg_check.is_bool(force, 'force flag')
+
+        # Execute the functional code.
+        pcs.corr_plot(format=format, file=file, dir=dir, force=force)
+
+
     def delete(self, align_id=None):
         """Delete the PCS data corresponding to the alignment ID.
 
@@ -316,7 +372,7 @@
 
         spin_name_col:  The spin name column (alternative to the 
spin_id_col).
 
-        data_col:  The RDC data column.
+        data_col:  The PCS data column.
 
         error_col:  The experimental error column.
 

Modified: 1.3/prompt/rdc.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/prompt/rdc.py?rev=11206&r1=11205&r2=11206&view=diff
==============================================================================
--- 1.3/prompt/rdc.py (original)
+++ 1.3/prompt/rdc.py Wed May 19 10:49:53 2010
@@ -149,6 +149,62 @@
 
         # Execute the functional code.
         rdc.copy(pipe_from=pipe_from, pipe_to=pipe_to, align_id=align_id)
+
+
+    def corr_plot(self, format='grace', file='rdc_corr_plot.agr', dir=None, 
force=False):
+        """Generate a correlation plot of the measured vs. the 
back-calculated RDCs.
+
+        Keyword Arguments
+        ~~~~~~~~~~~~~~~~~
+
+        format:  The format of the plot data.
+
+        file:  The name of the file.
+
+        dir:  The directory name.
+
+        force:  A flag which if True will cause the file to be overwritten.
+
+
+        Description
+        ~~~~~~~~~~~
+
+        Two formats are currently supported.  If format is set to 'grace', 
then a Grace plot file
+        will be created.  If the format arg is set to None, then a plain 
text list of the measured
+        and back-calculated data will be created.
+
+
+        Examples
+        ~~~~~~~~
+
+        To create a Grace plot of the data, type:
+
+        relax> rdc.corr_plot()
+
+
+        To create a plain text list of the measured and back-calculated 
data, type one of:
+
+        relax> rdc.corr_plot(None)
+        relax> rdc.corr_plot(format=None)
+        """
+
+        # Function intro text.
+        if self._exec_info.intro:
+            text = self._exec_info.ps3 + "rdc.corr_plot("
+            text = text + "format=" + repr(format)
+            text = text + ", file=" + repr(file)
+            text = text + ", dir=" + repr(dir)
+            text = text + ", force=" + repr(force) + ")"
+            print(text)
+
+        # The argument checks.
+        arg_check.is_str(format, 'format', can_be_none=True)
+        arg_check.is_str(file, 'file name')
+        arg_check.is_str(dir, 'directory name', can_be_none=True)
+        arg_check.is_bool(force, 'force flag')
+
+        # Execute the functional code.
+        rdc.corr_plot(format=format, file=file, dir=dir, force=force)
 
 
     def delete(self, align_id=None):

Modified: 1.3/specific_fns/n_state_model.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/specific_fns/n_state_model.py?rev=11206&r1=11205&r2=11206&view=diff
==============================================================================
--- 1.3/specific_fns/n_state_model.py (original)
+++ 1.3/specific_fns/n_state_model.py Wed May 19 10:49:53 2010
@@ -1829,6 +1829,56 @@
             return 'proton_type'
 
 
+    def return_grace_string(self, param):
+        """Return the Grace string representation of the parameter.
+
+        This is used for axis labelling.
+
+        @param param:   The specific analysis parameter.
+        @type param:    str
+        @return:        The Grace string representation of the parameter.
+        @rtype:         str
+        """
+
+        # The measured PCS.
+        if param == 'pcs':
+            return "Measured PCS"
+
+        # The back-calculated PCS.
+        if param == 'pcs_bc':
+            return "Back-calculated PCS"
+
+        # The measured RDC.
+        if param == 'rdc':
+            return "Measured RDC"
+
+        # The back-calculated RDC.
+        if param == 'rdc_bc':
+            return "Back-calculated RDC"
+
+
+    def return_units(self, param, spin=None, spin_id=None):
+        """Return a string representing the parameters units.
+
+        @param param:   The name of the parameter to return the units string 
for.
+        @type param:    str
+        @param spin:    The spin container (unused).
+        @type spin:     None
+        @param spin_id: The spin identification string (unused).
+        @type spin_id:  None
+        @return:        The parameter units string.
+        @rtype:         str
+        """
+
+        # PCSs.
+        if param == 'pcs' or param == 'pcs_bc':
+            return 'ppm'
+
+        # RDCs.
+        if param == 'rdc' or param == 'rdc_bc':
+            return 'Hz'
+
+
     set_doc = """
         N-state model set details
         ~~~~~~~~~~~~~~~~~~~~~~~~~




Related Messages


Powered by MHonArc, Updated Wed May 19 11:40:03 2010