Metadata-Version: 2.4
Name: mcta
Version: 0.0.11
Summary: McTa (Meta Crystal Toolkit & Analysis).
Author: Kan
License-Expression: MIT
Project-URL: Homepage, https://github.com/lkccrr/mcta
Keywords: DFT,VASP,DOS,band,plot,Phonon,materials-project,pymatgen,crystal-structure,SQS,Ising,Monte-Carlo,magnetism
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Physics
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
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: Programming Language :: Python :: 3.15
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.22.0
Requires-Dist: matplotlib>=3.6.0
Requires-Dist: ase>=3.22.0
Requires-Dist: spglib>=2.0
Provides-Extra: seek
Requires-Dist: pymatgen>=2024.1.1; extra == "seek"
Requires-Dist: mp-api>=0.40; extra == "seek"
Requires-Dist: scikit-learn>=1.3; extra == "seek"
Requires-Dist: joblib>=1.3; extra == "seek"
Requires-Dist: openai>=1.30; extra == "seek"
Provides-Extra: skl
Requires-Dist: scikit-learn>=1.3; extra == "skl"
Requires-Dist: joblib>=1.3; extra == "skl"
Provides-Extra: sqs
Requires-Dist: sqsgenerator>=0.5; extra == "sqs"
Provides-Extra: mc
Requires-Dist: numba>=0.54.0; extra == "mc"
Provides-Extra: all
Requires-Dist: mcta[mc,seek,skl,sqs]; extra == "all"
Dynamic: license-file

