{"id":32806300,"url":"https://github.com/albertkurtz/fast_dse","last_synced_at":"2026-05-06T13:34:40.385Z","repository":{"id":322587902,"uuid":"1056927508","full_name":"AlbertKurtz/fast_dse","owner":"AlbertKurtz","description":"Crystal Scattering Library with Rust and Python","archived":false,"fork":false,"pushed_at":"2025-11-05T08:01:13.000Z","size":149,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-05T10:04:43.976Z","etag":null,"topics":["crystal","debye","dse","maturin","pyo3","python","rust","scattering"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlbertKurtz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-15T03:37:59.000Z","updated_at":"2025-11-05T08:01:17.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/AlbertKurtz/fast_dse","commit_stats":null,"previous_names":["albertkurtz/fast_dse"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/AlbertKurtz/fast_dse","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlbertKurtz%2Ffast_dse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlbertKurtz%2Ffast_dse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlbertKurtz%2Ffast_dse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlbertKurtz%2Ffast_dse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlbertKurtz","download_url":"https://codeload.github.com/AlbertKurtz/fast_dse/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlbertKurtz%2Ffast_dse/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283019357,"owners_count":26765637,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-06T02:00:06.180Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crystal","debye","dse","maturin","pyo3","python","rust","scattering"],"created_at":"2025-11-06T14:00:50.528Z","updated_at":"2025-11-06T14:01:35.406Z","avatar_url":"https://github.com/AlbertKurtz.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fast_dse: Fast Debye Scattering Equation\n\nThis project exposes high-performance Rust functions to Python using PyO3 and maturin. It provides **simplified** utilities to generate 3D atomic point lattices (simple cubic only) and compute a Debye scattering-like intensity using parallel Rust code. This is an educational/demonstration project showing Rust-Python integration for scientific computing.\n\n\n\n\n\n- Rust module name (as seen from Python): `fast_dse`\n- Python demo entry point: `main.py`\n\n## Contents\n\n- `src/lib.rs` — Rust implementation of the Python module using PyO3 and Rayon\n- `main.py` — Example Python script that calls the Rust functions and plots results\n- `pyproject.toml` — maturin/PyO3 build configuration\n- `Cargo.toml` — Rust crate configuration\n- `LICENSE` — MIT License\n\n## What the library provides (`src/lib.rs`)\n\nThe Rust library defines a Python module named `fast_dse` with two functions:\n\n1) `crystal(shape: str, lattice_param: float, length: float) -\u003e list[list[float]]`\n   - Generates 3D lattice points with a simple step equal to `lattice_param`.\n   - Supported `shape` values:\n     - `\"cube\"`: all lattice points in a cube of side `length`.\n     - `\"sphere\"`: lattice points inside a sphere of diameter `length` (radius `length/2`).\n   - Returns: a list of 3D points `[x, y, z]` (floats) representing atom positions.\n\n2) `dse_optimized(min_q: float, max_q: float, q_step: float, crystal: list[list[float]]) -\u003e list[float]`\n   - Computes an intensity profile over `q` in `[min_q, max_q)` with spacing `q_step`.\n   - The intensity is calculated using the simplified Debye scattering equation:\n\n     $$I(q) = \\sum_{i=1}^{N} \\sum_{j=1}^{N} \\frac{\\sin(q \\cdot r_{ij})}{q \\cdot r_{ij}}$$\n\n     where $N$ is the number of atoms and $r_{ij}$ is the distance between atoms $i$ and $j$.\n\n   - Internally:\n     - Precomputes all pairwise squared distances between points in `crystal`.\n     - For each `q`, sums `sin(q * r) / (q * r)` over all pairs, with `r=0` contributing `1.0`.\n     - Uses Rayon for parallelism over `q` values.\n   - Returns: a list of intensities with length `floor((max_q - min_q) / q_step)`.\n\nThese functions are exported to Python with PyO3 via the `#[pymodule]` named `fast_dse`.\n\n## Important Limitations\n\nThis is a **simplified implementation** intended for educational purposes and basic simulations:\n\n- **Crystal structures**: The `crystal()` function generates simple cubic lattices only. It does **not** support common crystal structures like FCC (face-centered cubic), BCC (body-centered cubic), HCP (hexagonal close-packed), or other Bravais lattices.\n\n- **Atomic scattering factors**: The `dse_optimized()` function does **not** account for atomic scattering factors (form factors). This implementation is only accurate (up to a coefficient) for **monoatomic crystals** with identical scattering atoms. For real materials with different atom types or accurate X-ray/neutron scattering calculations, proper form factors must be included.\n\nFor production use in materials science or crystallography, consider using established libraries like [pymatgen](https://pymatgen.org/), [ASE](https://wiki.fysik.dtu.dk/ase/), or [diffpy](https://www.diffpy.org/).\n\n## Demo script (`main.py`)\n\n`main.py` shows how to:\n- Import the Rust functions from Python: `from fast_dse import crystal, dse_optimized`\n- Generate two crystals (sphere and cube)\n- Compute intensities for a `q` range\n- Plot both curves using matplotlib\n\nSnippet:\n```python\nfrom fast_dse import crystal, dse_optimized\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nlattice_param = 3.89\nlength = 30\nsphere_crystal = crystal(\"sphere\", lattice_param, length)\ncube_crystal = crystal(\"cube\", lattice_param, length)\n\nq_0, q_f, q_step = 1.0, 15.0, 0.1\nq_array = np.arange(q_0, q_f, q_step)\nintensity_sphere = dse_optimized(q_0, q_f, q_step, sphere_crystal)\nintensity_cube = dse_optimized(q_0, q_f, q_step, cube_crystal)\n\nplt.plot(q_array, intensity_sphere, label=\"sphere\")\nplt.plot(q_array, intensity_cube, label=\"cube\")\nplt.legend()\nplt.xlabel(\"q\")\nplt.ylabel(\"Intensity\")\nplt.title(\"Debye-like Scattering Intensity\")\nplt.show()\n```\n\n## Installation\n\n**Prerequisites:**\n- Rust toolchain (stable) — install via https://rustup.rs\n- Python 3.8+ (matching your environment)\n- **uv** (recommended) — a fast Python package installer and environment manager written in Rust. Install via `pip install uv` or see https://github.com/astral-sh/uv\n- On Windows, ensure your Python architecture (e.g., 64-bit) matches the Rust toolchain target. Using a recent MSVC build chain via Visual Studio Build Tools is recommended.\n\n**Setup with uv (recommended):**\n\n1. Clone the repository:\n```bash\ngit clone https://github.com/AlbertKurtz/fast_dse.git\ncd fast_dse\n```\n\n2. Create a virtual environment and install with dev dependencies:\n```bash\nuv venv\n# On Windows:\n.venv\\Scripts\\activate\n# On macOS/Linux:\nsource .venv/bin/activate\n\nuv pip install -e .[dev]\n```\n\nThis will compile the Rust extension and install it into your virtual environment so you can immediately `import fast_dse`.\n\n**Alternative with pip:**\n\n```bash\npython -m venv .venv\n# Activate virtual environment (see above)\npip install -e .[dev]\n```\n\n**Building a wheel manually:**\n\n```bash\nuv pip install maturin\nmaturin build --release\n# find the .whl in target/wheels/ and install it\nuv pip install target/wheels/\u003cyour_wheel_name\u003e.whl\n```\n\n## Running the demo\n\nAfter installation with dev dependencies (make sure your virtual environment is activated):\n\n```bash\npython main.py\n```\n\nThis will open a plot window comparing the intensity for a spherical and cubic crystal with the parameters from the script.\n\n## Performance notes\n\n- `dse_optimized` uses Rayon to parallelize over `q` values and precomputes all pairwise distances for cache efficiency.\n- For large crystals, the distance matrix is O(N^2) in memory and time to precompute; adjust `length` and `lattice_param` accordingly.\n\n## Troubleshooting\n\n- **ImportError: No module named `fast_dse`**\n  - Make sure you installed the package with `uv pip install -e .[dev]`\n  - Verify you're using the correct Python environment: `python -c \"import sys; print(sys.executable)\"`\n  - Make sure your virtual environment is activated\n\n- **Linker/build errors on Windows**\n  - Ensure you have the MSVC toolchain installed via Visual Studio Build Tools\n  - Verify that Rust targets your Python architecture (both should be 64-bit or both 32-bit)\n\n- **ImportError: No module named 'matplotlib'** (when running demo)\n  - Install matplotlib: `uv pip install matplotlib` or use dev dependencies: `uv pip install -e .[dev]`\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falbertkurtz%2Ffast_dse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falbertkurtz%2Ffast_dse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falbertkurtz%2Ffast_dse/lists"}