-
Notifications
You must be signed in to change notification settings - Fork 16
Bindings: Python
Note: PyO3 May not build correctly on MacOS. See Issue #143
First, the Python bindings require the following Python3 modules to be installed:
setuptools_rust
testresources
-
rustc
, must be available on your system PATH. - On Windows machines, you may need to install the Visual Studio C++ Build Tools.
Running:
python3 -m pip install .
Will compile RustBCA as a library, construct the Python bindings, and build a python module, libRustBCA.pybca, that can be immediately imported into any Python script. An annotated example, test_rustbca.py, is included in the examples folder.
examples/test_rustbca.py
uses simple_bca_list_py()
to simulate 1 keV helium on tungsten. To run, you need the Python bindings installed (see above), matplotlib, and numpy. It compares the sputtering yield to Yamamura's formula and the reflection coefficient to Thomas' formula. Differences between RustBCA simulation results and these formulas at moderate energy should be within 10% for most materials; it also produces the sputtered energy distribution and the implanted depth distribution using matplotlib, displayed below.
To run the example, simply call the script from the command line:
C:\rustbca>python examples\test_rustbca.py
or
username@PCNAME:/rustbca$python3 examples/test_rustbca.py
Sample output of test_rustbca.py looks like this:
Running RustBCA for 100000 He ions on W at 1.0 keV...
This may take several minutes.
Simulation complete. Processing data...
Data processing complete.
RustBCA Y: 0.0287 Yamamura Y: 0.025479590898842535
RustBCA R: 0.50558 Thomas R: 0.4780755087527244
Time per ion: 1.192930190563202 us/He
Implanted helium on tungsten at 1 keV
Energy distribution of tungsten sputtered by helium at 1 keV
- x, y, z: starting position in angstroms (Recommended: 0, 0, 0)
- ux, uy, uz: initial direction
- E: energy in eV
- Z1: atomic number of incident ion
- M1: atomic mass of incident ion (amu)
- Ec1: cutoff energy of incident ion (eV)
- Es1: surface binding energy of incident ion (eV)
- Z2: atomic number of material
- M2: atomic mass of material (amu)
- Ec2: cutoff energy of material (eV)
- Es2: surface binding energy of material (eV)
- n2: number density of material (1/angstrom^3)
- Eb2: bulk binding energy of material (eV)
The output of simple_bca_list_py
is a list of output particles with the following parameters:
[[Z, m (amu), E (eV) x (Angstrom), y (Angstrom), z (Angstrom), ux, uy, uz], ...]
Note that this includes implanted particles (with E < Es & x > 0), reflected particles (with E > 0 & x < 0), and sputtered particles (Z = Z_target & x < 0 & E > 0).