srim

class srim.TRIM(target, ion, calculation=1, number_ions=1000, **kwargs)

Automate TRIM Calculations

Parameters:
  • target (srim.core.target.Target) – constructed target for TRIM calculation

  • ion (srim.core.ion.Ion) – constructed ion for TRIM calculation

  • calculation (int, optional) – Default 1 quick KP calculation (1) Ion Distribution and Quick Calculation of Damage (quick KP) (2) Detailed Calculation with full Damage Cascades (full cascades) (3) Monolayer Collision Steps / Surface Sputtering (4) Ions with specific energy/angle/depth (quick KP damage) using TRIM.DAT (5) Ions with specific energy/angle/depth (full cascades) using TRIM.DAT (6) Recoil cascades from neutrons, etc. (full cascades) using TRIM.DAT (7) Recoil cascades and monolayer steps (full cascades) using TRIM.DAT (8) Recoil cascades from neutrons, etc. (quick KP damage) using TRIM.DAT

  • number_ions (int, optional) – number of ions that you want to simulate. Default 1000. A lot better than the 99999 default in TRIM…

  • kwargs – See srim.srim.TRIMSettings for available TRIM options. There are many and none are required defaults are appropriate for most cases.

Notes

If you are doing a simulation with over 1,000 ions it is recomended to split the calculaion into several smaller calculations. TRIM has been known to unexpectedly crash mainly due to memory usage.

beam

the sampled ions (srim.beam.exact.sample_ions)

Type:

exact mode of a distributed spec

static copy_output_files(src_directory, dest_directory, check_srim_output=True)

Copies known TRIM files in directory to destination directory

Parameters:
  • src_directory (str) – source directory to look for TRIM output files

  • dest_directory (str) – destination directory to copy TRIM output files to

  • check_srim_output (bool, optional) – also copy the files that SRIM writes to its SRIM Outputs subfolder (RANGE_3D.txt, COLLISON.txt …). Files are copied, never moved: the source is left as it is, so a Results of it keeps working.

classmethod from_spec(spec)

Build a TRIM from a srim.spec.RunSpec or its dict form.

to_spec followed by from_spec writes a byte-identical TRIM.IN.

classmethod from_yaml(path)

Build a TRIM from a run.yaml.

run(srim_directory=None, write_spec=True, *, work_dir=None, output_dir=None, keep=False, lock_timeout=None, run_dir=None)

Run configured srim calculation

By default the calculation runs in its own private run directory, a lightweight copy of the installed SRIM (see srim.rundir.RunDir), so any number of runs can happen at the same time and the installed SRIM directory is never written. This method:

  • writes the input file to <run directory>/TRIM.IN

  • launches <run directory>/TRIM.exe. Uses wine if available (needed for linux and osx), in a private clone of the wine prefix

  • after a successful run writes <run directory>/run.yaml (see below)

The returned Results reads from the run directory, which is kept (below work_dir, default <pysrim2 data dir>/runs); pass output_dir to get the outputs in a folder of your choice instead, in which case the run directory is removed. A run that fails keeps its run directory for debugging; the error mentions its path.

Parameters:
  • srim_directory (str, optional) – Run in place in this SRIM directory (the pre-0.9 behaviour: outputs are written into it) instead of in a private copy. Concurrent in-place runs on the same directory take turns (exclusive file lock). Default None: run isolated, copying srim_dir() (resolved when this method is called: $PYSRIM2_SRIM_DIR, then pysrim2’s data directory, then /tmp/srim if it holds an install).

  • write_spec (bool, optional) – write run.yaml next to the outputs (in the run directory, where the results are read from; copy_output_files() copies it along with them). It holds the RunSpec (including the seed) and the provenance: pysrim2 version, SRIM SHA-256 (from the .pysrim2-installed marker, if present), platform, backend (native or wine), start and end time (UTC) and host name. Default True.

  • work_dir (str, optional) – folder to create the run directory in (default <pysrim2 data dir>/runs).

  • output_dir (str, optional) – copy the output files (and run.yaml) here and read the results from here; the run directory is then removed unless keep.

  • keep (bool, optional) – keep the run directory even when output_dir is given. Default False.

  • lock_timeout (float, optional) – in-place runs only: seconds to wait for the directory lock before raising TimeoutError (default: wait; a message appears after 5 s).

  • run_dir (srim.rundir.RunDir, optional) – reuse this run directory (it is reset first, and left in place afterwards). For workers that run many calculations.

Returns:

its spec attribute is the run spec as a dict (without provenance, so exports carry no host name), used by Results.to_parquet etc.

Return type:

srim.output.Results

to_spec()

Describe this calculation as a srim.spec.RunSpec.

The random seed is always recorded (when none was given, the one TRIMSettings picked), so running the spec again gives the same TRIM.IN. settings only holds values that differ from the defaults, plus description and ranges.

to_yaml(path, provenance=None)

Write this calculation as a run.yaml (see srim.spec.RunSpec.to_yaml()).

class srim.SR(layer, ion, **kwargs)

Automate SR Calculations

Parameters:
  • leyer (srim.core.layer.Layer) – constructed layer for SR calculation

  • ion (srim.core.ion.Ion) – constructed ion for SR calculation

  • kwargs – See srim.srim.SRSettings for available SR options. There are a few and none are required. Defaults are appropriate for most cases.

run(srim_directory=None, *, work_dir=None, output_dir=None, keep=False, lock_timeout=None, run_dir=None)

Run configured srim calculation

