NISTMonte was developed in Java and can readily be integrated into Java language applications. However, for day-to-day work, creating new Java applications for each new simulation can be a little tedious. As an alternative, we suggest scripting in Jython.
From the Jython web site - “Jython is an implementation of the high-level, dynamic, object-oriented language Python written in 100% Pure Java, and seamlessly integrated with the Java platform “
We have developed many scripts of various levels of sophistication in Jython. It is a robust and flexible environment for developing Monte Carlo simulations. Anything that can be done in Java can (as best as I can tell) be done in Jython. Complex sample geometries with multiple detectors can be iteratively designed. The resulting simulations can be looped over almost any combination of parameters including beam location, beam energy, composition, sample orientation, sample size or sample shape. The resulting scripts can be used to document the simulation parameters.
The tight integration between Jython and Java means that it is possible to use any Java library as though it were an integral part of the Jython environment. This is true both for the default Java run-time libraries and third-party libraries such as NISTMonte.
Despite its interpreted nature, in most cases, Jython does not seem to introduce a substantial speed penalty. While it is true that interpreted Jython script is much slower than Java, most scripts spend most of their time executing the NISTMonte byte-code and so run at full Java speeds. The exception are scripts which involve a lot of setup or tear down or which develop classes which are used in a tight loop within NISTMonte.
To facilitate the use of Jython, NISTMonte comes with a simple GUI for executing Jython scripts. Another nice GUI for Jython in available through Artenum. The Artenum environment has the advantage of code completion.
NISTMonte also comes with an assortment of Jython scripts. These scripts demonstrate how Jython can be used to configure sample geometries, place and configure detectors, execute simulations and record the results. It is suggested that you use these scripts as a basis or template for your own scripts.
There are many different sources for information on Jython. Some web sites and a book are listed below. We have found the book by Pedroni and Rappin to be particularly useful.
Jython
Essentials by Samuele Pedroni, Noel Rappin
March
2002, O'Reilly Press, 304 pages ISBN: 0-596-00247-5
A document was written to help new users script NISTMonte using Jython. This document is available here. Please read this document carefully before trying to use NISTMonte.
JythonGUI can either be used to execute Python-syntax commands from the caret or to execute scripts. I typically use TextPad (Windows) or Kate (KDE) to edit scripts although any text editor will work. Open the scripts using the File - Open menu item. The output from scripts can be save to an standard text file using File - Save.
The JythonGUI defines a few useful variables which you can use on the command line or in scripts. Remember as a scripting environment that your current work environment consists of all previously defined variables plus those you define in your current statement or script.
ScriptFile: Defined during the execution of a script file as
full path to the current script file.
stdOut: A
Writer
representing the standard output stream. Output written to stdOut is displayed
in the JythonGUI window in the standard output text font and color.stdErr: A
Writer
representing the standard error stream. Output written to stdErr is displayed
in the JythonGUI window in red.ClassPath: A diagnostic for determining the class-path used
by the JythonGUI to search for JAR files.isWindows: Is the current instance of JythonGUI running on
Windows? (1 means yes, 0 means no) This is useful for determining where to
place and how to name scripts.UserHome: The user's home directory for documents.DefaultOutput: A suggested default output directory based
on the scripts name and location.PathSep: Either a forward slash or back slash character depending
upon the current operating systems preferences for path separation character.