Skip to content

[WIP] Draft of generalized RustBCA python wrapper(s) - #324

Merged
drobnyjt merged 12 commits into
devfrom
pythonize_test
Aug 6, 2026
Merged

[WIP] Draft of generalized RustBCA python wrapper(s)#324
drobnyjt merged 12 commits into
devfrom
pythonize_test

Conversation

@drobnyjt

@drobnyjt drobnyjt commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Thank you for your contribution to rustBCA!

Before submitting this PR, please make sure you have:

  • Opened an issue
  • Referenced the relevant issue number(s) below
  • Provided a description of the changes below
  • Ensured all tests pass and added any necessary tests for new code

Fixes #277

Description

This PR adds a new way to run RustBCA - a Python wrapper that takes an input-file-shaped dictionary and runs RustBCA without generating or parsing an input file.

This comes in two flavors: rustbca_py(input_file, geometry_mode) which produces identical output files to the standalone code and rustbca_local_py(input_file, geometry_mode) which produces a dict from this Rust struct:

pub struct FinishedParticlesContainer {
    sputtered: Vec<bool>,
    implanted: Vec<bool>,
    atomic_number: Vec<usize>,
    mass: Vec<f64>,
    energy: Vec<f64>,
    x: Vec<f64>,
    y: Vec<f64>,
    z: Vec<f64>,
    ux: Vec<f64>,
    uy: Vec<f64>,
    uz: Vec<f64>,
}

All of this is made possible with the newest version of PyO3 and the pythonize crate, which allows one to serialize/deserialize python dicts to structs that implement serde (de)serialization.

Tests

I've added tests that compare the output of the two new functions to the standalone code to make_input_file_and_run.py.

Todo

  • both functions should return a PyErr as appropriate (this is more idiomatic than the int flag suggested in issue [feature] General python binding for rustbca #277)
  • implement other geometry types (currently only has 1D)
  • clean up module imports etc.

@drobnyjt drobnyjt changed the title Draft of generalized RustBCA python wrapper(s) [WIP] Draft of generalized RustBCA python wrapper(s) Aug 5, 2026
@drobnyjt
drobnyjt merged commit 7b306cd into dev Aug 6, 2026
2 checks passed
@drobnyjt
drobnyjt deleted the pythonize_test branch August 6, 2026 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant