Claisen Rearrangement with GFN1-xTB

../_images/ts_optimized_24e9efa3.png

Optimized transition state.

Requires: AMS2026 or later

Related documentation

Summary

The neutral, closed-shell molecule C=CC(CCCC)C1C=CC(C)=CC1=O was treated in the gas phase with GFN1-xTB. The carbonyl oxygen and terminal vinyl carbon were identified from the ChemicalSystem.bonds graph as atoms 15 and 1, respectively. All thermochemical values are ideal-gas rigid-rotor/harmonic-oscillator results at the AMS default temperature of 298.15 K.

For the explicitly scanned direction—supplied dienone → short O–C aryl-ether endpoint—the reaction free-energy barrier is 18.06 kcal/mol, and the reaction free energy is -14.96 kcal/mol. The requested O–C contraction is the retro-Claisen direction. For the opposite, conventional aryl ether → dienone Claisen direction, the same stationary points give ΔG‡ = 33.02 kcal/mol and ΔG = 14.96 kcal/mol. The transition state has exactly one imaginary frequency, -522.65 cm⁻¹, and AMS classifies it as a transition state.

Stationary points

Reactant

Transition state

Product

Optimized reactant

Optimized transition state

Optimized product

Structure

Electronic energy (Hartree)

Electronic energy (kcal/mol)

Relative electronic energy (kcal/mol)

Gibbs free energy (Hartree)

Gibbs free energy (kcal/mol)

Relative Gibbs free energy (kcal/mol)

PES point character

Negative frequencies

Lowest frequency (cm^-1)

Reactant

-45.0435

-28265.2

0

-44.7908

-28106.7

0

local minimum

0

21.5804

TS

-45.018

-28249.2

15.9885

-44.7621

-28088.6

18.0607

transition state

1

-522.655

Product

-45.0708

-28282.3

-17.1168

-44.8147

-28121.6

-14.9631

local minimum

1

-14.1897

Electronic and Gibbs energies use identical GFN1-xTB settings. Relative values are referenced to the optimized reactant. The reactant has no negative frequencies and is classified as a local minimum. The product is classified as a local minimum by AMS; its lowest mode is -14.19 cm⁻¹. The small negative value is below the AMS PES-point-character tolerance and represents a very soft conformational mode rather than a chemically significant unstable mode.

Relaxed O–C distance scan

The optimized reactant O···C distance is 4.758 Å. To preserve an exact 0.2 Å grid ending at 1.5 Å, the relaxed scan begins at 4.9 Å, requiring a 0.142 Å adjustment at its first constrained point. The only scan warning records this difference between the initial geometry and first requested constraint. All 18 constrained optimizations converged. Point 16, at 1.90 Å, has the highest scan energy and was used directly as the TS-search starting structure.

Electronic energy versus O-C distance

Five representative relaxed-scan geometries, displayed in scan order in one row:

Five representative three-dimensional scan structures

Point

O-C distance (angstrom)

Electronic energy (Hartree)

Relative electronic energy (kcal/mol)

Converged

1

4.9

-45.0433

0

True

2

4.7

-45.0434

-0.0994

True

3

4.5

-45.0429

0.2206

True

4

4.3

-45.042

0.8207

True

5

4.1

-45.0408

1.5587

True

6

3.9

-45.0397

2.281

True

7

3.7

-45.0387

2.8487

True

8

3.5

-45.0382

3.1937

True

9

3.3

-45.0379

3.3608

True

10

3.1

-45.0406

1.6597

True

11

2.9

-45.0401

1.9894

True

12

2.7

-45.0393

2.4763

True

13

2.5

-45.0376

3.585

True

14

2.3

-45.0338

5.9742

True

15

2.1

-45.0274

9.947

True

16

1.9

-45.0201

14.5278

True

17

1.7

-45.0427

0.3462

True

18

1.5

-45.0676

-15.2562

True

Frequency and TS verification

  • Reactant: 99 vibrational modes; 0 negative frequencies; AMS character local minimum.

  • Transition state: 99 vibrational modes; 1 negative frequency (-522.65 cm⁻¹); AMS character transition state.

  • Product: 99 vibrational modes; 1 formally negative frequency (-14.19 cm⁻¹); AMS character local minimum.

The TS calculation explicitly used GeometryOptimization InitialHessian Type Calculate, requested final normal modes, and followed the O–C distance reaction coordinate.

Conclusion

At the GFN1-xTB/RRHO level, the requested O–C contraction has ΔG‡ = 18.06 kcal/mol and ΔG = -14.96 kcal/mol at 298.15 K; the opposite conventional Claisen direction has ΔG‡ = 33.02 kcal/mol and ΔG = 14.96 kcal/mol. The stationary-point classification and one-imaginary-frequency requirement are satisfied for the transition state. Because the molecule is conformationally flexible and only one UFF-generated starting conformer was refined, these values are a single-conformer estimate.

Calculation inputs and provenance

Reactant

GFN1-xTB reactant geometry optimization and harmonic normal modes.

Properties
  NormalModes yes
End

Task GeometryOptimization

System
  Atoms
              C      -1.0262011744       3.6046926978      -0.2030752582
              C      -0.9035269429       2.3901008178       0.3408609206
              C      -0.4009428537       1.2066229963      -0.4627217180
              C      -0.7776227692      -0.1290248391       0.2282156809
              C      -2.2934811062      -0.3814086734       0.2142972611
              C      -2.6329822843      -1.7213596794       0.8772441541
              C      -4.1372958777      -1.9767897946       0.8660277936
              C       1.1303217520       1.3264778198      -0.7117340959
              C       1.9147614601       1.2390177228       0.5837038809
              C       2.7911117108       0.2612237981       0.8372508888
              C       3.0893435188      -0.7949325961      -0.1531566567
              C       4.0845233772      -1.8654105033       0.1865977012
              C       2.5469104038      -0.7480427923      -1.3759398575
              C       1.5967756662       0.3149579130      -1.7373095423
              O       1.1622136995       0.3767158868      -2.9184606990
              H      -1.3934559320       4.4326652206       0.3943984043
              H      -0.7656343746       3.7807957810      -1.2422634043
              H      -1.1854283646       2.2565790784       1.3818262125
              H      -0.9131945896       1.2302176134      -1.4518142013
              H      -0.2836357033      -0.9723523125      -0.3009606569
              H      -0.4109781544      -0.1302659874       1.2786173024
              H      -2.6546413428      -0.3910944354      -0.8377006564
              H      -2.8155520622       0.4353890465       0.7582495012
              H      -2.1243020036      -2.5481141441       0.3349578458
              H      -2.2765053910      -1.7192668188       1.9304560262
              H      -4.5155582378      -2.0082479091      -0.1780047553
              H      -4.6686812035      -1.1773474916       1.4251395814
              H      -4.3522897820      -2.9522077118       1.3510970272
              H       1.3437069086       2.3280134690      -1.1451953696
              H       1.7442874387       1.9920817558       1.3433076540
              H       3.3012697072       0.2515915366       1.7926076621
              H       3.7924960109      -2.8332928298      -0.2746686918
              H       5.0872692461      -1.5710654156      -0.1877819966
              H       4.1396520738      -2.0134731165       1.2858798231
              H       2.8072671761      -1.4934461026      -2.1185896705
  End
  BondOrders
     1 2 2.0
     1 16 1.0
     1 17 1.0
     2 3 1.0
     2 18 1.0
     3 4 1.0
     3 8 1.0
     3 19 1.0
     4 5 1.0
     4 20 1.0
     4 21 1.0
     5 6 1.0
     5 22 1.0
     5 23 1.0
     6 7 1.0
     6 24 1.0
     6 25 1.0
     7 26 1.0
     7 27 1.0
     7 28 1.0
     8 9 1.0
     8 14 1.0
     8 29 1.0
     9 10 2.0
     9 30 1.0
     10 11 1.0
     10 31 1.0
     11 12 1.0
     11 13 2.0
     12 32 1.0
     12 33 1.0
     12 34 1.0
     13 14 1.0
     13 35 1.0
     14 15 2.0
  End
