https://github.com/agoose77/pysrim

Automation, Analysis, and Plotting of SRIM Calculations

https://github.com/agoose77/pysrim

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 2 DOI reference(s) in README
  • Academic publication links
    Links to: joss.theoj.org, zenodo.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.3%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Automation, Analysis, and Plotting of SRIM Calculations

Basic Info
Statistics
  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • Open Issues: 0
  • Releases: 0
Fork of costrouc/pysrim
Created about 4 years ago · Last pushed over 3 years ago
Metadata Files
Readme License

README.md

srim heatmap

pysrim: Automation, Analysis, and Plotting of SRIM Calculations

pysrim is a python package that aims to wrap and extend SRIM a popular tool for simulating ions traveling through a material. There are many pain points to SRIM and this package aims to address them. These include compatibility with all OS's, automation and crash recovery of SRIM calculations, parsing of all output files, and publication quality plots.

There is now a docker image costrouc/pysrim for running pysrim and SRIM! No setup necissary and does not require a display so it is server ready. If you would like to try it run the short command below (obviously requires docker). All output files will be stored in /tmp/output for this example. Benchmarks show the docker container is around 50-60% faster. I believe this is due to using xvfb

bash docker run -v $PWD/examples/docker:/opt/pysrim/ \ -v /tmp/output:/tmp/output \ -it costrouc/pysrim sh -c "xvfb-run -a python3.6 /opt/pysrim/ni.py" ls /tmp/output

Latest Release latest release
latest release
Package Status status
License license
Build Status gitlab pipeline status
Coverage coverage
Conda conda downloads
Documentation readthedocs documentation
Publication
DOI Repository Archive DOI

Documentation

Link to documentation on readthedocs

Features

Automate running SRIM and TRIM on all operating systems

While TRIM is a great code it has many downsides regarding automation. The TRIM.IN input file is tedious to write yourself and the gui that constructs the TRIM.IN will crash at unexpeced moments. One of these crashes everyone has encountered is the fact that a float text field can never be empty. TRIM also has a tendancy to crash becuase it stores all cascades in memory. Meaning that for large runs with full cascades greater than 1,000 ions it will run out of memory. pysrim addresses all of these issues by providing a simple API wrapper for the input file (supporting all of the features), ability to run on all operating systems (using wine for linux and OSX), and allowing batch runs of calculations see this notebook example.

Below is a hello world example of using pysrim for running a TRIM calcualtion. Note that /tmp/srim is the path to the SRIM executable directory (SRIM.exe should reside in this directory). pysrim will add all the necessary input files. If this ran successfully for you a SRIM window will popup and start the calculation.

``` python from srim import Ion, Layer, Target, TRIM

Construct a 3MeV Nickel ion

ion = Ion('Ni', energy=3.0e6)

Construct a layer of nick 20um thick with a displacement energy of 30 eV

layer = Layer({ 'Ni': { 'stoich': 1.0, 'E_d': 30.0, 'lattice': 0.0, 'surface': 3.0 }}, density=8.9, width=20000.0)

Construct a target of a single layer of Nickel

target = Target([layer])

Initialize a TRIM calculation with given target and ion for 25 ions, quick calculation

trim = TRIM(target, ion, number_ions=25, calculation=1)

Specify the directory of SRIM.exe

For windows users the path will include C://...

srimexecutabledirectory = '/tmp/srim'

takes about 10 seconds on my laptop

results = trim.run(srimexecutabledirectory)

If all went successfull you should have seen a TRIM window popup and run 25 ions!

results is srim.output.Results and contains all output files parsed

```

See documentation for all available options.

Copy SRIM output files to directory

After a SRIM calculation has completed run copy_output_files to take all of the output files and move them to a directory of your liking.

``` python from srim import TRIM

TRIM.copyoutputfiles('/tmp/srim', '/home/costrouc/scratch/srim') ```

Post processes SRIM output as numpy arrays

