Package test_suite :: Package system_tests :: Module noe
[hide private]
[frames] | no frames]

Source Code for Module test_suite.system_tests.noe

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2006-2008,2011-2015 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  # Python module imports. 
 23  from os import F_OK, access, sep 
 24  from tempfile import mkdtemp, mkstemp 
 25   
 26  # relax module imports. 
 27  from data_store import Relax_data_store; ds = Relax_data_store() 
 28  from pipe_control.mol_res_spin import spin_loop 
 29  from status import Status; status = Status() 
 30  from test_suite.system_tests.base_classes import SystemTestCase 
 31   
 32   
33 -class Noe(SystemTestCase):
34 """Class for testing various aspects specific to the NOE analysis.""" 35
36 - def setUp(self):
37 """Set up for all the functional tests.""" 38 39 # Create the data pipe. 40 self.interpreter.pipe.create('noe', 'noe') 41 42 # Create a temporary file. 43 ds.tmpfile_handle, ds.tmpfile = mkstemp() 44 45 # Create a temporary directory for dumping files. 46 ds.tmpdir = mkdtemp() 47 self.tmpdir = ds.tmpdir
48 49
51 """Catch U{bug #21562<https://web.archive.org/web/https://gna.org/bugs/?21562>}, the failure of the NOE analysis when replicated spectra are used.""" 52 53 # Execute the script. 54 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'noe'+sep+'bug_21562_noe_replicate_fail.py') 55 56 # Open the NOE output file. 57 file = open(ds.tmpfile) 58 lines = file.readlines() 59 file.close() 60 61 # How the file should look like. 62 data = [ 63 "# Parameter description: The steady-state NOE value.\n", 64 "#\n", 65 "# mol_name res_num res_name spin_num spin_name value error \n", 66 "2AT7_fmf 12 PHE 1 N 0.803029108487728 0.0199040298831904 \n", 67 "2AT7_fmf 13 ASN 21 N 0.829415981681132 0.0339996453012768 \n", 68 "2AT7_fmf 14 LYS 35 N 0.755789564728523 0.0250941717735858 \n" 69 ] 70 71 # Printout of the real and generated data. 72 print("\n\nThe real data:") 73 for i in range(len(lines)): 74 print(repr(data[i])) 75 print("\nThe generated data:") 76 for i in range(len(lines)): 77 print(repr(lines[i])) 78 print("\n") 79 80 # Check each line. 81 for i in range(len(lines)): 82 self.assertEqual(data[i], lines[i])
83 84
86 """Catch U{bug #21591<https://web.archive.org/web/https://gna.org/bugs/?21591>}, the failure of the NOE analysis.""" 87 88 # Generate the sequence. 89 self.interpreter.spin.create(mol_name='XYZ_mol1', res_num=120, res_name='GLY', spin_num=1865, spin_name='N') 90 91 # Load the reference spectrum and saturated spectrum peak intensities. 92 path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'peak_lists' 93 self.interpreter.spectrum.read_intensities(file='noe.140109.8.001.list', dir=path, spectrum_id='ref_ave') 94 self.interpreter.spectrum.read_intensities(file='noe.140109.8.002.list', dir=path, spectrum_id='sat_ave') 95 96 # Set the spectrum types. 97 self.interpreter.noe.spectrum_type('ref', 'ref_ave') 98 self.interpreter.noe.spectrum_type('sat', 'sat_ave') 99 100 # Set the errors. 101 self.interpreter.spectrum.baseplane_rmsd(error=1.3e06, spectrum_id='ref_ave') 102 self.interpreter.spectrum.baseplane_rmsd(error=1.4e06, spectrum_id='sat_ave') 103 104 # Peak intensity error analysis. 105 self.interpreter.spectrum.error_analysis() 106 107 # Calculate the NOEs. 108 self.interpreter.minimise.calculate() 109 110 # Save the NOEs. 111 self.interpreter.value.write(param='noe', file=ds.tmpfile, force=True) 112 113 # Open the NOE output file. 114 file = open(ds.tmpfile) 115 lines = file.readlines() 116 file.close() 117 118 # How the file should look like. 119 data = [ 120 "# Parameter description: The steady-state NOE value.\n", 121 "#\n", 122 "# mol_name res_num res_name spin_num spin_name value error \n", 123 "XYZ_mol1 120 GLY 1865 N 0.520373965716017 0.208104738641507 \n", 124 ] 125 126 # Printout of the real and generated data. 127 print("\n\nThe real data:") 128 for i in range(len(lines)): 129 print(repr(data[i])) 130 print("\nThe generated data:") 131 for i in range(len(lines)): 132 print(repr(lines[i])) 133 print("\n") 134 135 # Check each line. 136 for i in range(len(lines)): 137 self.assertEqual(data[i], lines[i])
138 139
140 - def test_noe_analysis(self):
141 """Test the NOE analysis. 142 143 The test has been modified to also catch U{bug #21863<https://web.archive.org/web/https://gna.org/bugs/?21863>}. 144 """ 145 146 # Execute the script. 147 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'noe'+sep+'noe.py') 148 149 # The real data. 150 sat = [5050.0, 51643.0, 53663.0, -65111.0, -181131.0, -105322.0] 151 ref = [148614.0, 166842.0, 128690.0, 99566.0, 270047.0, 130959.0] 152 noe = [0.033980647852826784, 0.30953237194471417, 0.4169943274535706, -0.6539481349054899, -0.6707387973204665, -0.8042364404126482] 153 noe_err = [0.02020329903276632, 0.2320024671657343, 0.026067523940084526, 0.038300618865378507, 0.014260663438353431, 0.03183614777183591] 154 155 # Check the data. 156 i = 0 157 for spin in spin_loop(): 158 # Skip deselected spins. 159 if not spin.select: 160 continue 161 162 # Check the intensity data. 163 self.assertEqual(sat[i], spin.peak_intensity['sat_ave']) 164 self.assertEqual(ref[i], spin.peak_intensity['ref_ave']) 165 166 # Check the NOE data. 167 self.assertEqual(noe[i], spin.noe) 168 self.assertAlmostEqual(noe_err[i], spin.noe_err) 169 170 # Increment the spin index. 171 i += 1 172 173 # The real Grace file data. 174 data = [[ 175 '@version 50121\n', 176 '@page size 842, 595\n', 177 '@with g0\n', 178 '@ view 0.15, 0.15, 1.28, 0.85\n', 179 '@ xaxis label "Residue number"\n', 180 '@ xaxis label char size 1.00\n', 181 '@ xaxis tick major size 0.50\n', 182 '@ xaxis tick major linewidth 0.5\n', 183 '@ xaxis tick minor linewidth 0.5\n', 184 '@ xaxis tick minor size 0.25\n', 185 '@ xaxis ticklabel char size 0.70\n', 186 '@ yaxis label "\\qPeak intensities\\Q"\n', 187 '@ yaxis label char size 1.00\n', 188 '@ yaxis tick major size 0.50\n', 189 '@ yaxis tick major linewidth 0.5\n', 190 '@ yaxis tick minor linewidth 0.5\n', 191 '@ yaxis tick minor size 0.25\n', 192 '@ yaxis ticklabel char size 0.70\n', 193 '@ legend on\n', 194 '@ legend box fill pattern 1\n', 195 '@ legend char size 1.0\n', 196 '@ frame linewidth 0.5\n', 197 '@ s0 symbol 1\n', 198 '@ s0 symbol size 0.45\n', 199 '@ s0 symbol linewidth 0.5\n', 200 '@ s0 errorbar size 0.5\n', 201 '@ s0 errorbar linewidth 0.5\n', 202 '@ s0 errorbar riser linewidth 0.5\n', 203 '@ s0 legend "ref_ave"\n', 204 '@ s1 symbol 2\n', 205 '@ s1 symbol size 0.45\n', 206 '@ s1 symbol linewidth 0.5\n', 207 '@ s1 errorbar size 0.5\n', 208 '@ s1 errorbar linewidth 0.5\n', 209 '@ s1 errorbar riser linewidth 0.5\n', 210 '@ s1 legend "sat_ave"\n', 211 '@target G0.S0\n', 212 '@type xydy\n', 213 ' 4.000000000000000 148614.000000000000000 3600.000000000000000\n', 214 ' 5.000000000000000 166842.000000000000000 122000.000000000000000\n', 215 ' 6.000000000000000 128690.000000000000000 3600.000000000000000\n', 216 ' 40.000000000000000 99566.000000000000000 3600.000000000000000\n', 217 ' 40.000000000000000 270047.000000000000000 3600.000000000000000\n', 218 ' 55.000000000000000 130959.000000000000000 3600.000000000000000\n', 219 '&\n', 220 '@target G0.S1\n', 221 '@type xydy\n', 222 ' 4.000000000000000 5050.000000000000000 3000.000000000000000\n', 223 ' 5.000000000000000 51643.000000000000000 8500.000000000000000\n', 224 ' 6.000000000000000 53663.000000000000000 3000.000000000000000\n', 225 ' 40.000000000000000 -65111.000000000000000 3000.000000000000000\n', 226 ' 40.000000000000000 -181131.000000000000000 3000.000000000000000\n', 227 ' 55.000000000000000 -105322.000000000000000 3000.000000000000000\n', 228 '&\n', 229 '@with g0\n', 230 '@autoscale\n' 231 ], [ 232 '@version 50121\n', 233 '@page size 842, 595\n', 234 '@with g0\n', 235 '@ view 0.15, 0.15, 1.28, 0.85\n', 236 '@ xaxis label "Residue number"\n', 237 '@ xaxis label char size 1.00\n', 238 '@ xaxis tick major size 0.50\n', 239 '@ xaxis tick major linewidth 0.5\n', 240 '@ xaxis tick minor linewidth 0.5\n', 241 '@ xaxis tick minor size 0.25\n', 242 '@ xaxis ticklabel char size 0.70\n', 243 '@ yaxis label "\\qNOE\\Q"\n', 244 '@ yaxis label char size 1.00\n', 245 '@ yaxis tick major size 0.50\n', 246 '@ yaxis tick major linewidth 0.5\n', 247 '@ yaxis tick minor linewidth 0.5\n', 248 '@ yaxis tick minor size 0.25\n', 249 '@ yaxis ticklabel char size 0.70\n', 250 '@ legend on\n', 251 '@ legend box fill pattern 1\n', 252 '@ legend char size 1.0\n', 253 '@ frame linewidth 0.5\n', 254 '@ s0 symbol 1\n', 255 '@ s0 symbol size 0.45\n', 256 '@ s0 symbol linewidth 0.5\n', 257 '@ s0 errorbar size 0.5\n', 258 '@ s0 errorbar linewidth 0.5\n', 259 '@ s0 errorbar riser linewidth 0.5\n', 260 '@ s0 legend "N spins"\n', 261 '@ s1 symbol 2\n', 262 '@ s1 symbol size 0.45\n', 263 '@ s1 symbol linewidth 0.5\n', 264 '@ s1 errorbar size 0.5\n', 265 '@ s1 errorbar linewidth 0.5\n', 266 '@ s1 errorbar riser linewidth 0.5\n', 267 '@ s1 legend "NE1 spins"\n', 268 '@target G0.S0\n', 269 '@type xydy\n', 270 ' 4.000000000000000 0.033980647852827 0.020203299032766\n', 271 ' 5.000000000000000 0.309532371944714 0.232002467165734\n', 272 ' 6.000000000000000 0.416994327453571 0.026067523940085\n', 273 ' 40.000000000000000 -0.653948134905490 0.038300618865379\n', 274 ' 55.000000000000000 -0.804236440412648 0.031836147771836\n', 275 '&\n', 276 '@target G0.S1\n', 277 '@type xydy\n', 278 ' 40.000000000000000 -0.670738797320466 0.014260663438353\n', 279 '&\n', 280 '@with g0\n', 281 '@autoscale\n' 282 ]] 283 284 # Check the Grace files. 285 ids = ['intensities', 'noe'] 286 for i in range(len(ids)): 287 # The file name. 288 file_name = "%s.agr" % ids[i] 289 290 # Does the file exist? 291 self.assert_(access(ds.tmpdir+sep+file_name, F_OK)) 292 293 # Open the file and extract the contents. 294 file = open(ds.tmpdir + sep + file_name) 295 lines = file.readlines() 296 file.close() 297 298 # Nothing. 299 self.assertNotEqual(lines, []) 300 301 # Check the file contents. 302 for j in range(len(lines)): 303 print(" '%s\\n'," % lines[j][:-1].replace('"', "\\\"")) 304 for j in range(len(lines)): 305 self.assertEqual(data[i][j], lines[j])
306