End

Engine dftb
  Model GFN1-xTB
EndEngine

Scan

Relaxed O···C distance scan used to locate the TS-search starting geometry.

PESScan
  ScanCoordinate
    Distance 15 1 4.90000000 1.50000000
    nPoints 18
  End
End

Task PESScan

System
  Atoms
              C      -1.4768962046       3.3710010886      -0.2660432725
              C      -0.8296109555       2.3624709099       0.2961452241
              C      -0.3377937283       1.1663138274      -0.4704503129
              C      -0.7704424781      -0.1458215069       0.2019805372
              C      -2.2957998312      -0.2814957815       0.2172593734
              C      -2.7278659743      -1.5958743579       0.8740081402
              C      -4.2491691452      -1.7358265259       0.8921579647
              C       1.2128063406       1.2071055728      -0.6238353582
              C       1.9299248920       1.0488976744       0.6730242660
              C       2.8783337450       0.1243084812       0.8695632889
              C       3.2648423695      -0.7950246192      -0.1789700821
              C       4.3330466113      -1.7989335531       0.1390641408
              C       2.6730234977      -0.7366904386      -1.3921352589
              C       1.6162085544       0.2158540618      -1.7110405145
              O       1.0613123584       0.2371809325      -2.7903580823
              H      -1.8175944810       4.2229704893       0.3068512941
              H      -1.6997487234       3.3941933878      -1.3251316790
              H      -0.6234882257       2.3661804894       1.3635572560
              H      -0.7439678812       1.1959660877      -1.4902927828
              H      -0.3358807825      -0.9877830167      -0.3462227052
              H      -0.3864165134      -0.1798846428       1.2276025489
              H      -2.6736173859      -0.2443523661      -0.8100739464
              H      -2.7320444638       0.5617590728       0.7636889629
              H      -2.2916595664      -2.4376602013       0.3254447428
              H      -2.3468119479      -1.6328085660       1.9005115271
              H      -4.6462444652      -1.7222330553      -0.1238116543
              H      -4.7019471101      -0.9161880419       1.4520715443
              H      -4.5336535981      -2.6770264334       1.3634989034
              H       1.4513187962       2.2023624136      -1.0251106476
              H       1.6566840656       1.7355824043       1.4675685922
              H       3.3848767268       0.0450999542       1.8255347799
              H       4.5370334805      -2.4431666072      -0.7153282093
              H       5.2531081374      -1.2852080866       0.4233120913
              H       4.0233983384      -2.4176524126       0.9832343894
              H       2.9447355481      -1.4236166349      -2.1859169701
  End
  BondOrders
     1 2 2.0
     1 16 1.0
     1 17 1.0
     2 3 1.0
     2 18 1.0
     3 4 1.0
     3 8 1.0
     3 19 1.0
     4 5 1.0
     4 20 1.0
     4 21 1.0
     5 6 1.0
     5 22 1.0
     5 23 1.0
     6 7 1.0
     6 24 1.0
     6 25 1.0
     7 26 1.0
     7 27 1.0
     7 28 1.0
     8 9 1.0
     8 14 1.0
     8 29 1.0
     9 10 2.0
     9 30 1.0
     10 11 1.0
     10 31 1.0
     11 12 1.0
     11 13 2.0
     12 32 1.0
     12 33 1.0
     12 34 1.0
     13 14 1.0
     13 35 1.0
     14 15 2.0
  End
End

Engine dftb
  Model GFN1-xTB
EndEngine

TS

GFN1-xTB transition-state search from the highest scan-energy geometry, with calculated initial Hessian and final normal modes.

GeometryOptimization
  InitialHessian
    Type Calculate
  End
End

Properties
  NormalModes yes
End

Task TransitionStateSearch

TransitionStateSearch
  ReactionCoordinate
    Distance 15 1 1.0
  End
End

System
  Atoms
              C      -0.2316361456       2.2807559308      -1.8136617243
              C      -0.8062612953       1.7962127505      -0.6720971478
              C      -0.2476286605       0.5848606872      -0.0655132351
              C      -1.1099093178       0.0011651211       1.0537746448
              C      -2.4664420638      -0.4512211188       0.4993192587
              C      -3.3468024410      -1.0411145964       1.6050450534
              C      -4.6987018997      -1.4955174275       1.0569713563
              C       1.2253041465       1.0449807669       0.5534669286
              C       1.8602850707      -0.0932119963       1.2364711661
              C       2.8173403506      -0.8364210099       0.6439142663
              C       3.3495585122      -0.4793093645      -0.6383245763
              C       4.4087265074      -1.3575073499      -1.2396883518
              C       2.9163345891       0.6536650062      -1.2596842803
              C       1.9522482407       1.5273339028      -0.6590874280
              O       1.5526154261       2.5693553880      -1.2278659562
              H      -0.4929889574       3.2691829894      -2.1701340678
              H       0.1202716719       1.6052348215      -2.5835685232
              H      -1.2952987071       2.4927581086       0.0038486361
              H      -0.0165980772      -0.1890842204      -0.8056381492
              H      -0.6069241543      -0.8594886862       1.5042741873
              H      -1.2641485972       0.7520512383       1.8357332091
              H      -2.3067775443      -1.2028827579      -0.2816042846
              H      -2.9759075223       0.4024920705       0.0403466936
              H      -2.8345249453      -1.8941520050       2.0632058006
              H      -3.5048270930      -0.2883756821       2.3848834899
              H      -4.5632298755      -2.2615722115       0.2920855003
              H      -5.2335913464      -0.6542588237       0.6138978311
              H      -5.3082418828      -1.9105357725       1.8600806243
              H       0.9756127232       1.8514023568       1.2459650093
              H       1.5120182939      -0.3389269411       2.2338722957
              H       3.2405737404      -1.6948630701       1.1550947815
              H       4.7413122793      -0.9696206675      -2.2019627016
              H       5.2682634275      -1.4224562927      -0.5697016981
              H       4.0207741768      -2.3678486307      -1.3823132687
              H       3.3492013700       0.9769174860      -2.2000472489
  End
End

Engine dftb
  Model GFN1-xTB
EndEngine

Product

GFN1-xTB geometry optimization and harmonic normal modes from the 1.5 Å scan endpoint.

Properties
  NormalModes yes
