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

Source Code for Module dep_check

  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 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  # profile C module (python development packages required). 
104  try: 
105      import cProfile 
106      cprofile_module = True 
107  except ImportError: 
108      cprofile_module = False 
109   
110  # BZ2 compression module. 
111  try: 
112      import bz2 
113      bz2_module = True 
114  except ImportError: 
115      message = sys.exc_info()[1] 
116      bz2_module = False 
117      bz2_module_message = message.args[0] 
118   
119  # Gzip compression module. 
120  try: 
121      import gzip 
122      gzip_module = True 
123  except ImportError: 
124      message = sys.exc_info()[1] 
125      gzip_module = False 
126      gzip_module_message = message.args[0] 
127   
128  # IO module. 
129  try: 
130      import io 
131      io_module = True 
132  except ImportError: 
133      message = sys.exc_info()[1] 
134      io_module = False 
135      io_module_message = message.args[0] 
136   
137  # Scipy import. 
138  try: 
139      import scipy 
140      scipy_module = True 
141  except: 
142      scipy_module = False 
143   
144  # VMD module imports. 
145  try: 
146      from Scientific.Visualization import VMD    # This requires Numeric to be installed (at least in Scientific 2.7.8). 
147      del VMD 
148      vmd_module = True 
149  except: 
150      vmd_module = False 
151   
152  # mpi4py. 
153  try: 
154      import mpi4py 
155      mpi4py_module = True 
156  except ImportError: 
157      message = sys.exc_info()[1] 
158      mpi4py_module = False 
159   
160      # The error message. 
161      mpi4py_message = """The dependency 'mpi4py' has not been installed. You should either: 
162   
163  1. Run without multiprocessor support i.e. remove the --multi mpi4py flag from the command line. 
164   
165  2. Install mpi4py. 
166   
167  3. Choose another multi processor method to give to the --multi command line flag.\n 
168      """ 
169    
170  # PyMOL. 
171  try: 
172      import pymol 
173      pymol_module = True 
174  except ImportError: 
175      message = sys.exc_info()[1] 
176      pymol_module = False 
177   
178  # XML. 
179  try: 
180      import xml 
181      xml_module = True 
182  except ImportError: 
183      message = sys.exc_info()[1] 
184      xml_module = False 
185  if xml_module: 
186      # The XML version mess! 
187      if hasattr(xml, '_MINIMUM_XMLPLUS_VERSION'): 
188          xml_version = "%s.%s.%s" % xml._MINIMUM_XMLPLUS_VERSION 
189          xml_type = 'internal' 
190      elif hasattr(xml, '__version__'): 
191          xml_version = xml.__version__ 
192          xml_type = 'PyXML' 
193      else: 
194          xml_version = '' 
195          xml_type = '' 
196   
197  # subprocess module. 
198  try: 
199      import subprocess 
200      subprocess_module = True 
201  except ImportError: 
202      message = sys.exc_info()[1] 
203      subprocess_module = False 
204      subprocess_module_message = message.args[0] 
205   
206  # ctypes module. 
207  try: 
208      import ctypes 
209      ctypes_module = True 
210  except ImportError: 
211      message = sys.exc_info()[1] 
212      ctypes_module = False 
213      ctypes_module_message = message.args[0] 
214  try: 
215      from ctypes import Structure 
216      ctypes_structure_module = True 
217  except ImportError: 
218      message = sys.exc_info()[1] 
219      ctypes_structure_module = False 
220      ctypes_structure_module_message = message.args[0] 
221   
222   
223   
224   
225  # Compiled C modules. 
226  ##################### 
227   
228  # Relaxation curve fitting. 
229  try: 
230      from target_functions import relax_fit 
231      from target_functions.relax_fit import setup 
232      del setup 
233      C_module_exp_fn = True 
234  except ImportError: 
235      # The OS. 
236      system = platform.system() 
237   
238      # Does the compiled file exist. 
239      file = 'relax_fit.so' 
240      if system == 'Windows' or system == 'Microsoft': 
241          file = 'relax_fit.pyd' 
242      if not access('target_functions' + sep + file, F_OK): 
243          C_module_exp_fn_mesg = "ImportError: relaxation curve fitting is unavailable, the corresponding C modules have not been compiled." 
244   
245      # Show the full error. 
246      else: 
247          message = sys.exc_info()[1] 
248          C_module_exp_fn_mesg = "ImportError: " + repr(message) + "\nRelaxation curve fitting is unavailable, try compiling the C modules." 
249   
250      # Set the flag. 
251      C_module_exp_fn = False 
252