Metadata-Version: 2.4
Name: qm_etdac_calculator
Version: 1.2.1
Summary: X-ray Absorption Spectroscopy (XAS) program that calculates excited-state charge transfer as a core-electron transition decomposition analysis
Author-email: "Carlos A. Ortiz-Mahecha" <ortizmahecha@proton.me>
License-Expression: GPL-3.0-or-later
Project-URL: Homepage, https://github.com/caraortizmah/atomistic_oscillator_strength
Project-URL: Repository, https://github.com/caraortizmah/atomistic_oscillator_strength.git
Project-URL: Documentation, https://github.com/caraortizmah/atomistic_oscillator_strength/blob/main/docs
Project-URL: Issues, https://github.com/caraortizmah/atomistic_oscillator_strength/issues
Keywords: quantum-chemistry,xas,x-ray,spectroscopy,excited-state,charge-transfer,molecular-orbitals
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Natural Language :: English
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Chemistry
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.26
Requires-Dist: pandas>=2.1
Requires-Dist: h5py>=3.10
Provides-Extra: dev
Requires-Dist: pip-tools>=7.4; extra == "dev"
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: pytest-cov>=5.0; extra == "dev"
Requires-Dist: ruff>=0.15; extra == "dev"
Requires-Dist: mypy>=1.10; extra == "dev"
Requires-Dist: pre-commit>=4.0; extra == "dev"
Requires-Dist: twine>=6.0; extra == "dev"
Dynamic: license-file

# atomistic_oscillator_strength

Calculates the **electron transition density atomic contribution (ETDAC) matrix** from X-ray absorption spectroscopy (XAS) calculations. The ETDAC matrix _splits_ the core-electron transition intensities (from core to virtual molecular orbitals) into contributions from pairs of atoms: the atom the core electron leaves (core atom) and the atom where it arrives (virtual atom). With it, excited-state charge transfer between molecular fragments can be quantified, for example in π-stacked aromatic amino acids.

The method and its applications are described in:

> *X-ray absorption spectroscopy reveals charge transfer in π-stacked aromatic amino acids*, Phys. Chem. Chem. Phys. (2025). https://doi.org/10.1039/D4CP04615C

The ETDAC matrix element is written in the paper as [$$\tilde{\gamma}^{[l,m]}_{AA^{\prime}}$$](https://pubs.rsc.org/en/content/articlelanding/2025/cp/d4cp04615c). It is built from three inputs per molecular geometry: the Löwdin populations of the core molecular orbitals (MOs) on each atom, the Löwdin populations of the virtual MOs on each atom, and the core-electron transition intensities from each core MO to each virtual MO.

## How it works

```mermaid
flowchart LR
    A["ORCA XAS<br/>calculations"] --> B["xas-qmol-parser"]
    B --> C["Inputs per geometry:<br/>core-MO populations,<br/>virtual-MO populations,<br/>core-electron<br/>transition intensities<br/>(3 list files + CSV matrices)"]
    C --> D["qm_etdac_calculator<br/>checks the inputs,<br/>calculates ETDAC"]
    D --> E["etdac_outputs/<br/>data_etdac_matrix.h5<br/>(one matrix per geometry)"]
    D --> F["data_etdac_matrix.log<br/>(what happened in the run)"]
    E --> G["Your analysis:<br/>heatmaps, notebooks"]
```

The inputs come from [xas-qmol-parser](https://github.com/caraortizmah/x-ray_scripting_out), which parses ORCA outputs. Their format, and how to keep one folder per system, are described in [docs/input-format.md](https://github.com/caraortizmah/atomistic_oscillator_strength/blob/main/docs/input-format.md). An earlier result is never overwritten: it is kept as `data_etdac_matrix_oldversionN.h5`.

## Install

Python 3.11 or newer, in a virtual environment:

```bash
python3 -m venv .venv && source .venv/bin/activate
pip install qm-etdac-calculator
qm-etdac-test        # checks that the installation calculates correctly
```

To run the example below with the data shipped in the repository, or to use the notebooks, install from a clone instead:

```bash
git clone https://github.com/caraortizmah/atomistic_oscillator_strength.git
cd atomistic_oscillator_strength
python3 -m venv .venv && source .venv/bin/activate
pip install .
```

More options in [docs/installation.md](https://github.com/caraortizmah/atomistic_oscillator_strength/blob/main/docs/installation.md).

## Run

From the folder with the three list files (the project folder), here the Phe–Tyr example data shipped with the tests:

```bash
cd tests/data/phe_tyr
qm-etdac noauto --list-input resA_MOcore_list.log resB_MOvirt_list.log corevirt_fosce_AB_list.log
```

The result is `etdac_outputs/data_etdac_matrix.h5` (one matrix per geometry), with the run log next to it. `qm-etdac-test` checks the installation in a second. Settings in a JSON file (`auto`), checking the inputs without calculating (`check`), the terms between fragments and a plotting script: [docs/examplesrun.md](https://github.com/caraortizmah/atomistic_oscillator_strength/blob/main/docs/examplesrun.md).

The same calculation from Python, run from the repository folder:

```python
from qm_etdac_calculator import ConfigMan, Scheme

config = ConfigMan(
    corepop="resA_MOcore_list.log",       # core-MO populations
    virtpop="resB_MOvirt_list.log",       # virtual-MO populations
    etranscv="corevirt_fosce_AB_list.log",  # core-electron transition intensities
    logspath="tests/data/phe_tyr",        # the folder with the three list files
)
scheme = Scheme(config)
paths = scheme.prepare_outputs()  # tests/data/phe_tyr/etdac_outputs/; an earlier result is kept
etdac = scheme.run(paths)         # {sample hash: core-atom x virtual-atom matrix}, also written to paths.h5
```

Each sample in the `.h5` file is a group `sample_<hash>` with the dataset `ETDAC_matrix`. The file also records which program version made it and which input files were used.

## Notebooks

The original analysis notebooks are kept in the repository:

- `popmatrices/`: ETDAC calculation and post-analysis. The reference calculation is [popmatrices/Bigscale/ETDAC_matrix_calculator.ipynb](https://github.com/caraortizmah/atomistic_oscillator_strength/blob/main/popmatrices/Bigscale/ETDAC_matrix_calculator.ipynb); the general post-analysis template is [popmatrices/Standard_analysis/postanalysis_generalcase.ipynb](https://github.com/caraortizmah/atomistic_oscillator_strength/blob/main/popmatrices/Standard_analysis/postanalysis_generalcase.ipynb). Examples: Phe–Tyr with the first 17 (`FY_1-17`) and 26 (`newFY_1-26`) excited states.
- `plot/`: XAS spectra plotted directly from the ORCA outputs.

## For developers

How the program is built, tested, logged, debugged and hardened: [docs/development.md](https://github.com/caraortizmah/atomistic_oscillator_strength/blob/main/docs/development.md). Design decisions: [docs/adr/](https://github.com/caraortizmah/atomistic_oscillator_strength/tree/main/docs/adr). Status and plans: [docs/project-state.md](https://github.com/caraortizmah/atomistic_oscillator_strength/blob/main/docs/project-state.md). Changes: [CHANGELOG.md](https://github.com/caraortizmah/atomistic_oscillator_strength/blob/main/CHANGELOG.md). Time, memory and disk for large data sets (100 to 1 000 000 samples): [docs/performance-and-scale.md](https://github.com/caraortizmah/atomistic_oscillator_strength/blob/main/docs/performance-and-scale.md).

## License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. See [LICENSE](https://github.com/caraortizmah/atomistic_oscillator_strength/blob/main/LICENSE).
