Metadata-Version: 2.4
Name: abhidharma
Version: 0.1.0
Summary: An educational Abhidhamma mind-process and kamma simulation toolkit
Author: Abhidharma contributors
License: MIT
Project-URL: Repository, https://github.com/ishanoshada/Abhidharma
Keywords: abhidharma,abhidhamma,citta,javana,kamma,buddhism,simulation
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Education
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Education
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: cli
Requires-Dist: rich>=13.7; extra == "cli"
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: ruff>=0.5; extra == "dev"
Requires-Dist: build>=1.2; extra == "dev"
Dynamic: license-file

# Abhidharma

**An educational Abhidhamma process simulator** — explore *citta-vīthi*, *javana*, *cetasika*, and *kamma* with Python APIs and a terminal animation.

> This is a simplified learning model of classical Theravāda Abhidhamma descriptions, not a scientific model of the brain, a way to inspect another person's mind, or a karmic prediction engine. Its data, terminology, transliterations, and explanations may contain mistakes or omissions. Verify doctrinal points against the original Theravāda Pāli Tipiṭaka and trusted teachers or editions; this software is not a canonical authority.

## Install

```bash
python -m pip install -e ".[cli]"
# or, after publication:
python -m pip install abhidharma
```

No runtime dependencies are required. Install the `cli` extra for the polished Rich terminal UI.

## Quick start — Python API

```python
from abhidharma import simulate_eye_vithi, simulate_mind_door_vithi
from abhidharma.animation import play

eye = simulate_eye_vithi(
    object_name="blue lotus",
    javana="kusala",           # kusala | akusala | kiriya
    feeling="somanassa",       # somanassa | upekkha | domanassa
)
print(eye.summary())
play(eye, speed=1.0, color=True, theme="ocean")

mind = simulate_mind_door_vithi(
    object_name="remembered sound",
    javana="kusala",
)
for moment in mind.moments:
    print(moment.index, moment.name, moment.singlish)
```

The Python renderers and animations use Ocean colors by default. To set them explicitly, pass `color=True, theme="ocean"` as in the example; pass `color=False` for plain output. `play` displays one moment at a time for about `0.45 / speed` seconds each, so an 18-moment process takes about 8 seconds at the default speed. Increase `speed` to shorten the animation, for example `play(eye, speed=2.0, color=True, theme="ocean")`.

## CLI

```bash
abhidharma
abhidharma simulate eye --object "blue lotus" --javana kusala --feeling somanassa
abhidharma simulate eye --object "blue lotus" --lang singlish
abhidharma simulate eye --object "blue lotus" --lang en
abhidharma --plain simulate eye --object "blue lotus" --lang singlish
abhidharma simulate profile --name "Demo User" --birthday 2000-01-01 --location "Colombo" --sex female --lang singlish
abhidharma simulate mind --object "memory of a song" --javana akusala
abhidharma karma --type kusala --function janaka
abhidharma javan --root alobha --feeling somanassa
abhidharma javan --expand --lang sin
abhidharma simulate live --lang sin --duration 60 --refresh-ms 50 --motion-speed 1.5
abhidharma simulate live --theme ocean --duration 60
abhidharma planes
abhidharma simulate rebirth
abhidharma simulate rebirth --to 9 --lang en
abhidharma simulate rebirth --to 9 --lang singlish --expand
abhidharma --plain simulate rebirth --to 9 --lang singlish
abhidharma explain vithi
abhidharma explain rebirth
abhidharma --help
```

### CLI quick reference

