mailr15168 - in /branches/spec_api/specific_fns: api_base.py api_objects.py


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

Header


Content

Posted by edward on January 18, 2012 - 15:17:
Author: bugman
Date: Wed Jan 18 15:17:34 2012
New Revision: 15168

URL: http://svn.gna.org/viewcvs/relax?rev=15168&view=rev
Log:
Created a special specific API object called SPIN_PARAMS.

This will be used to handle all operations to do with model parameters.  This 
is initialised in the
base class, and can be set up in the specific __init__() methods.  The object 
Param_list has methods
for parameter initialisation (where all info is specified such as Grace 
string, units, default
value, etc) and for determining if a parameter exists.  More methods will be 
added in the future to
expand the usability of this object and to simplify the specific API methods.


Added:
    branches/spec_api/specific_fns/api_objects.py
Modified:
    branches/spec_api/specific_fns/api_base.py

Modified: branches/spec_api/specific_fns/api_base.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/spec_api/specific_fns/api_base.py?rev=15168&r1=15167&r2=15168&view=diff
==============================================================================
--- branches/spec_api/specific_fns/api_base.py (original)
+++ branches/spec_api/specific_fns/api_base.py Wed Jan 18 15:17:34 2012
@@ -1,6 +1,6 @@
 
###############################################################################
 #                                                                            
 #
-# Copyright (C) 2004, 2006-2009 Edward d'Auvergne                            
 #
+# Copyright (C) 2004-2012 Edward d'Auvergne                                  
 #
 #                                                                            
 #
 # This file is part of the program relax.                                    
 #
 #                                                                            
 #
@@ -26,6 +26,7 @@
 # relax module imports.
 from generic_fns.mol_res_spin import count_spins, exists_mol_res_spin_data, 
return_spin, spin_loop
 from relax_errors import RelaxError, RelaxImplementError, RelaxLenError, 
RelaxNoSequenceError
+from specific_fns.api_objects import Param_list
 
 
 class API_base:
@@ -33,6 +34,10 @@
 
     All the methods here are prototype methods.  To identify that the method 
is not available for certain analysis types, if called a RelaxImplementError 
is raised if called.
     """
+
+    # Class variables.
+    SPIN_PARAMS = Param_list()
+
 
     def back_calc_ri(self, spin_index=None, ri_id=None, ri_type=None, 
frq=None):
         """Back-calculation of relaxation data.

Added: branches/spec_api/specific_fns/api_objects.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/spec_api/specific_fns/api_objects.py?rev=15168&view=auto
==============================================================================
--- branches/spec_api/specific_fns/api_objects.py (added)
+++ branches/spec_api/specific_fns/api_objects.py Wed Jan 18 15:17:34 2012
@@ -1,0 +1,89 @@
+###############################################################################
+#                                                                            
 #
+# Copyright (C) 2012 Edward d'Auvergne                                       
 #
+#                                                                            
 #
+# This file is part of the program relax.                                    
 #
+#                                                                            
 #
+# relax is free software; you can redistribute it and/or modify              
 #
+# it under the terms of the GNU General Public License as published by       
 #
+# the Free Software Foundation; either version 2 of the License, or          
 #
+# (at your option) any later version.                                        
 #
+#                                                                            
 #
+# relax is distributed in the hope that it will be useful,                   
 #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of             
 #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              
 #
+# GNU General Public License for more details.                               
 #
+#                                                                            
 #
+# You should have received a copy of the GNU General Public License          
 #
+# along with relax; if not, write to the Free Software                       
 #
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
 #
+#                                                                            
 #
+###############################################################################
+
+# Module docstring.
+"""A module of special objects used within the specific function API."""
+
+
+
+class Param_list:
+    """A special object for handling global and spin parameters."""
+
+    def __init__(self):
+        """Set up the class."""
+
+        # Initialise the lists and dictionaries for the parameter info.
+        self.names = []
+        self.string = {}
+        self.defaults = {}
+        self.units = {}
+        self.grace_string = {}
+
+
+    def add(self, name, string=None, default=None, units=None, 
grace_string=None):
+        """Add a parameter to the list.
+
+        @param name:            The name of the parameter.  This will be 
used as the variable name.
+        @type name:             str
+        @keyword string:        The string representation of the parameter.
+        @type string:           None or str
+        @keyword default:       The default value of the parameter.
+        @type default:          anything
+        @keyword units:         A string representing the parameters units.
+        @type units:            None or str
+        @keyword grace_string:  The string used for the axes in Grace plots 
of the data.
+        @type grace_string:     None or str
+        """
+
+        # Append the values.
+        self.names.append(name)
+        self.defaults[name] = default
+        self.units[name] = units
+
+        # The parameter string.
+        if string:
+            self.string[name] = string
+        else:
+            self.string[name] = name
+
+        # The Grace string.
+        if grace_string:
+            self.grace_string[name] = grace_string
+        else:
+            self.grace_string[name] = name
+
+
+    def contains(self, name):
+        """Determine if the given name is within the parameter list.
+
+        @param name:    The name of the parameter to search for.
+        @type name:     str
+        @return:        True if the parameter is within the list, False 
otherwise.
+        @rtype:         bool
+        """
+
+        # Check.
+        if name in self.names:
+            return True
+
+        # No match.
+        return False




Related Messages


Powered by MHonArc, Updated Wed Jan 18 15:40:02 2012