End

Task GeometryOptimization

System
  Atoms
              C       0.2727454588       2.1733276750      -1.0949727072
              C      -0.4695956457       1.2742361392      -0.1540261068
              C      -1.1050803480       0.1756719103      -0.5401584839
              C      -1.8905843685      -0.7033492757       0.3887482533
              C      -3.3850787001      -0.6737164224       0.0313866413
              C      -4.1961134004      -1.5791287731       0.9628849611
              C      -5.6828852851      -1.5498643388       0.6118206344
              C       3.6347404396       2.4047543696       0.4997113073
              C       4.7159874530       1.6134167929       0.8457288890
              C       4.7229710234       0.2576382213       0.5459763762
              C       3.6364681225      -0.3139508997      -0.1107070676
              C       3.6444542523      -1.7844534637      -0.4364030571
              C       2.5468038488       0.4764607905      -0.4637857683
              C       2.5403640294       1.8364356512      -0.1580102199
              O       1.5320352160       2.6887349682      -0.4636687950
              H      -0.2977883956       3.0870756354      -1.2888412653
              H       0.5183303018       1.6865500278      -2.0448223826
              H      -0.4668920139       1.5929689500       0.8839305572
              H      -1.1024816973      -0.1288932529      -1.5843745396
              H      -1.5245023888      -1.7327522204       0.3050965334
              H      -1.7543895805      -0.3770701537       1.4249711427
              H      -3.5166476048      -1.0011852344      -1.0054349599
              H      -3.7523887280       0.3552197272       0.1064017382
              H      -3.8241708482      -2.6065881731       0.8866697873
              H      -4.0604518958      -1.2506900076       1.9989161859
              H      -5.8410768346      -1.8937321509      -0.4113769329
              H      -6.0770378574      -0.5365996323       0.7018128823
              H      -6.2396700042      -2.2003106131       1.2868003253
              H       3.6183660932       3.4629726241       0.7296482927
              H       5.5634886637       2.0571999453       1.3567825361
              H       5.5730897941      -0.3557799202       0.8227697574
              H       2.7198414984      -2.0824863798      -0.9307355173
              H       4.4829563934      -2.0209507218      -1.0941816440
              H       3.7575440930      -2.3730567026       0.4758730382
              H       1.7066489154       0.0218949082      -0.9730723006
  End
End

Engine dftb
  Model GFN1-xTB
EndEngine

Prompts and Python scripts

Prompt (instruction for AI agent)
Use $ams2026

I want the reaction free energy barrier and reaction free energies for the
Claisen rearrangement of the molecule with SMILES C=CC(CCCC)C1C=CC(C)=CC1=O

Find the carbonyl oxygen and terminal vinyl carbon ChemicalSystem bonds methods

Method: GFN1-xTB

Do a bond scan where that distance is scanned to 1.5 angstrom in intervals of
0.2 angstrom

Plot the energy vs distance (include in report), and do five images in one row
of representative 3d molecular structures.

Use the highest energy point as initial structure for transition state search.
Make sure to calculate the initial hessian for the TS search and the normal
modes for free energy. Verify that TS has exactly one imaginary (negative)
frequency. Also optimize the reactant and product with normal modes.

Include in the report pictures and energies and relative energies (in kcal/mol)
of optimized reactant, TS, and product.
01-run.py
#!/usr/bin/env amspython
from __future__ import annotations

import math
from pathlib import Path

import numpy as np
from scm.base import ChemicalSystem, InputParser
from scm.plams import AMSJob, Settings, finish, init
from scm.utils.conversions import plams_molecule_to_chemsys


SMILES = "C=CC(CCCC)C1C=CC(C)=CC1=O"
SCAN_END_ANGSTROM = 1.5
SCAN_STEP_ANGSTROM = 0.2


def bonded_neighbors(system: ChemicalSystem, atom_index: int) -> list[tuple[int, float]]:
    """Return zero-based neighboring atom indices and bond orders."""
    neighbors: list[tuple[int, float]] = []
    for i, j, bond in system.bonds.get_bonds_for_atom(atom_index):
        other = j if i == atom_index else i
        neighbors.append((other, float(bond.order)))
    return neighbors


def find_reaction_atoms(system: ChemicalSystem) -> tuple[int, int]:
    """Find carbonyl O and terminal vinyl C from the ChemicalSystem bond graph."""
    carbonyl_oxygens: list[int] = []
    terminal_vinyl_carbons: list[int] = []
    for i, atom in enumerate(system):
        neighbors = bonded_neighbors(system, i)
        if atom.symbol == "O" and len(neighbors) == 1:
            j, order = neighbors[0]
            if system.atoms[j].symbol == "C" and order > 1.5:
                carbonyl_oxygens.append(i)
        if atom.symbol == "C":
            heavy_neighbors = [(j, order) for j, order in neighbors if system.atoms[j].symbol != "H"]
            carbon_double_bonds = [j for j, order in heavy_neighbors if system.atoms[j].symbol == "C" and order > 1.5]
            if len(heavy_neighbors) == 1 and len(carbon_double_bonds) == 1:
                terminal_vinyl_carbons.append(i)
    if len(carbonyl_oxygens) != 1 or len(terminal_vinyl_carbons) != 1:
        raise ValueError(
            "Expected one carbonyl oxygen and one terminal vinyl carbon; "
            f"found O={carbonyl_oxygens}, C={terminal_vinyl_carbons}"
        )
    return carbonyl_oxygens[0], terminal_vinyl_carbons[0]


def engine_settings() -> Settings:
    settings = Settings()
    settings.input.dftb.Model = "GFN1-xTB"
    return settings


def minimum_settings() -> Settings:
    settings = engine_settings()
    settings.input.ams.Task = "GeometryOptimization"
    settings.input.ams.Properties.NormalModes = "Yes"
    return settings


def scan_settings(oxygen: int, vinyl_carbon: int, start: float, npoints: int) -> Settings:
    settings = engine_settings()
    settings.input.ams.Task = "PESScan"
    settings.input.ams.PESScan.ScanCoordinate.nPoints = npoints
    settings.input.ams.PESScan.ScanCoordinate.Distance = (
        f"{oxygen + 1} {vinyl_carbon + 1} {start:.8f} {SCAN_END_ANGSTROM:.8f}"
    )
    return settings


def ts_settings(oxygen: int, vinyl_carbon: int) -> Settings:
    settings = engine_settings()
    settings.input.ams.Task = "TransitionStateSearch"
    settings.input.ams.Properties.NormalModes = "Yes"
    settings.input.ams.GeometryOptimization.InitialHessian.Type = "Calculate"
    settings.input.ams.TransitionStateSearch.ReactionCoordinate.Distance = (
        f"{oxygen + 1} {vinyl_carbon + 1} 1.0"
    )
    return settings


def validate(settings: Settings) -> None:
    input_text = AMSJob(settings=settings).get_input()
    InputParser().to_dict("ams", input_text)


def assert_success(job: AMSJob) -> None:
    if not job.ok():
        raise RuntimeError(f"AMS job failed: {job.path}")


