MCNP Language Server from NuCoMP
This extension is for anyone working with (or just reading) input files for Los Alamos
National Laboratory's MCNP Code. MCNP presents a complex and expansive input
format that can often be troublesome for both new and experienced users.
The MCNP Language Server addresses these issues by providing error-checking
and other common IDE functions.
Features
- Editor services for MCNP6.2 via the MCNP Language Server.
- Input validation.
- Outline view.
- Syntax highlighting supported by a Textmate grammar.
- Auto-completion.
- Reference finding.
- Customizable
Run
andPlot
context menus and titlebar buttons.
Installation
Manual Install
Until this is published on the VS Code Marketplace, it needs to be manually installed.
- Download the latest release.
- Only the
.vsix
file is necessary.
- Only the
- Run
code --install-extension nucomp-mcnp-VERSION.vsix
.- Or use
Ctrl+Shift+P
in VS Code and searchInstall from VSIX
.
- Or use
- Activate the extension is VS Code (if necessary).
This will install the extension to your VS Code extensions folder.
- Windows:
%USERPROFILE%\.vscode\extensions
. - Linux:
~/.vscode/extensions
. - Mac:
~/.vscode/extensions
.
Configuring MCNP Line Limit and Indents
The default line limit in MCNP is 128 characters. An indent of 5 or more spaces is
treated as a line continuation. To have VS Code assist with these specifications,
add the following to your settings.json
.
"[mcnp]": {
"editor.rulers": [128],
"editor.tabSize": 5
}
Updating
Full Extension
- Download and install the latest version. You might have to manually delete the old
version(s) from your VS Code extensions folder.
Language Server Only
- Build or download a new MCNP language server.
- Replace the
bin
andlib
directories found in.../mcnp-server
.
Input Validation
Format Requirements
For the language server to work properly, all MCNP inputs are required to:
- Use the
.mcnp
file extension (or validation messages will not display). - Begin with a
$
comment on the first line. - End with exactly one blank line.
- Not have any extra blank lines at the start or end of a file.
MCNP is insensitive to these requirements, but they are necessary for validation.
Known Issues
There are some syntaxes that can be used in MCNP, but are treated as invalid by the
Language Server.
- Deprecated formats are not necessarily supported. The Language Server was designed
for the current MCNP6.2 syntax. - Having a line continuation character
&
at the end of the last line on a multi-line card. - Exponent notations that do not use the
E
. - The multiplier operator
xM
is not accepted on every card.- It will work on cards where it is commonly used like
IMP
.
- It will work on cards where it is commonly used like
- Using excess parentheses on
FM
cards. Only use the required amount. Examples:- Error:
fm4 ((-1 5 -1))
- Good:
fm4 (-1 5 -1)
- Error:
- Ordering of mixed numeric and symbolic particle types on
SI
. Symbols must come
before number. Examples:- Error:
SI14 L 1 2 H
- Error:
SI14 L 1 H 2
- Good:
SI14 L H 1 2
- Error:
- A blank line with 5+ spaces followed by an indented line. To avoid this error, simply:
- Remove all spaces on the lines between deck sections.
- Or avoid indenting the first card of a section.
Tips for Troubleshooting
- The easiest way to cause numerous errors is with a broken reference.
- For example, expect errors on your Cell cards until all Surfaces and Materials
have been defined. - Note that VS Code will track references between files in your working directory.
Easily check for this by using theGo to References
andGo to Definition
options.
- For example, expect errors on your Cell cards until all Surfaces and Materials
- Ensure that your deck has Cell, Surface, and Data card sections.
- The language server expects a full deck (unless the
CONTINUE
card is used).
- The language server expects a full deck (unless the
- Using the
READ
card will not invoke cross-file validation.- The entire deck is expected to be in the same file.
READ
is supported only as a data card.
- Try inputting all optional parameters for a card.
- The language server might be expecting the full card specification.
- Double-check the syntax described in the MCNP6.2 manual.
Run and Plot Options
These features need to be configured through the Extension Settings
menu.
The custom plot and run commands can be used for executing user-developed
scripts and take priority over the other run/plot options.
Options
Custom Plot Command
- Used for custom plotting scripts.- E.g. -
bash .../my_run_script
.
- E.g. -
Custom Run Command
- Used for custom run scripts.- E.g. -
bash .../my_plot_script
.
- E.g. -
Executable
- The absolute path to the MCNP executable.- E.g. -
.../MCNP620/MCNP_CODE/bin/mcnp6
.
- E.g. -
Data_path
- The absolute path to MCNP's data directory.- E.g. -
.../MCNP620/MCNP_DATA
.
- E.g. -
Run_args
- Additional arguments for MCNP execution.- E.g. -
TASKS 6
.
- E.g. -
Plot_args
- Additional arguments for MCNP Plotter execution.Xsdir
- The absolute path to MCNP's cross section directory file.- E.g. -
.../MCNP620/MCNP_DATA/xsdir_mcnp6.2
.
- E.g. -
Note that the file currently being run or plotted from the editor will be
supplied as an argument to MCNP or any custom scripts.