1
2
3
4
5
6
7
8
9
10
11
12
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
30
32
33
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
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