def main() -> None:
    init(folder="01-run_workdir")
    initial = ChemicalSystem.from_smiles(SMILES, optimize_with_uff=True, num_trial_conformers=30)
    oxygen, vinyl_carbon = find_reaction_atoms(initial)
    print(f"Resolved carbonyl oxygen: atom {oxygen + 1}")
    print(f"Resolved terminal vinyl carbon: atom {vinyl_carbon + 1}")

    reactant_settings = minimum_settings()
    validate(reactant_settings)
    reactant_job = AMSJob(
        molecule=initial,
        settings=reactant_settings,
        name="reactant_opt_freq",
    )
    reactant_job.run()
    assert_success(reactant_job)
    reactant = reactant_job.results.get_main_system()

    optimized_distance = float(reactant.get_distance(oxygen, vinyl_carbon))
    n_intervals = int(math.ceil((optimized_distance - SCAN_END_ANGSTROM) / SCAN_STEP_ANGSTROM))
    scan_start = SCAN_END_ANGSTROM + n_intervals * SCAN_STEP_ANGSTROM
    npoints = n_intervals + 1
    print(f"Optimized reactant O...C distance: {optimized_distance:.8f} angstrom")
    print(f"Scan: {scan_start:.8f} to {SCAN_END_ANGSTROM:.8f} angstrom, {npoints} points")

    pes_settings = scan_settings(oxygen, vinyl_carbon, scan_start, npoints)
    validate(pes_settings)
    scan_job = AMSJob(molecule=reactant, settings=pes_settings, name="oc_distance_scan")
    scan_job.run()
    assert_success(scan_job)
    scan_results = scan_job.results.get_pesscan_results()
    energies = np.asarray(scan_results["PES"], dtype=float)
    converged = np.asarray(scan_results["Converged"], dtype=bool)
    if not np.all(converged):
        failed = (np.flatnonzero(~converged) + 1).tolist()
        raise RuntimeError(f"Unconverged PES scan points: {failed}")

    highest_index = int(np.argmax(energies))
    highest_system = plams_molecule_to_chemsys(scan_results["Molecules"][highest_index])
    print(f"Highest-energy scan point: {highest_index + 1} of {len(energies)}")

    transition_settings = ts_settings(oxygen, vinyl_carbon)
    validate(transition_settings)
    ts_job = AMSJob(molecule=highest_system, settings=transition_settings, name="ts_opt_freq")
    ts_job.run()
    assert_success(ts_job)

    product_start = plams_molecule_to_chemsys(scan_results["Molecules"][-1])
    product_settings = minimum_settings()
    validate(product_settings)
    product_job = AMSJob(
        molecule=product_start,
        settings=product_settings,
        name="product_opt_freq",
    )
    product_job.run()
    assert_success(product_job)

    ts_frequencies = np.asarray(ts_job.results.get_frequencies(unit="cm^-1"), dtype=float)
    negative = ts_frequencies[ts_frequencies < 0.0]
    character = ts_job.results.readrkf("AMSResults", "PESPointCharacter", file="engine")
    print(f"TS PES point character: {character}")
    print(f"TS negative frequencies (cm^-1): {negative.tolist()}")
    if len(negative) != 1:
        raise RuntimeError(f"TS verification failed: expected exactly one negative frequency, found {len(negative)}")

    Path("run_complete.txt").write_text(
        f"oxygen_atom_1based={oxygen + 1}\n"
        f"terminal_vinyl_carbon_1based={vinyl_carbon + 1}\n"
        f"optimized_reactant_distance_angstrom={optimized_distance:.8f}\n"
        f"scan_start_angstrom={scan_start:.8f}\n"
        f"scan_end_angstrom={SCAN_END_ANGSTROM:.8f}\n"
        f"scan_step_angstrom={SCAN_STEP_ANGSTROM:.8f}\n"
        f"scan_points={npoints}\n"
        f"highest_scan_point_1based={highest_index + 1}\n"
        f"ts_negative_frequencies_cm-1={negative.tolist()}\n"
        f"ts_pes_point_character={character}\n"
    )
    finish()


if __name__ == "__main__":
    main()
report.py
#!/usr/bin/env amspython
from __future__ import annotations

from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from scm.base import Units
from scm.plams import AMSJob, view


ROOT = Path(__file__).resolve().parent
SMILES = "C=CC(CCCC)C1C=CC(C)=CC1=O"


def latest_workdir(stem: str) -> Path:
    candidates = [path for path in ROOT.glob(f"{stem}*") if path.is_dir()]
    if not candidates:
        raise FileNotFoundError(f"No work directory matching {stem!r}")

    def generation(path: Path) -> int:
        suffix = path.name[len(stem) :]
        return 1 if not suffix else int(suffix.lstrip("."))

    return max(candidates, key=generation)


def gibbs_hartree(job: AMSJob) -> float:
    return float(job.results.readrkf("Thermodynamics", "Gibbs free Energy", file="engine"))


def render_system(system: object, path: Path, width: int = 480, height: int = 360) -> None:
    view(
        system,
        guess_bonds=len(system.bonds) == 0,
        direction="along_pca3",
        width=width,
        height=height,
        picture_path=str(path),
    )


