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  import os 
18  import sys 
19  import madgraph.various.misc as misc 
20   
21 -def load_model(name, decay=False):
22 23 # avoid final '/' in the path 24 if name.endswith('/'): 25 name = name[:-1] 26 27 28 29 path_split = name.split(os.sep) 30 if len(path_split) == 1: 31 try: 32 model_pos = 'models.%s' % name 33 __import__(model_pos) 34 return sys.modules[model_pos] 35 except Exception: 36 pass 37 for p in os.environ['PYTHONPATH']: 38 new_name = os.path.join(p, name) 39 try: 40 return load_model(new_name, decay) 41 except Exception: 42 pass 43 elif path_split[-1] in sys.modules: 44 model_path = os.path.realpath(os.sep.join(path_split)) 45 sys_path = os.path.realpath(os.path.dirname(sys.modules[path_split[-1]].__file__)) 46 if sys_path != model_path: 47 raise Exception, 'name %s already consider as a python library cann\'t be reassigned(%s!=%s)' % \ 48 (path_split[-1], model_path, sys_path) 49 50 with misc.TMP_variable(sys, 'path', [os.sep.join(path_split[:-1])]): 51 __import__(path_split[-1]) 52 output = sys.modules[path_split[-1]] 53 if decay: 54 dec_name = '%s.decays' % path_split[-1] 55 try: 56 __import__(dec_name) 57 except ImportError: 58 pass 59 else: 60 output.all_decays = sys.modules[dec_name].all_decays 61 62 return sys.modules[path_split[-1]]
63