Package lib :: Package spectrum :: Module objects
[hide private]
[frames] | no frames]

Source Code for Module lib.spectrum.objects

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2013 Edward d'Auvergne                                        # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Package docstring. 
 23  """Module containing objects used to handle peak list data. 
 24   
 25  These objects are only temporary.  In the future, they may be made permanent by shifting them into the relax data storage object. 
 26  """ 
 27   
 28  # relax module imports. 
 29  from lib.errors import RelaxError 
 30   
 31   
32 -class Assignment:
33 """A special container for a single assignment in a peak list."""
34 35 36
37 -class Peak_list(list):
38 """The object used to represent a peak list.""" 39
40 - def __init__(self, dim=2):
41 """Set up the object. 42 43 @keyword dim: The dimensionality of the peak list. 44 @type dim: int 45 """ 46 47 # Store the dimensionality. 48 self.dimensionality = dim
49 50
51 - def add(self, mol_names=None, res_nums=None, res_names=None, spin_nums=None, spin_names=None, shifts=None, intensity=None, intensity_name=None):
52 """Add a peak list element. 53 54 55 @keyword mol_names: The list of molecule names for each dimension of the assignment. 56 @type mol_names: list of str or None 57 @keyword res_nums: The list of residue numbers for each dimension of the assignment. 58 @type res_nums: list of int or None 59 @keyword res_names: The list of residue names for each dimension of the assignment. 60 @type res_names: list of str or None 61 @keyword spin_nums: The list of spin numbers for each dimension of the assignment. 62 @type spin_nums: list of int or None 63 @keyword spin_names: The list of spin names for each dimension of the assignment. 64 @type spin_names: list of str or None 65 @keyword shifts: The chemical shifts for each dimension of the assignment in ppm. 66 @type shifts: list of float or None 67 @keyword intensity: The optional intensity value for the peak. This can have multiple values as some peak lists cover multiple spectra. 68 @type intensity: list of float or None 69 @keyword intensity_name: The optional name of the intensity column. This can be used for automated spectrum ID generation. 70 @type intensity_name: list of str or None 71 """ 72 73 # Check the arguments. 74 if mol_names != None and len(mol_names) != self.dimensionality: 75 raise RelaxError("The molecule names %s must be a list of %s dimensions." % (mol_names, self.dimensionality)) 76 if res_nums != None and len(res_nums) != self.dimensionality: 77 raise RelaxError("The residue numbers %s must be a list of %s dimensions." % (res_nums, self.dimensionality)) 78 if res_names != None and len(res_names) != self.dimensionality: 79 raise RelaxError("The residue names %s must be a list of %s dimensions." % (res_names, self.dimensionality)) 80 if spin_nums != None and len(spin_nums) != self.dimensionality: 81 raise RelaxError("The spin numbers %s must be a list of %s dimensions." % (spin_nums, self.dimensionality)) 82 if spin_names != None and len(spin_names) != self.dimensionality: 83 raise RelaxError("The spin names %s must be a list of %s dimensions." % (spin_names, self.dimensionality)) 84 if shifts != None and len(shifts) != self.dimensionality: 85 raise RelaxError("The chemical shifts %s must be a list of %s dimensions." % (shifts, self.dimensionality)) 86 87 # Add a new element. 88 self.append(Assignment()) 89 90 # Store the data. 91 assign = self[-1] 92 assign.mol_names = mol_names 93 assign.res_nums = res_nums 94 assign.res_names = res_names 95 assign.spin_nums = spin_nums 96 assign.spin_names = spin_names 97 assign.shifts = shifts 98 assign.intensity = intensity 99 assign.intensity_name = intensity_name 100 101 # Convert certain None values to lists of None. 102 names = ['mol_names', 'res_names', 'res_nums', 'spin_names', 'spin_nums', 'shifts'] 103 for name in names: 104 obj = getattr(assign, name) 105 if obj == None: 106 setattr(assign, name, [None]*self.dimensionality)
107