[![mcta](https://img.shields.io/pypi/v/mcta?style=flat-square)](https://pypi.org/project/mcta/)
[![mcta](https://img.shields.io/pypi/pyversions/mcta?style=flat-square)](https://pypi.org/project/mcta/)
[![mcta](https://img.shields.io/pypi/l/mcta?style=flat-square)](https://pypi.org/project/mcta/)
[![mcta](https://img.shields.io/pypi/dm/mcta?style=flat-square)](https://pypi.org/project/mcta/)
[![mcta](https://img.shields.io/pypi/wheel/mcta?style=flat-square)](https://pypi.org/project/mcta/)
[![mcta](https://img.shields.io/github/last-commit/lkccrr/mcta?style=flat-square)](https://github.com/lkccrr/mcta)
[![mcta](https://img.shields.io/github/release-date/lkccrr/mcta?style=flat-square)](https://github.com/lkccrr/mcta)

### Meta Crystal Toolkit & Analysis (McTa)

* Install (Python &ge; 3.9; core dependencies: `numpy`, `matplotlib`, `ase`):
```bash
pip install mcta          # plotting tools only
pip install mcta[seek]    # + mt.seek (pymatgen, mp-api, openai); also enables mt.skl
pip install mcta[skl]     # + mt.skl (scikit-learn, joblib)
pip install mcta[sqs]     # + mt.sqs (sqsgenerator)
pip install mcta[mc]      # + mt.mc (numba)
pip install mcta[all]     # all: seek + skl + sqs + mc
```
Every extra is optional; only the tools that need one ask for it (`mt.seek` &rarr; `mcta[seek]`, `mt.skl` &rarr; `mcta[skl]`, `mt.sqs` &rarr; `mcta[sqs]`, `mt.mc` &rarr; `mcta[mc]`).
***
<b style="color:blue;"><i>mt</b></i> prints an overview, checks the current directory and suggests the next command.
***
<b style="color:blue;"><i>mt.band</b></i>: VASP band structures, with optional `vaspkit` data
* `-i` selects a directory (default: current); VASP output is preferred, otherwise `BAND.dat` / `PBAND*.dat` / `PDOS*.dat` are used. `-d` adds DOS, `-r -p Mo-d` adds projections, and `-D -d` makes a spin-polarized mirror plot.
* `-m` calculates effective masses; two or three directories compare calculations; `-l` sets k-path labels and `--export-dat DIR` exports vaspkit-style data.
* Energies are shifted to the Fermi level (`--no-shift` disables this); k-path labels come from `KPOINTS` / `KLABELS` or are computed automatically.
* For combined SCF-mesh/band-path calculations, only zero-weight path points are plotted; `--keep-weights` keeps every k point. vaspkit `.dat` files are used unchanged.
```bash
mt.band                         # bands of the current directory
mt.band -i calc_PBE -d -z       # bands + DOS (DOSCAR or PDOS*.dat)
mt.band -i calc_PBE -r -p Mo-d  # projected bands from PROCAR
mt.band -i calc_PBE -D -d       # spin-polarized bands + mirror DOS
mt.band -i calc_PBE -m 0.15     # effective masses from EIGENVAL
mt.band -i calc_PBE calc_HSE    # compare calculations
```
***
<b style="color:blue;"><i>mt.dos</b></i>: DOS / PDOS as a standalone figure, energy on the horizontal axis
* Reads `DOSCAR` (needs `LORBIT = 11`) or vaspkit `PDOS*.dat` / `TDOS*.dat`; `-i` takes a directory or `.dat` files, defaulting to the current directory.
* `-n` exchanges the axes to match the `mt.band -d` panel; `--no-mirror` keeps the spin-down DOS positive.
* `-p` picks projections, `-e` renames the legend, `-x` sets the DOS range, `-y` the energy window, and `-z` fills the curves.
```bash
mt.dos -i calc                 # DOS from DOSCAR / PDOS*.dat (energy on x)
mt.dos -i calc -p d -x 0 30    # d-orbital PDOS with a fixed DOS range
mt.dos -i calc -o PDOS.png -z  # filled curves
mt.dos -i calc -n              # energy vertical (mt.band -d orientation)
```
***
<b style="color:blue;"><i>mt.phband</i></b>: phonon band structure with an optional DOS panel
* `-i` takes `BAND.dat` written by `phonopy-bandplot --gnuplot`; `-l` labels high-symmetry points and `-y` sets the frequency window.
* `-d [FILE]` adds a DOS panel sharing the frequency axis (`projected_dos.dat` / `total_dos.dat` auto-detected); use `mt.phdos` for a standalone DOS figure.
* `-B start end` breaks the axis for optical branches; two or three files are compared side by side.
```bash
mt.phband -h                                # all parameters
mt.phband -i BAND.dat -o BAND.png -l g m k g -d projected_dos.dat -z
mt.phband -B 23 100 -l g m k g -y -2 110    # broken axis
mt.phband -i BAND1.dat BAND2.dat -B 20 100  # several files
```
***
<b style="color:blue;"><i>mt.phdos</b></i>: phonon DOS as a standalone figure, frequency on the horizontal axis
* Reads `projected_dos.dat` or `total_dos.dat`; `-i` takes a directory or `.dat` file, defaulting to the current directory.
* `-n` exchanges the axes to match the `mt.phband -d` panel.
* `-e` renames the legend, `-x` sets the DOS range, `-y` the frequency window, and `-z` fills the curves.
```bash
mt.phdos                   # DOS of the current directory
mt.phdos -i calc -z        # filled curves
mt.phdos -i calc -x 0 0.6  # fix the DOS range
mt.phdos -i calc -n        # frequency vertical (mt.phband -d orientation)
```
***
<b style="color:blue;"><i>mt.ph</b></i>: phonopy workflow helper
* The default interactive workflow covers supercell &rarr; force constants &rarr; band &rarr; DOS; `-b -d` writes `band.conf` + `mesh.conf`, `-Y` skips confirmation, and `-R` only prints commands.
* The unit cell is auto-detected (`POSCAR-unitcell` &rarr; `CONTCAR` &rarr; `POSCAR`) or set with `-c`; commands adapt to phonopy v3/v4.
* `fs` collects force data: one `vasprun.xml` uses `--fc`, while several files or displacement directories use `--sp -f`; sources come from names, `-n`, or `-x`.
* Additional steps include `band`, `dos`, `tprop`, `born`, `symmetry`, `qha`, and `gruneisen`; see `mt.ph -h` for all options.
* `w` / `W` queries the offline English/Chinese wordbook; `w c` lists setting tags, `--path` shows its location, and `MT_PH_DOCS` selects a custom JSON file.
```bash
mt.ph                      # interactive workflow (default: supercell)
mt.ph -b -d                # write band.conf + mesh.conf
mt.ph fs 001-003           # collect forces from displacement directories
mt.ph band                 # band.conf -> band.yaml -> BAND.dat
mt.ph dos --total          # mesh.conf -> projected_dos.dat + total_dos.dat
mt.ph w --dim BAND_LABELS  # English original, then Chinese translation
```
***
<b style="color:blue;"><i>mt.ph3</b></i>: phono3py lattice thermal-conductivity workflow
* Guides supercell generation, force collection, and thermal-conductivity calculations, with commands adapted to phono3py v3/v4; `-Y` skips confirmation and `-R` only prints commands.
* `-s` / `-S` set FC3 / FC2 supercell dimensions, `-c` sets the unit cell, and `--rd` creates random-direction displacements.
* `cf3` / `cf2` collect forces, while `cfs` and `fs2f2` convert force-set formats; `--sp` writes `phono3py_params.yaml`.
* `kappa` runs RTA by default (`--lbte` for direct LBTE); `kaccum` writes cumulative conductivity, `kdeplot` shows lifetime distributions, and `w` / `W` queries the offline wordbook.
```bash
mt.ph3 supercell -s 2 2 2 -S 4 4 4   # separate FC3 and FC2 supercells
mt.ph3 cf3 -n disp-{00001..00755}    # displacement forces -> FORCES_FC3
mt.ph3 kappa -m 11 11 11             # RTA -> kappa-m111111.hdf5
mt.ph3 kappa -m 11 11 11 --lbte      # direct LBTE solution
mt.ph3 kaccum -k kappa-m111111.hdf5  # cumulative conductivity -> kaccum.dat
mt.ph3 w --br --symfc                # English original, then Chinese translation
```
***
<b style="color:blue;"><i>mt.seek</b></i>: Materials Project retrieval and curation
Retrieves structures, writes CIF / POSCAR / JSON bundles with optional calculation templates, and filters or deduplicates local datasets; no calculations run locally. Set the API key once (free account at https://next-gen.materialsproject.org), then run searches or curation:
```bash
mkdir -p ~/.config/mcta
echo 'MP_API_KEY=your-key' >> ~/.config/mcta/config
chmod 600 ~/.config/mcta/config
mt.seek -c Ti-C -k 3 -n ti-c        # search by chemical system, export top 3
mt.seek -f MoS2 -k 5 -F cif,poscar  # search by formula
mt.seek -r -D 8 -o my-pick          # deduplicate + pick 8 diverse structures
```
Bundles land in `exports/<name>/` plus `exports/<name>.tar.gz`; `-I` accepts MP IDs, `-t` accepts natural-language tasks, and `-T` downloads more structures.
`mt.seek -h` lists all options, LLM engines, and `MT_SEEK_*` environment variables; short options are case-sensitive.
> ### Citation
>
> Structure data comes from the Materials Project: A. Jain et al., *APL Materials* 1, 011002 (2013).
***
<b style="color:blue;"><i>mt.sqs</b></i>: special quasirandom structures from a custom unit cell
Reads POSCAR / CONTCAR / CIF / JSON, expands a supercell, and randomises one sublattice toward a target composition using `sqsgenerator`; no network access is required.
```bash
mt.sqs -c cell.vasp -a "Cu:0.5,Au:0.5" -x 4,4,4 -n cuau-sqs
mt.sqs -c LaAlO3.cif --host La -a "La:0.5,Sr:0.5" -x 2,2,2    # A-site only
mt.sqs -c cell.vasp -a Cu,Au --iterations 1000 --number 5 -R  # dry-run: no disk write
```
Bundles contain `sqs.json` and `sqs_summary.csv`; `mt.sqs -h` lists every flag and default.
***
<b style="color:blue;"><i>mt.mc</b></i>: Monte Carlo simulation of phase transitions in 2D/3D magnetic materials
* Runs the Metropolis Ising model on built-in lattices (square, triangular, bilayer, simple-cubic) or from any crystal structure (`-s POSCAR -A Fe -D 3.0 3.6 -x 2 -y 2 -z 2`).
* `-x/-X`, `-y/-Y`, `-z/-Z` set lattice size (内置构型) or supercell multiplier (`-s` 结构模式), all defaulting to `32` (`-z` is ignored for 2D structures); `-e/-w` set equilibration/sampling sweeps, `-p/-J/-K` set couplings, `-a` sets anisotropy, `-i` selects the initial state; `--chain`, `--swaps`, and `--seeds` control parallel chains, replica exchange, and reproducibility.
* `-t` accepts a count (`35`), a range (`20 25`), start/stop/step (`20 26 2`), separate temperatures (`20 25 30`), or chained ranges.
* Structure mode (`-s`): reads any ASE-supported file, picks magnetic atoms (`-A Fe,Co` or auto-detects d/f-block), expands supercell with `-x/-y/-z`, builds the neighbor table by distance bins (`-D 3.0 3.6`); `-c` is ignored when `-s` is given. `--mom` sets nominal moments (default `2` → S=±1; per element via `--mom Fe 4.0 Cr 3.0` or `All 1.0`), `--ini` sets the initial state (default `fm`): `fm` / `afm` (alternating along z) / `random`, or a ±1 list in unit-cell magnetic-atom order (`--ini 1,-1,-1,1`). `-A`, `--mom`, `--ini` accept space- or comma-separated values.
* Vector spins: any of `-a`, `-J`, `-K` switches to the Heisenberg model; without them the Ising model is used. `-p` is the z-direction coupling; `-J` and/or `-K` override the x/y couplings.
* Requires `numba` (`pip install "mcta[mc]"`); ASE is also needed for structure mode. Plots are automatic unless `-R` is given, and `-o FILE -I pdf` re-plots a finished run.
```bash
mt.mc -x 128 -y 128 -t 0 40 2 --chain 6 --seeds 42   # 6 parallel chains, reproducible
mt.mc -c triangular -t 0 60 2 --seeds 42             # triangular lattice
mt.mc -c square -a 0.1 -t 20 40 2 -p 5 -J 4 -K 3     # vector spins with anisotropy
mt.mc -s POSCAR -A Fe -D 2.7 3.2 -x 2 -y 2 -z 2 -t 10 30 10 -p 5 2  # from crystal
mt.mc -o square_Ising_32_32.log -I pdf               # re-plot a finished run
```
***
<b style="color:blue;"><i>mt.sh</b></i>: run bash helper scripts by short name
* `mt.sh NAME [args...]` runs `NAME.sh` with bash; local `./NAME.sh` overrides `$MTSH_SCRIPTS`, then bundled scripts. Bare `mt.sh` lists available scripts.
* Strain scans `x|y|xy [POSCAR] [NPOINTS] [STEP]` write `<factor>/POSCAR` under `x/`, `y/`, or `xy/`; defaults are 4 points per side and step 0.01.
* `kb [POSCAR] [a [b [c]]] [OUT]` expands the structure with ASE and writes `SPOSCAR` by default; missing multipliers default to 1.
* `sy [POSCAR] [symprec]` reports spglib space-group and Wyckoff-site information; the default tolerance is `1e-3` &Aring;.
* Bundled VASP helpers target Linux/WSL; on Windows use Git Bash with `sed` / `awk` / `bc` available.
```bash
mt.sh x                  # x strain: x/0.960 ... x/1.040 (8 points, step 0.01)
mt.sh y POSCAR 2 0.02    # y strain, 2 points per side, step 0.02
mt.sh xy POSCAR          # x and y strained together
mt.sh kb POSCAR 2 2 1    # POSCAR -> SPOSCAR (2x2x1)
mt.sh sy POSCAR          # space group + Wyckoff sites (symprec 1e-3)
mt.sh sy CONTCAR 0.0001  # tighter tolerance: may lower the symmetry
```
***
<b style="color:blue;"><i>mt.server</b></i>: local file service and terminal in the browser
* Options: `-v/--version`, `-h/--help`, `-p/--port PORT` (default 9068), `-f/--foreground`, `-L/--host HOST` (default `127.0.0.1`; IPv4 and IPv6 literals such as `::1` are accepted), `-S/--stop`. The server goes to the background unless `-f` is given; starting it again on the same port stops the previous instance first.
* The log file `mcta-server-<port>.log` is written to the directory the command is started from; the PID file lives in `~/.cache/mcta/`. Leftover PID records are recognised and cleaned up automatically on the next start or `-S`.
* The service runs as the current user with no login step: it can read, edit and download everything that user can access. The browser opens in the directory where `mt.server` was started; paths outside it are shown as absolute. The terminal panel in the left column of the page is a real PTY shell (xterm.js) equivalent to an SSH session as the same user, also starting in that directory.
* Every start generates a new random token and prints it in the URL (`http://127.0.0.1:9068/?t=...`). All requests are checked against that token, so an old link stops working after a restart, and the link itself is the credential — do not share it.
* When the shell changes directory, the file browser follows it anywhere you have permission (paths outside the start directory are shown as absolute); the directory is polled every 2 seconds so new files and updated images appear automatically.
* Image previews follow the number of images in the directory: a single image takes 80% of the content width, two images share the row, and three or more are laid out three per row. Previews support PNG, JPG/JPEG, GIF, WebP, BMP, ICO and SVG; TIF/TIFF cannot be rendered by browsers and are downloaded as ordinary files.
* Loopback is the default. Binding another address requires an explicit `-L 0.0.0.0` (or similar) and prints a security warning; only do it on a network you trust.
```bash
mt.server                       # background on port 9068; the tokenized URL is printed
mt.server -p 8080               # another port
mt.server -L 0.0.0.0            # explicitly listen on all interfaces (prints a warning)
mt.server -f                    # foreground; Ctrl+C to stop
mt.server -S                    # stop the background service
```
