> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/field-specific/04-molecular-orbital-diagrams.md).

# Molecular orbital diagrams

This article provides a brief introduction to the creation of [molecular orbital diagrams](https://en.wikipedia.org/wiki/Molecular_orbital_diagram) in LaTeX using the [`modiagram` package](https://ctan.org/pkg/modiagram?lang=en). Readers are strongly encouraged to consult the [`modiagram` package documentation](http://mirrors.ctan.org/macros/latex/contrib/modiagram/modiagram_en.pdf) which contains numerous helpful examples to demonstrate its many features—far more than we can address in this short article.

For information about the more traditional *molecular structure diagrams* see our documentation about [chemistry formulae](/latex/field-specific/02-chemistry-formulae.md).

## Introduction

Molecular diagrams are created using the [`modiagram` package](https://ctan.org/pkg/modiagram?lang=en) which you import to your document by adding the following line to its preamble:

`\usepackage{modiagram}`\[$$\langle$$`options`$$\rangle$$]

The set of $$\langle$$`options`$$\rangle$$ are listed, and demonstrated, in the [package documentation](http://mirrors.ctan.org/macros/latex/contrib/modiagram/modiagram_en.pdf).

To apply package $$\langle$$`options`$$\rangle$$ *globally* you can

* set them when you load the package via `\usepackage{modiagram}`\[$$\langle$$`options`$$\rangle$$], or
* use the setup command `\setmodiagram`{$$\langle$$`options`$$\rangle$$}

MO diagrams are created using the `modiagram` environment, which supports local use of package $$\langle$$`options`$$\rangle$$:

`\begin{modiagram}`\[$$\langle$$`options`$$\rangle$$] ...

`\end{modiagram}`

The following example demonstrates a minimal `modiagram` environment without any using any $$\langle$$`options`$$\rangle$$:

```latex
\documentclass{article}
\usepackage{modiagram}
\begin{document}

First example atoms:

\begin{modiagram}
\atom{left}{1s, 2s, 2p}
\end{modiagram}
\end{document}
```

[Open this example in Overleaf.](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=example+of+molecular+diagram\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bmodiagram%7D%0A%5Cbegin%7Bdocument%7D%0A%0AFirst+example+atoms%3A%0A%0A%5Cbegin%7Bmodiagram%7D%0A%5Catom%7Bleft%7D%7B1s%2C+2s%2C+2p%7D%0A%5Cend%7Bmodiagram%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![Example of a molecular diagram produced in LaTeX](/files/Q8GOdzQDi1SsTFa5NdbU)

The basic command to draw MO diagrams is `\atom` which, as demonstrated in the example above, takes two arguments:

* `left`: the alignment of the atom.
* `1s, 2s, 2p`: the energy sub-levels to be drawn. These can be further customized as you will learn in the [next section](#atoms).

## Atoms

You can pass some extra information about the atomic orbitals to the command presented in the introductory example.

```latex
\documentclass{article}
\usepackage{modiagram}
\begin{document}

\begin{modiagram}
 \atom{right}{
    1s = { 0; pair} ,
    2s = { 1; pair} ,
    2p = {1.5; up, down }
 }

 \atom{left}{
    1s = { 0; pair} ,
    2s = { 1; pair} ,
    2p = {1.5; up, down }
 }
 \end{modiagram}
\end{document}
```

[Open this example in Overleaf.](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=example+of+molecular+diagram\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bmodiagram%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cbegin%7Bmodiagram%7D%0A+%5Catom%7Bright%7D%7B%0A++++1s+%3D+%7B+0%3B+pair%7D+%2C%0A++++2s+%3D+%7B+1%3B+pair%7D+%2C%0A++++2p+%3D+%7B1.5%3B+up%2C+down+%7D%0A+%7D%0A%0A+%5Catom%7Bleft%7D%7B%0A++++1s+%3D+%7B+0%3B+pair%7D+%2C%0A++++2s+%3D+%7B+1%3B+pair%7D+%2C%0A++++2p+%3D+%7B1.5%3B+up%2C+down+%7D%0A+%7D%0A+%5Cend%7Bmodiagram%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![example of atomic orbitals](/files/8RziWMyhJIdyu6V1yngx)

In this example, two identical atoms are drawn, left- and right-aligned respectively.

Following the style of the `modiagram` package documentation, the generic syntax to create atoms can be written as:

`\atom`\[$$\langle$$`name`$$\rangle$$]{$$\langle$$`left`$$\rangle$$|$$\langle$$`right`$$\rangle$$}{$$\langle$$`AO-spec`$$\rangle$$}

where

* $$\langle$$`name`$$\rangle$$ is an optional name for the atom
* $$\langle$$`left`$$\rangle$$ and $$\langle$$`right`$$\rangle$$ determine the placement in the diagram
* $$\langle$$`AO-spec`$$\rangle$$ is the specification of the Atomic Orbital.

The $$\langle$$`AO-spec`$$\rangle$$ takes the general form

```latex
sub-level = {energy; specifications}
```

where

* `sub-level` can be `1s`, `2s` or `2p`
* `energy` is the energy level, a number that determines the vertical spacing in the diagram. If omitted it is set to 0.
* `specifications` is a comma-separated list of the spins of the electrons contained in each orbital. The possible values are `up`, `down`, `pair` and empty (only the semicolon is typed) for an empty orbital. If omitted it is set to `pair`.

Here is a description of the commands used in the previous example:

* `1s = { 0; pair}`. The sub-level `1s` is in the `0` energy level, the orbital contains two (paired) electrons.
* `2s = { 1; pair}`. The sub-level `2s` drawn in the `1` energy level, there are two electrons in this orbital.
* `2p = {1.5; up, down}`. The sub-level `2p` drawn in the energy level `1.5`, i.e. in the diagram the vertical spacing is set to 1.5; this sub-energy level has two electrons: one with spin `up` in the first orbital and another with spin `down` in the second orbital.

The same commands are repeated for the second atom on the right.

To display the (optional) `name` of an atom use a `modiagram` environment with the `[names]` option:

```latex
\documentclass{article}
\usepackage{modiagram}
\begin{document}
\begin{modiagram}[names]
 \atom[Atom on the right]{right}{
    1s = { 0; pair} ,
    2s = { 1; pair} ,
    2p = {1.5; up, down }
 }

 \atom[Atom on the left]{left}{
    1s = { 0; pair} ,
    2s = { 1; pair} ,
    2p = {1.5; up, down }
 }
\end{modiagram}
\end{document}
```

[Open this example in Overleaf.](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Using+the+names+option+in+a+molecular+diagram\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bmodiagram%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bmodiagram%7D%5Bnames%5D%0A+%5Catom%5BAtom+on+the+right%5D%7Bright%7D%7B%0A++++1s+%3D+%7B+0%3B+pair%7D+%2C%0A++++2s+%3D+%7B+1%3B+pair%7D+%2C%0A++++2p+%3D+%7B1.5%3B+up%2C+down+%7D%0A+%7D%0A%0A+%5Catom%5BAtom+on+the+left%5D%7Bleft%7D%7B%0A++++1s+%3D+%7B+0%3B+pair%7D+%2C%0A++++2s+%3D+%7B+1%3B+pair%7D+%2C%0A++++2p+%3D+%7B1.5%3B+up%2C+down+%7D%0A+%7D%0A%5Cend%7Bmodiagram%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![Example molecular orbital](/files/CtNWffRuZMy45U9S423v)

## Molecules

The syntax for molecules is very similar to that of the [`\atom`](#atoms) and, in the style of the documentation, can be written as:

`\molecule`\[$$\langle$$`name`$$\rangle$$]{$$\langle$$`MO-spec`$$\rangle$$}

where

* $$\langle$$`name`$$\rangle$$ is an optional caption of the molecule
* $$\langle$$`MO-spec`$$\rangle$$ is the specification of the Molecular Orbital

The energy sub-levels `1s`, `2s` and `2p` become `1sMO`, `2sMO` and `2pMO` respectively. Here is a basic example:

```latex
\documentclass{article}
\usepackage{modiagram}
\begin{document}
\begin{modiagram}
 \atom{left}{1s}
 \atom{right}{1s={;up}}
 \molecule{
    1sMO={0.75;pair,up}
  }
\end{modiagram}
\end{document}
```

[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Molecule+example+with+modiagram+package\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bmodiagram%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bmodiagram%7D%0A+%5Catom%7Bleft%7D%7B1s%7D%0A+%5Catom%7Bright%7D%7B1s%3D%7B%3Bup%7D%7D%0A+%5Cmolecule%7B%0A++++1sMO%3D%7B0.75%3Bpair%2Cup%7D%0A++%7D%0A%5Cend%7Bmodiagram%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![example of molecule diagram](/files/lSPiEQ0voNkFN5T2NAHh)

In the example above, the molecular orbital specification ($$\langle$$`MO-spec`$$\rangle$$ ) is

```latex
1sMO={0.75;pair,up}
```

where

* `0.75` is now the ratio *(energy gain)/(energy loss)*.
* `pair, up` are the spins of the electrons in the bonding and anti-bonding molecular orbitals, respectively.

The next, slightly more elaborate, example should help you understand the syntax:

```latex
\documentclass{article}
\usepackage{modiagram}
\begin{document}
\begin{modiagram}
 \atom{left}{
      1s, 2s, 2p = {;pair,up,up}
  }
  \atom{right}{
      1s, 2s, 2p = {;pair,up,up}
  }
  \molecule{
      1sMO, 2sMO, 2pMO = {;pair,pair,pair,up,up}
  }
\end{modiagram}
\end{document}
```

[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=More+elaborate+modiagram+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bmodiagram%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bmodiagram%7D%0A+%5Catom%7Bleft%7D%7B%0A++++++1s%2C+2s%2C+2p+%3D+%7B%3Bpair%2Cup%2Cup%7D%0A++%7D%0A++%5Catom%7Bright%7D%7B%0A++++++1s%2C+2s%2C+2p+%3D+%7B%3Bpair%2Cup%2Cup%7D%0A++%7D%0A++%5Cmolecule%7B%0A++++++1sMO%2C+2sMO%2C+2pMO+%3D+%7B%3Bpair%2Cpair%2Cpair%2Cup%2Cup%7D%0A++%7D%0A%5Cend%7Bmodiagram%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![elaborated example of molecular orbital](/files/QnO7r7CtzyYpgqgKXYjJ)

Three atoms are set on each side of the diagram and the corresponding molecule is in the middle.

## Naming scheme

The following diagram is reproduced from the [`modiagram` package](https://ctan.org/pkg/modiagram?lang=en) documentation. It contains the names (labels) used for the orbitals, which are nodes in a `tikzpicture` and thus can be used in standard TikZ drawing commands within a `modiagram` environment.

![modiagram names for oribtals](/files/D0xoYmys7q9tvye7D2I8)

Here is an example using the name of the anti-bonding orbital `1sigma*` for relative positioning.

```latex
\documentclass{article}
\usepackage{modiagram}
\begin{document}
\begin{modiagram}
 \atom{left}{1s}
 \atom{right}{1s={;up}}
 \molecule{
    1sMO={;pair,up}
 }
 \draw[<-,shorten <=8pt,shorten >=15pt,blue]
 (1sigma*) --++(2,1) node {anti-bonding MO};
\end{modiagram}
\end{document}
```

[Open this example in Overleaf.](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Using+orbital+labels+in+an+modiagram+environment\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bmodiagram%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bmodiagram%7D%0A+%5Catom%7Bleft%7D%7B1s%7D%0A+%5Catom%7Bright%7D%7B1s%3D%7B%3Bup%7D%7D%0A+%5Cmolecule%7B%0A++++1sMO%3D%7B%3Bpair%2Cup%7D%0A+%7D%0A+%5Cdraw%5B%3C-%2Cshorten+%3C%3D8pt%2Cshorten+%3E%3D15pt%2Cblue%5D%0A+%281sigma%2A%29+--%2B%2B%282%2C1%29+node+%7Banti-bonding+MO%7D%3B%0A%5Cend%7Bmodiagram%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![example of orbital with anti-bonding](/files/lF2eVVICOYUYBsyJYya7)

## Further reading

For more information see:

* [Chemistry formulae](/latex/field-specific/02-chemistry-formulae.md)
* [Feynman diagrams](/latex/field-specific/03-feynman-diagrams.md)
* [TikZ package](/latex/figures-and-tables/05-tikz-package.md)
* [Drawing Diagrams Directly in LaTeX](/latex/figures-and-tables/04-picture-environment.md)
* [Inserting Images](/latex/more-topics/27-inserting-images.md)
* [List of Greek letters and math symbols](/latex/mathematics/11-list-of-greek-letters-and-math-symbols.md)
* [The `modiagram` manual](http://mirrors.ctan.org/macros/latex/contrib/modiagram/modiagram_en.pdf)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/field-specific/04-molecular-orbital-diagrams.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
