Metadata-Version: 2.5
Name: molcryst
Version: 0.3.0
Summary: Python package for manipulating molecular crystals
Project-URL: Homepage, https://delonecommons.github.io/molcryst
Project-URL: Documentation, https://delonecommons.github.io/molcryst
Project-URL: Repository, https://github.com/DeloneCommons/molcryst
Project-URL: Issues, https://github.com/DeloneCommons/molcryst/issues
Author-email: "Ivan Yu. Chernyshov" <ivan.chernyshoff@gmail.com>
License:                    GNU LESSER GENERAL PUBLIC LICENSE
                               Version 3, 29 June 2007
        
         Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
         Everyone is permitted to copy and distribute verbatim copies
         of this license document, but changing it is not allowed.
        
        
          This version of the GNU Lesser General Public License incorporates
        the terms and conditions of version 3 of the GNU General Public
        License, supplemented by the additional permissions listed below.
        
          0. Additional Definitions.
        
          As used herein, "this License" refers to version 3 of the GNU Lesser
        General Public License, and the "GNU GPL" refers to version 3 of the GNU
        General Public License.
        
          "The Library" refers to a covered work governed by this License,
        other than an Application or a Combined Work as defined below.
        
          An "Application" is any work that makes use of an interface provided
        by the Library, but which is not otherwise based on the Library.
        Defining a subclass of a class defined by the Library is deemed a mode
        of using an interface provided by the Library.
        
          A "Combined Work" is a work produced by combining or linking an
        Application with the Library.  The particular version of the Library
        with which the Combined Work was made is also called the "Linked
        Version".
        
          The "Minimal Corresponding Source" for a Combined Work means the
        Corresponding Source for the Combined Work, excluding any source code
        for portions of the Combined Work that, considered in isolation, are
        based on the Application, and not on the Linked Version.
        
          The "Corresponding Application Code" for a Combined Work means the
        object code and/or source code for the Application, including any data
        and utility programs needed for reproducing the Combined Work from the
        Application, but excluding the System Libraries of the Combined Work.
        
          1. Exception to Section 3 of the GNU GPL.
        
          You may convey a covered work under sections 3 and 4 of this License
        without being bound by section 3 of the GNU GPL.
        
          2. Conveying Modified Versions.
        
          If you modify a copy of the Library, and, in your modifications, a
        facility refers to a function or data to be supplied by an Application
        that uses the facility (other than as an argument passed when the
        facility is invoked), then you may convey a copy of the modified
        version:
        
           a) under this License, provided that you make a good faith effort to
           ensure that, in the event an Application does not supply the
           function or data, the facility still operates, and performs
           whatever part of its purpose remains meaningful, or
        
           b) under the GNU GPL, with none of the additional permissions of
           this License applicable to that copy.
        
          3. Object Code Incorporating Material from Library Header Files.
        
          The object code form of an Application may incorporate material from
        a header file that is part of the Library.  You may convey such object
        code under terms of your choice, provided that, if the incorporated
        material is not limited to numerical parameters, data structure
        layouts and accessors, or small macros, inline functions and templates
        (ten or fewer lines in length), you do both of the following:
        
           a) Give prominent notice with each copy of the object code that the
           Library is used in it and that the Library and its use are
           covered by this License.
        
           b) Accompany the object code with a copy of the GNU GPL and this license
           document.
        
          4. Combined Works.
        
          You may convey a Combined Work under terms of your choice that,
        taken together, effectively do not restrict modification of the
        portions of the Library contained in the Combined Work and reverse
        engineering for debugging such modifications, if you also do each of
        the following:
        
           a) Give prominent notice with each copy of the Combined Work that
           the Library is used in it and that the Library and its use are
           covered by this License.
        
           b) Accompany the Combined Work with a copy of the GNU GPL and this license
           document.
        
           c) For a Combined Work that displays copyright notices during
           execution, include the copyright notice for the Library among
           these notices, as well as a reference directing the user to the
           copies of the GNU GPL and this license document.
        
           d) Do one of the following:
        
               0) Convey the Minimal Corresponding Source under the terms of this
               License, and the Corresponding Application Code in a form
               suitable for, and under terms that permit, the user to
               recombine or relink the Application with a modified version of
               the Linked Version to produce a modified Combined Work, in the
               manner specified by section 6 of the GNU GPL for conveying
               Corresponding Source.
        
               1) Use a suitable shared library mechanism for linking with the
               Library.  A suitable mechanism is one that (a) uses at run time
               a copy of the Library already present on the user's computer
               system, and (b) will operate properly with a modified version
               of the Library that is interface-compatible with the Linked
               Version.
        
           e) Provide Installation Information, but only if you would otherwise
           be required to provide such information under section 6 of the
           GNU GPL, and only to the extent that such information is
           necessary to install and execute a modified version of the
           Combined Work produced by recombining or relinking the
           Application with a modified version of the Linked Version. (If
           you use option 4d0, the Installation Information must accompany
           the Minimal Corresponding Source and Corresponding Application
           Code. If you use option 4d1, you must provide the Installation
           Information in the manner specified by section 6 of the GNU GPL
           for conveying Corresponding Source.)
        
          5. Combined Libraries.
        
          You may place library facilities that are a work based on the
        Library side by side in a single library together with other library
        facilities that are not Applications and are not covered by this
        License, and convey such a combined library under terms of your
        choice, if you do both of the following:
        
           a) Accompany the combined library with a copy of the same work based
           on the Library, uncombined with any other library facilities,
           conveyed under the terms of this License.
        
           b) Give prominent notice with the combined library that part of it
           is a work based on the Library, and explaining where to find the
           accompanying uncombined form of the same work.
        
          6. Revised Versions of the GNU Lesser General Public License.
        
          The Free Software Foundation may publish revised and/or new versions
        of the GNU Lesser General Public License from time to time. Such new
        versions will be similar in spirit to the present version, but may
        differ in detail to address new problems or concerns.
        
          Each version is given a distinguishing version number. If the
        Library as you received it specifies that a certain numbered version
        of the GNU Lesser General Public License "or any later version"
        applies to it, you have the option of following the terms and
        conditions either of that published version or of any later version
        published by the Free Software Foundation. If the Library as you
        received it does not specify a version number of the GNU Lesser
        General Public License, you may choose any version of the GNU Lesser
        General Public License ever published by the Free Software Foundation.
        
          If the Library as you received it specifies that a proxy can decide
        whether future versions of the GNU Lesser General Public License shall
        apply, that proxy's public statement of acceptance of any version is
        permanent authorization for you to choose that version for the
        Library.
