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 new_name = os.path.join(p, name) 51 try: 52 return load_model(new_name, decay) 53 except Exception: 54 pass 55 except ImportError: 56 pass 57 elif path_split[-1] in sys.modules: 58 model_path = os.path.realpath(os.sep.join(path_split)) 59 sys_path = os.path.realpath(os.path.dirname(sys.modules[path_split[-1]].__file__)) 60 if sys_path != model_path: 61 raise Exception('name %s already consider as a python library cann\'t be reassigned(%s!=%s)' % \ 62 (path_split[-1], model_path, sys_path)) 63 64 # remove any link to previous model 65 for name in ['particles', 'object_library', 'couplings', 'function_library', 'lorentz', 'parameters', 'vertices', 'coupling_orders', 'write_param_card', 66 'CT_couplings', 'CT_vertices', 'CT_parameters']: 67 try: 68 del sys.modules[name] 69 except Exception: 70 continue 71 72 with misc.TMP_variable(sys, 'path', [os.sep.join(path_split[:-1]),os.sep.join(path_split)]): 73 try: 74 __import__(path_split[-1]) 75 except Exception as error: 76 raise UFOError(str(error)) 77 output = sys.modules[path_split[-1]] 78 if decay: 79 dec_name = '%s.decays' % path_split[-1] 80 try: 81 __import__(dec_name) 82 except ImportError: 83 pass 84 else: 85 output.all_decays = sys.modules[dec_name].all_decays 86 87 return sys.modules[path_split[-1]]
88