Module dep_check
[hide private]
[frames] | no frames]

Source Code for Module dep_check

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2008-2014 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 checking relax dependencies. 
 24   
 25  If essential dependencies are missing, then an error message is printed and the program terminated. 
 26  """ 
 27   
 28  # Python modules. 
 29  import platform 
 30  from os import F_OK, access, sep 
 31  import sys 
 32   
 33   
 34  # Essential packages. 
 35  ##################### 
 36   
 37  # numpy. 
 38  try: 
 39      import numpy 
 40      if float(numpy.version.version[:3]) < 1.6: 
 41          sys.stderr.write("Version %s of the 'numpy' dependency is not supported, numpy >= 1.6 is required.\n" % numpy.version.version) 
 42          sys.exit() 
 43  except ImportError: 
 44      sys.stderr.write("The dependency 'numpy' has not been installed.\n") 
 45      sys.exit() 
 46   
 47  # Command line option parser. 
 48  try: 
 49      import optparse 
 50  except ImportError: 
 51      sys.stderr.write("The dependency 'Optik' has not been installed.\n") 
 52      sys.exit() 
 53   
 54  # Minfx python package check. 
 55  try: 
 56      import minfx 
 57  except ImportError: 
 58      sys.stderr.write("The dependency 'minfx' has not been installed (see https://sourceforge.net/projects/minfx/).\n") 
 59      sys.exit() 
 60   
 61  # Optional packages. 
 62  #################### 
 63   
 64  # Bmrblib python package check. 
 65  try: 
 66      import bmrblib 
 67      bmrblib_module = True 
 68  except ImportError: 
 69      bmrblib_module = False 
 70   
 71  # wx module. 
 72  try: 
 73      import wx 
 74      wx_module = True 
 75  except ImportError: 
 76      wx_module = False 
 77      message = sys.exc_info()[1] 
 78      wx_module_message = message.args[0] 
 79   
 80  # epydoc module. 
 81  try: 
 82      import epydoc 
 83      epydoc_module = True 
 84  except ImportError: 
 85      epydoc_module = False 
 86   
 87  # Readline module (avoiding the damned ^[[?1034h escape code on Linux systems). 
 88  try: 
 89      import os 
 90      if 'TERM' in os.environ and os.environ['TERM'] == 'xterm': 
 91          os.environ['TERM'] = 'linux' 
 92      import readline 
 93      readline_module = True 
 94  except ImportError: 
 95      readline_module = False 
 96   
 97  # matplotlib module. 
 98  try: 
 99      import matplotlib 
100      matplotlib_module = True 
101  except ImportError: 
102      matplotlib_module = False 
103   
104  # runpy module. 
105  try: 
106      import runpy 
107      runpy_module = True 
108  except ImportError: 
109      runpy_module = False 
110   
111  # profile module (python development packages required). 
112  try: 
113      import profile 
114      profile_module = True 
115  except ImportError: 
116      profile_module = False 
117   
118  # profile C module (python development packages required). 
119  try: 
120      import cProfile 
121      cprofile_module = True 
122  except ImportError: 
123      cprofile_module = False 
124   
125  # BZ2 compression module. 
126  try: 
127      import bz2 
128      bz2_module = True 
129  except ImportError: 
130      message = sys.exc_info()[1] 
131      bz2_module = False 
132      bz2_module_message = message.args[0] 
133   
134  # Gzip compression module. 
135  try: 
136      import gzip 
137      gzip_module = True 
138  except ImportError: 
139      message = sys.exc_info()[1] 
140      gzip_module = False 
141      gzip_module_message = message.args[0] 
142   
143  # IO module. 
144  try: 
145      import io 
146      io_module = True 
147  except ImportError: 
148      message = sys.exc_info()[1] 
149      io_module = False 
150      io_module_message = message.args[0] 
151   
152  # Scipy import. 
153  try: 
154      import scipy 
155      scipy_module = True 
156  except: 
157      scipy_module = False 
158   
159  # VMD module imports. 
160  try: 
161      from Scientific.Visualization import VMD    # This requires Numeric to be installed (at least in Scientific 2.7.8). 
162      del VMD 
163      vmd_module = True 
164  except: 
165      vmd_module = False 
166   
167  # mpi4py. 
168  try: 
169      import mpi4py 
170      mpi4py_module = True 
171  except ImportError: 
172      message = sys.exc_info()[1] 
173      mpi4py_module = False 
174   
175      # The error message. 
176      mpi4py_message = """The dependency 'mpi4py' has not been installed. You should either: 
177   
178  1. Run without multiprocessor support i.e. remove the --multi mpi4py flag from the command line. 
179   
180  2. Install mpi4py. 
181   
182  3. Choose another multi processor method to give to the --multi command line flag.\n 
183      """ 
184    
185  # PyMOL. 
186  try: 
187      import pymol 
188      pymol_module = True 
189  except ImportError: 
190      message = sys.exc_info()[1] 
191      pymol_module = False 
192   
193  # XML. 
194  try: 
195      import xml 
196      xml_module = True 
197  except ImportError: 
198      message = sys.exc_info()[1] 
199      xml_module = False 
200  if xml_module: 
201      # The XML version mess! 
202      if hasattr(xml, '_MINIMUM_XMLPLUS_VERSION'): 
203          xml_version = "%s.%s.%s" % xml._MINIMUM_XMLPLUS_VERSION 
204          xml_type = 'internal' 
205      elif hasattr(xml, '__version__'): 
206          xml_version = xml.__version__ 
207          xml_type = 'PyXML' 
208      else: 
209          xml_version = '' 
210          xml_type = '' 
211   
212  # subprocess module. 
213  try: 
214      import subprocess 
215      subprocess_module = True 
216  except ImportError: 
217      message = sys.exc_info()[1] 
218      subprocess_module = False 
219      subprocess_module_message = message.args[0] 
220   
221  # ctypes module. 
222  try: 
223      import ctypes 
224      ctypes_module = True 
225  except ImportError: 
226      message = sys.exc_info()[1] 
227      ctypes_module = False 
228      ctypes_module_message = message.args[0] 
229  try: 
230      from ctypes import Structure 
231      ctypes_structure_module = True 
232  except ImportError: 
233      message = sys.exc_info()[1] 
234      ctypes_structure_module = False 
235      ctypes_structure_module_message = message.args[0] 
236   
237   
238   
239   
240  # Compiled C modules. 
241  ##################### 
242   
243  # Relaxation curve fitting. 
244  try: 
245      from target_functions import relax_fit 
246      from target_functions.relax_fit import setup 
247      del setup 
248      C_module_exp_fn = True 
249  except ImportError: 
250      # The OS. 
251      system = platform.system() 
252   
253      # Does the compiled file exist. 
254      file = 'relax_fit.so' 
255      if system == 'Windows' or system == 'Microsoft': 
256          file = 'relax_fit.pyd' 
257      if not access('target_functions' + sep + file, F_OK): 
258          C_module_exp_fn_mesg = "ImportError: relaxation curve fitting is unavailable, the corresponding C modules have not been compiled." 
259   
260      # Show the full error. 
261      else: 
262          message = sys.exc_info()[1] 
263          C_module_exp_fn_mesg = "ImportError: " + repr(message) + "\nRelaxation curve fitting is unavailable, try compiling the C modules." 
264   
265      # Set the flag. 
266      C_module_exp_fn = False 
267