mailr17975 - in /trunk/generic_fns: pcs.py rdc.py


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

Header


Content

Posted by edward on November 14, 2012 - 18:05:
Author: bugman
Date: Wed Nov 14 18:05:52 2012
New Revision: 17975

URL: http://svn.gna.org/viewcvs/relax?rev=17975&view=rev
Log:
Implemented the rdc.copy and pcs.copy user function backends.

This code is copied from the relax_data.copy user function and has been 
tailored to the different
data types.


Modified:
    trunk/generic_fns/pcs.py
    trunk/generic_fns/rdc.py

Modified: trunk/generic_fns/pcs.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/generic_fns/pcs.py?rev=17975&r1=17974&r2=17975&view=diff
==============================================================================
--- trunk/generic_fns/pcs.py (original)
+++ trunk/generic_fns/pcs.py Wed Nov 14 18:05:52 2012
@@ -33,10 +33,10 @@
 # relax module imports.
 from generic_fns import grace, pipes
 from generic_fns.align_tensor import get_tensor_index
-from generic_fns.mol_res_spin import exists_mol_res_spin_data, 
generate_spin_id, return_spin, spin_loop
+from generic_fns.mol_res_spin import exists_mol_res_spin_data, 
generate_spin_id, return_spin, spin_index_loop, spin_loop
 from maths_fns.pcs import ave_pcs_tensor
 from physical_constants import g1H, pcs_constant
-from relax_errors import RelaxError, RelaxNoPdbError, RelaxNoSequenceError
+from relax_errors import RelaxError, RelaxAlignError, RelaxNoAlignError, 
RelaxNoPdbError, RelaxNoSequenceError, RelaxPCSError
 from relax_io import open_write_file, read_spin_data, write_spin_data
 from relax_warnings import RelaxWarning, RelaxNoSpinWarning
 
@@ -200,6 +200,98 @@
         if verbosity:
             print("\nUsing all paramagnetic positions.")
         cdp.paramagnetic_centre = full_pos_list
