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 import os
18 import sys
19
21
22
23 if name.endswith('/'):
24 name = name[:-1]
25
26 path_split = name.split(os.sep)
27 if len(path_split) == 1:
28 model_pos = 'models.%s' % name
29 __import__(model_pos)
30 return sys.modules[model_pos]
31 elif path_split[-1] in sys.modules:
32 model_path = os.path.realpath(os.sep.join(path_split))
33 sys_path = os.path.realpath(os.path.dirname(sys.modules[path_split[-1]].__file__))
34 if sys_path != model_path:
35 raise Exception, 'name %s already consider as a python library cann\'t be reassigned' % \
36 path_split[-1]
37
38 sys.path.insert(0, os.sep.join(path_split[:-1]))
39 __import__(path_split[-1])
40 output = sys.modules[path_split[-1]]
41 if decay:
42 dec_name = '%s.decays' % path_split[-1]
43 try:
44 __import__(dec_name)
45 except ImportError:
46 pass
47 else:
48 output.all_decays = sys.modules[dec_name].all_decays
49
50 sys.path.pop(0)
51
52
53
54 return sys.modules[path_split[-1]]
55