| Task | Example |
|---|---|
| Open the dashboard / select Singlish | `abhidharma` / `abhidharma --lang sin` |
| Eye-door process | `abhidharma simulate eye --object "blue lotus" --javana kusala --feeling somanassa` |
| Print a non-animated JSON result | `abhidharma simulate eye --json` |
| Save JSON to a file | `abhidharma simulate eye --output eye.json` |
| Eye-door, English or Singlish | `abhidharma simulate eye --object "blue lotus" --lang en` / `abhidharma simulate eye --object "blue lotus" --lang singlish` |
| Plain eye-door output | `abhidharma --plain simulate eye --object "blue lotus" --lang sin` |
| Profile-context example | `abhidharma simulate profile --name "Demo User" --birthday 2000-01-01 --location "Colombo" --sex female --lang singlish` |
| Mind-door process | `abhidharma simulate mind --object "memory of a song" --javana akusala` |
| Kamma classification | `abhidharma karma --type kusala --function janaka` |
| Configure javana | `abhidharma javan --root alobha --feeling somanassa` |
| Explain seven javana moments | `abhidharma javan --expand --lang sin` |
| Run live simulation | `abhidharma simulate live --lang sin --duration 60 --refresh-ms 50 --motion-speed 1.5` |
| Choose a live color theme | `abhidharma simulate live --theme ocean --duration 60` |
| List the 31 planes | `abhidharma planes` |
| Choose rebirth destination interactively | `abhidharma simulate rebirth` |
| Select a rebirth destination | `abhidharma simulate rebirth --to 9 --lang en` |
| Expanded rebirth example | `abhidharma simulate rebirth --to 9 --lang singlish --expand` |
| Plain rebirth output | `abhidharma --plain simulate rebirth --to 9 --lang singlish` |
| Explain model topics | `abhidharma explain vithi` / `abhidharma explain rebirth` |
| Show command help | `abhidharma --help` |

### Python code examples

| Example | Demonstrates |
|---|---|
| Python quick start | Build and animate eye-door and mind-door processes |
| API recipe | Build a sense-door process, javana, kamma classification, and rebirth; render bilingual output |
| Profile-context example | Render a selected process with optional display-only profile information |
| 31-plane example | Browse `PLANES` and render a user-selected rebirth illustration |

### Python API quick reference

| API | Purpose |
|---|---|
| `simulate_eye_vithi(object_name=...)` | Build an eye-door process |
| `simulate_sense_door_vithi(door=..., object_name=...)` | Build an eye, ear, nose, tongue, or body process |
| `simulate_mind_door_vithi(object_name=...)` | Build a mind-door process |
| `simulate_javana(kind=..., root=...)` | Build a seven-moment javana example |
| `classify_kamma(...)` | Describe the selected kamma categories |
| `simulate_kamma_scenario(...)` | Return a structured kamma teaching scenario |
| `simulate_rebirth(destination)` | Build a user-selected rebirth illustration |
| `render(simulation, language=..., color=True, theme="ocean")` | Render English or Singlish text with the Ocean theme |
| `play(simulation, speed=1.0, color=True, theme="ocean")` | Animate a process in the terminal |
| `play_live(factory, ...)` | Continuously animate illustrative process examples |
| `PLANES` | Access the 31-plane catalogue |

### JSON output without animation

Use `--json` to print structured JSON instead of animating or rendering a command result. Use `--output FILE` to save UTF-8 JSON without printing the document; combine both flags to print and save it. These flags work before or after a command. The continuously running `simulate live` command does not support JSON output.

| Command | JSON result |
|---|---|
| `abhidharma simulate eye --json` (also `mind`, `profile`, or `rebirth`) | Simulation dictionary with moments and assumptions; profile adds context, rebirth adds an explanation |
| `abhidharma javan --json` | Javana simulation and moments |
| `abhidharma karma --json` | Structured kamma scenario |
| `abhidharma planes --json` | Array of 31 plane records |
| `abhidharma explain vithi --json` | Topic and explanation text |

```bash
# Print JSON to the terminal
abhidharma --json simulate eye --object "blue lotus"

# Save JSON to a file
abhidharma simulate eye --object "blue lotus" --output eye.json

# Print and save the same rebirth result
abhidharma simulate rebirth --to 9 --json --output rebirth.json
```

The Python API also returns data without starting an animation. Call `to_dict()` on a `VithiSimulation`, then print or save it with Python's standard `json` module:

```python
import json
from pathlib import Path

from abhidharma import simulate_eye_vithi

simulation = simulate_eye_vithi(object_name="blue lotus")
data = simulation.to_dict()
json_text = json.dumps(data, ensure_ascii=False, indent=2)

print(json_text)
Path("eye.json").write_text(json_text + "\n", encoding="utf-8")
```

