usif 0.12.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of usif might be problematic. Click here for more details.

Files changed (103) hide show
  1. usif-0.12.0/.github/workflows/ci.yml +99 -0
  2. usif-0.12.0/.github/workflows/publish.yml +148 -0
  3. usif-0.12.0/LICENSE +20 -0
  4. usif-0.12.0/MANIFEST.in +30 -0
  5. usif-0.12.0/PKG-INFO +218 -0
  6. usif-0.12.0/README.md +160 -0
  7. usif-0.12.0/docs/API_STABILITY.md +44 -0
  8. usif-0.12.0/docs/ARCHITECTURE.md +157 -0
  9. usif-0.12.0/docs/BINARY_FORMAT.md +150 -0
  10. usif-0.12.0/docs/CHANGELOG.md +495 -0
  11. usif-0.12.0/docs/CONTRIBUTING.md +85 -0
  12. usif-0.12.0/docs/FORMAT_VERSIONING.md +54 -0
  13. usif-0.12.0/docs/RELEASE.md +72 -0
  14. usif-0.12.0/examples/01_structures_and_records.py +50 -0
  15. usif-0.12.0/examples/02_dataset_workflow.py +56 -0
  16. usif-0.12.0/examples/03_library_conversion.py +33 -0
  17. usif-0.12.0/examples/04_upgrade_0_8_files.py +27 -0
  18. usif-0.12.0/examples/05_cli_workflow.py +47 -0
  19. usif-0.12.0/examples/06_local_dataset.py +49 -0
  20. usif-0.12.0/examples/07_agent_projects.py +87 -0
  21. usif-0.12.0/examples/08_export_query.py +58 -0
  22. usif-0.12.0/examples/README.md +26 -0
  23. usif-0.12.0/examples/quickstart.py +26 -0
  24. usif-0.12.0/pyproject.toml +152 -0
  25. usif-0.12.0/scripts/__init__.py +5 -0
  26. usif-0.12.0/scripts/benchmark.py +102 -0
  27. usif-0.12.0/scripts/check_release_metadata.py +194 -0
  28. usif-0.12.0/scripts/materials_project/__init__.py +21 -0
  29. usif-0.12.0/scripts/materials_project/__main__.py +91 -0
  30. usif-0.12.0/scripts/materials_project/archive.py +106 -0
  31. usif-0.12.0/scripts/materials_project/client.py +39 -0
  32. usif-0.12.0/scripts/materials_project/dependencies.py +25 -0
  33. usif-0.12.0/scripts/materials_project/downloader.py +112 -0
  34. usif-0.12.0/scripts/materials_project/loader.py +18 -0
  35. usif-0.12.0/scripts/materials_project/mapper.py +120 -0
  36. usif-0.12.0/scripts/materials_project/query.py +56 -0
  37. usif-0.12.0/setup.cfg +4 -0
  38. usif-0.12.0/tests/conftest.py +67 -0
  39. usif-0.12.0/tests/examples/test_examples.py +83 -0
  40. usif-0.12.0/tests/fixtures/format6/generate.py +206 -0
  41. usif-0.12.0/tests/fixtures/mp_structures.zip +0 -0
  42. usif-0.12.0/tests/integration/agent/test_agent_cli.py +300 -0
  43. usif-0.12.0/tests/integration/interop/test_backends_and_io.py +248 -0
  44. usif-0.12.0/tests/integration/materials_project/test_materials_project.py +120 -0
  45. usif-0.12.0/tests/integration/test_cli.py +205 -0
  46. usif-0.12.0/tests/reliability/test_upgrade.py +218 -0
  47. usif-0.12.0/tests/unit/agent/test_agent.py +562 -0
  48. usif-0.12.0/tests/unit/architecture/test_architecture.py +160 -0
  49. usif-0.12.0/tests/unit/codec/test_codec.py +376 -0
  50. usif-0.12.0/tests/unit/dataset/test_dataset.py +401 -0
  51. usif-0.12.0/tests/unit/model/test_model.py +266 -0
  52. usif-0.12.0/tests/unit/release/test_release_versioning.py +61 -0
  53. usif-0.12.0/tests/unit/symmetry/test_symmetry.py +142 -0
  54. usif-0.12.0/usif/__init__.py +78 -0
  55. usif-0.12.0/usif/agent/__init__.py +36 -0
  56. usif-0.12.0/usif/agent/config.py +212 -0
  57. usif-0.12.0/usif/agent/discover.py +352 -0
  58. usif-0.12.0/usif/agent/llm.py +133 -0
  59. usif-0.12.0/usif/agent/plan.py +441 -0
  60. usif-0.12.0/usif/agent/session.py +109 -0
  61. usif-0.12.0/usif/agent/tools.py +718 -0
  62. usif-0.12.0/usif/backends/__init__.py +23 -0
  63. usif-0.12.0/usif/backends/ase.py +166 -0
  64. usif-0.12.0/usif/backends/base.py +219 -0
  65. usif-0.12.0/usif/backends/matsimpy.py +140 -0
  66. usif-0.12.0/usif/backends/pymatgen.py +154 -0
  67. usif-0.12.0/usif/cli/__init__.py +12 -0
  68. usif-0.12.0/usif/cli/__main__.py +5 -0
  69. usif-0.12.0/usif/cli/agent.py +250 -0
  70. usif-0.12.0/usif/cli/common.py +49 -0
  71. usif-0.12.0/usif/cli/dataset.py +245 -0
  72. usif-0.12.0/usif/cli/plans.py +70 -0
  73. usif-0.12.0/usif/cli/root.py +221 -0
  74. usif-0.12.0/usif/codec/__init__.py +25 -0
  75. usif-0.12.0/usif/codec/columns.py +140 -0
  76. usif-0.12.0/usif/codec/compression.py +130 -0
  77. usif-0.12.0/usif/codec/jsondoc.py +126 -0
  78. usif-0.12.0/usif/codec/record.py +492 -0
  79. usif-0.12.0/usif/codec/wire.py +139 -0
  80. usif-0.12.0/usif/dataset/__init__.py +6 -0
  81. usif-0.12.0/usif/dataset/dataset.py +694 -0
  82. usif-0.12.0/usif/dataset/query.py +226 -0
  83. usif-0.12.0/usif/dataset/sql.py +160 -0
  84. usif-0.12.0/usif/elements.py +149 -0
  85. usif-0.12.0/usif/errors.py +63 -0
  86. usif-0.12.0/usif/fileio.py +56 -0
  87. usif-0.12.0/usif/formula.py +109 -0
  88. usif-0.12.0/usif/io.py +208 -0
  89. usif-0.12.0/usif/model/__init__.py +25 -0
  90. usif-0.12.0/usif/model/cell.py +125 -0
  91. usif-0.12.0/usif/model/properties.py +468 -0
  92. usif-0.12.0/usif/model/structure.py +285 -0
  93. usif-0.12.0/usif/symmetry/__init__.py +50 -0
  94. usif-0.12.0/usif/symmetry/expand.py +116 -0
  95. usif-0.12.0/usif/symmetry/reduce.py +168 -0
  96. usif-0.12.0/usif/symmetry/spacegroup.py +250 -0
  97. usif-0.12.0/usif/symmetry/tables.py +298 -0
  98. usif-0.12.0/usif/units.py +188 -0
  99. usif-0.12.0/usif/upgrade/__init__.py +21 -0
  100. usif-0.12.0/usif/upgrade/container_v2.py +272 -0
  101. usif-0.12.0/usif/upgrade/format6.py +464 -0
  102. usif-0.12.0/usif/version.py +95 -0
  103. usif-0.12.0/usif.egg-info/SOURCES.txt +100 -0
