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 -class UFOError(Exception): pass
30
31 -def load_model(name, decay=False):
32 33 # avoid final '/' in the path 34 if name.endswith('/'): 35 name = name[:-1] 36 37 38 39 path_split = name.split(os.sep) 40 if len(path_split) == 1: 41 try: 42 with misc.TMP_variable(sys, 'path', [pjoin(MG5DIR, 'models'), pjoin(MG5DIR, 'models', name), MG5DIR]): 43 model_pos = 'models.%s' % name 44 __import__(model_pos) 45 return sys.modules[model_pos] 46 except Exception as error: 47 pass 48 if 'PYTHONPATH' in os.environ: 49 for p in os.environ['PYTHONPATH'].split(':'): 50 if not p: 51 continue 52 new_name = os.path.join(p, name) 53 try: 54 return load_model(new_name, decay) 55 except Exception: 56 pass 57 except ImportError: 58 pass 59 elif path_split[-1] in sys.modules: 60 model_path = os.path.realpath(os.sep.join(path_split)) 61 sys_path = os.path.realpath(os.path.dirname(sys.modules[path_split[-1]].__file__)) 62 if sys_path != model_path: 63 raise Exception('name %s already consider as a python library cann\'t be reassigned(%s!=%s)' % \ 64 (path_split[-1], model_path, sys_path)) 65 66 # remove any link to previous model 67 for name in ['particles', 'object_library', 'couplings', 'function_library', 'lorentz', 'parameters', 'vertices', 'coupling_orders', 'write_param_card', 68 'CT_couplings', 'CT_vertices', 'CT_parameters']: 69 try: 70 del sys.modules[name] 71 except Exception: 72 continue 73 74 with misc.TMP_variable(sys, 'path', [os.sep.join(path_split[:-1]),os.sep.join(path_split)]): 75 try: 76 __import__(path_split[-1]) 77 except Exception as error: 78 raise UFOError(str(error)) 79 output = sys.modules[path_split[-1]] 80 if decay: 81 dec_name = '%s.decays' % path_split[-1] 82 try: 83 __import__(dec_name) 84 except ImportError: 85 pass 86 else: 87 output.all_decays = sys.modules[dec_name].all_decays 88 89 return sys.modules[path_split[-1]]
90