-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathweightsum
executable file
·70 lines (51 loc) · 2.07 KB
/
weightsum
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
""" - Main program code for "weightsum" - A program to sum the
combinatorial weights of a list of Feynman diagrams.
This program is part of the feyncop/feyngen package.
"""
# See also: https://github.com/michibo/feyncop
# Author: Michael Borinsky
# Python3 port: Frédéric Chapoton
# Bugreports, comments, or suggestions are always welcome.
# For instance, via github or email
from fractions import Fraction
import argparse
import sys
# from math import *
# from stuff import *
import parsefg
# from graph import Graph
# from hopf_graph import HopfGraph
def main():
"""Main program section. Reads the options and parameters and starts the
relevant subroutines."""
parser = argparse.ArgumentParser(description='Sum the symmetry factors of a list of diagrams')
parser.add_argument('-u', '--non_leg_fixed', dest='non_leg_fixed', action='store_true', help='Input non-leg-fixed graphs. I.e. external legs of graphs are not given with leg labels. (default: false)')
parser.add_argument('-w', '--no_warning', dest='no_warning', action='store_true', help='Do not print warnings. (default: false)')
args = parser.parse_args()
string = ""
try:
string = next(sys.stdin)
except StopIteration:
return
var_name, ev, el = parsefg.parse_var_name(string)
if var_name:
string = string[el:]
graphs_fac = frozenset(parsefg.parse_input_lines(sys.stdin, None, string))
sum_fac = Fraction(0, 1)
for g, fac, ym in graphs_fac:
g_sym = 0
if not args.non_leg_fixed:
g_sym = next(g.permute_external_edges()).unlabeled_graph.symmetry_factor
else:
g_sym = g.unlabeled_graph.symmetry_factor
if Fraction(1, g_sym) != Fraction(fac, 1) and not args.no_warning:
sys.stderr.write("Warning: %s doesn't have symmetry factor %s. It has %s. (Non-)Fixed legs?\n" % (g, fac, Fraction(1, g_sym)))
sum_fac += fac
print("%s" % sum_fac)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("")
print("Cancelled")