Package models
[hide private]
[frames] | no frames]

Source Code for Package models

 1  ################################################################################ 
 2  # 
 3  # Copyright (c) 2009 The MadGraph5_aMC@NLO Development team and Contributors 
 4  # 
 5  # This file is a part of the MadGraph5_aMC@NLO project, an application which  
 6  # automatically generates Feynman diagrams and matrix elements for arbitrary 
 7  # high-energy processes in the Standard Model and beyond. 
 8  # 
 9  # It is subject to the MadGraph5_aMC@NLO license which should accompany this  
10  # distribution. 
11  # 
12  # For more information, visit madgraph.phys.ucl.ac.be and amcatnlo.web.cern.ch 
13  # 
14  ################################################################################ 
15  """All models for MG5, in particular UFO models (by FeynRules)""" 
16   
17  from __future__ import absolute_import 
18  import os 
19  import sys 
20  import madgraph.various.misc as misc 
21  from madgraph import MG5DIR 
22  import six 
23  import logging 
24   
25  logger = logging.getLogger('madgraph.models') 
26   
27  pjoin = os.path.join 
28   
29 -def load_model(name, decay=False):
30 31 # avoid final '/' in the path 32 if name.endswith('/'): 33 name = name[:-1] 34 35 36 37 path_split = name.split(os.sep) 38 if len(path_split) == 1: 39 try: 40 with misc.TMP_variable(sys, 'path', [pjoin(MG5DIR, 'models'), pjoin(MG5DIR, 'models', name), MG5DIR]): 41 model_pos = 'models.%s' % name 42 __import__(model_pos) 43 return sys.modules[model_pos] 44 except Exception as error: 45 pass 46 for p in os.environ['PYTHONPATH'].split(':'): 47 new_name = os.path.join(p, name) 48 try: 49 return load_model(new_name, decay) 50 except Exception: 51 pass 52 except ImportError: 53 pass 54 elif path_split[-1] in sys.modules: 55 model_path = os.path.realpath(os.sep.join(path_split)) 56 sys_path = os.path.realpath(os.path.dirname(sys.modules[path_split[-1]].__file__)) 57 if sys_path != model_path: 58 raise Exception('name %s already consider as a python library cann\'t be reassigned(%s!=%s)' % \ 59 (path_split[-1], model_path, sys_path)) 60 61 # remove any link to previous model 62 for name in ['particles', 'object_library', 'couplings', 'function_library', 'lorentz', 'parameters', 'vertices', 'coupling_orders', 'write_param_card', 63 'CT_couplings', 'CT_vertices', 'CT_parameters']: 64 try: 65 del sys.modules[name] 66 except Exception: 67 continue 68 69 with misc.TMP_variable(sys, 'path', [os.sep.join(path_split[:-1]),os.sep.join(path_split)]): 70 try: 71 __import__(path_split[-1]) 72 except Exception as error: 73 if six.PY3: 74 logger.critical('It is likely that your UFO model is NOT python3 compatible.\n Most common issue with python2/3 compatibility can be solve with the "convert model" command of MG5aMC.') 75 logger.warning('If you want to try that automatic conversion please run:') 76 logger.warning('convert model %s' % '/'.join(path_split)) 77 raise 78 output = sys.modules[path_split[-1]] 79 if decay: 80 dec_name = '%s.decays' % path_split[-1] 81 try: 82 __import__(dec_name) 83 except ImportError: 84 pass 85 else: 86 output.all_decays = sys.modules[dec_name].all_decays 87 88 return sys.modules[path_split[-1]]
89