Like TRIM.run(), this runs in a private run directory by default (the installed SRIM is never written); srim_directory= runs in place under a file lock. This method:

  • writes the input file to <run directory>/SR Module/TRIM.IN

  • launches <run directory>/SR Module/SRModule.exe. Uses wine if available (needed for linux and osx)

Parameters:
  • srim_directory (str, optional) – run in place in this SRIM directory (TRIM.exe should be located in it), the pre-0.9 behaviour, under an exclusive file lock. Default None: run in a private copy of srim_dir() (resolved when this method is called: $PYSRIM2_SRIM_DIR, then pysrim2’s data directory, then /tmp/srim if it holds an install).

  • work_dir – see TRIM.run(); output_dir receives the SR output file.

  • output_dir – see TRIM.run(); output_dir receives the SR output file.

  • keep – see TRIM.run(); output_dir receives the SR output file.

  • lock_timeout – see TRIM.run(); output_dir receives the SR output file.

  • run_dir – see TRIM.run(); output_dir receives the SR output file.

class srim.Ion(identifier, energy, mass=None)

Representation of ion traveling through medium

Similar to srim.core.element.Element but associates an energy with the element.

Parameters:
  • identifier (str, int) – Symbol, Name, or Atomic Number of ion

  • energy (float) – Energy [eV] of ion

  • mass (float, optional) – Mass [amu] of element. Default is most common isotope atomic weight

Examples

Constructing a Helium Ion.

>>> Ion('He', 1e6)
"<Ion element:He mass:4.00 energy:1.00e6 eV>"
>>> Ion('He', energy=1e6, mass=4.2)
"<Ion element:He mass:4.20 energy:1.00e6 eV>"
property energy

Ion’s energy [eV]

property velocity

Ion’s velocity [m/s]

class srim.Layer(elements, density, width, phase=0, name=None)

Represents a layer in target

Parameters:
  • elements (dict) –

    dictionary of elements (srim.core.elements.Element, str, or int) with properties
    • stoich (float, int, required): Stoichiometry of element (fraction)

    • E_d (float, int, optional): Displacement energy [eV] default 25.0 eV

    • lattice (float, int, optional): Lattice binding energies [eV] default 0.0 eV

    • surface (float, int, optional): Surface binding energies [eV] default 3.0 eV

  • density (float) – density [g/cm^3] of material

  • width (float) – width [Angstroms] of layer

  • phase (int) – phase of material (solid = 0, gas = 1). Default solid (0).

  • name (str, optional) – name of the Layer (defaults to the element symbols joined by “+”, e.g. Si+C)

Examples

Construct a layer of SiC with experimental values.

>>> Layer({
    'Si': {
       'stoich': 0.5,
       'E_d': 35.0, # Displacement Energy [eV]
       'lattice': 0.0,
       'surface': 3.0
    },
    'C': {
       'stoich': 0.5,
       'E_d': 20.0, # Displacement Energy [eV]
       'lattice': 0.0,
       'surface': 3.0
}, density=3.21, width=10000.0)
classmethod from_formula(chemical_formula, density, width, phase=0, name=None)

Creation Layer from chemical formula string, density, width, phase, and name

Parameters:
  • chemical_formula (str) – see srim.core.material.Material.from_formula() for allowed formulas. Quite flexible.

  • density (float) – density [g/cm^3] of material

  • width (float) – width [Angstroms] of layer

  • phase (int) – phase of material (solid = 0, gas = 1). Default solid (0).

  • name (str, optional) – name of the Layer (defaults to chemical_formula, e.g. SiC; unlike Layer, which joins the element symbols with “+”)

Notes

This method is not used as much since you do not have an easy way to set the displacement energy.

property name

Layer’s Name

property width

Layer’s width

class srim.Target(layers)

Target that Ion Impacts

Parameters:

layers (list) – list of srim.core.layer.Layer to construct Target

Examples

Lets construct a SiC target. While only one layer is shown an arbitrary number of them can be used.

>>> Target([Layer({
    'Si': {
       'stoich': 0.5,
       'E_d': 35.0, # Displacement Energy [eV]
       'lattice': 0.0,
       'surface': 3.0
    },
    'C': {
       'stoich': 0.5,
       'E_d': 20.0, # Displacement Energy [eV]
       'lattice': 0.0,
       'surface': 3.0
}, density=3.21, width=10000.0)])
property width

total width of target (sum of layers)

class srim.Element(identifier, mass=None)

Element from periodic table

Parameters:
  • identifier (str, int) – Symbol, Name, or Atomic Number of element

  • mass (float, optional) – Mass [amu] of element. Default is most common isotope atomic weight

Examples

Constructing a Helium Atom.

>>> Element('He')
<Element symbol:He name:Helium mass:4.00>
>>> Element('Helium')
<Element symbol:He name:Helium mass:4.00>
>>> Element(2)
<Element symbol:He name:Helium mass:4.00>
>>> Element('He', 4.3)
<Element symbol:He name:Helium mass:4.30>
property atomic_number

Element’s atomic number

property mass

Element’s mass

property name

Element’s formal name

property symbol

Element’s atomic symbol

class srim.Material(elements, density, phase=0)

Material Representation

property chemical_formula

Material’s chemical formula

property density

Material’s density

classmethod from_formula(chemical_formula, density, phase=0)

Creation Material from chemical formula string and density

Parameters:
  • chemical_formula (str) – chemical formula string in specific format

  • density (float) – density [g/cm^3] of material

  • phase (int, optional) – phase of material (solid = 0, gas = 1). Default solid (0).

Notes

Examples of chemical_formula that can be used:
  • SiC

  • CO2

  • AuFe1.5

  • Al10.0Fe90.0

Chemical Formula will be normalized to 1.0

property phase

Material’s phase