Skip to main content

Energy level diagram plotting from graphs

Project description

leveldiagram

PyPI Python Version License Docs

leveldiagram

This module creates energy level diagrams common to atomic physics as matplotlib graphics. The level structure is defined using networkx graphs.

Quick Usage

This package takes networkx directional graphs, which can be used to effectively define a system hamiltonian, and creates an energy diagram representing the system. The nodes of the graph represent the energy levels. The edges of the graph represent the couplings between levels.

Passing a simple graph to the basic level diagram constructor will produce a passable output for simple visualization purposes.

nodes = (0,1,2)
edges = ((0,1),(1,2))
graph = nx.DiGraph()
graph.add_nodes_from(nodes)
graph.add_edges_from(edges)
d = ld.LD(graph)
d.draw()

Simple 3-level diagram with default options

Global settings for the three primitive objects used by leveldiagram can be set by passing keyword argument dictionaries to the LD constructor. To control options for a single level or coupling, save these keyword arguments to the respective node or edge of the supplied graph. Generally, the levels and couplings take standard matplotlib 2D line configuration arguments.

nodes = ((0,{'bottom_text':'ground'}),
         (1,{'right_text':'excited'}),
         (2,{'top_text':'rydberg'}))
edges = ((0,1, {'label':'$\\Omega_p$'}),
         (1,2, {'label':'$\\Omega_c$'}))
graph = nx.DiGraph()
graph.add_nodes_from(nodes)
graph.add_edges_from(edges)
d = ld.LD(graph, coupling_defaults = {'arrowsize':0.15,'lw':3})
d.draw()

3-level diagram with some custom options

With some basic scripting to create the graph appropriately, much more complicated level diagrams can be made with relative ease.

hf_nodes =  [((f,i), {('top' if f==2 else 'bottom') + '_text':'$m_F='+f'{i:d}'+'$',
                      'energy':f-1,
                      'xpos':i,
                      'width':0.75,
                      'text_kw':{'fontsize':'large'}})
             for f in [1,2]
             for i in range(-f,f+1)]
lin_couples = [((1,i),(2,i),{'label':l,'color':'C0',
                            'label_kw':{'fontsize':'medium','color':'C0'}})
               for i,l in zip(range(-1,2), ['1/2','2/3','1/2'])]
sp_couples = [((1,i),(2,i+1),{'label':l,'color':'C1',
                              'label_offset':'right',
                             'label_kw':{'fontsize':'medium','color':'C1'}})
              for i,l in zip(range(-1,2), ['1/6','1/2','1'])]
sm_couples = [((1,i),(2,i-1),{'label':l, 'color':'C2',
                              'label_offset':'left',
                             'label_kw':{'fontsize':'medium','color':'C2'}})
              for i,l in zip(range(-1,2), ['1','1/2','1/6'])]
hf_edges = lin_couples + sp_couples + sm_couples
hf_graph = nx.DiGraph()
hf_graph.add_nodes_from(hf_nodes)
hf_graph.add_edges_from(hf_edges)
d = ld.LD(hf_graph, default_label = 'none')
d.ax.margins(y=0.2)
d.draw()

Hyperfine states with Clebsh-Gordon Coefficients

Installation

Presently, installation must be done manually using a copy of the repository.

Pure pip installation

To install in an editable way (which allows edits of the source code), run:

pip install -e .

from within the top level leveldiagram directory (i.e. where the setup.cfg file resides). This command will use pip to install all necessary dependencies.

To install normally, run:

pip install .

from the same directory.

Updating an existing installation

Upgrading an existing installation is simple. Simply run the pip installation commands described above with the update flag.

pip install -U .

This command will also install any new dependencies that are required.

If using an editable install, simply replacing the files in the same directory is sufficient. Though it is recommended to also run the appropriate pip update command as well.

pip install -U -e .

Dependencies

Requires matplotlib, networkx, and numpy.

Documentation

A PDF copy of the documentation is avaiable in the docs/build/latex/ directory.

Examples

Example jupyter notebooks that demonstrate leveldiagrams can be found in the examples subdirectory. Printouts of these notebooks are available in the docs as well.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

leveldiagram-0.2.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

leveldiagram-0.2.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file leveldiagram-0.2.0.tar.gz.

File metadata

  • Download URL: leveldiagram-0.2.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for leveldiagram-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7dba9006a876f93219aea96058cec5713136e46cbae4d1b088812538ef8e0f1d
MD5 1f2761d9f36aa91ba485a3575b1f1642
BLAKE2b-256 4a8f1078629d43b71345066a4450e0d6601dd13be221ed8bdbc036f23afb5c41

See more details on using hashes here.

File details

Details for the file leveldiagram-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: leveldiagram-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for leveldiagram-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b35886d6c335689fdc0924a565f22218830c6503811d48d0d83c37cc7572179d
MD5 8797b76111efd515ff00bc507da672cf
BLAKE2b-256 90264476e2560c12e111feb828f4ed1d91cc8c81c536b0b1c6267c8a52142ee1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page