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
31
32 if name.endswith('/'):
33 name = name[:-1]
34
35
36
37 path_split = name.split(os.sep)
38 if len(path_split) == 1:
39 try:
40 with misc.TMP_variable(sys, 'path', [pjoin(MG5DIR, 'models'), pjoin(MG5DIR, 'models', name), MG5DIR]):
41 model_pos = 'models.%s' % name
42 __import__(model_pos)
43 return sys.modules[model_pos]
44 except Exception as error:
45 pass
46 if 'PYTHONPATH' in os.environ:
47 for p in os.environ['PYTHONPATH'].split(':'):
48 new_name = os.path.join(p, name)
49 try:
50 return load_model(new_name, decay)
51 except Exception:
52 pass
53 except ImportError:
54 pass
55 elif path_split[-1] in sys.modules:
56 model_path = os.path.realpath(os.sep.join(path_split))
57 sys_path = os.path.realpath(os.path.dirname(sys.modules[path_split[-1]].__file__))
58 if sys_path != model_path:
59 raise Exception('name %s already consider as a python library cann\'t be reassigned(%s!=%s)' % \
60 (path_split[-1], model_path, sys_path))
61
62
63 for name in ['particles', 'object_library', 'couplings', 'function_library', 'lorentz', 'parameters', 'vertices', 'coupling_orders', 'write_param_card',
64 'CT_couplings', 'CT_vertices', 'CT_parameters']:
65 try:
66 del sys.modules[name]
67 except Exception:
68 continue
69
70 with misc.TMP_variable(sys, 'path', [os.sep.join(path_split[:-1]),os.sep.join(path_split)]):
71 try:
72 __import__(path_split[-1])
73 except Exception as error:
74 if six.PY3:
75 logger.critical('It is likely that your UFO model is NOT python3 compatible.\n Most common issue with python2/3 compatibility can be solve with the "convert model" command of MG5aMC.')
76 logger.warning('If you want to try that automatic conversion please run:')
77 logger.warning('convert model %s' % '/'.join(path_split))
78 raise
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