Metadata-Version: 2.4
Name: cathedralpkg-cantor
Version: 2026.0
Summary: Automatic generation of search-ready Z-matrices with one proper torsion per rotatable axis
Author-email: David Ferro-Costas <david.ferro@usc.es>
License-Expression: MIT
Project-URL: Homepage, https://github.com/cathedralpkg/cantor
Keywords: Z-matrix,internal coordinates,torsions,rotatable bonds,conformational search,computational chemistry
Classifier: Programming Language :: Python :: 3
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Chemistry
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: numpy
Requires-Dist: networkx
Provides-Extra: smiles
Requires-Dist: rdkit; extra == "smiles"
Provides-Extra: all
Requires-Dist: rdkit; extra == "all"
Requires-Dist: ase; extra == "all"

# CANTOR

**CA**rtesian-to-**N**on-redundant **TOR**sional coordinates

```text
+---------------------------------+
|   ____          _____           |
|  / ___|__ _ _ _|_   _|__  _ __  |
| | |   / _` | '_ \| |/ _ \| '__| |
| | |__| (_| | | | | | (_) | |    |
|  \____\__,_|_| |_|_|\___/|_|    |
|                                 |
+---------------------------------+
```

CANTOR is a Python program for the **automatic generation of search-ready
Z-matrices** from Cartesian coordinates or SMILES strings.

Torsion-driven conformational searches explore molecular flexibility by
assigning values to a predefined set of dihedral coordinates. This requires
every internal rotation to be described exactly once, by a coordinate that
moves the corresponding fragment as a whole. A conventional Z-matrix
guarantees neither condition: in the Z-matrix of ethanol written by most
programs, the three methyl hydrogens are placed by three H–C–C–O dihedrals
on the same C–C axis, and changing one of them moves a single hydrogen
instead of rotating the methyl group.

A Z-matrix written by CANTOR is **search-ready**:

- it is **valid**: every row is well defined, with no linear bond angle and
  no collinear reference atoms (dummy atoms are added where needed);
- it is **non-redundant**: it contains exactly one proper torsion for each
  rotatable axis;
- each of these torsions drives a **rigid rotation** of one side of its axis
  with respect to the other.

The three properties are checked explicitly, and the same checks can be
applied to Z-matrices written by other programs. The torsions to be sampled
are labeled in the Z-matrix, which can be passed directly to the
conformational search of TorsiFlex, also part of the **Cathedral** package.

## How it works

**Molecular graph.** Two atoms are bonded when their distance, relative to
the sum of their covalent radii, falls below `RHO_CONN`; a bond is regarded as
multiple when this ratio falls below `RHO_MBOND`. Fragments that are not
bonded to each other (complexes, salts) are joined by artificial edges.

**Rods and rotatable axes.** Bonds that meet at a (near-)linear angle form a
*rod*, a straight chain of bonds such as the C–C≡C–C unit of 2-butyne; most
rods are a single bond. A rod is a *rotatable axis* when (i) it contains at
least one single bond, (ii) none of its bonds lies on a ring, and (iii) both
of its terminal atoms have a neighbor outside the rod. Hydrogen atoms count
as neighbors, so the rotations of methyl and hydroxyl groups are included:
ethanol has two rotatable axes, C–C and C–O.

**Construction.** The molecular graph is decomposed into ring systems,
chains, and terminal hydrogen atoms, and the Z-matrix is built along this
decomposition. Only the first atom placed on each side of an axis is given a
torsion about it; the other atoms on that side are placed from it (the
*sibling rule*), so that changing that torsion rotates the whole side.
Dummy atoms are inserted at linear fragments, where a bond angle would be
180° or a dihedral would be undefined.

**Classification.** Every dihedral is classified, and its class is the
prefix of its variable name:

| Prefix | Class |
|---|---|
| `ptor` | proper torsion of a rotatable axis (the coordinates to be sampled) |
| `rtor` | proper torsion of an axis with a cyclic bond |
| `etor` | proper torsion excluded because its axis is a multiple bond, an all-multiple rod (allene), or an artificial edge between fragments |
| `itor` | improper torsion, including every dihedral that involves a dummy atom |

## Requirements

- Python ≥ 3.8
- `numpy`
- `networkx`

Optional:

- `rdkit`, required for SMILES input;
- `ase` or `rdkit`, which provide the covalent radii (a built-in table with
  the same values, from Cordero *et al.*, is used otherwise).

## Installation

### From PyPI

```bash
pip install cathedralpkg-cantor
```

To include the optional dependencies (RDKit for SMILES input):

```bash
pip install "cathedralpkg-cantor[smiles]"
```

### From GitHub

```bash
pip install git+https://github.com/cathedralpkg/cantor.git
```

### In a conda environment

```bash
conda create -n cantor python=3.11
conda activate cantor
pip install "cathedralpkg-cantor[smiles]"
```

Any of the above installs the `cantor` command in your `PATH`. The script can
also be executed directly with Python (`python3 cantor.py ...`) if the
required dependencies are available.

## Usage

```bash
cantor STRUCTURE ZMATFILE             # generate a Z-matrix
cantor -a | --audit EXTZMAT [ZMATFILE] # check a Z-matrix written by another program
cantor -p | --parameters              # write the parameter file
cantor -h | --help                    # show help
cantor -v | --version                 # show program version
```

`STRUCTURE` is an `xyz` file (in Ångström) or a SMILES string:

```bash
cantor butanol.xyz butanol.zmat
cantor "CCCCO"     butanol.zmat
```

For SMILES input, the Cartesian geometry is generated with RDKit (ETKDGv3
embedding with the seed of the parameter file, followed by MMFF or, if MMFF
parameters are missing, UFF optimization) and written next to the Z-matrix
(`butanol.xyz`). An existing file is never overwritten; a warning is printed
instead.

## Parameter file

The parameters are read from the file `.cathedralpkg.cantor` in the working
directory, if it exists; otherwise the default values are used. A template is
written with

```bash
cantor -p
```

```text
# two atoms are considered bonded if d_AB/(r_A+r_B) falls below this value
RHO_CONN   1.30

# a bond is regarded as multiple when d_AB/(r_A+r_B) falls below this value
RHO_MBOND  0.93

# a reference triad closer than this (in degrees) to 0 or 180 needs a dummy
EPS_LIN    5.00

# seed used by RDKit so that a SMILES always yields the same geometry
SEED       2025

# covalent radius (Angstrom) to use for a given element, overriding the
# tabulated one; useful when the default gives a poor connectivity
#RADIUS_Fe  1.32
```

| Keyword | Default | Meaning |
|---|---:|---|
| `RHO_CONN` | `1.30` | connectivity threshold, d<sub>AB</sub>/(r<sub>A</sub>+r<sub>B</sub>) |
| `RHO_MBOND` | `0.93` | multiple-bond threshold; must be smaller than `RHO_CONN` |
| `EPS_LIN` | `5.00` | linearity tolerance, in degrees, used to define rods and to detect linear angles and collinear references |
| `SEED` | `2025` | seed for the RDKit embedding of SMILES strings |
| `RADIUS_X` | tabulated | covalent radius of element X, in Ångström; any number of these lines may be given |

## Output

The standard output reports the parameters, the Cartesian coordinates, the
molecular graph (artificial bonds, rings, bonds joining rings, and rods of
more than one bond), the number of torsions of each class, the outcome of the
three checks, the list of `ptor` coordinates with their axes, the dummy
atoms, the RMSD of the geometry rebuilt from the Z-matrix, and the
correspondence between the rows of the Z-matrix and the input atoms, since
the construction renumbers the atoms. All atoms are numbered from 1. For
ethanol:

```text
(atoms numbered by their row in the Z-matrix)
torsions: ptor=2 rtor=0 etor=0 itor=4
valid Z-matrix: yes
non-redundant: yes (2 proper torsions for 2 rotatable axes)
rigid rotations: yes (2 of 2 proper torsions)
   ptor04      4-3-2-1   axis 3-2
   ptor05      5-1-2-3   axis 2-1
rebuilt geometry, RMSD to input: 6.52e-16 A

atom order (Z-matrix row <- input atom):
     1 <- 3       2 <- 2       3 <- 1       4 <- 4       5 <- 9       6 <- 5
     7 <- 6       8 <- 7       9 <- 8
```

The Z-matrix file has the usual two blocks, the rows with named variables and
the values of the variables:

```text
 O
 C     1  dist02
 C     2  dist03      1  angl03
 H     3  dist04      2  angl04      1  ptor04
 H     1  dist05      2  angl05      3  ptor05
 H     3  dist06      2  angl06      4  itor06
 H     3  dist07      2  angl07      6  itor07
 H     2  dist08      1  angl08      3  itor08
 H     2  dist09      1  angl09      8  itor09

dist02         1.420178
dist03         1.514604
angl03       109.979154
dist04         1.094947
angl04       110.600997
ptor04       -58.180637
...
```

The methyl group is rotated by `ptor04` alone: its other two hydrogens are
placed from the first one (`itor06`, `itor07`) and follow it.

## Auditing Z-matrices from other programs

```bash
cantor --audit molden.zmat [renamed.zmat]
```

The Cartesian geometry is rebuilt from the Z-matrix, the molecular graph is
built from that geometry, and the rows are classified and checked as they
are. If a second file is given, the Z-matrix is rewritten there with the
variable names of CANTOR. Two layouts are read:

- the Gaussian layout, written by Gaussian, GaussView, Molden, Open Babel,
  Chemcraft, and most other programs: each reference is followed by its
  value, values may be given inline or as variables defined after the
  matrix, and references may be row numbers or atom labels;
- the ORCA layout (the internal-coordinate block of its output): the three
  references come first, with 0 for none, and then the three values.

Dummy atoms may be labeled `X`, `XX`, `Du`, `Q`, or `Bq`.

## Exit status

| Status | Meaning |
|---:|---|
| 0 | success |
| 1 | wrong usage |
| 2 | unreadable input |
| 3 | the Z-matrix is not search-ready (it is still written, so that it can be inspected, unless the construction itself failed) |

## Python interface

Every object of the construction is also available from Python:

```python
import cantor

xcc, symbols = cantor.read_xyz("butanol.xyz")
mol = cantor.MolGraph(xcc, symbols)
mol.calculate_connectivity()
print(mol.rotatable_axes())          # rods with their bonds, atoms and ends

zmat = cantor.ZMatrix(mol)
zmat.build()
for row in zmat.classify():          # one dict per row (atom indices from 0)
    print(row["row"], row["refs"], row["kind"], row["central"])
print(zmat.checks())                 # (valid, nonredundant, rigid)
```

## Cu## Current scope

Most limitations arise from inferring chemical information from the
geometry:

- the molecular graph depends on `RHO_CONN` and on the covalent radii, and
  distance criteria may fail for transition-metal complexes, unusual
  coordination environments, weakly bound complexes, or strongly distorted
  structures such as transition states; the connectivity, rings, and rods
  printed in the output should be checked in such cases, and the radius of
  individual elements can be changed in the parameter file (`RADIUS_X`);
- `EPS_LIN` determines the rods: a C≡C fragment bent beyond the tolerance is
  split into shorter rods;
- the multiple-bond criterion is empirical and limited to carbon, nitrogen,
  and oxygen.

CANTOR builds and checks Z-matrices; it does not search conformations. It
exposes internal rotations only: ring puckering is outside its scope, and
different ring conformers must be supplied as separate structures.

tation

If you use CANTOR in your work, please cite:

> A. Lema-Saavedra, M. Castiñeira Reis, D. Ferro-Costas, *Cantor: a program
> for the automatic generation of search-ready Z-matrices with one torsion per
> rotatable axis*, submitted to *Journal of Chemical Information and
> Modeling* (2026).

Please replace the provisional citation above with the final bibliographic
information once the article is published.

## License

Distributed under the MIT License. See `LICENSE` for details.

## Author

David Ferro-Costas — Universidade de Santiago de Compostela  
ORCID: 0000-0002-8365-4047
