PyMCNP Library¶
Warning
PyMCNP is in active development! Please, double check everything works. Reports error on [GitHub](https://github.com/FSIBT/PyMCNP).
PyMCNP provides the backend for the CLI and useful tools for programatically interfacing with MCNP. This package supports INP, OUTP, PTRAC, and MESHTAL parsing using subpackages.
Table of Contents¶
AST Classes¶
PyMCNP represents MCNP files using the Inp, Meshtal, and Ptrac AST classes and
inp, meshtal, and ptrac subpackages. These classes have important methods for translating PyMCNP and MCNP:
from_mcnp. Parses MCNP source, checking for syntax and semantic errors.to_mcnp. Generates MCNP source from PyMCNP objects, reformatting.from_file. Parses MCNP file.to_file. Generates MCNP file from PyMCNP objects.
Inp Class¶
- class pymcnp.Inp(title: String, cells: _Tuple, surfaces: _Tuple, data: _Tuple, message: String = None, other: String = None)¶
Represents INP files.
- classmethod from_file(filename: Path | str)¶
Generates McnpFile from MCNP files.
- Parameters:
filename – MCNP file path.
- Raises:
CliError – RUNTIME_PATH.
- static from_mcnp(source: str)¶
Generates Inp from INP.
- Parameters:
source – INP for Inp.
- Returns:
Inp.
- Raises:
InpError – SYNTAX_FILE.
- to_file(filename: str | Path)¶
Generates MCNP files from McnpFile.
- Parameters:
filename – new MCNP file path.
- to_mcnp()¶
Generates INP from Inp.
- Returns:
INP for Inp.
Outp Class¶
- class pymcnp.Outp(header: Header, blocks: _Tuple)¶
Represents OUTP files.
- header¶
OUPT header.
- blocks¶
OUTP tables.
OUTP footer.
- classmethod from_file(filename: Path | str)¶
Generates McnpFile from MCNP files.
- Parameters:
filename – MCNP file path.
- Raises:
CliError – RUNTIME_PATH.
- static from_mcnp(source: str)¶
Generates Outp from OUTP.
- Parameters:
source – OUTP for Outp.
- Returns:
Outp.
- to_dataframe()¶
Generates pandas.DataFrame from Outp.
- Returns:
Tuple of pandas.DataFrame.
- to_file(filename: str | Path)¶
Generates MCNP files from McnpFile.
- Parameters:
filename – new MCNP file path.
- to_mcnp()¶
Generates OUTP from Outp.
- Returns:
OUTP for Outp.
Ptrac Class¶
- class pymcnp.Ptrac(header: Header, histories: Generator[History, None, None])¶
Represents PTRAC files.
- header¶
PTRAC header.
- histories¶
PTRAC histories.
- classmethod from_file(filename: Path | str)¶
Generates McnpFile from MCNP files.
- Parameters:
filename – MCNP file path.
- Raises:
CliError – RUNTIME_PATH.
- static from_mcnp(source: str)¶
Generates Ptrac from PTRAC.
- Parameters:
source – PTRAC for Ptrac.
- Returns:
Ptrac.
- Raises:
PtracError – SYNTAX_FILE.
- to_file(filename: str | Path)¶
Generates MCNP files from McnpFile.
- Parameters:
filename – new MCNP file path.
- to_mcnp()¶
Generates PTRAC from Ptrac.
- Returns:
PTRAC for Ptrac.
Meshtal Class¶
- class pymcnp.Meshtal(header: Header, tallies: _Generator)¶
Represents MESTHAL files.
- header¶
MESHTAL header.
- tallies¶
MESTHAL tallies.
- classmethod from_file(filename: Path | str)¶
Generates McnpFile from MCNP files.
- Parameters:
filename – MCNP file path.
- Raises:
CliError – RUNTIME_PATH.
- static from_mcnp(source: str)¶
Generates Meshtal from MESHTAL.
- Parameters:
source – MESHTAL for Meshtal.
- Returns:
Meshtal.
- to_file(filename: str | Path)¶
Generates MCNP files from McnpFile.
- Parameters:
filename – new MCNP file path.
- to_mcnp()¶
Generates MESHTAL from Meshtal.
- Returns:
INP for Meshtal.
Doer Classes¶
The *Filter and *Processor classes help handle large Meshtal and Ptrac using generators.
PtracFilter and MeshtalFilter have overridable methods for filtering data, PtracProcessor
and MeshtalProcessor have overridable methods for processing data, and all can be run:
check_*. ReturnsTrue/Falseif data should be kept/removed.process_*. Operates with side effects on data.run. Runs the filter or processor.
MeshtalFilter Class¶
PtracFilter Class¶
- class pymcnp.PtracFilter¶
Filters PTRAC files.
- static check_bank(event: EventType) bool¶
Runs when filtering bank events.
- Parameters:
event – Event to filter.
- Returns:
True/False if the given event should/shouldn’t be kept.
- static check_collision(event: EventType) bool¶
Runs when filtering collision events.
- Parameters:
event – Event to filter.
- Returns:
True/False if the given event should/shouldn’t be kept.
- static check_source(event: EventType) bool¶
Runs when filtering source events.
- Parameters:
event – Event to filter.
- Returns:
True/False if the given event should/shouldn’t be kept.
- static check_surface(event: EventType) bool¶
Runs when filtering surface events.
- Parameters:
event – Event to filter.
- Returns:
True/False if the given event should/shouldn’t be kept.
- static check_terminal(event: EventType) bool¶
Runs when filtering terminal events.
- Parameters:
event – Event to filter.
- Returns:
True/False if the given event should/shouldn’t be kept.
MeshtalProcessor Class¶
PtracProcessor Class¶
- class pymcnp.PtracProcessor¶
Processes Ptrac.
- posthook()¶
Runs after processing.
- prehook()¶
Runs before processing.
- process_bank(event: EventType)¶
Runs when processing bank events.
- Parameters:
event – Event to process.
- process_collision(event: EventType)¶
Runs when processing collision events.
- Parameters:
event – Event to process.
- process_source(event: EventType)¶
Runs when processing source events.
- Parameters:
event – Event to process.
- process_surface(event: EventType)¶
Runs when processing surface events.
- Parameters:
event – Event to process.
- process_terminal(event: EventType)¶
Runs when processing termianl events.
- Parameters:
event – Event to process.
Check Class¶
Check compares and fixes MCNP files, using difflib,
Convert Class¶
Convert converts OUTP files to csv or parquet files, using pandas.
- class pymcnp.Convert(outp: Outp)¶
Converts OUTP files.
- Attribute:
outp: OUTP to convert.
- to_csv(number: str, path: str | Path)¶
Converts file to CSV.
- Parameter:
number: Tally to read. path: Path to new csv file.
- to_parquet(number: str, path: str | Path)¶
Converts file to PARQUET.
- Parameters:
number – Tally to read.
path – Path to new parquet file.
Plot Class¶
Plot plots OUTP files, using matplotlib.
Run Class¶
Run runs MCNP simulations in parallel, using subprocess.
- class pymcnp.Run(inps: Inp, command='mcnp6')¶
Runs INP files.
- inps¶
Files to run.
- command¶
Command to run.
- posthook_batch(path: Path)¶
Runs after the batch.
- Parameters:
path – Path to batch directory.
- posthook_file(path: Path, index: int)¶
Runs after a file.
- Parameters:
path – Path to run directory.
index – Run number.
- prehook_batch(path: Path)¶
Runs before the batch.
- Parameters:
path – Path to batch directory.
- prehook_file(path: Path, index: int)¶
Runs before a file.
- Parameters:
path – Path to run directory.
index – Run number.
- run(path: str | Path)¶
Runs a file.
- Parameters:
path – Directory for run.
Visualize Class¶
Visualize visualizes INP surfaces and cell geometries, using pyvista.
- class pymcnp.Visualize(inpt: Inp)¶
Visualizes INP files.
- inpt¶
Files to visualize.
- to_pdf_cell(number: tuple[str], path: str | Path)¶
Saves render of cells as PDF.
- Parameters:
number – Cell numbers to visualize.
path – Path to new pdf file.
- to_pdf_cells(path: str | Path)¶
Saves render of cells as PDF.
- Parameters:
path – Path to new pdf file.
- to_pdf_surface(number: tuple[str], path: str | Path)¶
Saves render of surfaces as PDF.
- Parameters:
number – Surface numbers to visualize.
path – Path to new pdf file.
- to_pdf_surfaces(path: str | Path)¶
Saves render of surfaces as PDF.
- Parameters:
path – Path to new pdf file.
- to_show_cell(number: tuple[str]) Plotter¶
Visualizes INP cell(s).
- Parameters:
numbers – Cell number to visualize.
- to_show_cells(skip=()) Plotter¶
Visualizes INP all cells.
- to_show_surface(number: tuple[str]) Plotter¶
Visualizes INP surface(s).
- Parameters:
number – Surface number to visualize.
- to_show_surfaces(skip=()) Plotter¶
Visualizes INP all surfaces.