diff --git a/diagrams.py b/diagrams.py index 064ee4e9c2e181e69a11bda97691e38acbd64f24..b10311ce2f98ee37a245108fe3b27de58fa6c7dd 100644 --- a/diagrams.py +++ b/diagrams.py @@ -401,6 +401,7 @@ class Diagram: # Clear old data: if clear: self.clear() + self.isKeldysh = False # Remove ignored characters for c in ignore: @@ -476,6 +477,22 @@ class Diagram: if vertex_indices: print('Warning: diagram contains uncontracted indices:', *vertex_indices.keys(), file=sys.stderr) + # Tell contours about their order in Keldysh diagram. + if self.isKeldysh: + self.updateKeldyshOrder() + + def updateKeldyshOrder(self): + 'Tell contours about their order in Keldysh diagram.' + keldysh_order = 0 + for i, contour in enumerate(self.contours, 1): + # First draw the contour. + contour.keldysh_order = keldysh_order + try: + if self.interruptions[i].isKeldysh(): + keldysh_order += 1 + except IndexError: + break + def pprint(self): ''' Produce more or less human readable output (without contractions!) for debugging. @@ -528,10 +545,8 @@ class Diagram: # Iterate over contours, interruptions and elements to draw vertices and interruptions. last_node = self.interruptions[0] - keldysh_order = -1 + self.isKeldysh for i, contour in enumerate(self.contours, 1): # First draw the contour. - contour.keldysh_order = keldysh_order for j, e in enumerate(contour.elements): if type(e) != BaseLine: factor = getattr(contour.elements[j-1], 'factor', 1) or 1 @@ -545,7 +560,6 @@ class Diagram: else: assert type(last_node) == Interrupt last_node = self.interruptions[i] - keldysh_order += 1 elif self.interruptions[i].label: factor = getattr(contour.elements[-1], 'factor', 1) or 1 print(self.interruptions[i].tikz(position='right of=%s, xshift=%g%s'%(last_node.right(), factor*self.sep, self.sep_unit)), file=file)