```python
from abhidharma import (
    classify_kamma,
    simulate_eye_vithi,
    simulate_javana,
    simulate_rebirth,
    simulate_sense_door_vithi,
)
from abhidharma.animation import render

eye = simulate_eye_vithi(object_name="blue lotus")
ear = simulate_sense_door_vithi(door="ear", object_name="birdsong")
javana = simulate_javana(kind="kusala", root="alobha")
rebirth = simulate_rebirth(destination=9)

print(eye.summary())
print(render(ear, language="singlish", color=True, theme="ocean"))
print(javana.moments[0].english)
print(classify_kamma().function_english)
print(render(rebirth, language="en", color=True, theme="ocean"))
```

`abhidharma` opens an interactive dashboard when run without arguments. Use `abhidharma --lang sin` (or `--lang s`) to open its Singlish version; `--lang e` selects English. Dashboard option 6 explains anicca, dukkha, and anatta in the selected language; option 7 opens the [Abhidhamma learning website](https://abhidhamma.ishanoshada.com/) in your browser (see its [source repository](https://github.com/ishanoshada/abhidharma-margaya-visualizer)); option 8 starts the live citta-vīthi simulation (stop it with Ctrl-C); option 9 prints ten example CLI commands; option 10 shows accuracy notes and Tipiṭaka resources. Language-aware subcommands also accept those aliases. `abhidharma javan --expand` explains each of the seven repeated javana moments, their possible kamma result timings, and their place in a mind-door process; the result timings are possibilities, not guarantees. Press Ctrl-C to stop an animation without a traceback. The installed distribution, command, and Python import namespace are all named `abhidharma`. Arrow-free keyboard menus work in basic terminals; Rich is used when installed. `--plain` can be used for script-friendly output.

`abhidharma simulate live` continuously cycles through illustrative eye-, ear-, nose-, tongue-, body-, and mind-door processes, choosing a random starting door, next door, and example object. The live panel reflows to the current terminal width, including while it is resized, and shows the current citta sequence and progress. Ctrl-C leaves the last panel visible and prints a stop message. This is a display randomizer, not a model or prediction of anyone's actual mental stream. Stop it with Ctrl-C or pass `--duration SECONDS`. `--refresh-ms` sets the display refresh (default 16 ms; allowed 8–2000 ms) independently of `--motion-speed` (default 1.0; values above 1 move through citta moments faster). Very high motion speeds are limited by the selected refresh rate and shown on screen; elapsed time is not displayed. Live mode does not create log files.

The whole CLI, including the interactive dashboard and every command, uses the `ocean` color theme by default. Use `--theme` to select another palette (`lotus`, `forest`, `sunset`, or `mono`), or `--no-color` to disable ANSI colors. These options work before or after a command; for example, `abhidharma simulate live --theme sunset`.

### Profile-context simulation

`simulate profile` animates the standard eye-door process by default and can display optional name, birth date, location, and explicitly selected sex/rūpa-example context. The current local date-time is shown for each run. These values are display-only: they do not alter the process or predict citta, kamma, personality, or future events. Profile values are kept in memory for the run and are not written to package data or files.

For Python, import and render the simulation directly:

```python
from abhidharma import simulate_eye_vithi
from abhidharma.animation import render

simulation = simulate_eye_vithi(object_name="visible form")
print(render(simulation, language="singlish", color=True, theme="ocean"))
```

### 31-plane rebirth teaching simulation

`abhidharma planes` lists all 31 planes with their Pāli names, English descriptions, and Singlish pronunciations. Run `abhidharma simulate rebirth` to display the list and choose a destination by number interactively, or pass `--to 9` for a direct choice. Select animation text with `--lang en`/`--lang e` or `--lang singlish`/`--lang sin`/`--lang s`. The normal animation shows cuti-citta, paṭisandhi-citta, and bhavaṅga, followed by an explanation in both English and Singlish. Add `--expand` for 2 illustrative preceding bhavaṅga moments, the 3 core moments, and 2 later bhavaṅga moments; set a count from 1–10 with `--expand 8`. These added counts are display examples, not fixed doctrinal counts. This is a user-selected teaching example, not a prediction: the package does not use personal details or calculate kamma or the conditions for an actual rebirth.

```python
import sys

from abhidharma import PLANES, simulate_rebirth
from abhidharma.animation import render

if hasattr(sys.stdout, "reconfigure"):
    sys.stdout.reconfigure(encoding="utf-8")

for plane in PLANES:
    print(plane.number, plane.english, "|", plane.singlish)

simulation = simulate_rebirth(9)  # user-selected destination
print(render(simulation, language="singlish"))
```

## What is modelled

### Citta-vīthi

The five-door visual example follows the textbook's explanatory sequence:

1. Atīta-bhavaṅga — past life-continuum moment
2. Bhavaṅga-calana — vibration of the life-continuum
3. Bhavaṅgupaccheda — arrest of the life-continuum
4. Pañcadvārāvajjana — five-door adverting
5. Cakkhuviññāṇa — eye-consciousness
6. Sampaṭicchana — receiving
7. Santīraṇa — investigating
8. Votthapana — determining
9. Javana × 7 — impulsion
10. Tadārammaṇa × 2 — registration (where applicable)
11. Return to bhavaṅga

The process is an **illustrative full-strength eye-door pattern**. The source text also describes other object-strength classes and cases where registration does not occur. This implementation does not pretend one sequence covers every possible vīthi.

The mind-door API uses a compact teaching pattern: manodvārāvajjana followed by seven javana moments and return to bhavaṅga. It is intentionally labelled a teaching template, not an exhaustive catalogue of the nine patterns discussed in the source.

### Javana

Javana is represented as a repeated run of seven impulsion moments in the standard example. The selected ethical class is a user-supplied scenario parameter. The library does not infer a person's kusala/akusala state from their behaviour.

### Kamma

The API exposes the three fourfold classifications explained in *Abhidharma Mārga*:

- **By function:** janaka, upatthambhaka, upapīḷaka, upaghātaka.
- **By order of giving result:** garuka, āsanna, āciṇṇa, katattā.
- **By time of result:** diṭṭhadhammavedanīya, upapajjavedanīya, aparāpariyavedanīya, ahosi.

These are doctrinal categories. The package can demonstrate category descriptions and priority rules, but cannot calculate a real person's future birth, lifespan, fortune, illness, or karmic result.

## English and Singlish

Each core term carries:
- Pāli transliteration
- English explanation
- Singlish (Sinhala pronunciation-based phrasing written in Latin characters), for example `Athitha bhawanga chiththaya`.

Singlish is a learning aid, not a canonical translation. Use `language="en"` or `language="singlish"` in renderers.

## Project layout

```text
abhidharma/
  citta/          Citta classifications and roots
  cetasika/       Mental factors and groups
  chiththa_vithi/ Five-door and mind-door process builders
  javan/          Javana configuration and seven moments
  karma/          Kamma classifications and scenario descriptions
  simulation/     Shared event model and deterministic engine
  animation/      Terminal timeline / 2D-style renderer
  data/           Built-in terminology catalogue
  cli.py          Command-line interface
  api.py          Public convenience API
```

## Source basis

The initial doctrinal map is based on the two user-provided Sinhala books by Rērukāne Candavimala Thero:

- *Abhidharmaye Mūlika Karuṇu*: citta, cetasika, roots, and paccaya topics.
- *Abhidharma Mārga*: citta-vīthi (chapter 4, printed pp. 89–116), kamma classifications and death/relinking topics (chapter 5, printed pp. 127–147), plus the citta/cetasika classifications.

For checking primary texts, see the [Chaṭṭha Saṅgāyana Pāli Tipiṭaka](https://www.tipitaka.org/) and [SuttaCentral's Pāli texts and translations](https://suttacentral.net/). The book's terminology and teaching sequence are prioritised. Some implementation details are explicitly marked as simplifications where a complete rule table would be required. The package can contain mistakes and is not a substitute for studying the original texts with a qualified teacher.

## Development

```bash
python -m pytest
abhidharma
```

MIT License. See `LICENSE`.