+
+
+def copy(pipe_from=None, pipe_to=None, align_id=None):
+    """Copy the PCS data from one data pipe to another.
+
+    @keyword pipe_from: The data pipe to copy the PCS data from.  This 
defaults to the current data pipe.
+    @type pipe_from:    str
+    @keyword pipe_to:   The data pipe to copy the PCS data to.  This 
defaults to the current data pipe.
+    @type pipe_to:      str
+    @param align_id:    The alignment ID string.
+    @type align_id:     str
+    """
+
+    # Defaults.
+    if pipe_from == None and pipe_to == None:
+        raise RelaxError("The pipe_from and pipe_to arguments cannot both be 
set to None.")
+    elif pipe_from == None:
+        pipe_from = pipes.cdp_name()
+    elif pipe_to == None:
+        pipe_to = pipes.cdp_name()
+
+    # Test if the pipe_from and pipe_to data pipes exist.
+    pipes.test(pipe_from)
+    pipes.test(pipe_to)
+
+    # Get the data pipes.
+    dp_from = pipes.get_pipe(pipe_from)
+    dp_to = pipes.get_pipe(pipe_to)
+
+    # Test if pipe_from contains sequence data.
+    if not exists_mol_res_spin_data(pipe_from):
+        raise RelaxNoSequenceError
+
+    # Test if pipe_to contains sequence data.
+    if not exists_mol_res_spin_data(pipe_to):
+        raise RelaxNoSequenceError
+
+    # Test if alignment ID string exists for pipe_from.
+    if align_id and (not hasattr(dp_from, 'align_ids') or align_id not in 
dp_from.align_ids):
+        raise RelaxNoAlignError(align_id, pipe_from)
+
+    # Test if PCS data for the alignment ID exists.
+    if not hasattr(dp_from, 'pcs_ids'):
+        raise RelaxError("No PCS data exists.")
+    elif align_id and align_id not in dp_from.pcs_ids:
+        raise RelaxNoPCSError(align_id)
+
+    # The IDs.
+    if align_id == None:
+        align_ids = dp_from.align_ids
+    else:
+        align_ids = [align_id]
+
+    # Init target pipe global structures.
+    if not hasattr(dp_to, 'align_ids'):
+        dp_to.align_ids = []
+    if not hasattr(dp_to, 'pcs_ids'):
+        dp_to.pcs_ids = []
+
+    # Loop over the align IDs.
+    for align_id in align_ids:
+        # Test if PCS ID string exists for pipe_to.
+        if align_id in dp_to.pcs_ids:
+            raise RelaxPCSError(align_id)
+
+        # Copy the global data.
+        dp_to.align_ids.append(align_id)
+        dp_to.pcs_ids.append(align_id)
+
+        # Spin loop.
+        for mol_index, res_index, spin_index in spin_index_loop():
+            # Alias the spin containers.
+            spin_from = 
dp_from.mol[mol_index].res[res_index].spin[spin_index]
+            spin_to = dp_to.mol[mol_index].res[res_index].spin[spin_index]
+
+            # No data or errors.
+            if (not hasattr(spin_from, 'pcs') or not align_id in 
spin_from.pcs) and (not hasattr(spin_from, 'pcs_err') or not align_id in 
spin_from.pcs_err):
+                continue
+
+            # Initialise the spin data if necessary.
+            if hasattr(spin_from, 'pcs') and not hasattr(spin_to, 'pcs'):
+                spin_to.pcs = {}
+            if hasattr(spin_from, 'pcs_err') and not hasattr(spin_to, 
'pcs_err'):
+                spin_to.pcs_err = {}
+
+            # Copy the value and error from pipe_from.
+            print spin_from
+            print spin_to
+            if hasattr(spin_from, 'pcs'):
+                spin_to.pcs[align_id] = spin_from.pcs[align_id]
+            if hasattr(spin_from, 'pcs_err'):
+                spin_to.pcs_err[align_id] = spin_from.pcs_err[align_id]
 
 
 def corr_plot(format=None, file=None, dir=None, force=False):

Modified: trunk/generic_fns/rdc.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/generic_fns/rdc.py?rev=17975&r1=17974&r2=17975&view=diff
==============================================================================
--- trunk/generic_fns/rdc.py (original)
+++ trunk/generic_fns/rdc.py Wed Nov 14 18:05:52 2012
@@ -36,10 +36,10 @@
 from generic_fns import grace, pipes
 from generic_fns.align_tensor import get_tensor_index
 from generic_fns.interatomic import create_interatom, interatomic_loop, 
return_interatom
-from generic_fns.mol_res_spin import exists_mol_res_spin_data, 
generate_spin_id, return_spin, spin_loop
+from generic_fns.mol_res_spin import exists_mol_res_spin_data, 
generate_spin_id, return_spin, spin_index_loop, spin_loop
 from maths_fns.rdc import ave_rdc_tensor
 from physical_constants import dipolar_constant, return_gyromagnetic_ratio
-from relax_errors import RelaxError, RelaxNoRDCError, RelaxNoSequenceError, 
RelaxSpinTypeError
+from relax_errors import RelaxError, RelaxAlignError, RelaxNoAlignError, 
RelaxNoRDCError, RelaxNoSequenceError, RelaxSpinTypeError
 from relax_io import extract_data, open_write_file, strip, write_data
 from relax_warnings import RelaxWarning
 
@@ -149,6 +149,96 @@
 
     # Return the converted value.
     return value * factor
+
+
+def copy(pipe_from=None, pipe_to=None, align_id=None):
+    """Copy the RDC data from one data pipe to another.
+
+    @keyword pipe_from: The data pipe to copy the RDC data from.  This 
defaults to the current data pipe.
+    @type pipe_from:    str
+    @keyword pipe_to:   The data pipe to copy the RDC data to.  This 
defaults to the current data pipe.
+    @type pipe_to:      str
+    @param align_id:    The alignment ID string.
+    @type align_id:     str
+    """
+
+    # Defaults.
+    if pipe_from == None and pipe_to == None:
+        raise RelaxError("The pipe_from and pipe_to arguments cannot both be 
set to None.")
+    elif pipe_from == None:
+        pipe_from = pipes.cdp_name()
+    elif pipe_to == None:
+        pipe_to = pipes.cdp_name()
+
+    # Test if the pipe_from and pipe_to data pipes exist.
+    pipes.test(pipe_from)
+    pipes.test(pipe_to)
+
+    # Get the data pipes.
+    dp_from = pipes.get_pipe(pipe_from)
+    dp_to = pipes.get_pipe(pipe_to)
+
+    # Test if pipe_from contains sequence data.
+    if not exists_mol_res_spin_data(pipe_from):
+        raise RelaxNoSequenceError
+
+    # Test if pipe_to contains sequence data.
+    if not exists_mol_res_spin_data(pipe_to):
+        raise RelaxNoSequenceError
+
+    # Test if alignment ID string exists for pipe_from.
+    if align_id and (not hasattr(dp_from, 'align_ids') or align_id not in 
dp_from.align_ids):
+        raise RelaxNoAlignError(align_id, pipe_from)
+
+    # Test if RDC data for the alignment ID exists.
+    if not hasattr(dp_from, 'rdc_ids'):
+        raise RelaxError("No RDC data exists.")
+    elif align_id and align_id not in dp_from.rdc_ids:
+        raise RelaxNoRDCError(align_id)
+
+    # The IDs.
+    if align_id == None:
+        align_ids = dp_from.align_ids
+    else:
+        align_ids = [align_id]
+
+    # Init target pipe global structures.
+    if not hasattr(dp_to, 'align_ids'):
+        dp_to.align_ids = []
+    if not hasattr(dp_to, 'rdc_ids'):
+        dp_to.rdc_ids = []
+
+    # Loop over the align IDs.
+    for align_id in align_ids:
+        # Test if RDC ID string exists for pipe_to.
+        if align_id in dp_to.rdc_ids:
+            raise RelaxRDCError(align_id)
+
+        # Copy the global data.
+        dp_to.align_ids.append(align_id)
+        dp_to.rdc_ids.append(align_id)
+
+        # Spin loop.
+        for mol_index, res_index, spin_index in spin_index_loop():
+            # Alias the spin containers.
+            spin_from = 
dp_from.mol[mol_index].res[res_index].spin[spin_index]
+            spin_to = dp_to.mol[mol_index].res[res_index].spin[spin_index]
+
+            # No data or errors.
+            if (not hasattr(spin_from, 'rdc') or not align_id in 
spin_from.rdc) and (not hasattr(spin_from, 'rdc_err') or not align_id in 
spin_from.rdc_err):
+                continue
+
+            # Initialise the spin data if necessary.
+            if hasattr(spin_from, 'rdc') and not hasattr(spin_to, 'rdc'):
+                spin_to.rdc = {}
+            if hasattr(spin_from, 'rdc_err') and not hasattr(spin_to, 
'rdc_err'):
+                spin_to.rdc_err = {}
+
+            # Copy the value and error from pipe_from.
+            if hasattr(spin_from, 'rdc'):
+                spin_to.rdc[align_id] = spin_from.rdc[align_id]
+            if hasattr(spin_from, 'rdc_err'):
+                spin_to.rdc_err[align_id] = spin_from.rdc_err[align_id]
 
 
 def corr_plot(format=None, file=None, dir=None, force=False):




Related Messages


Powered by MHonArc, Updated Wed Nov 14 18:40:02 2012