GithubHelp home page GithubHelp logo

feiyang472 / feynwrap.py Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 63 KB

Generate simple Feynman diagrams easily with python. Written for Cambridge Part II Particle Physics introductory course.

Python 100.00%
feynman-diagrams

feynwrap.py's Introduction

feynwrap.py

Purpose: Writing tikz makes me sad, so I wrap a layer of python around it to allow continuous creation of vertices and edges in Feynman diagrams.

Installation

git clone https://github.com/Feiyang472/feynwrap.py.git

cd feynwrap.py

pip3 install .

Drell-Yan example

from feynwrap import vert

vert('q').br().bl(r'\bar{q}',True).ppgt(r'\gamma', 'boson').br('l',True).ar('anti fermion',r'\bar{l}', True)

vert.save_tex('demo.tex', path='./examples/')

vert.compile_pdf()

Result

Drell-Yan

Tutorial

The first method is always vert, which creates a vertex. We can give it a label, and/or specify its location with respect to another vert instance.

a = vert('\lambda')

The label $\lambda$ will be put on this just created vertex. Now we can get a propagator from a, and retrieve the vertex where the propagator arrives.

b = a.ppgt()
b.ppgt('fermion')
b.ppgt('below right', 'boson').ppgt('below left', 'gluon' True).ppgt('e', 'below right')

The propagate method takes 0 to 4 arguments in any order. It recognizes special strings specifying particle type ('anti fermion', 'boson', 'gluon' etc.) and relative locations ('above left' etc.), as well as a Boolean value which specifies whether the destination of this propagation is at ends of the diagram.

At ends of the diagram, propagator labels are put on vertices. Otherwise, they are put alongside the edges.

The program then allows us to save to a .tex file and build it to pdf. The associated .aux and .log files are always removed after build.

vert.save_tex('demo.tex', path='./examples/')
# vert.save_tex('demo', path='./examples/') # is exactly the same

vert.compile_pdf() 

If you want to keep the tex file and make some edits, specify clean=[] in compile_pdf.


This is an example of the generated .tex.

\begin{tikzpicture}
\begin{feynhand}
\vertex (v1)  {\(q\)};
\vertex (v2) [below right = of v1] ;
\vertex (v3) [below left = of v2] {\(\bar{{q}}\)};
\vertex (v4) [right = of v2] ;
\vertex (v5) [below right = of v4] {\(l\)};
\vertex (v6) [above right = of v4] {\(\bar{{l}}\)};

\propag [fermion] (v1) to (v2);
\propag [fermion] (v2) to (v3);
\propag [boson] (v2) to [edge label = \(\gamma\)] (v4);
\propag [fermion] (v4) to (v5);
\propag [anti fermion] (v4) to (v6);
\end{feynhand}
\end{tikzpicture}

feynwrap.py's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.