License-File: COPYING
License-File: LICENSE
License-File: NOTICE.md
Keywords: chemistry,crystallography,molecular crystals,periodic,symmetry
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
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: Topic :: Scientific/Engineering :: Chemistry
Classifier: Topic :: Scientific/Engineering :: Physics
Requires-Python: >=3.10
Requires-Dist: atomref<0.2,>=0.1.4
Requires-Dist: gemmi>=0.7
Requires-Dist: pbcgraph>=0.1.4
Requires-Dist: scipy>=1.10
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == 'dev'
Requires-Dist: flake8>=7; extra == 'dev'
Requires-Dist: twine>=5; extra == 'dev'
Provides-Extra: docs
Requires-Dist: ipykernel>=6; extra == 'docs'
Requires-Dist: mkdocs-include-markdown-plugin>=6.2; extra == 'docs'
Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
Requires-Dist: mkdocs<2,>=1.6; extra == 'docs'
Requires-Dist: mkdocstrings[python]>=0.25; extra == 'docs'
Requires-Dist: nbconvert>=7; extra == 'docs'
Requires-Dist: pymdown-extensions>=10.0; extra == 'docs'
Requires-Dist: tomli>=2; (python_version < '3.11') and extra == 'docs'
Provides-Extra: test
Requires-Dist: pytest>=7; extra == 'test'
Requires-Dist: tomli>=2; (python_version < '3.11') and extra == 'test'
Description-Content-Type: text/markdown

# molcryst

