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
18
from six.moves import range
17
20
class WrongFermionFlow(Exception):
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]:
56
59
if not obj.spin_ind:
58
61
ind1, ind2 = obj.spin_ind
59
if ind1 not in link.keys():
62
if ind1 not in list(link.keys()):
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()):
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)
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()):
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:
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:
80
if pos in link.keys() and i in rlink.keys():
83
if pos in list(link.keys()) and i in list(rlink.keys()):
83
elif pos in rlink.keys() and i in link.keys():
86
elif pos in list(rlink.keys()) and i in list(link.keys()):
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')
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')
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
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
138
141
rlink[ind2] = ind1
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:
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:
149
raise WrongFermionFlow, 'Not coherent Incoming/outcoming fermion flow'
152
raise WrongFermionFlow('Not coherent Incoming/outcoming fermion flow')