By far the hardest part about running TRIM calculations is analyzing the output files. pysrim comes with parsers for IONIZ.txt, VACANCY.txt, NOVAC.txt, E2RECOIL.txt, PHONON.txt, RANGE.txt, and COLLISON.txt. The COLLISON.txt file can get quite large so the Collision parser uses a buffered reader that can handle any file size. Additinally a class srim.output.Results will processes all output files in a directory and provide a dictionary of each parsed output file. pysrim comes with some helpful plotting utilities such a plotting the DPA vs depth. However, pysrim's most powerful feature is that all of the text files are exposed as numpy arrays. The example below shows how to plot DPA using a simple math and numpy. This enables the user to seamlessly use TRIM and do analysis.

``` python from srim.output import Phonons, Ioniz

def plotdamageenergy(folder, ax): phon = Phonons(folder) dx = max(phon.depth) / 100.0 energydamage = (phon.ions + phon.recoils) * dx ax.plot(phon.depth, energydamage / phon.numions, label='{}'.format(folder)) return sum(energydamage)

def plot_ionization(folder, ax): ioniz = Ioniz(folder) dx = max(ioniz.depth) / 100.0 ax.plot(ioniz.depth, ioniz.ions, label='Ionization from Ions') ax.plot(ioniz.depth, ioniz.recoils, label='Ionization from Recoils') ```

Set folders to list of directories to SRIM outputs. See Analysis for detailed example. Notice how there is a python class for each SRIM output file and gives simple access to each column. This did require some complex regex to get working just right.

``` python folders = ['testfiles/2', 'testfiles/4'] image_directory = 'examples/images'

fig, axes = plt.subplots(1, len(folders), sharey=True, sharex=True)

for ax, folder in zip(np.ravel(axes), folders): plotdamageenergy(folder, ax) plotionization(folder, ax) ax.legend() ax.setylabel('eV') ax.setxlabel('Depth [Angstroms]') fig.suptitle('Ionization Energy vs Depth', fontsize=15) fig.setsizeinches((20, 6)) fig.savefig(os.path.join(imagedirectory, 'ionizationvsdepth.png'), transparent=True) ```

srim heatmap

See jupyter notebook for full demonstration of features.

An example of creating some publication graphics with pysrim can also be found in that directory. I have used this in a publication.

Installation

Installation of pysrim is easy via pip or conda.

Available on PyPi

  • pip install pysrim

Available on Conda

  • conda install -c costrouc pysrim

Available on Docker

  • docker pull costrouc/pysrim

Unless you are using the docker image, you will need to install SRIM on your machine using the instructions bellow for linux, OSX, and windows.

Docker

There is a docker container with pysrim and SRIM already installed. Some interesting tricks had to be done with using wine and faking an X11 session. xvfb-run -a creates a fake X11 session within the docker container therefore allowing SRIM to run on servers without displays. This is the method that I always use to run SRIM.

Image: costrouc/pysrim

Linux and OSX

For linux an OSX you will need to first have wine installed. See this post on installation of wine on OSX. For linux you will typically be able to install wine via apt get install wine or yum install wine. SRIM is compatible with wine.

Once you have wine installed run the installer script install.sh.

Click extract and then done.

Windows

A collegue of mine has gotten it to work easily on Windows but I myself have no experience. Just download the executable at srim.org. Next you will extract the SRIM files into a directory on your windows machine. Note the directory of installation as it will be needed from trim.run().

Contributing

All contributions, bug reports, bug fixes, documentation improvements, enhancements and ideas are welcome! These should be submitted at the Github repository. Github is only used for visibility.

Contributors: - Chris Ostrouchov (maintainer) - Alex Hanson - dschwen

License

MIT

Owner

  • Name: Angus Hollands
  • Login: agoose77
  • Kind: user
  • Location: United Kingdom
  • Company: 2i2c

Open Source Infrastructure Engineer @ 2i2c. Executable Books core team member. PhD in Nuclear Physics from the University of Birmingham.

GitHub Events

Total
Last Year

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 0
  • Total pull requests: 7
  • Average time to close issues: N/A
  • Average time to close pull requests: 3 minutes
  • Total issue authors: 0
  • Total pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 7
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
  • agoose77 (7)
Top Labels
Issue Labels
Pull Request Labels