def main() -> None:
    workdir = latest_workdir("01-run_workdir")
    figures = ROOT / "figures"
    tables = ROOT / "tables"
    figures.mkdir(exist_ok=True)
    tables.mkdir(exist_ok=True)

    # Each job is loaded directly from its AMS results directory. The accompanying
    # string documents why that calculation supports the report.
    jobs_with_justification = {
        "Reactant": (
            AMSJob.load_external(str(workdir / "reactant_opt_freq")),
            "GFN1-xTB reactant geometry optimization and harmonic normal modes.",
        ),
        "TS": (
            AMSJob.load_external(str(workdir / "ts_opt_freq")),
            "GFN1-xTB transition-state search from the highest scan-energy geometry, with calculated initial Hessian and final normal modes.",
        ),
        "Product": (
            AMSJob.load_external(str(workdir / "product_opt_freq")),
            "GFN1-xTB geometry optimization and harmonic normal modes from the 1.5 Å scan endpoint.",
        ),
        "Scan": (
            AMSJob.load_external(str(workdir / "oc_distance_scan")),
            "Relaxed O···C distance scan used to locate the TS-search starting geometry.",
        ),
    }
    reactant_job = jobs_with_justification["Reactant"][0]
    ts_job = jobs_with_justification["TS"][0]
    product_job = jobs_with_justification["Product"][0]
    scan_job = jobs_with_justification["Scan"][0]

    hartree_to_kcal = Units.conversion_factor("hartree", "kcal/mol")
    bohr_to_angstrom = Units.conversion_factor("bohr", "angstrom")

    rows: list[dict[str, object]] = []
    for label, job in (("Reactant", reactant_job), ("TS", ts_job), ("Product", product_job)):
        frequencies = np.asarray(job.results.get_frequencies(unit="cm^-1"), dtype=float)
        rows.append(
            {
                "Structure": label,
                "Electronic energy (Hartree)": float(job.results.get_energy(unit="hartree")),
                "Gibbs free energy (Hartree)": gibbs_hartree(job),
                "PES point character": str(
                    job.results.readrkf("AMSResults", "PESPointCharacter", file="engine")
                ),
                "Negative frequencies": int(np.sum(frequencies < 0.0)),
                "Lowest frequency (cm^-1)": float(np.min(frequencies)),
            }
        )
    energy_df = pd.DataFrame(rows)
    energy_df["Electronic energy (kcal/mol)"] = energy_df["Electronic energy (Hartree)"] * hartree_to_kcal
    energy_df["Relative electronic energy (kcal/mol)"] = (
        energy_df["Electronic energy (Hartree)"] - energy_df.loc[0, "Electronic energy (Hartree)"]
    ) * hartree_to_kcal
    energy_df["Gibbs free energy (kcal/mol)"] = energy_df["Gibbs free energy (Hartree)"] * hartree_to_kcal
    energy_df["Relative Gibbs free energy (kcal/mol)"] = (
        energy_df["Gibbs free energy (Hartree)"] - energy_df.loc[0, "Gibbs free energy (Hartree)"]
    ) * hartree_to_kcal
    column_order = [
        "Structure",
        "Electronic energy (Hartree)",
        "Electronic energy (kcal/mol)",
        "Relative electronic energy (kcal/mol)",
        "Gibbs free energy (Hartree)",
        "Gibbs free energy (kcal/mol)",
        "Relative Gibbs free energy (kcal/mol)",
        "PES point character",
        "Negative frequencies",
        "Lowest frequency (cm^-1)",
    ]
    energy_df = energy_df[column_order]
    energy_df.to_csv(tables / "stationary_points.csv", index=False)

    scan = scan_job.results.get_pesscan_results()
    distances = np.asarray(scan["RaveledPESCoords"][0], dtype=float) * bohr_to_angstrom
    scan_energies = np.asarray(scan["PES"], dtype=float)
    relative_scan_energies = (scan_energies - scan_energies[0]) * hartree_to_kcal
    scan_df = pd.DataFrame(
        {
            "Point": np.arange(1, len(distances) + 1),
            "O-C distance (angstrom)": distances,
            "Electronic energy (Hartree)": scan_energies,
            "Relative electronic energy (kcal/mol)": relative_scan_energies,
            "Converged": np.asarray(scan["Converged"], dtype=bool),
        }
    )
    scan_df.to_csv(tables / "distance_scan.csv", index=False)
    highest_index = int(np.argmax(scan_energies))

    fig, ax = plt.subplots(figsize=(6.4, 4.2))
    ax.plot(distances, relative_scan_energies, "o-", color="#2457a6", linewidth=1.5, markersize=4)
    ax.scatter(
        [distances[highest_index]],
        [relative_scan_energies[highest_index]],
        color="#b2292e",
        marker="*",
        s=130,
        zorder=3,
        label=f"TS-search start (point {highest_index + 1})",
    )
    ax.set_xlabel("Carbonyl O–terminal vinyl C distance (Å)")
    ax.set_ylabel("Electronic energy relative to first scan point (kcal/mol)")
    ax.invert_xaxis()
    ax.grid(alpha=0.25)
    ax.legend(frameon=False)
    fig.tight_layout()
    fig.savefig(figures / "energy_vs_distance.png", dpi=220)
    plt.close(fig)

    stationary_images: list[tuple[str, Path]] = []
    for label, job in (("Reactant", reactant_job), ("TS", ts_job), ("Product", product_job)):
        image_path = figures / f"{label.lower()}_optimized.png"
        system = job.results.get_main_system()
        render_system(system, image_path)
        stationary_images.append((label, image_path))

    representative_indices = np.linspace(0, len(distances) - 1, 5).round().astype(int).tolist()
    representative_paths: list[Path] = []
    for sequence, point_index in enumerate(representative_indices, start=1):
        molecule = scan["Molecules"][point_index]
        image_path = figures / f"scan_representative_{sequence}.png"
        render_system(molecule, image_path, width=360, height=300)
        representative_paths.append(image_path)

    fig, axes = plt.subplots(1, 5, figsize=(15, 3.2))
    for ax, image_path, point_index in zip(axes, representative_paths, representative_indices):
        ax.imshow(plt.imread(image_path))
        ax.set_title(f"{distances[point_index]:.1f} Å\npoint {point_index + 1}", fontsize=10)
        ax.axis("off")
    fig.tight_layout(w_pad=0.1)
    fig.savefig(figures / "scan_structures_one_row.png", dpi=180, bbox_inches="tight")
    plt.close(fig)

    barrier = float(energy_df.loc[energy_df["Structure"] == "TS", "Relative Gibbs free energy (kcal/mol)"].iloc[0])
    reaction_free_energy = float(
        energy_df.loc[energy_df["Structure"] == "Product", "Relative Gibbs free energy (kcal/mol)"].iloc[0]
    )
    reverse_barrier = barrier - reaction_free_energy
    reverse_reaction_free_energy = -reaction_free_energy
    ts_frequencies = np.asarray(ts_job.results.get_frequencies(unit="cm^-1"), dtype=float)
    ts_negative = ts_frequencies[ts_frequencies < 0.0]
    reactant_frequencies = np.asarray(reactant_job.results.get_frequencies(unit="cm^-1"), dtype=float)
    product_frequencies = np.asarray(product_job.results.get_frequencies(unit="cm^-1"), dtype=float)

    display_energy_df = energy_df.copy()
    numeric_columns = display_energy_df.select_dtypes(include=[np.number]).columns
    display_energy_df[numeric_columns] = display_energy_df[numeric_columns].round(4)
    display_scan_df = scan_df.copy()
    display_scan_df["O-C distance (angstrom)"] = display_scan_df["O-C distance (angstrom)"].round(4)
    display_scan_df["Electronic energy (Hartree)"] = display_scan_df["Electronic energy (Hartree)"].round(8)
    display_scan_df["Relative electronic energy (kcal/mol)"] = display_scan_df[
        "Relative electronic energy (kcal/mol)"
    ].round(4)

    inputs = []
    for label in ("Reactant", "Scan", "TS", "Product"):
        job, justification = jobs_with_justification[label]
        inputs.append(
            f"### {label}\n\n{justification}\n\n```ams\n{job.get_input().rstrip()}\n```"
        )

    report = f"""# GFN1-xTB Claisen rearrangement profile

## Summary

The neutral, closed-shell molecule `{SMILES}` was treated in the gas phase with GFN1-xTB. The carbonyl oxygen and terminal vinyl carbon were identified from the `ChemicalSystem.bonds` graph as atoms 15 and 1, respectively. All thermochemical values are ideal-gas rigid-rotor/harmonic-oscillator results at the AMS default temperature of 298.15 K.

For the explicitly scanned direction—supplied dienone → short O–C aryl-ether endpoint—the reaction free-energy barrier is **{barrier:.2f} kcal/mol**, and the reaction free energy is **{reaction_free_energy:.2f} kcal/mol**. The requested O–C contraction is the retro-Claisen direction. For the opposite, conventional aryl ether → dienone Claisen direction, the same stationary points give ΔG‡ = **{reverse_barrier:.2f} kcal/mol** and ΔG = **{reverse_reaction_free_energy:.2f} kcal/mol**. The transition state has exactly one imaginary frequency, **{ts_negative[0]:.2f} cm⁻¹**, and AMS classifies it as a transition state.

## Stationary points

| Reactant | Transition state | Product |
|:--:|:--:|:--:|
| ![Optimized reactant](figures/reactant_optimized.png) | ![Optimized transition state](figures/ts_optimized.png) | ![Optimized product](figures/product_optimized.png) |

{display_energy_df.to_markdown(index=False)}

Electronic and Gibbs energies use identical GFN1-xTB settings. Relative values are referenced to the optimized reactant. The reactant has no negative frequencies and is classified as a local minimum. The product is classified as a local minimum by AMS; its lowest mode is {np.min(product_frequencies):.2f} cm⁻¹. The small negative value is below the AMS PES-point-character tolerance and represents a very soft conformational mode rather than a chemically significant unstable mode.

## Relaxed O–C distance scan

The optimized reactant O···C distance is 4.758 Å. To preserve an exact 0.2 Å grid ending at 1.5 Å, the relaxed scan begins at 4.9 Å, requiring a 0.142 Å adjustment at its first constrained point. The only scan warning records this difference between the initial geometry and first requested constraint. All 18 constrained optimizations converged. Point {highest_index + 1}, at {distances[highest_index]:.2f} Å, has the highest scan energy and was used directly as the TS-search starting structure.

![Electronic energy versus O-C distance](figures/energy_vs_distance.png)

Five representative relaxed-scan geometries, displayed in scan order in one row:

![Five representative three-dimensional scan structures](figures/scan_structures_one_row.png)

{display_scan_df.to_markdown(index=False)}

## Frequency and TS verification

- Reactant: {len(reactant_frequencies)} vibrational modes; {int(np.sum(reactant_frequencies < 0.0))} negative frequencies; AMS character `local minimum`.
- Transition state: {len(ts_frequencies)} vibrational modes; {len(ts_negative)} negative frequency ({ts_negative[0]:.2f} cm⁻¹); AMS character `transition state`.
- Product: {len(product_frequencies)} vibrational modes; {int(np.sum(product_frequencies < 0.0))} formally negative frequency ({np.min(product_frequencies):.2f} cm⁻¹); AMS character `local minimum`.

The TS calculation explicitly used `GeometryOptimization InitialHessian Type Calculate`, requested final normal modes, and followed the O–C distance reaction coordinate.

## Conclusion

At the GFN1-xTB/RRHO level, the requested O–C contraction has ΔG‡ = **{barrier:.2f} kcal/mol** and ΔG = **{reaction_free_energy:.2f} kcal/mol** at 298.15 K; the opposite conventional Claisen direction has ΔG‡ = **{reverse_barrier:.2f} kcal/mol** and ΔG = **{reverse_reaction_free_energy:.2f} kcal/mol**. The stationary-point classification and one-imaginary-frequency requirement are satisfied for the transition state. Because the molecule is conformationally flexible and only one UFF-generated starting conformer was refined, these values are a single-conformer estimate.

## Calculation inputs and provenance

{chr(10).join(inputs)}
"""
    (ROOT / "report.md").write_text(report)
    print(f"Wrote {ROOT / 'report.md'}")
    print(f"Barrier: {barrier:.4f} kcal/mol")
    print(f"Reaction free energy: {reaction_free_energy:.4f} kcal/mol")
    print(f"TS negative frequencies: {ts_negative.tolist()}")


