Package pipe_control :: Module noesy
[hide private]
[frames] | no frames]

Source Code for Module pipe_control.noesy

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2008-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  # Module docstring. 
 23  """Module for NOESY related operations.""" 
 24   
 25  # Python module imports. 
 26  from re import search 
 27  from warnings import warn 
 28   
 29  # relax module imports. 
 30  from lib.errors import RelaxError, RelaxNoSequenceError 
 31  from lib.io import open_read_file 
 32  from lib.software import xplor 
 33  from lib.warnings import RelaxWarning 
 34  from pipe_control import pipes 
 35  from pipe_control.mol_res_spin import exists_mol_res_spin_data, return_spin, tokenise 
 36   
 37   
38 -def __file_format(lines):
39 """Determine the format of the NOE restraints data. 40 41 @param lines: The file data converted to a list of file lines. 42 @type lines: list of str 43 @return: The format of the file. 44 @rtype: str 45 """ 46 47 # Loop over the lines. 48 for line in lines: 49 # Xplor format. 50 if search('^assign ', line): 51 print("Xplor formatted file.") 52 return 'xplor' 53 54 # Print out. 55 print("Generic formatted file.") 56 return 'generic'
57 58
59 -def parse_noe_restraints(lines, proton1_col=None, proton2_col=None, lower_col=None, upper_col=None, sep=None):
60 """Parse and return the NOE restraints from the generic formatted file. 61 62 @param lines: The file, or file fragment, split into lines. 63 @type lines: list of str 64 @keyword proton1_col: The column containing the first proton of the NOE or ROE cross peak. 65 @type proton1_col: None or int 66 @keyword proton2_col: The column containing the second proton of the NOE or ROE cross peak. 67 @type proton2_col: None or int 68 @keyword lower_col: The column containing the lower NOE bound. 69 @type lower_col: None or int 70 @keyword upper_col: The column containing the upper NOE bound. 71 @type upper_col: None or int 72 @keyword sep: The column separator (the default is white space). 73 @type sep: None or str 74 @return: The NOE restraint list in the format of two atom identification strings 75 and the lower and upper restraints. 76 @rtype: list of lists of [str, str, float, float] 77 """ 78 79 # Default column numbers. 80 if proton1_col == None: 81 warn(RelaxWarning("The proton1_col argument has not been supplied, defaulting to column 1.")) 82 proton1_col = 1 83 if proton2_col == None: 84 warn(RelaxWarning("The proton2_col argument has not been supplied, defaulting to column 2.")) 85 proton2_col = 2 86 if lower_col == None: 87 warn(RelaxWarning("The lower_col argument has not been supplied, defaulting to column 3.")) 88 lower_col = 3 89 if upper_col == None: 90 warn(RelaxWarning("The upper_col argument has not been supplied, defaulting to column 4.")) 91 upper_col = 4 92 93 # Loop over the lines. 94 data = [] 95 for line in lines: 96 # Split the line. 97 row = line.split(sep) 98 99 # Header lines: 100 if len(row) < 4: 101 continue 102 try: 103 tokenise(row[proton1_col-1]) 104 except RelaxError: 105 continue 106 107 # Pack the data. 108 data.append([row[proton1_col-1], row[proton2_col-1], float(row[lower_col-1]), float(row[upper_col-1])]) 109 110 # Return the data. 111 return data
112 113
114 -def read_restraints(file=None, dir=None, proton1_col=None, proton2_col=None, lower_col=None, upper_col=None, sep=None):
115 """Load NOESY or ROESY constraint information from file. 116 117 If the input file is a pre-formatted Xplor file, the column number and separator arguments will 118 be ignored. 119 120 121 @keyword file: The name of the file containing the relaxation data. 122 @type file: str 123 @keyword dir: The directory where the file is located. 124 @type dir: None or str 125 @keyword proton1_col: The column containing the first proton of the NOE or ROE cross peak. 126 @type proton1_col: None or int 127 @keyword proton2_col: The column containing the second proton of the NOE or ROE cross peak. 128 @type proton2_col: None or int 129 @keyword lower_col: The column containing the lower NOE bound. 130 @type lower_col: None or int 131 @keyword upper_col: The column containing the upper NOE bound. 132 @type upper_col: None or int 133 @keyword sep: The column separator (the default is white space). 134 @type sep: None or str 135 """ 136 137 # Test if the current data pipe exists. 138 pipes.test() 139 140 # Test if sequence data is loaded. 141 if not exists_mol_res_spin_data(): 142 raise RelaxNoSequenceError 143 144 # Open the file. 145 file = open_read_file(file_name=file, dir=dir) 146 lines = file.readlines() 147 file.close() 148 149 # Determine the file type. 150 format = __file_format(lines) 151 152 # Parse and extract the NOE restraints. 153 if format == 'xplor': 154 noe_restraints = xplor.parse_noe_restraints(lines) 155 elif format == 'generic': 156 noe_restraints = parse_noe_restraints(lines, proton1_col=proton1_col, proton2_col=proton2_col, lower_col=lower_col, upper_col=upper_col, sep=sep) 157 158 # Pseudoatom conversion. 159 for i in range(len(noe_restraints)): 160 # Loop over atom IDs. 161 for j in range(2): 162 # Skip normal atoms. 163 if isinstance(noe_restraints[i][j], str): 164 continue 165 166 # Loop over the pseudoatoms. 167 pseudo_name = None 168 for k in range(len(noe_restraints[i][j])): 169 # Get the spin. 170 spin = return_spin(noe_restraints[i][j][k]) 171 172 # Check the pseudoatom consistency. 173 if pseudo_name and pseudo_name != spin.pseudo_name: 174 raise RelaxError("The pseudoatom names '%s' and '%s' do not match." % (pseudo_name, spin.pseudo_name)) 175 176 # Set the name. 177 pseudo_name = spin.pseudo_name 178 179 # No pseudoatom. 180 if not pseudo_name: 181 raise RelaxError("Cannot find the pseudoatom corresponding to the atoms in %s." % noe_restraints[i][j]) 182 183 # Otherwise, place the pseudoatom name into the NOE restraint list. 184 noe_restraints[i][j] = pseudo_name 185 186 # Place the restraints into the current data pipe. 187 cdp.noe_restraints = noe_restraints 188 189 # Check for the presence of the spin containers corresponding to the atom ids. 190 for restraint in cdp.noe_restraints: 191 if not return_spin(restraint[0]): 192 raise RelaxError("The spin container corresponding to '%s' cannot be found." % restraint[0]) 193 if not return_spin(restraint[1]): 194 raise RelaxError("The spin container corresponding to '%s' cannot be found." % restraint[1])
195