Metadata-Version: 2.4
Name: pymolsym
Version: 1.0
Summary: Analytic point group algebra for molecular symmetry operations.
Author: Ole Hüter
License-Expression: MIT
Project-URL: Homepage, https://ohueter.github.io/pymolsym/
Project-URL: Repository, https://github.com/ohueter/pymolsym
Project-URL: Issues, https://github.com/ohueter/pymolsym/issues
Keywords: molecule,symmetry,operation,point group,group theory,representation,irreducible,reducible,character,Mulliken
Classifier: Development Status :: 5 - Production/Stable
Classifier: Programming Language :: Python :: 3
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Chemistry
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Dynamic: license-file

# pymolsym

Molecular point groups and their irreducible representations as Python objects that you can
calculate with: multiply and add irreps, reduce representations, and follow irreps when the
symmetry is lowered.

pymolsym knows the character table of every point group it supports without storing any: each
group is defined by its generators, and its classes, characters and Mulliken symbols are
derived from them in exact arithmetic.

**Home page:** <https://ohueter.github.io/pymolsym/>, with character tables, examples and a
Python console that run in the browser.

**Contents:** [Features](#features) · [Installation](#installation) ·
[Quick start](#quick-start) · [Examples](#examples) · [Conventions](#conventions) ·
[How it works](#how-it-works) · [Literature](#literature) · [Reference](#reference) ·
[Limitations](#limitations) · [Outlook](#outlook) · [Development](#development) ·
[Release](#release) · [License](#license)

## Features

- **Point groups**: C1, Cs, Ci, and Cn, Cnv, Cnh, Dn, Dnh, Dnd and Sn for any n, by name
  (`PointGroup('D5h')`) or by family (`PointGroup('Dnh', n=5)`); the cubic and icosahedral
  groups T, Td, Th, O, Oh, I and Ih; the linear groups C∞v and D∞h.
- **Character tables** with classes, characters and Mulliken symbols, including irrational
  characters (2cos72° in D5h) and the complex pairs of Cn, Cnh, Sn, T and Th.
- **Algebra of irreps**: direct products `x * y`, direct sums `x + y`, powers `x ** n`, also
  with lists of irreps, so that expressions like `b2u * e2g * dipole` can be written as such.
- **Reduction** of a representation, given by its characters, into irreps.
- **Lowering of symmetry**: the irreps of a subgroup that an irrep correlates with,
  correlation tables, and all the ways a subgroup can be oriented in a group.
- **Symmetry operations** as objects: every operation of a group, sorted into classes, as
  a 3×3 matrix that can be applied to coordinates, composed and printed (`C6^5(z)`, `σ(xz)`).
- No dependencies, Python 3.9 or newer.

## Installation

```bash
pip install pymolsym
```

## Quick start

A point group is made from its name. Its irreps are its attributes, named by their Mulliken
symbols in lowercase:

```python
>>> from pymolsym import PointGroup
>>> d6h = PointGroup('D6h')

>>> # direct product of two irreps
>>> print(d6h.b2g * d6h.b1u)
a2u

>>> # a product of degenerate irreps is a list of irreps
>>> print(*(d6h.e1g * d6h.e2u))
b1u b2u e1u

>>> # the six p_z orbitals of benzene
>>> print(*d6h.reduce((6, 0, 0, 0, -2, 0, 0, 0, 0, -6, 2, 0)))
b2g e1g a2u e2u

```

The characters passed to `reduce` are in the order of the classes of the group (here with the
carbon atoms on the C2′ axes):

```python
>>> print(*d6h.classes)
E 2C6 2C3 C2 3C2′ 3C2″ i 2S6 2S3 σh 3σv 3σd

```

This order, the orientation of the axes and the Mulliken symbols follow fixed rules, see
[Conventions](#conventions). They differ between textbooks, so check them before you copy
characters from a table. For the theory of point groups and their representations, see for
example Hollas [[1]](#literature).

## Examples

### Character table

```python
>>> c3v = PointGroup('C3v')
>>> print(*c3v.classes)
E 2C3 3σv

>>> for symbol, irrep in c3v.elements.items():
...     print(symbol, *irrep.irrep)
a1 1 1 1
a2 1 1 -1
e 2 -1 0

```

### Products and selection rules

An electric dipole transition between two states can only have a non-zero transition moment
if the direct product of the irreps of the two states and of a component of the dipole moment
contains the totally symmetric irrep, `PointGroup.ts`.

The electronic ground state of benzene is ¹A1g, its lowest excited singlet state ¹B2u. The
electronic transition between them (the band near 260 nm) is forbidden by symmetry for all
three components of the dipole moment. It becomes allowed vibronically: with one quantum of a
vibration of symmetry e2g excited in the upper state, the vibronic state is B2u × e2g = E1u,
which the (x, y) component of the dipole moment connects to the vibrationless ground state.

```python
>>> # electronic states
>>> ground, excited = d6h.a1g, d6h.b2u

>>> # the components of the dipole moment: z and (x, y)
>>> dipole = [d6h.a2u, d6h.e1u]
>>> d6h.ts in ground * excited * dipole
False

>>> # vibronic state with one quantum of an e2g vibration
>>> print(excited * d6h.e2g)
e1u

>>> d6h.ts in ground * (excited * d6h.e2g) * dipole
True

>>> # for z and for (x, y) separately
>>> [d6h.ts in ground * (excited * d6h.e2g) * component for component in dipole]
[False, True]

```

Sums, powers and longer expressions:

```python
>>> print(*(d6h.e1g ** 2))
a1g a2g e2g

>>> print(*(d6h.e2u + d6h.e1g * d6h.e2u * d6h.e2u + d6h.a1g))
a1g b1g b2g e1g e1g e1g e2u

```

### Reducing a representation

The three B–F σ bonds of BF3 (D3h) are unchanged by E, by one C2′, by σh and by one σv:

```python
>>> d3h = PointGroup('D3h')
>>> print(*d3h.classes)
E 2C3 3C2′ 2S3 σh 3σv

>>> print(*d3h.reduce((3, 0, 1, 0, 3, 1)))
a1p ep

```

`a1p` is A1′ and `ep` is E′, see [Mulliken symbols](#mulliken-symbols).

The nine Cartesian displacements of water (C2v, molecule in the yz plane):

```python
>>> c2v = PointGroup('C2v')
>>> print(*c2v.classes)
E C2 σv σd

>>> print(*c2v.reduce((9, -1, 1, 3)))
a1 a1 a1 a2 b1 b1 b2 b2 b2

```

### Lowering the symmetry

`x.lower(H)` gives the irreps of the subgroup H that the irrep x splits into, and
`G.correlation(H)` does so for all irreps of G:

```python
>>> oh = PointGroup('Oh')
>>> print(*oh.t2g.lower(PointGroup('D4h')))
b2g eg

>>> for irrep, lowered in oh.correlation(PointGroup('Td')).items():
...     print(irrep, '->', *lowered)
a1g -> a1
a2g -> a2
eg -> e
t1g -> t1
t2g -> t2
a1u -> a2
a2u -> a1
eu -> e
t1u -> t2
t2u -> t1

```

By default both groups are in their standard orientation (see [Axes](#axes)). Other
orientations are given by the directions in G that the z and x axes of H point to,
`orientation=(z_to, x_to)`. This is needed where the standard orientation is no subgroup, or
a different one: for D3d in Oh, whose C3 axis is a body diagonal, or for the C2v whose σv
planes are σd planes of D6h:

```python
>>> d3d = PointGroup('D3d')
>>> d3d.is_subgroup_of(oh)
False

>>> print(*oh.t2g.lower(d3d, orientation=((1, 1, 1), (1, 0, -1))))
a1g eg

>>> print(*d6h.b1u.lower(c2v))
b1

>>> print(*d6h.b1u.lower(c2v, orientation=((0, 0, 1), (0, 1, 0))))
b2

```

`G.orientations(H)` finds the orientations: one for each different correlation table, the
standard orientation first if H fits in it. C2v, for example, fits in Oh with its C2 along a
C4 axis and σ(xz) in a σh or a σd plane, or with its C2 along a C2′ axis and σ(xz) in a σh
or a σd plane:

```python
>>> oh.orientations(d3d)
[((1, 1, 1), (1, 0, -1))]

>>> for orientation in oh.orientations(c2v):
...     print(*orientation, ':', *oh.eg.lower(c2v, orientation))
(0, 0, 1) (1, 0, 0) : a1 a1
(0, 0, 1) (1, 1, 0) : a1 a2
(1, 0, 1) (0, 1, 0) : a1 b2
(1, 0, 1) (1, 0, -1) : a1 b1

```

Irreps of different point groups can be combined directly if one group is a subgroup of the
other in standard orientation. They are lowered to the subgroup first:

```python
>>> print(*(d6h.e1u * c2v.a2))
b1 b2

```

### Linear molecules

C∞v and D∞h have an irrep for every k = 1, 2, 3, …: Π, Δ, Φ and so on. They are named `e1`,
`e2`, `e3`, …, and Σ+ and Σ− are `a1` and `a2`, see [Linear groups](#linear-groups). The
Greek symbols are understood as well:

```python
>>> # the same as PointGroup('Dinfh')
>>> dinfh = PointGroup('D∞h')

>>> # the same irrep as dinfh.pi_u and dinfh.e1u
>>> pi_u = dinfh('Πu')
>>> print(pi_u, pi_u.greek, pi_u.irrep)
e1u Πu (2, '2cos(φ)', 0, -2, '2cos(φ)', 0)

>>> print(*(dinfh('Πg') * pi_u))
a1u a2u e2u

```

Two electrons in a πg orbital, as in the ground state configuration of O2, give states
with these spatial symmetries:

```python
>>> print(*(irrep.greek for irrep in dinfh.pi_g ** 2))
Σg+ Σg− Δg

```

When a linear AB2 molecule is bent, its symmetry is lowered to C2v, whose C2 axis is
perpendicular to the axis of the linear molecule. With the bent molecule in the yz plane of
C2v, that axis becomes y:

```python
>>> # z and x of C2v in the frame of D∞h, whose axis is z
>>> bent = ((1, 0, 0), (0, 1, 0))
>>> for symbol in ('Σg+', 'Σu+', 'Πg', 'Πu'):
...     print(symbol, '->', *dinfh(symbol).lower(c2v, bent))
Σg+ -> a1
Σu+ -> b2
Πg -> a2 b2
Πu -> a1 b1

```

### Symmetry operations

```python
>>> print(*d6h.generators)
C6(z) C2(x) σ(xy)

>>> # the operations of the class 2S6
>>> print(*d6h.classes[7])
S6(z) S6^5(z)

>>> from pymolsym import SymmetryOperation
>>> c4 = SymmetryOperation.rotation((0, 0, 1), 4)

>>> # applied to a point
>>> c4((1, 0, 0))
(0.0, 1.0, 0.0)

>>> print(SymmetryOperation.reflection((0, 0, 1)) * c4)
S4(z)

```

### Named classes

The most common point groups have a class of their own as a shorthand, like `D2h` or `Td`
(see [the list](#named-classes-1)). Called with a Mulliken symbol, it gives the irrep directly:

```python
>>> from pymolsym import D2h
>>> D2h() == PointGroup('D2h')
True

>>> print(D2h('b2g') * D2h('b1u'))
b3u

>>> print(repr(D2h('b1g')))
IrreducibleRepresentation(pg=D2h(), irrep=(1, 1, -1, -1, 1, 1, -1, -1))

>>> from pymolsym import Td
>>> print(*Td().elements)
a1 a2 e t1 t2

```

## Conventions

### Axes

z is the principal axis. C2′ axes and σv planes contain the x axis; the other C2 axes
perpendicular to z are C2″, the other planes containing z are σd. Cubic groups have their
C2, C4 or S4 axes along x, y and z and a C3 axis along (1, 1, 1); icosahedral groups have C2
axes along x, y and z, C3 along (1, 1, 1) and C5 along (0, 1, φ), φ = (1 + √5)/2.

The groups are generated by C_n(z), plus σ(xz) for Cnv, σh for Cnh, C2(x) for Dn, C2(x) and
σh for Dnh; S_2n(z) and C2(x) for Dnd; C2(z) and C3(1, 1, 1) for T, S4(z) and C3 for Td,
C4(z) and C3 for O, C2(z), C3 and C5(0, 1, φ) for I, and i in addition for Th, Oh and Ih.

### Columns

There is one column per class of symmetry operations, as given by
`[str(c) for c in pg.classes]`. They follow one rule: proper before improper operations;
within each, E (or i) first, then the operations about z by their rotation angle (C6, C3,
C2, C3², C6⁵; S6, S3, S3⁵ = σh C3², S6⁵, and σh = S1, a full turn, last), then those
perpendicular to z, along x first. Examples:

| Group | Classes                                                |
| ----- | ------------------------------------------------------ |
| C1    | E                                                      |
| C2v   | E, C2, σv, σd                                          |
| D3    | E, 2C3, 3C2′                                           |
| D2h   | E, C2, C2′, C2″, i, σh, σv, σd                         |
| D6h   | E, 2C6, 2C3, C2, 3C2′, 3C2″, i, 2S6, 2S3, σh, 3σv, 3σd |
| D3h   | E, 2C3, 3C2′, 2S3, σh, 3σv                             |
| D5h   | E, 2C5, 2C5², 5C2′, 2S5, 2S5³, σh, 5σv                 |
| D4d   | E, 2C4, C2, 4C2′, 2S8, 2S8³, 4σd                       |
| C6h   | E, C6, C3, C2, C3², C6⁵, i, S6, S3, S3⁵, S6⁵, σh       |
| C5h   | E, C5, C5², C5³, C5⁴, S5, S5⁷, S5³, S5⁹, σh            |

In C2v and D2h, where every class is a single operation, C2 is C2(z), C2′ is C2(x), C2″ is
C2(y), σh is σ(xy), σv is σ(xz) and σd is σ(yz).

Cubic and icosahedral groups have no principal axis and follow their own rule: proper
before improper operations; within each, E (or i) first, then by decreasing n and increasing
power k of C_n^k and S_n^k (σ = S1), operations about x, y, z first. C2 and σh are about or
perpendicular to x, y and z, C2′ and σd the others:

| Group | Classes                                                  |
| ----- | -------------------------------------------------------- |
| Td    | E, 8C3, 3C2, 6S4, 6σd                                    |
| Oh    | E, 6C4, 8C3, 3C2, 6C2′, i, 8S6, 6S4, 3σh, 6σd            |
| Ih    | E, 12C5, 12C5², 20C3, 15C2, i, 12S10, 12S10³, 20S6, 15σh |

Other references order the columns differently: Katzer [[2]](#literature) for example has D3h
as E, 2C3, 3C2′, σh, 2S3, 3σv and D4d as E, 2S8, 2C4, 2S8³, C2, 4C2′, 4σd, others D6h as … i,
2S3, 2S6, σh, 3σd, 3σv. Characters taken from such a table must be reordered before they are
passed to `PointGroup.reduce()` or `IrreducibleRepresentation()`.

The representative of a class is its operation of lowest power (C5² rather than C5³, S5³
rather than S5⁷), preferring axes and planes along x and y (C2(x) for 3C2′, C2(y) for 3C2″).
It is the first operation of its class.

### Characters

Characters are tuples, one number per column: ints where they are integers, else floats or
complex numbers rounded to 12 digits (e.g. 2cos72° = 0.61803398875 in C5v, exp(2πi/3) =
(-0.5+0.866025403784j) in C3). `reduce` handles such numbers up to a rounding error, using
the complex conjugate of the irreps' characters. Products of irreps and `lower` do not use
the rounded numbers, see [How it works](#how-it-works).

### Mulliken symbols

Irreps are named by lowercase Mulliken symbols (`a1g`, `e2u`, …). The symbols follow
Mulliken's rules [[3]](#literature), decided by the characters under these operations:

- A, B: symmetric or antisymmetric under the principal rotation C_n(z); in groups with
  S_2n(z) but not i (S4, D2d, D4d, …) under S_2n. E is two-dimensional.
- D2, D2h: B1, B2, B3 are symmetric under C2(z), C2(y), C2(x).
- Subscripts 1, 2 of A and B: symmetric or antisymmetric under C2(x) (C2′), or if there is
  none, under σ(xz) (σv). E_k, if there are several E: the principal rotation (C_n or
  S_2n) of order m acts on it as a rotation by 2πk/m.
- Separably degenerate E (in Cn, Cnh, Sn): a pair of complex conjugate one-dimensional
  irreps, named by the E symbol with `a` or `b` appended. The principal rotation multiplies
  the `a` irrep by exp(+2πik/m), the `b` irrep by exp(−2πik/m): `ea`, `eb` in C3, `e1a`,
  `e1b`, `e2a`, `e2b` in C5, `ega`, `egb` in S6, `eppa`, `eppb` in C3h. They are
  one-dimensional (`dimension == 1`), and `ea * ea` is `eb` in C3.
- g, u: symmetric or antisymmetric under i; without i, ′ and ″ under σh. Primes are
  spelled `p` and `pp` (`a1p` for A1′, `a1pp` for A1″), so that every symbol works as an
  attribute name (`d3h.a1pp`). Lookup by call also accepts primes: `d3h("a1''")`,
  `d3h('A1″')` and `d3h('a1pp')` are the same irrep.

In the cubic and icosahedral groups, the letters are A, E, T, G and H for dimensions 1
to 5 (E also for the complex pair `ea`, `eb` of T and Th). If there are two irreps of the
same letter and g/u, subscript 1 goes to the one with the larger character under the
principal operation P, the proper rotation of highest order (C3, C4 or C5), or S4 in Td:
T1 and T2 in O have χ(C4) = 1 and −1. This gives eg. `t1u` for x, y, z in Oh and `t2` in Td;
in Ih the four- and five-dimensional irreps are `gg`, `gu`, `hg` and `hu`.

The canonical order of the irreps is the row order of the character table: g before u
(′ before ″), then A, B, E, T, G, H, then by subscript, then `a` before `b`. It starts with
the totally symmetric irrep. Every list returned by pymolsym is sorted in this order.

### Linear groups

The axis of C∞v and D∞h is z. Their classes are E, 2C(φ), ∞σv, and E, 2C(φ), ∞C2′, i, 2S(φ),
∞σv, where C(φ) and S(φ) stand for the rotations and improper rotations by any angle φ
about z, and C2′ for the C2 axes perpendicular to z.

The irreps are named like those of the finite groups, so that the symbols are attribute
names: `a1` is Σ+, `a2` is Σ−, symmetric and antisymmetric under σv, and `e1`, `e2`, `e3`, …
are Π, Δ, Φ, …; a rotation by φ about z has the character 2cos(kφ) in `e`k. In D∞h, `g` or `u` follows: `a1g` is Σg+, `e1u`
is Πu. Lookup also accepts the Greek letters Σ, Π, Δ, Φ and Γ or their names: `'Σg+'`,
`'Σ+g'`, `'sigma_g_plus'`, `'Πu'`, `'pi_u'`. `x.greek` gives the Greek symbol of an irrep.
Their canonical order is g before u, then Σ+, Σ−, Π, Δ, ….

### Symmetry operations

- C_n^k is a rotation by 2πk/n following the right-hand rule (counterclockwise when looking
  down the axis towards the origin).
- S_n^k = σ^k C_n^k, with σ the reflection in the plane perpendicular to the axis; S1 = σ
  and S2 = i. Improper rotations are written with odd powers: `S3^5`, not `S3^2`, which is
  `C3^2`.
- A product `a * b` applies `b` first: `(a * b)(v) == a(b(v))`.
- Axes point in the direction whose first non-zero component is positive, so a rotation
  by 60° about −z is `C6^5(z)`.

## How it works

**Derivation.** A point group is defined by its generators only (`_GENERATORS` in
`pointgroup.py`). They generate the multiplication table of the group. Its classes are
labelled and ordered by the rules above, the characters are derived with Dixon's method
[[4]](#literature) (`character_table.py`), and the Mulliken symbols are read from the characters.
The linear groups are infinite and have their irreps, characters and products in closed
form instead (`linear.py`).

**Exactness.** No floating point number decides whether two things are equal.

- The groups are generated from operations in exact arithmetic (`exact.py`). An operation of
  a group with a principal axis is a rotation about z by a rational fraction of a turn,
  optionally combined with the reflections y → −y and z → −z: its angle is stored, not its
  cosine. An operation of a cubic or icosahedral group is a matrix with entries a + b√5,
  a and b rational. Each group is its multiplication table of integers.
- Dixon's method works in modular arithmetic. The characters are kept as the multiplicities
  of the eigenvalues exp(2πik/o) of each operation (of order o) in each irrep, which are
  integers. Mulliken symbols, products of irreps and `lower` are computed from them.
- Floats are used to show operations and characters, and where they are given: the matrix
  or axis of a `SymmetryOperation`, an orientation, and the characters passed to `reduce`.

## Literature

1. J.M. Hollas, "Symmetry in Molecules," Chapman&Hall, London (1972)
2. G. Katzer, "Character Tables for Point Groups used in Chemistry,"
   <http://www.gernot-katzers-spice-pages.com/character_tables/>
3. R.S. Mulliken, "Report on Notation for the Spectra of Polyatomic Molecules,"
   J. Chem. Phys. 23, 1997 (1955)
4. J.D. Dixon, "High speed computation of group characters," Numer. Math. 10, 446 (1967)

## Reference

`from pymolsym import *` gives `PointGroup`, `IrreducibleRepresentation`, `ConjugacyClass`,
`SymmetryOperation` and the [named classes](#named-classes-1) except `T`, `O` and `I`. Their
objects are hashable and can be copied and pickled. The docstrings give parameters, errors and examples
(`help(PointGroup.reduce)`).

### PointGroup

`PointGroup(pg, n=None)`: `pg` is a name like `'D6h'` or a family name like `'Dnh'` with
`n`; names are case-insensitive. Raises `ValueError` for groups that are not implemented, for
names like `C1v` or `S3` that are not groups of their own (the message names the group to
use), and for more than 1000 operations; `TypeError` if `n` is missing or not an integer.

| Member                                       | Meaning                                                                                                                                                                                              |
| -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `pg.a1g`, `pg('a1g')`, `pg.irrep('a1g')`     | The irrep with this Mulliken symbol, case-insensitive. `AttributeError` if there is none (`KeyError` from `irrep`).                                                                                  |
| `pg.elements`                                | Read-only mapping from symbol to irrep, in canonical order: the character table.                                                                                                                     |
| `pg.ts`                                      | The totally symmetric irrep.                                                                                                                                                                         |
| `pg.symbol(irrep)`                           | The Mulliken symbol of an irrep.                                                                                                                                                                     |
| `pg.classes`                                 | The classes as `ConjugacyClass` objects, in column order.                                                                                                                                            |
| `pg.symop_multiplicity`                      | The number of operations in each class.                                                                                                                                                              |
| `pg.order`                                   | The number of operations.                                                                                                                                                                            |
| `pg.operations`                              | All operations as `SymmetryOperation` objects, ordered by class.                                                                                                                                     |
| `pg.generators`                              | The operations that generate the group.                                                                                                                                                              |
| `pg.reduce(characters)`                      | The irreps contained in a representation, as a sorted list with multiplicities. `ValueError` for a wrong number of characters, `ArithmeticError` if they are not the characters of a representation. |
| `pg.is_subgroup_of(group, orientation=None)` | Whether `pg` is a subgroup of `group`.                                                                                                                                                               |
| `pg.correlation(subgroup, orientation=None)` | Dict from each irrep to the list of irreps of the subgroup it is lowered to.                                                                                                                         |
| `pg.orientations(subgroup)`                  | List of orientations `(z_to, x_to)` of the subgroup, one per different correlation table; empty if it is no subgroup.                                                                                |
| `str(pg)`, `repr(pg)`                        | `'D6h'` and `'PointGroup(pg="dnh", n=6)'`.                                                                                                                                                           |
| `pg == other`, `hash(pg)`                    | Point groups are equal if they are the same group.                                                                                                                                                   |

An `orientation` is a pair of vectors `(z_to, x_to)`: the directions in the frame of the
group that the z and x axes of the subgroup point to. They must be perpendicular and need
not be normalized. Without it, both groups are in their standard orientation.

`PointGroup('C∞v')` and `PointGroup('D∞h')` (or `'Cinfv'`, `'Dinfh'`) are linear point groups.
They have infinitely many operations and irreps, which changes these members:

| Member                                             | Meaning for C∞v and D∞h                                                                               |
| -------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| `pg.e7u`, `pg('Πu')`, `pg.irrep('pi_u')`           | Any irrep, by its Mulliken or Greek symbol, see [Linear groups](#linear-groups).                      |
| `pg.irreps(kmax=3)`                                | List of the irreps up to `e`kmax, in canonical order.                                                 |
| `pg.elements`                                      | The irreps up to Φ (k = 3) only.                                                                      |
| `pg.classes`                                       | The labels of the classes, as strings.                                                                |
| `pg.order`, `pg.symop_multiplicity`                | Infinity, and `(1, 2, inf)` or `(1, 2, inf, 1, 2, inf)`.                                              |
| `pg.correlation(subgroup, orientation=None, kmax=3)` | For the irreps up to `e`kmax.                                                                       |
| `pg.orientations(subgroup)`                        | The z axis of the subgroup along the axis, or perpendicular to it with its x or y axis along the axis. |
| `pg.operations`, `pg.generators`                   | Not available: `ValueError`.                                                                          |
| `pg.reduce(characters)`                            | Not available: `NotImplementedError`, see [Outlook](#outlook).                  |

Their irreps have the additional members `x.k` (0 for Σ, 1 for Π, …), `x.sign` (1 or −1 for
Σ+ and Σ−, else 0), `x.parity` (1 for g, −1 for u, 0 in C∞v) and `x.greek`. Their characters `x.irrep` contain
text like `'2cos(2φ)'` for the classes 2C(φ) and 2S(φ).

### IrreducibleRepresentation

Irreps are taken from a point group (`d6h.e1g`). `IrreducibleRepresentation(pg, characters)`
makes one from its characters, in column order.

| Member                                | Meaning                                                                                                                       |
| ------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `x.pg`                                | Its point group.                                                                                                              |
| `x.irrep`                             | Its characters, a tuple with one number per class.                                                                            |
| `x.dimension`                         | Its character under E.                                                                                                        |
| `x.degenerate`                        | True if the dimension is above one.                                                                                           |
| `x * y`                               | Direct product: a single irrep if at least one factor is one-dimensional, else a sorted list of irreps with multiplicities.   |
| `x + y`                               | Direct sum, always a sorted list.                                                                                             |
| `x * [...]`, `[...] * x`              | The products of `x` with every irrep of the list, as one sorted list.                                                         |
| `x + [...]`, `[...] + x`              | The list with `x` added, sorted.                                                                                              |
| `x ** n`                              | n-fold direct product; `x ** 0` is the totally symmetric irrep. `ValueError` for negative n.                                  |
| `x.lower(subgroup, orientation=None)` | The irreps of the subgroup that `x` correlates with, as a sorted list. `ValueError` if it is no subgroup in this orientation. |
| `str(x)`, `repr(x)`                   | Its Mulliken symbol, and an expression that recreates it.                                                                     |
| `x == y`, `x < y`, `sorted([...])`    | Equal if group and characters are equal; ordered by the canonical order of their group.                                       |
| `len(x)`, `iter(x)`, `y in x`         | An irrep behaves like a list of itself, so the result of a product can be iterated over whether it is one irrep or several.   |

Irreps of different point groups are lowered to the group that is a subgroup of the others
in standard orientation, and combined there: `d6h.e1u * c2v.a2` is `[b1, b2]` of C2v, the
C2v whose σv contains x, which is a σv plane of D6h. If there is no such group, combining
them raises `ValueError`; use `lower()` with an orientation instead.

### ConjugacyClass

A class of conjugate symmetry operations, one column of the character table.

| Member                         | Meaning                                                        |
| ------------------------------ | -------------------------------------------------------------- |
| `c.label`                      | Its label without the number of operations, eg. `'C2′'`.       |
| `str(c)`                       | Its label as in the header of a character table, eg. `'3C2′'`. |
| `c.operations`                 | Its operations as a tuple of `SymmetryOperation`.              |
| `c.representative`             | Its first operation, see [Columns](#columns).                  |
| `len(c)`, `iter(c)`, `op in c` | Number of, iteration over and membership of its operations.    |

### SymmetryOperation

An orthogonal 3×3 matrix acting on Cartesian coordinates.

| Member                                              | Meaning                                                                                                                                                                                                       |
| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `SymmetryOperation(matrix)`                         | From a 3×3 matrix. `ValueError` if it is not orthogonal.                                                                                                                                                      |
| `SymmetryOperation.identity()`, `.inversion()`      | E and i.                                                                                                                                                                                                      |
| `SymmetryOperation.rotation(axis, n, k=1)`          | C_n^k about `axis`, a vector of any length.                                                                                                                                                                   |
| `SymmetryOperation.improper_rotation(axis, n, k=1)` | S_n^k about `axis`.                                                                                                                                                                                           |
| `SymmetryOperation.reflection(normal)`              | σ in the plane perpendicular to `normal`.                                                                                                                                                                     |
| `op(vector)`                                        | The image of a point, as a tuple.                                                                                                                                                                             |
| `a * b`, `op ** k`, `op.inverse()`                  | Composition (`b` is applied first), powers (also negative) and the inverse.                                                                                                                                   |
| `op.matrix`                                         | The matrix as a tuple of rows.                                                                                                                                                                                |
| `op.determinant`, `op.is_proper`                    | 1 and True for rotations, −1 and False for reflections, i and S_n.                                                                                                                                            |
| `op.trace`                                          | The trace of the matrix, the character of (x, y, z).                                                                                                                                                          |
| `op.order`                                          | The smallest m > 0 with `op ** m == E`.                                                                                                                                                                       |
| `op.describe()`                                     | Named tuple `(kind, axis, n, k)`: kind is `'E'`, `'i'`, `'C'`, `'σ'` or `'S'`, axis the rotation axis or plane normal as a unit vector. `ValueError` for a rotation that is not of finite order (up to 1000). |
| `str(op)`, `repr(op)`                               | The Schoenflies symbol with its axis, eg. `C6^5(z)`, `S3^5(z)`, `σ(xz)`, and an expression that recreates it.                                                                                                 |
| `a == b`, `hash(op)`                                | Operations are equal if their matrix entries round to the same points of a grid of 1e-8.                                                                                                                      |

Equality on a grid absorbs rounding errors (`C6**6 == E`) and allows operations to be
collected in sets. Only an entry on a boundary of the grid (about one in 10^7) can make two
matrices of one operation differ. The point groups do not depend on this: a
`SymmetryOperation` is how their exact operations are shown, and applied to coordinates.

### Named classes

`D2h()` is `PointGroup('D2h')`, and `D2h('b1g')` is its irrep `b1g`. There is a class for
each of these point groups (`pymolsym/named_groups.py`):

| Groups                  | Classes                                |
| ----------------------- | -------------------------------------- |
| Without axis            | `C1`, `Cs`, `Ci`                       |
| Cn                      | `C2`, `C3`, `C4`, `C5`, `C6`           |
| Cnv                     | `C2v`, `C3v`, `C4v`, `C5v`, `C6v`      |
| Cnh                     | `C2h`, `C3h`, `C4h`, `C5h`, `C6h`      |
| Dn                      | `D2`, `D3`, `D4`, `D5`, `D6`           |
| Dnh                     | `D2h`, `D3h`, `D4h`, `D5h`, `D6h`      |
| Dnd                     | `D2d`, `D3d`, `D4d`, `D5d`, `D6d`      |
| Sn                      | `S4`, `S6`, `S8`                       |
| Cubic and icosahedral   | `T`, `Td`, `Th`, `O`, `Oh`, `I`, `Ih`  |
| Linear (C∞v, D∞h)       | `Cinfv`, `Dinfh`                       |

`from pymolsym import *` does not give `T`, `O` and `I`, whose names are too short to be
imported unasked: use `from pymolsym import T, O, I`. All other point groups are made with
`PointGroup`.

## Limitations

- Double groups are not supported.
- The linear groups C∞v and D∞h have no list of operations, and `reduce` is not available
  for them, see [Outlook](#outlook).
- pymolsym does not find the point group of a molecule from its coordinates.
- Point groups can have up to 1000 symmetry operations (n ≤ 250 for Dnh and Dnd). Large
  ones take long to derive: D24h (96 operations) about 0.2 seconds, D48h (192 operations)
  about one second and C128 about twelve; groups with n ≤ 12 less than 0.1 seconds. A group
  is derived once per Python session.
- `reduce` accepts characters that give whole multiplicities to within 1e-6. The vectors of
  an orientation must be accurate to about nine digits.

## Outlook

### What the linear groups lack, and why

Some members of C∞v and D∞h are missing or reduced because the groups are infinite, one
because it is not written yet:

| Member                              | Reason                                                                                                                                                             | Can it be improved?                          |
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------- |
| `operations`, `generators`, `order` | Mathematical: there is an operation for every angle φ, so they cannot be listed, and no finite set of operations generates the group.                              | No.                                          |
| `elements` up to Φ only             | Mathematical: there is an irrep for every k, so they cannot all be listed. The limit of k = 3 is a choice, and every irrep can be looked up by its symbol.         | Only the limit.                              |
| `classes` as labels, characters as text | Mathematical in part: there is a class for every φ, so no tuple holds the character table. That `'2cos(2φ)'` is text and cannot be evaluated is a shortcut.    | Yes: characters as functions of φ.           |
| `reduce`                            | Not implemented. The multiplicities are well defined: the sum over the classes in the reduction formula becomes an integral over φ.                                | Yes, see below.                              |

### Reducing representations of the linear groups

A tuple of numbers cannot describe the character of a representation of C∞v or D∞h, because
the characters of the classes 2C(φ) and 2S(φ) depend on φ. `reduce` would have to take them
as functions of φ, in one of two forms:

- **Cosine coefficients.** The character of a finite-dimensional representation is always
  c0 + c1·2cos(φ) + c2·2cos(2φ) + … with whole numbers ck. Given these, the reduction is
  arithmetic with integers and exact: ck is the number of times `e`k is contained, and c0 is
  divided between Σ+ and Σ− by the character of σv. In D∞h the characters of i and 2S(φ)
  divide each of them between g and u in the same way.
- **A Python function of φ**, eg. `lambda phi: 3 * (1 + 2 * cos(phi))` for the displacements
  of three atoms on the axis. It would be evaluated at a number of angles to find the
  coefficients, and the result checked at further angles, in floats.

Lowering the irreps to a finite subgroup does not replace this. It gives the irreps of the
subgroup, and a small subgroup cannot tell the irreps of the linear group apart: in D2h, Δg
and Σg+ + Σg− both become ag + b1g.

## Development

```bash
pip install -e '.[test]'
pytest

# with line and branch coverage report
pytest --cov
```

`pytest` also runs the examples in this README and in the docstrings as doctests.

| File                             | Contents                                                                                                                   |
| -------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| `pymolsym/pointgroup.py`         | `PointGroup`, `IrreducibleRepresentation`, `ConjugacyClass`; generators of the groups, classes and their labels, subgroups |
| `pymolsym/character_table.py`    | Dixon's method and the Mulliken symbols                                                                                    |
| `pymolsym/named_groups.py`       | The named classes                                                                                                          |
| `pymolsym/linear.py`             | The linear point groups C∞v and D∞h                                                                                        |
| `pymolsym/exact.py`              | Symmetry operations in exact arithmetic                                                                                    |
| `pymolsym/symmetry_operation.py` | `SymmetryOperation`                                                                                                        |

A new point group needs an entry in `_GENERATORS`; a new family with variable n also one in
`_FAMILY_MIN_N` and `_FAMILY_ORDER`.

The conventions are checked by `tests/test_character_tables.py`, which compares the derived
tables with Katzer's [[2]](#literature), derives characters of x, y, z, rotations and the
benzene σ and π orbitals from 3×3 matrices of the symmetry operations and reduces them.
`tests/test_derivation.py` checks the derivation directly from generators, from Ci to Ih,
`tests/test_cubic.py` the irreps of x, y, z, rotations and d orbitals in the cubic groups,
`tests/test_families.py` the families for a range of n, `tests/test_lowering.py` subgroups
and orientations, `tests/test_exact.py` the exact operations against their matrices, and
`tests/test_linear.py` the lowering of the linear groups against characters computed from
matrices. `tests/test_web_demo.py` checks the Python side of the home page.

The home page, `web/index.html`, runs the package in the browser and loads it from the
repository. To view it from a clone, serve the repository with `python -m http.server` and
open <http://localhost:8000/web/>. The workflow `.github/workflows/pages.yml` publishes it
with GitHub Pages on every push to `master`.

## Release

A release is made by setting the version in `pyproject.toml` and publishing a release on
GitHub whose tag is that version with a `v` in front, eg. `v1.0`. The workflow
`.github/workflows/publish.yml` then builds the package, runs the tests and uploads it to PyPI.

## License

MIT, see [LICENSE](https://github.com/ohueter/pymolsym/blob/master/LICENSE).