if __name__ == "__main__":
    main()
Original Markdown report
# GFN1-xTB Claisen rearrangement profile

## Summary

The neutral, closed-shell molecule `C=CC(CCCC)C1C=CC(C)=CC1=O` was treated in the gas phase with GFN1-xTB. The carbonyl oxygen and terminal vinyl carbon were identified from the `ChemicalSystem.bonds` graph as atoms 15 and 1, respectively. All thermochemical values are ideal-gas rigid-rotor/harmonic-oscillator results at the AMS default temperature of 298.15 K.

For the explicitly scanned direction—supplied dienone → short O–C aryl-ether endpoint—the reaction free-energy barrier is **18.06 kcal/mol**, and the reaction free energy is **-14.96 kcal/mol**. The requested O–C contraction is the retro-Claisen direction. For the opposite, conventional aryl ether → dienone Claisen direction, the same stationary points give ΔG‡ = **33.02 kcal/mol** and ΔG = **14.96 kcal/mol**. The transition state has exactly one imaginary frequency, **-522.65 cm⁻¹**, and AMS classifies it as a transition state.

## Stationary points

| Reactant | Transition state | Product |
|:--:|:--:|:--:|
| ![Optimized reactant](figures/reactant_optimized.png) | ![Optimized transition state](figures/ts_optimized.png) | ![Optimized product](figures/product_optimized.png) |

| Structure   |   Electronic energy (Hartree) |   Electronic energy (kcal/mol) |   Relative electronic energy (kcal/mol) |   Gibbs free energy (Hartree) |   Gibbs free energy (kcal/mol) |   Relative Gibbs free energy (kcal/mol) | PES point character   |   Negative frequencies |   Lowest frequency (cm^-1) |
|:------------|------------------------------:|-------------------------------:|----------------------------------------:|------------------------------:|-------------------------------:|----------------------------------------:|:----------------------|-----------------------:|---------------------------:|
| Reactant    |                      -45.0435 |                       -28265.2 |                                  0      |                      -44.7908 |                       -28106.7 |                                  0      | local minimum         |                      0 |                    21.5804 |
| TS          |                      -45.018  |                       -28249.2 |                                 15.9885 |                      -44.7621 |                       -28088.6 |                                 18.0607 | transition state      |                      1 |                  -522.655  |
| Product     |                      -45.0708 |                       -28282.3 |                                -17.1168 |                      -44.8147 |                       -28121.6 |                                -14.9631 | local minimum         |                      1 |                   -14.1897 |

Electronic and Gibbs energies use identical GFN1-xTB settings. Relative values are referenced to the optimized reactant. The reactant has no negative frequencies and is classified as a local minimum. The product is classified as a local minimum by AMS; its lowest mode is -14.19 cm⁻¹. The small negative value is below the AMS PES-point-character tolerance and represents a very soft conformational mode rather than a chemically significant unstable mode.

## Relaxed O–C distance scan

The optimized reactant O···C distance is 4.758 Å. To preserve an exact 0.2 Å grid ending at 1.5 Å, the relaxed scan begins at 4.9 Å, requiring a 0.142 Å adjustment at its first constrained point. The only scan warning records this difference between the initial geometry and first requested constraint. All 18 constrained optimizations converged. Point 16, at 1.90 Å, has the highest scan energy and was used directly as the TS-search starting structure.

![Electronic energy versus O-C distance](figures/energy_vs_distance.png)

Five representative relaxed-scan geometries, displayed in scan order in one row:

![Five representative three-dimensional scan structures](figures/scan_structures_one_row.png)

|   Point |   O-C distance (angstrom) |   Electronic energy (Hartree) |   Relative electronic energy (kcal/mol) | Converged   |
|--------:|--------------------------:|------------------------------:|----------------------------------------:|:------------|
|       1 |                       4.9 |                      -45.0433 |                                  0      | True        |
|       2 |                       4.7 |                      -45.0434 |                                 -0.0994 | True        |
|       3 |                       4.5 |                      -45.0429 |                                  0.2206 | True        |
|       4 |                       4.3 |                      -45.042  |                                  0.8207 | True        |
|       5 |                       4.1 |                      -45.0408 |                                  1.5587 | True        |
|       6 |                       3.9 |                      -45.0397 |                                  2.281  | True        |
|       7 |                       3.7 |                      -45.0387 |                                  2.8487 | True        |
|       8 |                       3.5 |                      -45.0382 |                                  3.1937 | True        |
|       9 |                       3.3 |                      -45.0379 |                                  3.3608 | True        |
|      10 |                       3.1 |                      -45.0406 |                                  1.6597 | True        |
|      11 |                       2.9 |                      -45.0401 |                                  1.9894 | True        |
|      12 |                       2.7 |                      -45.0393 |                                  2.4763 | True        |
|      13 |                       2.5 |                      -45.0376 |                                  3.585  | True        |
|      14 |                       2.3 |                      -45.0338 |                                  5.9742 | True        |
|      15 |                       2.1 |                      -45.0274 |                                  9.947  | True        |
|      16 |                       1.9 |                      -45.0201 |                                 14.5278 | True        |
|      17 |                       1.7 |                      -45.0427 |                                  0.3462 | True        |
|      18 |                       1.5 |                      -45.0676 |                                -15.2562 | True        |

## Frequency and TS verification

- Reactant: 99 vibrational modes; 0 negative frequencies; AMS character `local minimum`.
- Transition state: 99 vibrational modes; 1 negative frequency (-522.65 cm⁻¹); AMS character `transition state`.
- Product: 99 vibrational modes; 1 formally negative frequency (-14.19 cm⁻¹); AMS character `local minimum`.

The TS calculation explicitly used `GeometryOptimization InitialHessian Type Calculate`, requested final normal modes, and followed the O–C distance reaction coordinate.

## Conclusion

At the GFN1-xTB/RRHO level, the requested O–C contraction has ΔG‡ = **18.06 kcal/mol** and ΔG = **-14.96 kcal/mol** at 298.15 K; the opposite conventional Claisen direction has ΔG‡ = **33.02 kcal/mol** and ΔG = **14.96 kcal/mol**. The stationary-point classification and one-imaginary-frequency requirement are satisfied for the transition state. Because the molecule is conformationally flexible and only one UFF-generated starting conformer was refined, these values are a single-conformer estimate.

## Calculation inputs and provenance

### Reactant

GFN1-xTB reactant geometry optimization and harmonic normal modes.

```ams
Properties
  NormalModes yes
End

Task GeometryOptimization

System
  Atoms
              C      -1.0262011744       3.6046926978      -0.2030752582
              C      -0.9035269429       2.3901008178       0.3408609206
              C      -0.4009428537       1.2066229963      -0.4627217180
              C      -0.7776227692      -0.1290248391       0.2282156809
              C      -2.2934811062      -0.3814086734       0.2142972611
              C      -2.6329822843      -1.7213596794       0.8772441541
              C      -4.1372958777      -1.9767897946       0.8660277936
              C       1.1303217520       1.3264778198      -0.7117340959
              C       1.9147614601       1.2390177228       0.5837038809
              C       2.7911117108       0.2612237981       0.8372508888
              C       3.0893435188      -0.7949325961      -0.1531566567
              C       4.0845233772      -1.8654105033       0.1865977012
              C       2.5469104038      -0.7480427923      -1.3759398575
              C       1.5967756662       0.3149579130      -1.7373095423
              O       1.1622136995       0.3767158868      -2.9184606990
              H      -1.3934559320       4.4326652206       0.3943984043
              H      -0.7656343746       3.7807957810      -1.2422634043
              H      -1.1854283646       2.2565790784       1.3818262125
              H      -0.9131945896       1.2302176134      -1.4518142013
              H      -0.2836357033      -0.9723523125      -0.3009606569
              H      -0.4109781544      -0.1302659874       1.2786173024
              H      -2.6546413428      -0.3910944354      -0.8377006564
              H      -2.8155520622       0.4353890465       0.7582495012
              H      -2.1243020036      -2.5481141441       0.3349578458
              H      -2.2765053910      -1.7192668188       1.9304560262
              H      -4.5155582378      -2.0082479091      -0.1780047553
              H      -4.6686812035      -1.1773474916       1.4251395814
              H      -4.3522897820      -2.9522077118       1.3510970272
              H       1.3437069086       2.3280134690      -1.1451953696
              H       1.7442874387       1.9920817558       1.3433076540
              H       3.3012697072       0.2515915366       1.7926076621
              H       3.7924960109      -2.8332928298      -0.2746686918
              H       5.0872692461      -1.5710654156      -0.1877819966
              H       4.1396520738      -2.0134731165       1.2858798231
              H       2.8072671761      -1.4934461026      -2.1185896705
  End
  BondOrders
     1 2 2.0
     1 16 1.0
     1 17 1.0
     2 3 1.0
     2 18 1.0
     3 4 1.0
     3 8 1.0
     3 19 1.0
     4 5 1.0
     4 20 1.0
     4 21 1.0
     5 6 1.0
     5 22 1.0
     5 23 1.0
     6 7 1.0
     6 24 1.0
     6 25 1.0
     7 26 1.0
     7 27 1.0
     7 28 1.0
     8 9 1.0
     8 14 1.0
     8 29 1.0
     9 10 2.0
     9 30 1.0
     10 11 1.0
     10 31 1.0
     11 12 1.0
     11 13 2.0
     12 32 1.0
     12 33 1.0
     12 34 1.0
     13 14 1.0
     13 35 1.0
     14 15 2.0
  End
End

Engine dftb
  Model GFN1-xTB
EndEngine
```
### Scan

Relaxed O···C distance scan used to locate the TS-search starting geometry.

```ams
PESScan
  ScanCoordinate
    Distance 15 1 4.90000000 1.50000000
    nPoints 18
  End
End

Task PESScan

System
  Atoms
              C      -1.4768962046       3.3710010886      -0.2660432725
              C      -0.8296109555       2.3624709099       0.2961452241
              C      -0.3377937283       1.1663138274      -0.4704503129
              C      -0.7704424781      -0.1458215069       0.2019805372
              C      -2.2957998312      -0.2814957815       0.2172593734
              C      -2.7278659743      -1.5958743579       0.8740081402
              C      -4.2491691452      -1.7358265259       0.8921579647
              C       1.2128063406       1.2071055728      -0.6238353582
              C       1.9299248920       1.0488976744       0.6730242660
              C       2.8783337450       0.1243084812       0.8695632889
              C       3.2648423695      -0.7950246192      -0.1789700821
              C       4.3330466113      -1.7989335531       0.1390641408
              C       2.6730234977      -0.7366904386      -1.3921352589
              C       1.6162085544       0.2158540618      -1.7110405145
              O       1.0613123584       0.2371809325      -2.7903580823
              H      -1.8175944810       4.2229704893       0.3068512941
              H      -1.6997487234       3.3941933878      -1.3251316790
              H      -0.6234882257       2.3661804894       1.3635572560
              H      -0.7439678812       1.1959660877      -1.4902927828
              H      -0.3358807825      -0.9877830167      -0.3462227052
              H      -0.3864165134      -0.1798846428       1.2276025489
              H      -2.6736173859      -0.2443523661      -0.8100739464
              H      -2.7320444638       0.5617590728       0.7636889629
              H      -2.2916595664      -2.4376602013       0.3254447428
              H      -2.3468119479      -1.6328085660       1.9005115271
              H      -4.6462444652      -1.7222330553      -0.1238116543
              H      -4.7019471101      -0.9161880419       1.4520715443
              H      -4.5336535981      -2.6770264334       1.3634989034
              H       1.4513187962       2.2023624136      -1.0251106476
              H       1.6566840656       1.7355824043       1.4675685922
              H       3.3848767268       0.0450999542       1.8255347799
              H       4.5370334805      -2.4431666072      -0.7153282093
              H       5.2531081374      -1.2852080866       0.4233120913
              H       4.0233983384      -2.4176524126       0.9832343894
              H       2.9447355481      -1.4236166349      -2.1859169701
  End
  BondOrders
     1 2 2.0
     1 16 1.0
     1 17 1.0
     2 3 1.0
     2 18 1.0
     3 4 1.0
     3 8 1.0
     3 19 1.0
     4 5 1.0
     4 20 1.0
     4 21 1.0
     5 6 1.0
     5 22 1.0
     5 23 1.0
     6 7 1.0
     6 24 1.0
     6 25 1.0
     7 26 1.0
     7 27 1.0
     7 28 1.0
     8 9 1.0
     8 14 1.0
     8 29 1.0
     9 10 2.0
     9 30 1.0
     10 11 1.0
     10 31 1.0
     11 12 1.0
     11 13 2.0
     12 32 1.0
     12 33 1.0
     12 34 1.0
     13 14 1.0
     13 35 1.0
     14 15 2.0
  End
End

Engine dftb
  Model GFN1-xTB
EndEngine
```
### TS

GFN1-xTB transition-state search from the highest scan-energy geometry, with calculated initial Hessian and final normal modes.

```ams
GeometryOptimization
  InitialHessian
    Type Calculate
  End
End

Properties
  NormalModes yes
End

Task TransitionStateSearch

TransitionStateSearch
  ReactionCoordinate
    Distance 15 1 1.0
  End
End

System
  Atoms
              C      -0.2316361456       2.2807559308      -1.8136617243
              C      -0.8062612953       1.7962127505      -0.6720971478
              C      -0.2476286605       0.5848606872      -0.0655132351
              C      -1.1099093178       0.0011651211       1.0537746448
              C      -2.4664420638      -0.4512211188       0.4993192587
              C      -3.3468024410      -1.0411145964       1.6050450534
              C      -4.6987018997      -1.4955174275       1.0569713563
              C       1.2253041465       1.0449807669       0.5534669286
              C       1.8602850707      -0.0932119963       1.2364711661
              C       2.8173403506      -0.8364210099       0.6439142663
              C       3.3495585122      -0.4793093645      -0.6383245763
              C       4.4087265074      -1.3575073499      -1.2396883518
              C       2.9163345891       0.6536650062      -1.2596842803
              C       1.9522482407       1.5273339028      -0.6590874280
              O       1.5526154261       2.5693553880      -1.2278659562
              H      -0.4929889574       3.2691829894      -2.1701340678
              H       0.1202716719       1.6052348215      -2.5835685232
              H      -1.2952987071       2.4927581086       0.0038486361
              H      -0.0165980772      -0.1890842204      -0.8056381492
              H      -0.6069241543      -0.8594886862       1.5042741873
              H      -1.2641485972       0.7520512383       1.8357332091
              H      -2.3067775443      -1.2028827579      -0.2816042846
              H      -2.9759075223       0.4024920705       0.0403466936
              H      -2.8345249453      -1.8941520050       2.0632058006
              H      -3.5048270930      -0.2883756821       2.3848834899
              H      -4.5632298755      -2.2615722115       0.2920855003
              H      -5.2335913464      -0.6542588237       0.6138978311
              H      -5.3082418828      -1.9105357725       1.8600806243
              H       0.9756127232       1.8514023568       1.2459650093
              H       1.5120182939      -0.3389269411       2.2338722957
              H       3.2405737404      -1.6948630701       1.1550947815
              H       4.7413122793      -0.9696206675      -2.2019627016
              H       5.2682634275      -1.4224562927      -0.5697016981
              H       4.0207741768      -2.3678486307      -1.3823132687
              H       3.3492013700       0.9769174860      -2.2000472489
  End
End

Engine dftb
  Model GFN1-xTB
EndEngine
```
### Product

GFN1-xTB geometry optimization and harmonic normal modes from the 1.5 Å scan endpoint.

```ams
Properties
  NormalModes yes
End

Task GeometryOptimization

System
  Atoms
              C       0.2727454588       2.1733276750      -1.0949727072
              C      -0.4695956457       1.2742361392      -0.1540261068
              C      -1.1050803480       0.1756719103      -0.5401584839
              C      -1.8905843685      -0.7033492757       0.3887482533
              C      -3.3850787001      -0.6737164224       0.0313866413
              C      -4.1961134004      -1.5791287731       0.9628849611
              C      -5.6828852851      -1.5498643388       0.6118206344
              C       3.6347404396       2.4047543696       0.4997113073
              C       4.7159874530       1.6134167929       0.8457288890
              C       4.7229710234       0.2576382213       0.5459763762
              C       3.6364681225      -0.3139508997      -0.1107070676
              C       3.6444542523      -1.7844534637      -0.4364030571
              C       2.5468038488       0.4764607905      -0.4637857683
              C       2.5403640294       1.8364356512      -0.1580102199
              O       1.5320352160       2.6887349682      -0.4636687950
              H      -0.2977883956       3.0870756354      -1.2888412653
              H       0.5183303018       1.6865500278      -2.0448223826
              H      -0.4668920139       1.5929689500       0.8839305572
              H      -1.1024816973      -0.1288932529      -1.5843745396
              H      -1.5245023888      -1.7327522204       0.3050965334
              H      -1.7543895805      -0.3770701537       1.4249711427
              H      -3.5166476048      -1.0011852344      -1.0054349599
              H      -3.7523887280       0.3552197272       0.1064017382
              H      -3.8241708482      -2.6065881731       0.8866697873
              H      -4.0604518958      -1.2506900076       1.9989161859
              H      -5.8410768346      -1.8937321509      -0.4113769329
              H      -6.0770378574      -0.5365996323       0.7018128823
              H      -6.2396700042      -2.2003106131       1.2868003253
              H       3.6183660932       3.4629726241       0.7296482927
              H       5.5634886637       2.0571999453       1.3567825361
              H       5.5730897941      -0.3557799202       0.8227697574
              H       2.7198414984      -2.0824863798      -0.9307355173
              H       4.4829563934      -2.0209507218      -1.0941816440
              H       3.7575440930      -2.3730567026       0.4758730382
              H       1.7066489154       0.0218949082      -0.9730723006
  End
End

Engine dftb
  Model GFN1-xTB
EndEngine
```