Package: pysrim
All issues and contributions should be done onGitlab. Github is used only as a
mirror for visibilitypysrim: Automation, Analysis, and Plotting of SRIM Calculationspysrimis 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 imagecostrouc/pysrimfor
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/outputfor this example.Benchmarks
showthe
docker container is around 50-60% faster. I believe this is due to
usingxvfbdockerrun-v$PWD/examples/docker:/opt/pysrim/\-v/tmp/output:/tmp/output\-itcostrouc/pysrimsh-c"xvfb-run -a python3.6 /opt/pysrim/ni.py"ls/tmp/outputLatest ReleasePackage StatusLicenseBuild StatusCoverageCondaDocumentationPublicationDOI Repository ArchiveDocumentationLink todocumentation on readthedocsFeaturesAutomate running SRIM and TRIM on all operating systemsWhile TRIM is a great code it has many downsides regarding
automation. TheTRIM.INinput file is tedious to write yourself and
the gui that constructs theTRIM.INwill 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.pysrimaddresses 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 (usingwinefor linux and OSX), and allowing batch runs of calculations seethis
notebook
example.Below is a hello world example of usingpysrimfor running a TRIM
calcualtion. Note that/tmp/srimis the path to the SRIM executable
directory (SRIM.exeshould reside in this directory).pysrimwill
add all the necessary input files. If this ran successfully for you a
SRIM window will popup and start the calculation.fromsrimimportIon,Layer,Target,TRIM# Construct a 3MeV Nickel ionion=Ion('Ni',energy=3.0e6)# Construct a layer of nick 20um thick with a displacement energy of 30 eVlayer=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 Nickeltarget=Target([layer])# Initialize a TRIM calculation with given target and ion for 25 ions, quick calculationtrim=TRIM(target,ion,number_ions=25,calculation=1)# Specify the directory of SRIM.exe# For windows users the path will include C://...srim_executable_directory='/tmp/srim'# takes about 10 seconds on my laptopresults=trim.run(srim_executable_directory)# 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 parsedSeedocumentationfor all available options.Copy SRIM output files to directoryAfter a SRIM calculation has completed runcopy_output_filesto take
all of the output files and move them to a directory of your liking.fromsrimimportTRIMTRIM.copy_output_files('/tmp/srim','/home/costrouc/scratch/srim')Post processes SRIM output as numpy arraysBy far the hardest part about running TRIM calculations is analyzing
the output files.pysrimcomes with parsers forIONIZ.txt,VACANCY.txt,NOVAC.txt,E2RECOIL.txt,PHONON.txt,RANGE.txt,
andCOLLISON.txt. The
COLLISON.txt file can get quite large so theCollisionparser uses a
buffered reader that can handle any file size. Additinally a classsrim.output.Resultswill processes all output files in a directory and provide a
dictionary of each parsed output file.pysrimcomes with some
helpful plotting utilities such a plotting the DPA vs depth. However,pysrim'smost 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.fromsrim.outputimportPhonons,Ionizdefplot_damage_energy(folder,ax):phon=Phonons(folder)dx=max(phon.depth)/100.0energy_damage=(phon.ions+phon.recoils)*dxax.plot(phon.depth,energy_damage/phon.num_ions,label='{}'.format(folder))returnsum(energy_damage)defplot_ionization(folder,ax):ioniz=Ioniz(folder)dx=max(ioniz.depth)/100.0ax.plot(ioniz.depth,ioniz.ions,label='Ionization from Ions')ax.plot(ioniz.depth,ioniz.recoils,label='Ionization from Recoils')Setfoldersto list of directories to SRIM outputs. SeeAnalysisfor 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.folders=['test_files/2','test_files/4']image_directory='examples/images'fig,axes=plt.subplots(1,len(folders),sharey=True,sharex=True)forax,folderinzip(np.ravel(axes),folders):plot_damage_energy(folder,ax)plot_ionization(folder,ax)ax.legend()ax.set_ylabel('eV')ax.set_xlabel('Depth [Angstroms]')fig.suptitle('Ionization Energy vs Depth',fontsize=15)fig.set_size_inches((20,6))fig.savefig(os.path.join(image_directory,'ionizationvsdepth.png'),transparent=True)See [jupyter
notebook](<https://gitlab.com/costrouc/pysrim/blob/master/examples/notebooks/Analysis.ipynb)
for full demonstration of features.An example of creating some publication graphics with pysrim can also
be found in thatdirectory. I
have used this in apublication.InstallationInstallation ofpysrimis easy via pip or conda.Available on PyPipip install pysrimAvailable on Condaconda install -c costrouc pysrimAvailable on Dockerdocker pull costrouc/pysrimUnless you are using the docker image, you will need to install SRIM
on your machine using the instructions bellow for linux, OSX, and
windows.DockerThere is a docker container withpysrimand SRIM already
installed. Some interesting tricks had to be done with using wine and
faking an X11 session.xvfb-run -acreates 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/pysrimLinux and OSXFor linux an OSX you will need to first have wine installed. Seethis poston installation of wine on OSX. For linux you will typically be able to install wine viaapt get install wineoryum install wine. SRIM iscompatiblewith wine.Once you have wine installed run theinstaller scriptinstall.sh.Click extract and then done.WindowsA collegue of mine has gotten it to work easily on Windows but I
myself have no experience. Just download the executable atsrim.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 fromtrim.run().ContributingAll contributions, bug reports, bug fixes, documentation improvements,
enhancements and ideas are welcome! These should be submitted at theGitlab repository. Github is
only used for visibility.Contributors:Chris Ostrouchov(maintainer)Alex HansondschwenLicenseMIT