@@ -0,0 +1,99 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ # CI quality command guardrails for tests: black --check | isort --check-only | mypy usif | bandit -q -r usif | pip-audit | python scripts/check_release_metadata.py | pytest tests/unit | pytest tests (coverage gate) | python -m build | dist/*.whl
11
+ #
12
+ # Coverage gate: `fail_under = 80` in pyproject.toml applies to the whole suite, which runs in
13
+ # the `integration` job (unit + integration + reliability + examples, all optional backends
14
+ # installed). The unit layer alone cannot reach it: modules such as usif/io.py, usif/upgrade and
15
+ # the backends are exercised only by the integration and reliability layers. The `unit` matrix
16
+ # therefore reports coverage per Python version without the gate (--cov-fail-under=0).
17
+ lint-type-security:
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - uses: actions/setup-python@v5
22
+ with:
23
+ python-version: "3.12"
24
+ cache: pip
25
+ - name: Install dev dependencies
26
+ run: python -m pip install -e ".[dev,pymatgen,ase]" -r scripts/materials_project/requirements.txt
27
+ - name: Formatting
28
+ run: |
29
+ black --check usif tests examples scripts
30
+ isort --check-only usif tests examples scripts
31
+ - name: Type check
32
+ run: mypy usif
33
+ - name: Security scan
34
+ run: |
35
+ bandit -q -r usif -x tests
36
+ pip-audit
37
+ - name: Release metadata guard
38
+ run: python scripts/check_release_metadata.py
39
+
40
+ unit:
41
+ runs-on: ubuntu-latest
42
+ strategy:
43
+ fail-fast: false
44
+ matrix:
45
+ python-version: ["3.10", "3.11", "3.12"]
46
+ steps:
47
+ - uses: actions/checkout@v4
48
+ - uses: actions/setup-python@v5
49
+ with:
50
+ python-version: ${{ matrix.python-version }}
51
+ cache: pip
52
+ - name: Install runtime and test dependencies
53
+ run: python -m pip install -e ".[dev]"
54
+ - name: Unit tests (coverage reported, gated in `integration`)
55
+ run: pytest tests/unit --cov=usif --cov-report=term --cov-fail-under=0
56
+
57
+ integration:
58
+ runs-on: ubuntu-latest
59
+ needs: unit
60
+ steps:
61
+ - uses: actions/checkout@v4
62
+ - uses: actions/setup-python@v5
63
+ with:
64
+ python-version: "3.12"
65
+ cache: pip
66
+ - name: Install integration dependencies
67
+ run: python -m pip install -e ".[dev,pymatgen,ase]" -r scripts/materials_project/requirements.txt
68
+ - name: Full suite with the coverage gate (fail_under = 80)
69
+ run: pytest tests --cov=usif --cov-report=xml --cov-report=term-missing
70
+
71
+ build-smoke:
72
+ runs-on: ubuntu-latest
73
+ needs: [lint-type-security, integration]
74
+ steps:
75
+ - uses: actions/checkout@v4
76
+ - uses: actions/setup-python@v5
77
+ with:
78
+ python-version: "3.12"
79
+ cache: pip
80
+ - name: Install build tool
81
+ run: python -m pip install build
82
+ - name: Build sdist and wheel
83
+ run: python -m build
84
+ - name: Install wheel in clean environment
85
+ run: |
86
+ python -m venv /tmp/usif-wheel-smoke
87
+ /tmp/usif-wheel-smoke/bin/python -m pip install dist/*.whl
88
+ /tmp/usif-wheel-smoke/bin/usif version
89
+ /tmp/usif-wheel-smoke/bin/usif --version
90
+ cd /tmp # import the installed wheel, not the checkout
91
+ /tmp/usif-wheel-smoke/bin/python - <<'PY'
92
+ import usif
93
+ assert usif.__version__ == "0.12.0"
94
+ assert usif.RELEASE_RECORD == "20261126.021"
95
+ from usif import Cell, Dataset, Structure, decode, encode
96
+ s = Structure.from_fractional(["Na", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]], Cell.cubic(5.64))
97
+ assert decode(encode(s)) == s
98
+ print("USIF wheel smoke OK", usif.__version__)
99
+ PY
@@ -0,0 +1,148 @@
1
+ name: Publish to PyPI
2
+
3
+ # Build, verify and publish the usif sdist and wheel.
4
+ #
5
+ # * Publishing a GitHub release whose tag is v<project.version> (e.g. v0.8.0)
6
+ # uploads to PyPI.
7
+ # * Running the workflow manually uploads to TestPyPI (or PyPI if chosen).
8
+ #
9
+ # Uses PyPI trusted publishing (OIDC): no API token is stored in the repository.
10
+ # One-time setup on pypi.org / test.pypi.org -> project "usif" -> Publishing:
11
+ # owner: haidi-ustc, repository: usif, workflow: publish.yml,
12
+ # environment: pypi (or testpypi)
13
+
14
+ on:
15
+ release:
16
+ types: [published]
17
+ workflow_dispatch:
18
+ inputs:
19
+ repository:
20
+ description: "Target package index"
21
+ type: choice
22
+ options: [testpypi, pypi]
23
+ default: testpypi
24
+
25
+ permissions:
26
+ contents: read
27
+
28
+ concurrency:
29
+ group: publish-${{ github.ref }}
30
+ cancel-in-progress: false
31
+
32
+ jobs:
33
+ build:
34
+ name: Build and verify distributions
35
+ runs-on: ubuntu-latest
36
+ steps:
37
+ - uses: actions/checkout@v4
38
+
39
+ - uses: actions/setup-python@v5
40
+ with:
41
+ python-version: "3.12"
42
+
43
+ - name: Install build tools
44
+ run: python -m pip install --upgrade build twine
45
+
46
+ - name: Validate release metadata
47
+ run: python scripts/check_release_metadata.py --write-report release-checks.txt
48
+
49
+ - name: Check release tag matches project version
50
+ if: github.event_name == 'release'
51
+ env:
52
+ TAG: ${{ github.event.release.tag_name }}
53
+ run: |
54
+ python - <<'PY'
55
+ import os
56
+ import tomllib
57
+
58
+ with open("pyproject.toml", "rb") as handle:
59
+ version = tomllib.load(handle)["project"]["version"]
60
+ tag = os.environ["TAG"]
61
+ if tag != f"v{version}":
62
+ raise SystemExit(f"release tag {tag!r} does not match project version v{version}")
63
+ print(f"tag {tag} matches project version {version}")
64
+ PY
65
+
66
+ - name: Build sdist and wheel
67
+ run: python -m build
68
+
69
+ - name: Check distribution metadata
70
+ run: python -m twine check --strict dist/*
71
+
72
+ - name: Smoke-test the wheel in a clean environment
73
+ run: |
74
+ python -m venv /tmp/usif-wheel-smoke
75
+ /tmp/usif-wheel-smoke/bin/python -m pip install dist/*.whl
76
+ /tmp/usif-wheel-smoke/bin/usif version
77
+ cd /tmp
78
+ /tmp/usif-wheel-smoke/bin/python - <<'PY'
79
+ import sys
80
+
81
+ import usif
82
+ from usif import Cell, Dataset, Structure
83
+ from usif.codec import decode_with_info, encode_with_info
84
+
85
+ # The core must not pull in any optional structure library.
86
+ loaded = [m for m in ("pymatgen", "ase", "matsimpy") if m in sys.modules]
87
+ assert not loaded, f"core imported optional backends: {loaded}"
88
+
89
+ frac = [[0, 0, 0], [0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0],
90
+ [0.5, 0.5, 0.5], [0.5, 0, 0], [0, 0.5, 0], [0, 0, 0.5]]
91
+ nacl = Structure.from_fractional([11] * 4 + [17] * 4, frac, Cell.cubic(5.64))
92
+ data, info = encode_with_info(nacl, symmetry="auto", compression="none")
93
+ assert info.symmetric, "spglib symmetry reduction did not apply"
94
+ decoded, _ = decode_with_info(data)
95
+ assert decoded.allclose(nacl, atol=1e-5) and decoded.reduced_formula == "NaCl"
96
+ with Dataset("/tmp/usif-smoke.usifc", "w") as ds:
97
+ ds.add(nacl, "nacl")
98
+ assert len(ds) == 1
99
+ print("usif wheel smoke OK", usif.__version__, usif.RELEASE_RECORD)
100
+ PY
101
+
102
+ - uses: actions/upload-artifact@v4
103
+ with:
104
+ name: dist
105
+ path: |
106
+ dist/
107
+ release-checks.txt
108
+ if-no-files-found: error
109
+
110
+ publish-pypi:
111
+ name: Publish to PyPI
112
+ needs: build
113
+ if: >-
114
+ github.event_name == 'release' ||
115
+ (github.event_name == 'workflow_dispatch' && inputs.repository == 'pypi')
116
+ runs-on: ubuntu-latest
117
+ environment:
118
+ name: pypi
119
+ url: https://pypi.org/project/usif/
120
+ permissions:
121
+ id-token: write
122
+ steps:
123
+ - uses: actions/download-artifact@v4
124
+ with:
125
+ name: dist
126
+ - uses: pypa/gh-action-pypi-publish@release/v1
127
+ with:
128
+ packages-dir: dist/
129
+
130
+ publish-testpypi:
131
+ name: Publish to TestPyPI
132
+ needs: build
133
+ if: github.event_name == 'workflow_dispatch' && inputs.repository == 'testpypi'
134
+ runs-on: ubuntu-latest
135
+ environment:
136
+ name: testpypi
137
+ url: https://test.pypi.org/project/usif/
138
+ permissions:
139
+ id-token: write
140
+ steps:
141
+ - uses: actions/download-artifact@v4
142
+ with:
143
+ name: dist
144
+ - uses: pypa/gh-action-pypi-publish@release/v1
145
+ with:
146
+ repository-url: https://test.pypi.org/legacy/
147
+ packages-dir: dist/
148
+ skip-existing: true
usif-0.12.0/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ USIF (Universal Structure Interchange Format)
2
+ Copyright (c) 2025 Haidi
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to use,
6
+ copy, modify, merge, and distribute the Software **for academic and research purposes only**,
7
+ subject to the following conditions:
8
+
9
+ 1. Commercial use, including but not limited to incorporating the Software into
10
+ proprietary or paid products, or using it for profit, is strictly prohibited
11
+ without explicit written permission from the copyright holder.
12
+
13
+ 2. The above copyright notice and this permission notice shall be included
14
+ in all copies or substantial portions of the Software.
15
+
16
+ 3. The Software is provided "AS IS", without warranty of any kind.
17
+
18
+ For commercial licensing or collaboration inquiries, please contact:
19
+ Email: haidi@hfut.edu.cn
20
+
@@ -0,0 +1,30 @@
1
+ include README.md
2
+ include LICENSE
3
+ include pyproject.toml
4
+ include docs/ARCHITECTURE.md
5
+ include docs/FORMAT_VERSIONING.md
6
+ include docs/API_STABILITY.md
7
+ include docs/BINARY_FORMAT.md
8
+ include docs/CHANGELOG.md
9
+ include docs/CONTAINER_FORMAT.md
10
+ include docs/CONTRIBUTING.md
11
+ include docs/PROPERTY_SYSTEM.md
12
+ include docs/RELEASE.md
13
+ include docs/TESTING.md
14
+ include docs/VERSIONING.md
15
+ recursive-include docs/site *.md
16
+ recursive-include examples *.py *.md
17
+ recursive-include scripts *.py
18
+ recursive-include tests *.py
19
+ recursive-include tests/fixtures *.zip
20
+ recursive-exclude docs/archive *
21
+ recursive-exclude * __pycache__
22
+ recursive-exclude * *.py[cod]
23
+ recursive-exclude * *.so
24
+ recursive-exclude * .DS_Store
25
+ recursive-exclude * .pytest_cache
26
+ recursive-exclude build *
27
+ recursive-exclude dist *
28
+ recursive-exclude *.egg-info *
29
+
30
+ recursive-include .github/workflows *.yml
usif-0.12.0/PKG-INFO ADDED
@@ -0,0 +1,218 @@
1
+ Metadata-Version: 2.4
2
+ Name: usif
3
+ Version: 0.12.0
4
+ Summary: Exact, compact and queryable storage for atomistic structures
5
+ Author-email: "haidi@hfut.edu.cn" <haidi@hfut.edu.cn>
6
+ License-Expression: LicenseRef-USIF-NonCommercial
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Intended Audience :: Science/Research
9
+ Classifier: Topic :: Scientific/Engineering :: Chemistry
10
+ Classifier: Topic :: Scientific/Engineering :: Physics
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: numpy>=1.19.0
19
+ Requires-Dist: spglib>=2.5.0
20
+ Requires-Dist: tomli>=2.0.0; python_version < "3.11"
21
+ Requires-Dist: typer>=0.12.0
22
+ Provides-Extra: matsimpy
23
+ Requires-Dist: matsimpy>=0.11.0; extra == "matsimpy"
24
+ Provides-Extra: pymatgen
25
+ Requires-Dist: pymatgen>=2022.0.0; extra == "pymatgen"
26
+ Provides-Extra: ase
27
+ Requires-Dist: ase>=3.22.0; extra == "ase"
28
+ Provides-Extra: zstd
29
+ Requires-Dist: zstandard>=0.21.0; extra == "zstd"
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest>=7.0; extra == "dev"
32
+ Requires-Dist: pytest-cov>=2.0; extra == "dev"
33
+ Requires-Dist: flake8>=6.0.0; extra == "dev"
34
+ Requires-Dist: isort>=5.12.0; extra == "dev"
35
+ Requires-Dist: black>=23.0.0; extra == "dev"
36
+ Requires-Dist: mypy>=1.8.0; extra == "dev"
37
+ Requires-Dist: bandit>=1.7.0; extra == "dev"
38
+ Requires-Dist: pip-audit>=2.7.0; extra == "dev"
39
+ Requires-Dist: build>=1.0.0; extra == "dev"
40
+ Requires-Dist: tomli>=2.0.0; python_version < "3.11" and extra == "dev"
41
+ Requires-Dist: typer>=0.12.0; extra == "dev"
42
+ Provides-Extra: all
43
+ Requires-Dist: zstandard>=0.21.0; extra == "all"
44
+ Requires-Dist: pymatgen>=2022.0.0; extra == "all"
45
+ Requires-Dist: ase>=3.22.0; extra == "all"
46
+ Requires-Dist: pytest>=7.0; extra == "all"
47
+ Requires-Dist: pytest-cov>=2.0; extra == "all"
48
+ Requires-Dist: flake8>=6.0.0; extra == "all"
49
+ Requires-Dist: isort>=5.12.0; extra == "all"
50
+ Requires-Dist: black>=23.0.0; extra == "all"
51
+ Requires-Dist: mypy>=1.8.0; extra == "all"
52
+ Requires-Dist: bandit>=1.7.0; extra == "all"
53
+ Requires-Dist: pip-audit>=2.7.0; extra == "all"
54
+ Requires-Dist: build>=1.0.0; extra == "all"
55
+ Requires-Dist: tomli>=2.0.0; python_version < "3.11" and extra == "all"
56
+ Requires-Dist: typer>=0.12.0; extra == "all"
57
+ Dynamic: license-file
58
+
59
+ # USIF: Universal Structure Interchange Format
60
+
61
+ USIF stores atomistic structures (crystals and molecules) exactly, compactly and queryably.
62
+
63
+ - **One simple model.** A `Structure` is columns: atomic numbers, Cartesian positions, an optional
64
+ cell, per-atom arrays and structure properties. Every value carries a dtype and a unit.
65
+ - **Exact files.** A `.usif` record holds one structure, bit-for-bit (float64) by default, with a
66
+ checksum and content hashes. Opt-in float32, compression and lossless symmetry reduction make
67
+ it smaller. A `.json` document is the readable alternative.
68
+ - **Datasets you can query.** A `.usifc` dataset is an SQLite file of many structures. It stores
69
+ identical content once, organises entries in groups with attributes, and answers indexed
70
+ queries (formula, elements, atom count, property ranges).
71
+ - **Works with your tools.** USIF converts to and from matsimpy, ASE and pymatgen objects, reads
72
+ and writes every file format they support, and has a `usif` command line.
73
+ - **A data agent you talk to.** Register a group's calculations in one local dataset, then query
74
+ it, create projects and save data into them in plain words. An LLM proposes every change as a
75
+ plan; nothing is written until a person approves it.
76
+ - **Small core.** Only numpy, spglib and typer are required; every structure library is optional.
77
+
78
+ Python 3.10+. Version 0.12.0 (see the [changelog](docs/CHANGELOG.md)). Files written by USIF 0.8 and earlier are still readable (see
79
+ [Upgrading from 0.8](#upgrading-from-08)).
80
+
81
+ ## Installation
82
+
83
+ ```bash
84
+ pip install usif # core
85
+ pip install "usif[ase]" # + ASE: conversion and ASE's file formats
86
+ pip install "usif[pymatgen]" # + pymatgen
87
+ pip install "usif[zstd]" # + zstd record compression
88
+ ```
89
+
90
+ | Extra | Installs | For |
91
+ |---|---|---|
92
+ | `ase` | ase | `usif.convert(..., "ase")` and ASE file formats (POSCAR, extxyz, CIF, ...) |
93
+ | `pymatgen` | pymatgen | `usif.convert(..., "pymatgen")` and pymatgen file formats |
94
+ | `matsimpy` | matsimpy | the matsimpy backend (not on PyPI: `pip install -e /path/to/matsimpy`) |
95
+ | `zstd` | zstandard | `compression="zstd"` |
96
+ | `dev` | pytest, black, isort, mypy, bandit, pip-audit, build | development |
97
+ | `all` | everything above except matsimpy | |
98
+
99
+ There is no `mp` extra any more: the Materials Project download script is a development tool in
100
+ `scripts/materials_project/`, and its dependencies (mp-api, monty) are in
101
+ `scripts/materials_project/requirements.txt`.
102
+
103
+ ## Quickstart
104
+
105
+ ```python
106
+ import usif
107
+ from usif import Cell, Dataset, Q, Structure
108
+
109
+ nacl = Structure.from_fractional(
110
+ ["Na", "Cl"],
111
+ [[0, 0, 0], [0.5, 0.5, 0.5]],
112
+ Cell.cubic(5.64),
113
+ properties={"energy": -6.8}, # unit "eV" comes from the default schema
114
+ )
115
+ nacl.arrays["force"] = [[0, 0, 0.01], [0, 0, -0.01]] # per-atom, eV/Å
116
+
117
+ usif.write(nacl, "nacl.usif") # binary record
118
+ assert usif.read("nacl.usif") == nacl # exact round trip
119
+ usif.write(nacl, "nacl.json") # readable JSON, also exact
120
+
121
+ with Dataset("data.usifc") as ds: # SQLite dataset, created if missing
122
+ ds.add(nacl, "nacl", "/salts", attrs={"source": "example"})
123
+ for entry in ds.query(Q.elements("Na") & (Q.prop("energy") < 0)):
124
+ print(entry.path, entry.structure.reduced_formula) # /salts/nacl NaCl
125
+ ```
126
+
127
+ With ASE installed, other formats and objects work the same way:
128
+ `usif.read("POSCAR")`, `usif.write(s, "frames.extxyz")`, `usif.convert(atoms)`,
129
+ `usif.convert(s, "ase")`.
130
+
131
+ ## Concepts in brief
132
+
133
+ | Concept | Summary | Guide |
134
+ |---|---|---|
135
+ | Structure | `Structure(numbers, positions, cell=None, *, pbc, arrays, properties)`. Immutable geometry; exact `==`, tolerant `allclose()`; derived `formula`, `volume`, ... | [structures](docs/guide/structures.md) |
136
+ | Properties | `arrays` (per atom) and `properties` (per structure) hold numbers, arrays or JSON, each with a unit. Built-ins such as `energy` (eV), `force` (eV/Å), `stress` (GPa) come from `DEFAULT_SCHEMA`. Stored values are never converted. | [properties](docs/guide/properties.md) |
137
+ | Records | `usif.encode(s, compression="zlib", precision="f64", symmetry="off")`. Encoding is deterministic, and `record_hash`/`geometry_hash` identify content. | [records](docs/guide/records.md) |
138
+ | Datasets | `Dataset(path)`: `add`, `add_many`, `link`, `query(Q...)`, `count`, groups and attributes, `check`, `compact`. Many readers can work alongside one writer. | [datasets](docs/guide/datasets.md) |
139
+ | Data agent | `usif dataset import` and `usif agent ask/chat`: provenance-tracked import, plain-language queries, projects, change plans you approve. | [agent](docs/guide/agent.md) |
140
+ | Backends | matsimpy, ASE and pymatgen built in; values convert to each library's units. Third-party backends plug in through the `usif.backends` entry point. | [libraries](docs/guide/libraries.md) |
141
+
142
+ ## Command line
143
+
144
+ ```bash
145
+ usif inspect nacl.usif # .usif, .json, any backend format or a .usifc
146
+ usif convert POSCAR nacl.usif --symmetry auto
147
+ usif validate data.usifc --full # exit code 1 if invalid
148
+ usif dataset add data.usifc *.cif --group /cifs
149
+ usif dataset list data.usifc --elements Na,Cl --prop 'energy<-1.5'
150
+ usif dataset export data.usifc salts.extxyz --group /salts --prop 'energy<-1.5' # never overwrites without --overwrite
151
+ ```
152
+
153
+ See the [command-line guide](docs/guide/command-line.md) for every command and option.
154
+
155
+ ## A local dataset for your group, with an AI agent
156
+
157
+ Register the calculations scattered across project directories in one searchable dataset, and
158
+ work with it in plain words:
159
+
160
+ ```bash
161
+ usif dataset import ~/projects/oer group.usifc --group /oer # VASP dirs, CIF, extxyz, ... + provenance
162
+ export DEEPSEEK_API_KEY=... # any OpenAI-compatible LLM; DeepSeek by default
163
+ usif agent ask group.usifc "Which Ti oxides do we have, and with which ENCUT?"
164
+ usif agent ask group.usifc "Create a project 'stable' and save every Ti oxide below -40 eV into it"
165
+ usif agent ask new.usifc "Start a project for the OER work" # a new dataset, created on approval
166
+ usif agent chat group.usifc --allow ~/projects # "save the new runs in ~/projects/oer into oer"
167
+ export USIF_DATASET=$PWD/group.usifc # optional default (or [agent] dataset in ~/.usif/config.toml)
168
+ usif agent ask "Which projects do we have?"
169
+ ```
170
+
171
+ What you can ask for:
172
+
173
+ - **Query.** Search by formula, elements, atom count, property ranges (`energy < -10`),
174
+ attributes and text in paths, notes and INCAR parameters; list projects and their contents.
175
+ - **Create a project.** A project is the group `/projects/<name>` with a description. The dataset
176
+ is created if it does not exist yet.
177
+ - **Save into a project.** New files from allowed directories are imported with provenance;
178
+ entries already in the dataset (for example what a search found) are *linked*, so nothing is
179
+ copied.
180
+
181
+ The agent reads the dataset and your files and proposes changes as a change plan. Nothing is
182
+ written until you approve the plan (`[y/N]`; the agent itself can never approve): changes are
183
+ applied in one transaction, checked against source-file hashes, and each new entry records the
184
+ plan that added it. The agent never writes files either: for an export it gives you the
185
+ `usif dataset export` command to run. See the [agent guide](docs/guide/agent.md) and
186
+ [`examples/07_agent_projects.py`](examples/07_agent_projects.py), which runs offline with a
187
+ scripted model.
188
+
189
+ ## Upgrading from 0.8
190
+
191
+ 0.9.0 is a redesign: the 0.8 API (`USIFStructure`, `USIF`, `StructureContainer`,
192
+ `usif.services`, `usif.interop`, `SymmetryPolicy`, `PropertyRegistry`) is replaced. Files from
193
+ 0.8 and earlier still open. `usif.read()` reads format-5/6 `.usif` records, and version-2
194
+ `.usifc` containers are copied into a dataset with `Dataset.import_v2()`; `usif convert
195
+ old.usif new.usif` rewrites a record as format 7. The [upgrade guide](docs/guide/upgrading.md) and the migration table in
196
+ the [changelog](docs/CHANGELOG.md) map each old call to its replacement.
197
+
198
+ ## Documentation
199
+
200
+ - [Documentation index](docs/README.md): the user guide, the format specifications, architecture
201
+ and project documents
202
+ - [examples/](examples/README.md): runnable scripts, one per topic
203
+ - [scripts/](scripts): development scripts (`python -m scripts.benchmark`,
204
+ `python -m scripts.materials_project`, `scripts/check_release_metadata.py`)
205
+
206
+ ## Development
207
+
208
+ ```bash
209
+ python -m pip install -e ".[dev,pymatgen,ase]" -r scripts/materials_project/requirements.txt
210
+ pytest # from the repository root; always tests this checkout
211
+ ```
212
+
213
+ See [CONTRIBUTING.md](docs/CONTRIBUTING.md) for the checks CI runs, the test layout and the
214
+ project's rules, and [RELEASE.md](docs/RELEASE.md) for versioning and releases.
215
+
216
+ ## License
217
+
218
+ See [LICENSE](LICENSE).
usif-0.12.0/README.md ADDED
@@ -0,0 +1,160 @@
1
+ # USIF: Universal Structure Interchange Format
2
+
3
+ USIF stores atomistic structures (crystals and molecules) exactly, compactly and queryably.
4
+
5
+ - **One simple model.** A `Structure` is columns: atomic numbers, Cartesian positions, an optional
6
+ cell, per-atom arrays and structure properties. Every value carries a dtype and a unit.
7
+ - **Exact files.** A `.usif` record holds one structure, bit-for-bit (float64) by default, with a
8
+ checksum and content hashes. Opt-in float32, compression and lossless symmetry reduction make
9
+ it smaller. A `.json` document is the readable alternative.
10
+ - **Datasets you can query.** A `.usifc` dataset is an SQLite file of many structures. It stores
11
+ identical content once, organises entries in groups with attributes, and answers indexed
12
+ queries (formula, elements, atom count, property ranges).
13
+ - **Works with your tools.** USIF converts to and from matsimpy, ASE and pymatgen objects, reads
14
+ and writes every file format they support, and has a `usif` command line.
15
+ - **A data agent you talk to.** Register a group's calculations in one local dataset, then query
16
+ it, create projects and save data into them in plain words. An LLM proposes every change as a
17
+ plan; nothing is written until a person approves it.
18
+ - **Small core.** Only numpy, spglib and typer are required; every structure library is optional.
19
+
20
+ Python 3.10+. Version 0.12.0 (see the [changelog](docs/CHANGELOG.md)). Files written by USIF 0.8 and earlier are still readable (see
21
+ [Upgrading from 0.8](#upgrading-from-08)).
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ pip install usif # core
27
+ pip install "usif[ase]" # + ASE: conversion and ASE's file formats
28
+ pip install "usif[pymatgen]" # + pymatgen
29
+ pip install "usif[zstd]" # + zstd record compression
30
+ ```
31
+
32
+ | Extra | Installs | For |
33
+ |---|---|---|
34
+ | `ase` | ase | `usif.convert(..., "ase")` and ASE file formats (POSCAR, extxyz, CIF, ...) |
35
+ | `pymatgen` | pymatgen | `usif.convert(..., "pymatgen")` and pymatgen file formats |
36
+ | `matsimpy` | matsimpy | the matsimpy backend (not on PyPI: `pip install -e /path/to/matsimpy`) |
37
+ | `zstd` | zstandard | `compression="zstd"` |
38
+ | `dev` | pytest, black, isort, mypy, bandit, pip-audit, build | development |
39
+ | `all` | everything above except matsimpy | |
40
+
41
+ There is no `mp` extra any more: the Materials Project download script is a development tool in
42
+ `scripts/materials_project/`, and its dependencies (mp-api, monty) are in
43
+ `scripts/materials_project/requirements.txt`.
44
+
45
+ ## Quickstart
46
+
47
+ ```python
48
+ import usif
49
+ from usif import Cell, Dataset, Q, Structure
50
+
51
+ nacl = Structure.from_fractional(
52
+ ["Na", "Cl"],
53
+ [[0, 0, 0], [0.5, 0.5, 0.5]],
54
+ Cell.cubic(5.64),
55
+ properties={"energy": -6.8}, # unit "eV" comes from the default schema
56
+ )
57
+ nacl.arrays["force"] = [[0, 0, 0.01], [0, 0, -0.01]] # per-atom, eV/Å
58
+
59
+ usif.write(nacl, "nacl.usif") # binary record
60
+ assert usif.read("nacl.usif") == nacl # exact round trip
61
+ usif.write(nacl, "nacl.json") # readable JSON, also exact
62
+
63
+ with Dataset("data.usifc") as ds: # SQLite dataset, created if missing
64
+ ds.add(nacl, "nacl", "/salts", attrs={"source": "example"})
65
+ for entry in ds.query(Q.elements("Na") & (Q.prop("energy") < 0)):
66
+ print(entry.path, entry.structure.reduced_formula) # /salts/nacl NaCl
67
+ ```
68
+
69
+ With ASE installed, other formats and objects work the same way:
70
+ `usif.read("POSCAR")`, `usif.write(s, "frames.extxyz")`, `usif.convert(atoms)`,
71
+ `usif.convert(s, "ase")`.
72
+
73
+ ## Concepts in brief
74
+
75
+ | Concept | Summary | Guide |
76
+ |---|---|---|
77
+ | Structure | `Structure(numbers, positions, cell=None, *, pbc, arrays, properties)`. Immutable geometry; exact `==`, tolerant `allclose()`; derived `formula`, `volume`, ... | [structures](docs/guide/structures.md) |
78
+ | Properties | `arrays` (per atom) and `properties` (per structure) hold numbers, arrays or JSON, each with a unit. Built-ins such as `energy` (eV), `force` (eV/Å), `stress` (GPa) come from `DEFAULT_SCHEMA`. Stored values are never converted. | [properties](docs/guide/properties.md) |
79
+ | Records | `usif.encode(s, compression="zlib", precision="f64", symmetry="off")`. Encoding is deterministic, and `record_hash`/`geometry_hash` identify content. | [records](docs/guide/records.md) |
80
+ | Datasets | `Dataset(path)`: `add`, `add_many`, `link`, `query(Q...)`, `count`, groups and attributes, `check`, `compact`. Many readers can work alongside one writer. | [datasets](docs/guide/datasets.md) |
81
+ | Data agent | `usif dataset import` and `usif agent ask/chat`: provenance-tracked import, plain-language queries, projects, change plans you approve. | [agent](docs/guide/agent.md) |
82
+ | Backends | matsimpy, ASE and pymatgen built in; values convert to each library's units. Third-party backends plug in through the `usif.backends` entry point. | [libraries](docs/guide/libraries.md) |
83
+
84
+ ## Command line
85
+
86
+ ```bash
87
+ usif inspect nacl.usif # .usif, .json, any backend format or a .usifc
88
+ usif convert POSCAR nacl.usif --symmetry auto
89
+ usif validate data.usifc --full # exit code 1 if invalid
90
+ usif dataset add data.usifc *.cif --group /cifs
91
+ usif dataset list data.usifc --elements Na,Cl --prop 'energy<-1.5'
92
+ usif dataset export data.usifc salts.extxyz --group /salts --prop 'energy<-1.5' # never overwrites without --overwrite
93
+ ```
94
+
95
+ See the [command-line guide](docs/guide/command-line.md) for every command and option.
96
+
97
+ ## A local dataset for your group, with an AI agent
98
+
99
+ Register the calculations scattered across project directories in one searchable dataset, and
100
+ work with it in plain words:
101
+
102
+ ```bash
103
+ usif dataset import ~/projects/oer group.usifc --group /oer # VASP dirs, CIF, extxyz, ... + provenance
104
+ export DEEPSEEK_API_KEY=... # any OpenAI-compatible LLM; DeepSeek by default
105
+ usif agent ask group.usifc "Which Ti oxides do we have, and with which ENCUT?"
106
+ usif agent ask group.usifc "Create a project 'stable' and save every Ti oxide below -40 eV into it"
107
+ usif agent ask new.usifc "Start a project for the OER work" # a new dataset, created on approval
108
+ usif agent chat group.usifc --allow ~/projects # "save the new runs in ~/projects/oer into oer"
109
+ export USIF_DATASET=$PWD/group.usifc # optional default (or [agent] dataset in ~/.usif/config.toml)
110
+ usif agent ask "Which projects do we have?"
111
+ ```
112
+
113
+ What you can ask for:
114
+
115
+ - **Query.** Search by formula, elements, atom count, property ranges (`energy < -10`),
116
+ attributes and text in paths, notes and INCAR parameters; list projects and their contents.
117
+ - **Create a project.** A project is the group `/projects/<name>` with a description. The dataset
118
+ is created if it does not exist yet.
119
+ - **Save into a project.** New files from allowed directories are imported with provenance;
120
+ entries already in the dataset (for example what a search found) are *linked*, so nothing is
121
+ copied.
122
+
123
+ The agent reads the dataset and your files and proposes changes as a change plan. Nothing is
124
+ written until you approve the plan (`[y/N]`; the agent itself can never approve): changes are
125
+ applied in one transaction, checked against source-file hashes, and each new entry records the
126
+ plan that added it. The agent never writes files either: for an export it gives you the
127
+ `usif dataset export` command to run. See the [agent guide](docs/guide/agent.md) and
128
+ [`examples/07_agent_projects.py`](examples/07_agent_projects.py), which runs offline with a
129
+ scripted model.
130
+
131
+ ## Upgrading from 0.8
132
+
133
+ 0.9.0 is a redesign: the 0.8 API (`USIFStructure`, `USIF`, `StructureContainer`,
134
+ `usif.services`, `usif.interop`, `SymmetryPolicy`, `PropertyRegistry`) is replaced. Files from
135
+ 0.8 and earlier still open. `usif.read()` reads format-5/6 `.usif` records, and version-2
136
+ `.usifc` containers are copied into a dataset with `Dataset.import_v2()`; `usif convert
137
+ old.usif new.usif` rewrites a record as format 7. The [upgrade guide](docs/guide/upgrading.md) and the migration table in
138
+ the [changelog](docs/CHANGELOG.md) map each old call to its replacement.
139
+
140
+ ## Documentation
141
+
142
+ - [Documentation index](docs/README.md): the user guide, the format specifications, architecture
143
+ and project documents
144
+ - [examples/](examples/README.md): runnable scripts, one per topic
145
+ - [scripts/](scripts): development scripts (`python -m scripts.benchmark`,
146
+ `python -m scripts.materials_project`, `scripts/check_release_metadata.py`)
147
+
148
+ ## Development
149
+
150
+ ```bash
151
+ python -m pip install -e ".[dev,pymatgen,ase]" -r scripts/materials_project/requirements.txt
152
+ pytest # from the repository root; always tests this checkout
153
+ ```
154
+
155
+ See [CONTRIBUTING.md](docs/CONTRIBUTING.md) for the checks CI runs, the test layout and the
156
+ project's rules, and [RELEASE.md](docs/RELEASE.md) for versioning and releases.
157
+
158
+ ## License
159
+
160
+ See [LICENSE](LICENSE).