[![CI](https://github.com/DeloneCommons/molcryst/actions/workflows/ci.yml/badge.svg)](https://github.com/DeloneCommons/molcryst/actions/workflows/ci.yml) [![Docs](https://github.com/DeloneCommons/molcryst/actions/workflows/docs.yml/badge.svg)](https://github.com/DeloneCommons/molcryst/actions/workflows/docs.yml) [![PyPI](https://img.shields.io/pypi/v/molcryst.svg)](https://pypi.org/project/molcryst/) [![Python versions](https://img.shields.io/pypi/pyversions/molcryst.svg)](https://pypi.org/project/molcryst/) [![License](https://img.shields.io/pypi/l/molcryst.svg)](https://github.com/DeloneCommons/molcryst/blob/main/LICENSE)

**Documentation:** https://delonecommons.github.io/molcryst/


---

molcryst is a Python package for representing and analyzing **molecular crystals**,
with an emphasis on a clear crystal object model (COM) and exact, reproducible
symmetry handling.

The core goals are:

- a clear **crystal object model (COM)** (records → entities → keys → views)
- **exact, reproducible symmetry handling** (deterministic integer-grid logic)
- practical building blocks for workflows around **bonds, components, and contacts**

## Current candidate

The current candidate source reports version `0.3.0`. WP1–WP4 are accepted and
merged; exact-revision qualification and publication remain pending under WP5.
Its implemented building blocks include:

- the canonical root façade `import molcryst as mc`
- deterministic integer-grid symmetry primitives (`FracQ`, `SymOp`, `derive_Q`)
- a strict structure-owned symmetry service via `Structure.symmetry`
- uniform orbit helpers on `Atom`, `Bond`, `Component`, and `Contact`
- CIF I/O through `gemmi`, including multi-block helpers
- periodic covalent bonds and covalent components (molecules vs networks)
- reusable contact definitions via `Structure.contacts(...)` and `ContactSet`
- declarative contact filtering via `ContactSelection` and `ContactSubset`
- line-of-sight (LoS) contact annotation on top of stored contacts
- record-level hydrogen normalization with configurable `XHScheme` / overrides
- atomref-backed curated element, radii, and X-H dataset lookup through `molcryst.chem`

## Status

molcryst is **pre-alpha and under closed, maintainer-led development**. Scientific
correctness comes first; architectural simplicity comes second. There are currently
no external users and no external-user backward-compatibility commitment. Obsolete
or unnecessary functionality, APIs, and abstractions are removed outright within
approved work; internal callers, tests, examples, and documentation are updated
together. See the [closed-development policy](https://delonecommons.github.io/molcryst/development/workflow/#closed-development-policy).

Only the maintainer decides when development opens and what compatibility
commitments follow. There is no scheduled opening date. Correct native xyz2mol
functionality, a minimum useful feature set to be defined during development,
and qualification on COD are the anticipated basis for considering that decision;
completing them does not automatically open the project.

The current root façade is the preferred interface to teach and test:

- the root import path and the structure/view object model are the primary public surface
- symmetry partitions and representative choice are owned by `Structure.symmetry`
- hard dependencies (`atomref`, `pbcgraph`) are expected to fail eagerly on normal import paths

Known limitations include restricted operation denominators, a finite-image
nearest-distance search, and incomplete handling of unresolved disorder. See
[capabilities and limitations](https://delonecommons.github.io/molcryst/guide/capabilities/) before relying on general
CIF coverage. Recording these limitations does not implement their fixes.

## Where to go next

- **Guide**
    - Installation and local workflows: [Install](https://delonecommons.github.io/molcryst/guide/install/)
    - Minimal workflow and usage patterns: [Quickstart](https://delonecommons.github.io/molcryst/guide/quickstart/)
    - Supported workflows and known risks: [Capabilities and limitations](https://delonecommons.github.io/molcryst/guide/capabilities/)
    - Contacts and LoS: [Contacts and LoS](https://delonecommons.github.io/molcryst/guide/contacts_and_los/)
    - The COM mental model: [Mental model](https://delonecommons.github.io/molcryst/guide/mental_model/)

- **Examples**
    - User-oriented notebook workflows based on the main public interface
    - Advanced notebooks that show internal representations and lower-level workflows

- **API**
    - API reference generated from docstrings

- **Development**
    - Start here: [Development documentation](https://delonecommons.github.io/molcryst/development/)
    - Current architecture, accepted/proposed decisions, plans, audit evidence, and validation

- **Project**
    - Scientific intent: [Scope](https://delonecommons.github.io/molcryst/project/scope/)
    - Longer-term direction: [Roadmap](https://delonecommons.github.io/molcryst/project/roadmap/)
    - [Changelog](https://delonecommons.github.io/molcryst/project/changelog/) and [license information](https://delonecommons.github.io/molcryst/project/license/)

---

## Quickstart

A minimal end-to-end workflow looks like this:

1. read a CIF,
2. build a reusable contact definition,
3. compute LoS annotations,
4. narrow to a filtered subset,
5. traverse through structure-bound views.

### Load a structure

```python
import molcryst as mc

# Load the first CIF block by default.
s = mc.Structure.from_cif_file('my_structure.cif')

# If a CIF contains multiple blocks, choose by index or block name.
# s = mc.Structure.from_cif_file('multi.cif', block=0)
# s = mc.Structure.from_cif_file('multi.cif', block='MYBLOCK')
```

The `Structure` object is the main convenience façade. It lazily builds and
caches canonical **atom entities**, **bonds/components**, **contacts**, and
several periodic graph views.

### Build a contact definition

```python
# Intermolecular contacts up to a cutoff (Å).
base = s.contacts(cutoff=3.5, scope='inter')

print('n selected:', len(base))
print('n store total:', len(s.contact_store))
```

Notes:

- `Structure` owns a single mutable `ContactStore`.
- `base` is a lightweight `ContactSet` bound to a full contact definition
  (`ContactSettings`), not just a `(cutoff, scope)` pair.
- public contact definitions are non-covalent relative to the active bond
  layer, so directly bonded pairs are excluded from the store.
- Passing `cutoff=` to `Structure.contacts(...)` is a convenience that asks for
  an absolute-distance contact definition.

### Compute LoS annotations

```python
# Compute LoS (line-of-sight) for this definition.
params_id = base.ensure_los(definition='chernyshov2020')

# You can also request the Taylor definition.
# params_id = base.ensure_los(definition='taylor2014')
```

LoS is implemented as an **annotation layer** on top of the selected contacts.
No new contacts are enumerated; existing contacts are annotated.

### Narrow to a filtered subset

```python
los = base.select(
    mc.ContactSelection(
        annotation_method='los',
        annotation_params_id=params_id,
        annotation_where=lambda ann: bool(ann.data['los']),
    )
)

print('n LoS:', len(los))
```

You can use the same API for distance windows, vdW-gap windows, or additional
scope filtering.

### Inspect one contact

```python
k = los.keys[0]
c = los.get(k)
ann = c.annotations[('los', params_id)]

print('edge:', k)
print('distance:', c.distance)
print('los:', ann.data['los'])
print('dR:', ann.data['dR'])
print('shield atom:', ann.data['shield_atom_id'], (ann.data['shield_tx'], ann.data['shield_ty'], ann.data['shield_tz']))
print('valid:', ann.data['valid'], 'radii_complete:', ann.data['radii_complete'])
```

### Traverse with views and build graphs

```python
center = s.atom(0)
print('bonded neighbors:', center.bonded_neighbors())
print('LoS contact neighbors:', center.contact_neighbors(sel=los))

atom_graph = los.atom_graph()
component_graph, bundles = los.component_graph()

print('atom graph edges:', len(atom_graph.edges))
print('component graph edges:', len(component_graph.edges))
```

### Work with symmetry orbits

All orbit partitioning is owned by `Structure.symmetry`.

```python
print('unique atom ids:', s.symmetry.unique_atom_ids())
print('unique bond edges:', [b.edge for b in s.symmetry.unique_bonds()])
print('unique component ids:', s.symmetry.unique_component_ids())

unique_contacts = s.symmetry.unique_contacts(los, rep_policy='canonical')
print('unique LoS contacts:', [c.edge for c in unique_contacts])
```

Views expose matching convenience helpers:

```python
atom = s.atom(0)
print('atom orbit size:', atom.orbit_size())
print('atom rep:', atom.orbit_rep().atom_id)

contact = unique_contacts[0]
print('contact orbit size in selection:', contact.orbit_size(selection=los))
print('contact rep in selection:', contact.orbit_rep(selection=los).edge)
```

Notes:

- `Atom`, `Bond`, and `Component` orbit helpers classify the underlying
  reference-cell object; the view `shift` does not change orbit identity.
- `Contact` orbit helpers are **selection-scoped**, so the selection must be
  passed explicitly.
- Symmetry queries are strict: if a requested surface is unavailable or not
  symmetry-closed, molcryst raises instead of silently degrading.

---

## Installation and local development

molcryst is a research-focused, **pre-alpha** Python package.

### Requirements

- Package metadata requires Python **>=3.10**. The explicit v0.3 release
  qualification matrix is **3.10–3.13**; candidate qualification remains pending.
  Python 3.14 is outside that matrix.
- Runtime dependencies are installed automatically:
    - `atomref` (curated element/radii/X-H datasets and transfer engine)
    - `gemmi` (CIF parsing)
    - `scipy` (KDTree-based neighbour candidates)
    - `pbcgraph` (periodic graph utilities)

### Published release

After `0.3.0` has been qualified and published, install the published release with:

```bash
python -m pip install molcryst==0.3.0
```

The current source is a `0.3.0` candidate; this command is not a claim that
publication has happened.

### Local candidate wheel

To inspect a locally supplied candidate wheel, create a separate environment
and install the exact file:

```bash
python -m venv .venv-candidate
# Activate .venv-candidate using the command appropriate for your shell.
python -m pip install /path/to/molcryst-0.3.0-py3-none-any.whl
```

Installing a candidate does not establish release qualification.

### Contributor editable checkout

Run contributor commands from a repository checkout:

```bash
python -m venv .venv
# Activate .venv using the command appropriate for your shell.
python -m pip install -e ".[test,docs,dev]"
```

Respect the declared dependency ranges, including `pbcgraph>=0.1.4` and
`atomref>=0.1.4,<0.2`; an arbitrary sibling checkout may not satisfy them. Installing
sibling HEADs or widening their ranges is a separate compatibility task, not a
prerequisite for ordinary documentation work.

This installs:

- the package itself
- test dependencies (`pytest`)
- docs dependencies (`mkdocs`, `mkdocs-material`, `mkdocstrings`, `nbconvert`, ...)
- development tools (`flake8`, build helpers)

For a runtime-only editable checkout, omit the extras:

```bash
python -m pip install -e .
```

The test, documentation and notebook commands below are **repository workflows**.
The public sdist contains package source, build metadata, README and legal files
plus `.gitignore`; it does not contain tests, docs, notebooks or contributor tools.

### Run repository tests

```bash
python -m pytest
```

### Build or preview existing documentation

For a prose/navigation change, regenerate/check only the README and build the
site from the committed example pages:

```bash
python tools/gen_readme.py
python tools/gen_readme.py --check
python -m mkdocs build --clean --strict
# Or preview the same pages locally:
python -m mkdocs serve
```

See [development validation](https://delonecommons.github.io/molcryst/development/validation/) and the
[development entry point](https://delonecommons.github.io/molcryst/development/) for checks and work plans.

### Generated docs artifacts

The local docs workflow maintains two generated artifacts:

- example pages under `docs/examples/`, rendered from the source notebooks in `notebooks/`
- the root `README.md`, generated from selected docs pages so the package landing page stays aligned with the site

The current README source pages are:

- `docs/index.md`
- `docs/guide/quickstart.md`
- `docs/guide/install.md`

The notebook renderer executes source notebooks **in place** and writes their
outputs. `sync_docs.py --check-readme` also executes notebooks unless paired with
`--readme-only`. Do not run a notebook refresh merely to validate a prose edit;
use a disposable copy when qualifying notebook execution.

For an intentional notebook/output refresh, refresh both generated artifacts and
build the site:

```bash
python tools/sync_docs.py
python -m mkdocs build
```

After that intentional refresh, `python -m mkdocs serve` previews the generated
pages without another notebook execution.

Under the hood, this runs `tools/render_examples.py` (examples) and `tools/gen_readme.py` (README).

### Sync only the README

```bash
python tools/sync_docs.py --readme-only
# or:
python tools/gen_readme.py
```

To verify that the committed README is still in sync without rewriting it:

```bash
python tools/sync_docs.py --readme-only --check-readme
# or:
python tools/gen_readme.py --check
```

---

*This README is auto-generated from selected docs pages (`docs/index.md`, `docs/guide/quickstart.md`, and `docs/guide/install.md`).*
To update it, edit those docs pages and re-run: `python tools/sync_docs.py --readme-only` (or `python tools/gen_readme.py`).
