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

Source Code for Module dep_check

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