TikZ-Feynman
[1]:
from pyfeyn2.feynmandiagram import FeynmanDiagram, Leg, Propagator, Vertex, PDG
from pyfeyn2.render.latex.tikzfeynman import TikzFeynmanRender
from pyfeyn2.auto.position import feynman_adjust_points
import pyfeyn2
print(pyfeyn2.__version__)
2.3.2
Simple Case
We set the positions of all vertices here.
[2]:
v1 = Vertex("v1").with_xy(-1, 0).with_shape("blob")
v2 = Vertex("v2").with_xy(1, 0).with_style("symbol : dot")
fd = FeynmanDiagram().add(
v1,v2,
Propagator(name="g").connect(v1, v2),
Leg(name="g").with_target(v1).with_xy(-2, 1).with_incoming(),
Leg(name="g").with_target(v1).with_xy(-2, -1).with_incoming().with_class("notred"),
Leg(name="g").with_target(v2).with_xy(2, 1).with_outgoing().with_class("red"),
Leg("myid1",name="g").with_target(v2).with_xy(2, -1).with_outgoing().with_style_property("bend-direction","right")
)
/tmp/ipykernel_5127/1904706615.py:1: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
v1 = Vertex("v1").with_xy(-1, 0).with_shape("blob")
/tmp/ipykernel_5127/1904706615.py:2: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
v2 = Vertex("v2").with_xy(1, 0).with_style("symbol : dot")
/tmp/ipykernel_5127/1904706615.py:4: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
fd = FeynmanDiagram().add(
/tmp/ipykernel_5127/1904706615.py:6: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
Propagator(name="g").connect(v1, v2),
/tmp/ipykernel_5127/1904706615.py:7: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
Leg(name="g").with_target(v1).with_xy(-2, 1).with_incoming(),
/tmp/ipykernel_5127/1904706615.py:8: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
Leg(name="g").with_target(v1).with_xy(-2, -1).with_incoming().with_class("notred"),
/tmp/ipykernel_5127/1904706615.py:9: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
Leg(name="g").with_target(v2).with_xy(2, 1).with_outgoing().with_class("red"),
/tmp/ipykernel_5127/1904706615.py:10: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
Leg("myid1",name="g").with_target(v2).with_xy(2, -1).with_outgoing().with_style_property("bend-direction","right")
Style
[3]:
fd = fd.with_rule("""
* {
bend-direction: left;
color: green;
}
""")
[4]:
fd.add_rules("""
.red {
color: red;
}
.notred {
color: blue;
}
#myid1 {
color: gray;
}
[pdgid="21"] {
color: black;
}
#myid2 {
color: gray;
}
diagram.propagator {
color: green;
}
""")
fd.sheet.cssText
[4]:
b'* {\n bend-direction: left;\n color: green\n }\n.red {\n color: red\n }\n.notred {\n color: blue\n }\n#myid1 {\n color: gray\n }\n[pdgid="21"] {\n color: black\n }\n#myid2 {\n color: gray\n }\ndiagram.propagator {\n color: green\n }'
[5]:
fd.to_xml()
[5]:
'<?xml version="1.0" encoding="UTF-8"?>\n<diagram id="FeynmanDiagram7" style="" sheet="* { bend-direction: left; color: green } .red { color: red } .notred { color: blue } #myid1 { color: gray } [pdgid="21"] { color: black } #myid2 { color: gray } diagram.propagator { color: green }">\n <propagator xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Propagator8" pdgid="21" type="gluon" style="" xsi:type="Propagator">\n <name>g</name>\n <source>v1</source>\n <target>v2</target>\n </propagator>\n <vertex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="v1" style="" x="-1.0" y="0.0" shape="blob" xsi:type="Vertex"/>\n <vertex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="v2" style="symbol: dot" x="1.0" y="0.0" xsi:type="Vertex"/>\n <leg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Leg9" pdgid="21" type="gluon" style="" x="-2.0" y="1.0" xsi:type="Leg">\n <name>g</name>\n <target>v1</target>\n <sense>incoming</sense>\n </leg>\n <leg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Leg10" pdgid="21" type="gluon" style="" class="notred" x="-2.0" y="-1.0" xsi:type="Leg">\n <name>g</name>\n <target>v1</target>\n <sense>incoming</sense>\n </leg>\n <leg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Leg11" pdgid="21" type="gluon" style="" class="red" x="2.0" y="1.0" xsi:type="Leg">\n <name>g</name>\n <target>v2</target>\n <sense>outgoing</sense>\n </leg>\n <leg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="myid1" pdgid="21" type="gluon" style="bend-direction: right" x="2.0" y="-1.0" xsi:type="Leg">\n <name>g</name>\n <target>v2</target>\n <sense>outgoing</sense>\n </leg>\n</diagram>\n'
[6]:
tfd = TikzFeynmanRender(fd)
print(tfd.get_src())
\documentclass[preview,crop,tikz]{standalone}%
\usepackage[T1]{fontenc}%
\usepackage[utf8]{inputenc}%
\usepackage{lmodern}%
\usepackage{textcomp}%
\usepackage{lastpage}%
%
\RequirePackage{luatex85}%
\usepackage[compat=1.1.0]{tikz-feynman}%
%
\begin{document}%
\normalsize%
\begin{tikzpicture}
\begin{feynman}
\vertex (v1) [blob] at (-1.0,0.0) {};
\vertex (v1clone) [] at (-1.0,0.0);
\vertex (v2) [dot] at (1.0,0.0) {};
\vertex (v2clone) [] at (1.0,0.0);
\vertex (Leg9) [] at (-2.0,1.0);
\vertex (Leg10) [] at (-2.0,-1.0);
\vertex (Leg11) [] at (2.0,1.0);
\vertex (myid1) [] at (2.0,-1.0);
\diagram*{
(v1) -- [gluon,black,bend left] (v2),
(Leg9) -- [gluon,black,bend left] (v1),
(Leg10) -- [gluon,blue,bend left] (v1),
(v2) -- [gluon,red,bend left] (Leg11),
(v2) -- [gluon,gray,bend right] (myid1),
};
\end{feynman}
\end{tikzpicture}
%
\end{document}
/home/apn/git/feynml/feynml/feynmandiagram.py:136: UserWarning: No parent fml, returning default style
warnings.warn("No parent fml, returning default style")
/home/apn/git/feynml/feynml/feynmandiagram.py:143: UserWarning: No parent fml, returning default sheet
warnings.warn("No parent fml, returning default sheet")
[7]:
tfd.render("test.pdf")
[7]:
Complicated Case
We only set the positions of the Legs here.
[8]:
fd = FeynmanDiagram().with_rules(
""" * {color: red;}
[type=fermion] {color: blue; line: gluon}
#p1 {color: green;}
:not([type=fermion]) { color : black; line: fermion}""")
v1 = Vertex("v1")
v2 = Vertex("v2")
v3 = Vertex("v3")
v4 = Vertex("v4")
p1 = Propagator("p1").connect(v1, v2).with_type("gluon")
p2 = Propagator("p2").connect(v1, v3).with_type("gluon")
p3 = Propagator("p3").connect(v3, v2).with_type("gluon")
p4 = Propagator("p4").connect(v4, v3).with_type("gluon")
p5 = Propagator("p5").connect(v4, v2).with_type("gluon")
l1 = Leg("l1").with_target(v1).with_type("gluon").with_incoming().with_xy(-2, 1)
l2 = Leg("l2").with_target(v1).with_type("gluon").with_incoming().with_xy(-2, -1)
l3 = Leg("l3").with_target(v2).with_type("fermion").with_outgoing().with_xy(2, -2).with_class("blue")
l4 = Leg("l4").with_target(v3).with_type("fermion").with_outgoing().with_xy(2, 2)
l5 = Leg("l5").with_target(v4).with_type("gluon").with_outgoing().with_xy(2, 1)
l6 = Leg("l6").with_target(v4).with_type("gluon").with_outgoing().with_xy(2, -1)
l6.style.color = "orange"
fd.propagators.extend([p1, p2, p3, p4, p5])
fd.vertices.extend([v1, v2, v3, v4])
fd.legs.extend([l1, l2, l3, l4, l5, l6])
/tmp/ipykernel_5127/1594115405.py:1: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
fd = FeynmanDiagram().with_rules(
/tmp/ipykernel_5127/1594115405.py:6: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
v1 = Vertex("v1")
/tmp/ipykernel_5127/1594115405.py:7: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
v2 = Vertex("v2")
/tmp/ipykernel_5127/1594115405.py:8: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
v3 = Vertex("v3")
/tmp/ipykernel_5127/1594115405.py:9: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
v4 = Vertex("v4")
/tmp/ipykernel_5127/1594115405.py:10: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
p1 = Propagator("p1").connect(v1, v2).with_type("gluon")
/tmp/ipykernel_5127/1594115405.py:11: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
p2 = Propagator("p2").connect(v1, v3).with_type("gluon")
/tmp/ipykernel_5127/1594115405.py:12: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
p3 = Propagator("p3").connect(v3, v2).with_type("gluon")
/tmp/ipykernel_5127/1594115405.py:13: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
p4 = Propagator("p4").connect(v4, v3).with_type("gluon")
/tmp/ipykernel_5127/1594115405.py:14: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
p5 = Propagator("p5").connect(v4, v2).with_type("gluon")
/tmp/ipykernel_5127/1594115405.py:15: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
l1 = Leg("l1").with_target(v1).with_type("gluon").with_incoming().with_xy(-2, 1)
/tmp/ipykernel_5127/1594115405.py:16: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
l2 = Leg("l2").with_target(v1).with_type("gluon").with_incoming().with_xy(-2, -1)
/tmp/ipykernel_5127/1594115405.py:17: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
l3 = Leg("l3").with_target(v2).with_type("fermion").with_outgoing().with_xy(2, -2).with_class("blue")
/tmp/ipykernel_5127/1594115405.py:18: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
l4 = Leg("l4").with_target(v3).with_type("fermion").with_outgoing().with_xy(2, 2)
/tmp/ipykernel_5127/1594115405.py:19: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
l5 = Leg("l5").with_target(v4).with_type("gluon").with_outgoing().with_xy(2, 1)
/tmp/ipykernel_5127/1594115405.py:20: DeprecatedWarning: __init__ is deprecated as of 2.2.6 and will be removed in 2.4.0.
l6 = Leg("l6").with_target(v4).with_type("gluon").with_outgoing().with_xy(2, -1)
Now calculate the positions of vertices.
[9]:
ffd= feynman_adjust_points(fd)
/home/apn/git/feynml/feynml/feynmandiagram.py:136: UserWarning: No parent fml, returning default style
warnings.warn("No parent fml, returning default style")
/home/apn/git/feynml/feynml/feynmandiagram.py:143: UserWarning: No parent fml, returning default sheet
warnings.warn("No parent fml, returning default sheet")
[10]:
TikzFeynmanRender(ffd).render()
[10]:
[11]:
fd.get_sheets()[0].cssText
/home/apn/git/feynml/feynml/feynmandiagram.py:143: UserWarning: No parent fml, returning default sheet
warnings.warn("No parent fml, returning default sheet")
[11]:
b'/*************************************************************************/\n/* Diagram */\n/*************************************************************************/\ndiagram {\n direction: right;\n layout: neato\n }\n/*************************************************************************/\n/* Vertex */\n/*************************************************************************/\n[shape=dot] {\n symbol: dot\n }\n[shape=empty] {\n symbol: empty\n }\n[shape=square] {\n symbol: square\n }\n[shape=cross] {\n symbol: cross\n }\n[shape=blob] {\n symbol: blob\n }\n/*************************************************************************/\n/* Propagator */\n/*************************************************************************/\n/* General */\n[type=fermion] {\n line: fermion;\n arrow-sense: 1\n }\n[type="anti fermion"] {\n line: anti fermion;\n arrow-sense: -1\n }\n[type=boson] {\n line: boson;\n arrow-sense: 0\n }\n[type=vector] {\n line: vector;\n arrow-sense: 0\n }\n[type=scalar] {\n line: scalar;\n arrow-sense: 0\n }\n[type=majorana] {\n line: majorana\n }\n/* SM */\n[type=photon] {\n line: photon;\n arrow-sense: 0\n }\n[type=higgs] {\n line: higgs;\n arrow-sense: 0\n }\n[type=gluon] {\n line: gluon;\n arrow-sense: 0;\n xamp: 0.025;\n yamp: 0.035;\n nloops: 7\n }\n[type=ghost] {\n line: ghost;\n arrow-sense: 0\n }\n/* BSM */\n[type=graviton] {\n line: graviton;\n arrow-sense: 0\n }\n[type=gluino] {\n line: gluino;\n arrow-sense: 0;\n xamp: 0.025;\n yamp: 0.035;\n nloops: 7\n }\n[type=squark] {\n line: squark;\n arrow-sense: 1\n }\n[type=slepton] {\n line: slepton;\n arrow-sense: 1\n }\n[type=gaugino] {\n line: gaugino;\n arrow-sense: 0\n }\n[type=neutralino] {\n line: neutralino;\n arrow-sense: 0\n }\n[type=chargino] {\n line: chargino;\n arrow-sense: 0\n }\n[type=higgsino] {\n line: higgsino;\n arrow-sense: 0\n }\n[type=gravitino] {\n line: gravitino;\n arrow-sense: 0\n }\n/* util */\n[type=phantom] {\n line: phantom;\n arrow-sense: 0\n }\n[type=line] {\n line: line;\n arrow-sense: 0\n }'
[12]:
fd.get_sheets()[1].cssText
[12]:
b'* {\n color: red\n }\n[type=fermion] {\n color: blue;\n line: gluon\n }\n#p1 {\n color: green\n }\n:not([type=fermion]) {\n color: black;\n line: fermion\n }'
[13]:
fd.get_sheets()
[13]:
[cssutils.css.CSSStyleSheet(href=None, media=None, title=None),
cssutils.css.CSSStyleSheet(href=None, media=None, title=None)]
[ ]: