# Saving and reopening results

**Save results (.zip)** in the workbench (or the `export_results` tool, or `GET /api/export`)
writes one zip with every view of the analysis:

| File | What it is | Open it with |
|---|---|---|
| `spectra.vms` | The spectra as acquired, with each fit stored the way CasaXPS stores its own | CasaXPS, any VAMAS reader |
| `fits/<spectrum>.csv` | One row per point: binding energy (calibrated and as acquired), counts, background, every component, envelope, residual | Excel, Origin, Igor, Avantage, Python |
| `components.csv` | One row per component: position, width, area and share, with one-sigma uncertainties | Spreadsheets |
| `quantification.csv` | Atomic and weight percent with the sensitivity factors used | Spreadsheets |
| `models/<spectrum>.yaml` | Each fit model | Load model in the workbench |
| `results.json` | The full record: fits, audits, model selection, provenance | Scripts |
| `session.json` | What xpsflow needs to rebuild the session | xpsflow |
| `original/` | The instrument files the session was loaded from | Any reader |
| `report.html`, `report.pdf` | The reports | A browser |

## Reopening

Drop the zip on the workbench, or call `load_data` with its path. The original files are read
again (or `spectra.vms` when they are absent), the recorded calibration shift is reapplied,
every model and hand-set window is put back, and each spectrum is refitted with its saved
model. Change anything and save a new package.

## CasaXPS

CasaXPS keeps its processing in each VAMAS block comment, after a `Casa Info Follows` line:
processing steps (`Calib M = 285.10 A = 284.8 BE ADD`), then `CASA region` lines (window,
background, sensitivity factor, tag) and `CASA comp` lines (line shape and the value, limits and
link of the area, width and position). `spectra.vms` writes the same lines:

- **Energies.** Region and component energies are kinetic, `KE = hv - BE`, on the calibrated
  scale. The spectrum stays as acquired, and the calibration is a `Calib` line, as CasaXPS
  writes it.
- **Line shapes.** The sum-form pseudo-Voigt is `SGL(m)` and the product form `GL(m)`, with `m`
  the Lorentzian percentage. CasaXPS shapes have a fixed mix, so the fitted mix is written.
  Asymmetric shapes have no exact CasaXPS form; they are written as the nearest symmetric shape
  and the package README lists each one.
- **Doublets and ties.** A doublet's second line is a component of its own, linked to the main
  line. Its area is the ratio times the main area; its position is the main position plus the
  splitting, written as an offset of minus the splitting on the kinetic scale. Ties of the form
  `{A.center} + d`, `{A.area} * r` and `{A.fwhm} * f` become the same links.
- **Sensitivity factors and masses.** These are filled in when the session has been quantified,
  so CasaXPS's own quantification uses the same factors.

The reverse also works. A VAMAS file that CasaXPS has fitted loads with each block's components
as that spectrum's model, with links turned into ties. When every block records the same `Calib`
shift, that shift is applied. Refit with model selection off to fit the CasaXPS model exactly as
written.

No CasaXPS manual documents these lines. The layout follows files saved by CasaXPS and the open
readers that parse them, and the test suite reads lines exactly as CasaXPS writes them. Two
fields have no documented meaning, the averaging width and the region's next-to-last number;
they are written with the values CasaXPS itself writes most often. Saving one fit from CasaXPS
and comparing it with an xpsflow export is the check that settles them.

## Avantage and other programs

Avantage keeps its data in its own binary files and exports fits to Excel. It can read the CSV
tables. Whether it imports VAMAS is not documented. Any program that reads VAMAS gets the
spectra from `spectra.vms`.
