~maddevelopers/mg5amcnlo/color_ordering

« back to all changes in this revision

Viewing changes to aloha/aloha_fct.py

  • Committer: olivier-mattelaer
  • Date: 2021-02-21 11:03:42 UTC
  • mfrom: (50.85.73 madgraph5)
  • Revision ID: olivier-mattelaer-20210221110342-wn2nvdefctey5e0k
merge up to 2.8.0 --not python3 compatible

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
#
11
11
#
12
12
################################################################################
 
13
from __future__ import absolute_import
 
14
from __future__ import print_function
13
15
from aloha.aloha_object import *
14
16
import aloha.aloha_lib as aloha_lib
15
17
import cmath
 
18
from six.moves import range
16
19
 
17
20
class WrongFermionFlow(Exception):
18
21
    pass
29
32
    try:
30
33
        expr = eval(expression)
31
34
    except Exception as error:
32
 
        print error
 
35
        print(error)
33
36
        return
34
37
    expr = expr.simplify()
35
38
    #expr is now a valid AddVariable object if they are a sum or
40
43
    for term in expr:
41
44
        if term.vartype == 0: # Single object
42
45
            if not term.spin_ind in [[1,2], [2,1]]:
43
 
                raise WrongFermionFlow, 'Fermion should be the first particles of any interactions'
 
46
                raise WrongFermionFlow('Fermion should be the first particles of any interactions')
44
47
            if isinstance(term, (Gamma, Gamma5, Sigma)):
45
48
                if term.spin_ind == [2,1]:
46
49
                    out[1] = 2
56
59
                if not obj.spin_ind:
57
60
                    continue
58
61
                ind1, ind2 = obj.spin_ind
59
 
                if ind1 not in link.keys():
 
62
                if ind1 not in list(link.keys()):
60
63
                    link[ind1] = ind2
61
64
                else:
62
 
                    raise WrongFermionFlow, 'a spin indices should appear only once on the left indices of an object: %s' % expr
63
 
                if ind2 not in rlink.keys():
 
65
                    raise WrongFermionFlow('a spin indices should appear only once on the left indices of an object: %s' % expr)
 
66
                if ind2 not in list(rlink.keys()):
64
67
                    rlink[ind2] = ind1
65
68
                else: 
66
 
                    raise WrongFermionFlow, 'a spin indices should appear only once on the left indices of an object: %s' % expr             
 
69
                    raise WrongFermionFlow('a spin indices should appear only once on the left indices of an object: %s' % expr)             
67
70
             
68
71
            for i in range(1, nb_fermion):
69
 
                if i in out.keys() or i in out.values():
 
72
                if i in list(out.keys()) or i in list(out.values()):
70
73
                    continue
71
74
                old = []
72
75
                pos = i
73
76
                while 1:
74
77
                    old.append(pos)
75
 
                    if pos in link.keys() and link[pos] not in old:
 
78
                    if pos in list(link.keys()) and link[pos] not in old:
76
79
                        pos = link[pos]
77
 
                    elif pos in rlink.keys() and rlink[pos] not in old:
 
80
                    elif pos in list(rlink.keys()) and rlink[pos] not in old:
78
81
                        pos = rlink[pos]
79
82
                    else:
80
 
                        if pos in link.keys() and i in rlink.keys():
 
83
                        if pos in list(link.keys()) and i in list(rlink.keys()):
81
84
                            out[i] = pos
82
85
                            break
83
 
                        elif pos in rlink.keys() and i in link.keys():
 
86
                        elif pos in list(rlink.keys()) and i in list(link.keys()):
84
87
                            out[pos] = i
85
88
                            break
86
89
                        else:
87
 
                            raise WrongFermionFlow,  'incoherent IO state: %s' % expr
 
90
                            raise WrongFermionFlow('incoherent IO state: %s' % expr)
88
91
    if not len(out) == nb_fermion //2:
89
 
        raise WrongFermionFlow, 'Not coherent Incoming/outcoming fermion flow'
 
92
        raise WrongFermionFlow('Not coherent Incoming/outcoming fermion flow')
90
93
    return out
91
94
 
92
95
 
112
115
    for term in expr:
113
116
        if term.vartype == 0: # Single object
114
117
            if not term.spin_ind in [[1,2], [2,1]]:
115
 
                raise WrongFermionFlow, 'Fermion should be the first particles of any interactions'
 
118
                raise WrongFermionFlow('Fermion should be the first particles of any interactions')
116
119
            if isinstance(term, (Gamma, Gamma5, Sigma)):
117
120
                if not term.spin_ind == [2,1]:
118
 
                    raise WrongFermionFlow, 'Not coherent Incoming/outcoming fermion flow'
 
121
                    raise WrongFermionFlow('Not coherent Incoming/outcoming fermion flow')
119
122
        
120
123
        elif term.vartype == 2: # product of object
121
124
            link, rlink = {}, {}
127
130
                if isinstance(obj, (Gamma, Sigma)):
128
131
                    if (ind1 in range(1, nb_fermion+1) and ind1 % 2 == 1) or \
129
132
                       (ind2 in range(2, nb_fermion+1) and ind2 % 2 == 0 ):
130
 
                        raise WrongFermionFlow, 'Not coherent Incoming/outcoming fermion flow'
131
 
                if ind1 not in link.keys():
 
133
                        raise WrongFermionFlow('Not coherent Incoming/outcoming fermion flow')
 
134
                if ind1 not in list(link.keys()):
132
135
                    link[ind1] = ind2
133
136
                else:
134
137
                    rlink[ind1] = ind2
135
 
                if ind2 not in link.keys():
 
138
                if ind2 not in list(link.keys()):
136
139
                    link[ind2] = ind1
137
140
                else: 
138
141
                    rlink[ind2] = ind1                    
141
144
                pos = i
142
145
                while 1:
143
146
                    old.append(pos)
144
 
                    if pos in link.keys() and link[pos] not in old:
 
147
                    if pos in list(link.keys()) and link[pos] not in old:
145
148
                        pos = link[pos]
146
 
                    elif pos in rlink.keys() and rlink[pos] not in old:
 
149
                    elif pos in list(rlink.keys()) and rlink[pos] not in old:
147
150
                        pos = rlink[pos]
148
151
                    elif pos != i+1:
149
 
                        raise WrongFermionFlow, 'Not coherent Incoming/outcoming fermion flow'
 
152
                        raise WrongFermionFlow('Not coherent Incoming/outcoming fermion flow')
150
153
                    elif pos == i+1:
151
154
                        break
152
155