"Fossies" - the Fresh Open Source Software Archive

Member "relax-5.0.0/test_suite/system_tests/palmer.py" (25 Aug 2020, 15071 Bytes) of package /linux/privat/relax-5.0.0.src.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "palmer.py": 4.1.3_vs_5.0.0.

    1 ###############################################################################
    2 #                                                                             #
    3 # Copyright (C) 2008 Sebastien Morin                                          #
    4 # Copyright (C) 2008-2009,2012-2014,2017,2020 Edward d'Auvergne               #
    5 #                                                                             #
    6 # This file is part of the program relax (http://www.nmr-relax.com).          #
    7 #                                                                             #
    8 # This program is free software: you can redistribute it and/or modify        #
    9 # it under the terms of the GNU General Public License as published by        #
   10 # the Free Software Foundation, either version 3 of the License, or           #
   11 # (at your option) any later version.                                         #
   12 #                                                                             #
   13 # This program is distributed in the hope that it will be useful,             #
   14 # but WITHOUT ANY WARRANTY; without even the implied warranty of              #
   15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
   16 # GNU General Public License for more details.                                #
   17 #                                                                             #
   18 # You should have received a copy of the GNU General Public License           #
   19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
   20 #                                                                             #
   21 ###############################################################################
   22 
   23 # Python module imports.
   24 from math import pi
   25 from os import sep
   26 from tempfile import mkdtemp
   27 
   28 # relax module imports.
   29 from data_store import Relax_data_store; ds = Relax_data_store()
   30 import dep_check
   31 from pipe_control import pipes
   32 from pipe_control.mol_res_spin import return_spin
   33 from lib.errors import RelaxError
   34 from lib.io import test_binary
   35 from status import Status; status = Status()
   36 from test_suite.system_tests.base_classes import SystemTestCase
   37 
   38 
   39 class Palmer(SystemTestCase):
   40     """Class for testing various aspects specific to model-free analysis using the program 'Modelfree4'."""
   41 
   42     def __init__(self, methodName='runTest'):
   43         """Skip the tests if the subprocess module is not available (Python 2.3 and earlier).
   44 
   45         @keyword methodName:    The name of the test.
   46         @type methodName:       str
   47         """
   48 
   49         # Execute the base class method.
   50         super(Palmer, self).__init__(methodName)
   51 
   52         # Missing module.
   53         if not dep_check.subprocess_module:
   54             # Store in the status object. 
   55             status.skipped_tests.append([methodName, 'subprocess', self._skip_type])
   56 
   57         # Test for the presence of the Modelfree4 binary (skip the test if not present).
   58         try:
   59             test_binary('modelfree4')
   60         except:
   61             status.skipped_tests.append([methodName, "Art Palmer's Modelfree4 software", self._skip_type])
   62 
   63 
   64     def setUp(self):
   65         """Set up for all the functional tests."""
   66 
   67         # Create a temporary directory for ModelFree4 outputs.
   68         ds.tmpdir = mkdtemp()
   69 
   70 
   71     def test_palmer(self):
   72         """Test a complete model-free analysis using the program 'Modelfree4'."""
   73 
   74         # Execute the script.
   75         self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'palmer.py')
   76 
   77         # Determine if the Gnu gcc or Portland C compiler version is being used.
   78         spin = return_spin(spin_id=':0@N', pipe='m2')
   79         if spin.te == 1.951*1e-12:
   80             binary = 'linux-i386-gcc'   # Linux Gnu gcc modelfree4 version.
   81         else:
   82             binary = 'linux-i386-pgf'   # Linux Portland C compiler modelfree4 version.
   83         spin = return_spin(spin_id=':-2@N', pipe='m1')
   84         if spin.chi2 == 36.62:
   85             binary = 'mac-i386'         # Mac OS X intel binary.
   86         if not binary:
   87             raise RelaxError("The Modelfree4 binary cannot be identified, therefore the parameters cannot be meaningfully checked.")
   88         print("\nDetected the '%s' Modelfree4 binary." % binary)
   89 
   90         # Checks for model m1, m2, and m3 mfout file reading.
   91         models = ['m1', 'm2', 'm3']
   92         params = [['s2'], ['s2', 'te'], ['s2', 'rex']]
   93         spin_names = [':-2@N', ':-1@N', ':0@N']
   94         s2 = [[0.869, 0.732, None], [0.869, 0.730, None], [0.715, 0.643, None]]
   95         if binary == 'linux-i386-gcc':
   96             te = [[None, None, None], [0.0, 1.951, None], [None, None, None]]
   97         else:
   98             te = [[None, None, None], [0.0, 1.952, None], [None, None, None]]
   99         rex = [[None, None, None], [None, None, None], [4.308, 4.278, None]]
  100         chi2 = [[36.6223, 20.3954, None], [36.6223, 20.3299, None], [1.9763, 0.6307, None]]
  101         if binary == 'mac-i386':
  102             chi2 = [[36.62, 20.40, None], [36.62, 20.33, None], [1.976, 0.6307, None]]
  103         for model_index in range(3):
  104             print("Model " + repr(models[model_index]))
  105             for spin_index in range(3):
  106                 print("Spin " + repr(spin_names[spin_index]))
  107 
  108                 # Get the spin.
  109                 spin = return_spin(spin_id=spin_names[spin_index], pipe=models[model_index])
  110 
  111                 # Conversions.
  112                 if te[model_index][spin_index]:
  113                     te[model_index][spin_index] = te[model_index][spin_index] * 1e-12
  114                 if rex[model_index][spin_index]:
  115                     rex[model_index][spin_index] = rex[model_index][spin_index] / (2.0 * pi * cdp.spectrometer_frq[cdp.ri_ids[0]])**2
  116 
  117                 # Checks.
  118                 self.assertEqual(spin.model, models[model_index])
  119                 self.assertEqual(spin.params, params[model_index])
  120                 self.assertEqual(spin.s2, s2[model_index][spin_index])
  121                 self.assertEqual(spin.s2f, None)
  122                 self.assertEqual(spin.s2s, None)
  123                 if te[model_index][spin_index] == None:
  124                     self.assertEqual(spin.te, te[model_index][spin_index])
  125                 else:
  126                     self.assertAlmostEqual(spin.te, te[model_index][spin_index])
  127                 self.assertEqual(spin.tf, None)
  128                 self.assertEqual(spin.ts, None)
  129                 self.assertEqual(spin.rex, rex[model_index][spin_index])
  130                 self.assertEqual(spin.chi2, chi2[model_index][spin_index])
  131 
  132         # Checks for the final mfout file reading.
  133         models = ['m3', 'm3']
  134         params = [['s2', 'rex'], ['s2', 'rex']]
  135         s2 = [0.844, 0.760]
  136         te = [None, None]
  137         rex = [0.005, 0.404]
  138         chi2 = [1.7966, 0.7389]
  139         if binary == 'mac-i386':
  140             chi2 = [1.796, 0.7392]
  141         for spin_index in range(3):
  142             # Get the spin.
  143             spin = return_spin(spin_id=spin_names[spin_index], pipe='aic')
  144 
  145             # Deselected spin.
  146             if not spin.select:
  147                 continue
  148 
  149             # Conversions.
  150             if te[spin_index]:
  151                 te[spin_index] = te[spin_index] * 1e-12
  152             if rex[spin_index]:
  153                 rex[spin_index] = rex[spin_index] / (2.0 * pi * cdp.spectrometer_frq[cdp.ri_ids[0]])**2
  154 
  155             # Checks.
  156             self.assertEqual(spin.model, models[spin_index])
  157             self.assertEqual(spin.params, params[spin_index])
  158             self.assertAlmostEqual(spin.s2, s2[spin_index])
  159             self.assertEqual(spin.s2f, None)
  160             self.assertEqual(spin.s2s, None)
  161             if te[spin_index]:
  162                 self.assertAlmostEqual(spin.te, te[spin_index])
  163             else:
  164                 self.assertEqual(spin.te, None)
  165             self.assertEqual(spin.tf, None)
  166             self.assertEqual(spin.ts, None)
  167             self.assertAlmostEqual(spin.rex, rex[spin_index])
  168             self.assertEqual(spin.chi2, chi2[spin_index])
  169 
  170         # Final global values.
  171         final_pipe = pipes.get_pipe('aic')
  172         if binary == 'mac-i386':
  173             self.assertAlmostEqual(final_pipe.chi2, 2.5355)
  174             self.assertAlmostEqual(final_pipe.diff_tensor.tm, 12.051)
  175         else:
  176             self.assertAlmostEqual(final_pipe.chi2, 2.5356)
  177             self.assertAlmostEqual(final_pipe.diff_tensor.tm, 12.045)
  178 
  179 
  180     def test_palmer_omp(self):
  181         """Test a complete model-free analysis using 'Modelfree4' with the OMP relaxation data, a PDB file, and a spheroid tensor."""
  182 
  183         # Execute the script.
  184         self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'palmer_omp.py')
  185 
  186         # Catch a the old, buggy modelfree4 versions and complain loudly!
  187         spin = return_spin(spin_id=':9@N', pipe='m2')
  188         if spin.s2 == 0.855:
  189             raise RelaxError("You are using an old, buggy Modelfree4 version!  You must upgrade to version 4.20 or later.")
  190 
  191         # Determine the Modelfree4 binary type used.
  192         spin = return_spin(spin_id=':9@N', pipe='aic')
  193         binary = None
  194         if spin.te * 1e12 == 52.195:
  195             binary = 'linux-i386-gcc'   # Linux Gnu gcc modelfree4 version.
  196         elif spin.te * 1e12 == 52.197:
  197             binary = 'linux-i386-pgf'   # Linux Portland C compiler modelfree4 version.
  198         elif spin.te * 1e12 == 52.194:
  199             binary = 'linux-x86_64-gcc'   # 64-bit Linux Gnu gcc modelfree4 version.
  200         spin = return_spin(spin_id=':9@N', pipe='m1')
  201         if binary == None and spin.chi2 == 143.7:
  202             binary = 'mac-i386'         # Mac OS X intel binary.
  203         if not binary:
  204             raise RelaxError("The Modelfree4 binary cannot be identified, therefore the parameters cannot be meaningfully checked.")
  205         print("\nDetected the '%s' Modelfree4 binary." % binary)
  206 
  207         # Model m1, m2, and m3 mfout file data.
  208         models = ['m1', 'm2', 'm3']
  209         params = [['s2'], ['s2', 'te'], ['s2', 'rex']]
  210         spin_names = [':9@N', ':10@N', ':11@N']
  211         s2 = [[0.822, 0.799, 0.823], [0.788, 0.777, 0.812], [0.822, 0.799, 0.823]]
  212         te = [[None, None, None], [61.506, 36.087, 20.039], [None, None, None]]
  213         if binary in ['mac-i386', 'linux-x86_64-gcc']:
  214             te = [[None, None, None], [61.504, 36.087, 20.039], [None, None, None]]
  215         rex = [[None, None, None], [None, None, None], [0.0, 0.0, 0.0]]
  216         chi2 = [[143.6773, 105.1767, 61.6684], [40.9055, 57.1562, 48.4927], [143.6773, 105.1767, 61.6684]]
  217         if binary in ['mac-i386', 'linux-x86_64-gcc']:
  218             chi2 = [[143.7, 105.2, 61.67], [40.91, 57.16, 48.49], [143.7, 105.2, 61.67]]
  219 
  220         # Checks for model m1, m2, and m3 mfout file reading.
  221         for model_index in range(3):
  222             print("Model " + repr(models[model_index]))
  223             for spin_index in range(3):
  224                 print("Spin " + repr(spin_names[spin_index]))
  225 
  226                 # Get the spin.
  227                 spin = return_spin(spin_id=spin_names[spin_index], pipe=models[model_index])
  228 
  229                 # Conversions.
  230                 if rex[model_index][spin_index]:
  231                     rex[model_index][spin_index] = rex[model_index][spin_index] / (2.0 * pi * cdp.spectrometer_frq[cdp.ri_ids[0]])**2
  232 
  233                 # Checks.
  234                 self.assertEqual(spin.model, models[model_index])
  235                 self.assertEqual(spin.params, params[model_index])
  236                 self.assertAlmostEqual(spin.s2, s2[model_index][spin_index])
  237                 self.assertEqual(spin.s2f, None)
  238                 self.assertEqual(spin.s2s, None)
  239                 if te[model_index][spin_index]:
  240                     self.assertAlmostEqual(spin.te * 1e12, te[model_index][spin_index])
  241                 self.assertEqual(spin.tf, None)
  242                 self.assertEqual(spin.ts, None)
  243                 self.assertEqual(spin.rex, rex[model_index][spin_index])
  244                 self.assertEqual(spin.chi2, chi2[model_index][spin_index])
  245 
  246         # Final mfout file data.
  247         models = ['m2', 'm2', 'm2']
  248         params = [['s2', 'te'], ['s2', 'te'], ['s2', 'te']]
  249         s2 = [0.755, 0.761, 0.787]
  250         if binary == 'linux-i386-gcc':
  251             te = [52.195, 29.356, 12.678]
  252         elif binary == 'linux-i386-pgf':
  253             te = [52.197, 29.361, 12.677]
  254         elif binary == 'mac-i386':
  255             te = [52.197, 29.357, 12.676]
  256         elif binary == 'linux-x86_64-gcc':
  257             te = [52.194, 29.351, 12.673]
  258         chi2 = [7.254, 8.0437, 0.5327]
  259         if binary in ['mac-i386', 'linux-x86_64-gcc']:
  260             chi2 = [7.254, 8.044, 0.5327]
  261 
  262         # Checks for the final mfout file reading.
  263         for spin_index in range(3):
  264             # Get the spin.
  265             spin = return_spin(spin_id=spin_names[spin_index], pipe='aic')
  266 
  267             # Checks.
  268             self.assertEqual(spin.model, models[spin_index])
  269             self.assertEqual(spin.params, params[spin_index])
  270             self.assertAlmostEqual(spin.s2, s2[spin_index])
  271             self.assertEqual(spin.s2f, None)
  272             self.assertEqual(spin.s2s, None)
  273             if te[spin_index]:
  274                 self.assertAlmostEqual(spin.te * 1e12, te[spin_index])
  275             self.assertEqual(spin.tf, None)
  276             self.assertEqual(spin.ts, None)
  277             self.assertEqual(spin.rex, None)
  278             self.assertAlmostEqual(spin.chi2, chi2[spin_index])
  279 
  280         # Final global values.
  281         final_pipe = pipes.get_pipe('aic')
  282         if binary == 'linux-i386-gcc':
  283             self.assertEqual(final_pipe.chi2, 15.8304)
  284             self.assertAlmostEqual(final_pipe.diff_tensor.tm, 8.443)
  285             self.assertAlmostEqual(final_pipe.diff_tensor.Dratio, 1.053)
  286             self.assertAlmostEqual(final_pipe.diff_tensor.theta * 360 / 2.0 / pi, 68.592)
  287             self.assertAlmostEqual(final_pipe.diff_tensor.phi * 360 / 2.0 / pi, 73.756)
  288         elif binary == 'linux-i386-pgf':
  289             self.assertEqual(final_pipe.chi2, 15.8304)
  290             self.assertAlmostEqual(final_pipe.diff_tensor.tm, 8.443)
  291             self.assertAlmostEqual(final_pipe.diff_tensor.Dratio, 1.053)
  292             self.assertAlmostEqual(final_pipe.diff_tensor.theta * 360 / 2.0 / pi, 68.864)
  293             self.assertAlmostEqual(final_pipe.diff_tensor.phi * 360 / 2.0 / pi, 73.913)
  294         elif binary == 'mac-i386':
  295             self.assertEqual(final_pipe.chi2, 15.8304)
  296             self.assertAlmostEqual(final_pipe.diff_tensor.tm, 8.459)
  297             self.assertAlmostEqual(final_pipe.diff_tensor.Dratio, 1.049)
  298             self.assertAlmostEqual(final_pipe.diff_tensor.theta * 360 / 2.0 / pi, 64.611)
  299             self.assertAlmostEqual(final_pipe.diff_tensor.phi * 360 / 2.0 / pi, 79.281)
  300         elif binary == 'linux-x86_64-gcc':
  301             self.assertEqual(final_pipe.chi2, 15.8308)
  302             self.assertAlmostEqual(final_pipe.diff_tensor.tm, 8.394)
  303             self.assertAlmostEqual(final_pipe.diff_tensor.Dratio, 1.073)
  304             self.assertAlmostEqual(final_pipe.diff_tensor.theta * 360 / 2.0 / pi, 77.152)
  305             self.assertAlmostEqual(final_pipe.diff_tensor.phi * 360 / 2.0 / pi, 63.848)