MCNP Input and Output Interfaces – pyne.mcnp

There is a class for a variety of types of files that MCNP produces. The functionality of the module can be obtained by importing as such:

from pyne import mcnp

You may also want to consult the userguide page MCNP.

MCNP API

Module for parsing MCNP output data. MCNP is a general-purpose Monte Carlo N-Particle code developed at Los Alamos National Laboratory that can be used for neutron, photon, electron, or coupled neutron/photon/electron transport. Further information on MCNP can be obtained from http://mcnp.lanl.gov/

Mctal and Runtpe classes still need work. Also should add Meshtal and Outp classes.

If PyTAPS is not installed, then Wwinp, Meshtal, and Meshtally will not be available to use.

class pyne.mcnp.MeshTally(f, tally_number, tag_names=None, mesh_has_mats=False)[source]

This class stores all information from all single MCNP mesh tally that exists within some meshtal file. Header information is stored as attributes and the “mesh” attribute is a MOAB mesh with all result and relative error data tagged. This class inherits from StatMesh, exposing all statistical mesh manipulation methods.

Notes

All Mesh/StatMesh attributes are also present via a super() call to StatMesh.__init__().

Attributes:
tally_number : int

The MCNP tally number. Must end in 4 (e.g. 4, 14, 214).

particle : string

Either “neutron” for a neutron mesh tally or “photon” for a photon mesh tally.

dose_response : bool

True is the tally is modified by a dose response function.

x_bounds : list of floats

The locations of mesh vertices in the x direction.

y_bounds : list of floats

The locations of mesh vertices in the y direction.

z_bounds : list of floats

The locations of mesh vertices in the z direction.

e_bounds : list of floats

The minimum and maximum bounds for energy bins

mesh :

An iMesh instance tagged with all results and relative errors

tag_names : iterable

Four strs that specify the tag names for the results, relative errors, total results, and relative errors of the total results.

Create MeshTally object from a filestream open to the second line of a mesh tally header (the neutron/photon line). MeshTally objects should be instantiated only through the Meshtal class.

Parameters:
f : filestream

Open to the neutron/photon line.

tally_number : int

The MCNP fmesh4 tally number (e.g. 4, 14, 24).

tag_names : iterable, optional

Four strs that specify the tag names for the results, relative errors, total results and relative errors of the total results. This should come from the Meshtal.tags attribute dict.

mesh_has_mats : bool

If false, Meshtally objects will be created without PyNE material objects.

class pyne.mcnp.Meshtal(filename, tags=None, meshes_have_mats=False)[source]

This class stores all the information from an MCNP meshtal file with single or multiple fmesh4 neutron or photon tallies. The “tally” attribute provides key/value access to invidial MeshTally objects.

Attributes:
filename : string

Path to an MCNP meshtal file

version : float

The MCNP verison number

ld : string

The MCNP verison date

title : string

Title card from the MCNP input

histories : int

Number of histories from the MCNP simulation

tally : dict

A dictionary with MCNP fmesh4 tally numbers (e.g. 4, 14, 24) as keys and MeshTally objects as values.

tags : dict

Maps integer tally numbers to iterables containing four strs, the results tag name, the relative error tag name, the total results tag name, and the total relative error tag name. If tags is None the tags are named ‘x_result’, ‘x_rel_error’, ‘x_result_total’, ‘x_rel_error_total’ where x is n or p for neutrons or photons.

Parameters:
filename : str

MCNP meshtal file.

tags : dict, optional

Maps integer tally numbers to iterables containing four strs: the results tag name, the relative error tag name, the total results tag name, and the total relative error tag name. If tags is None the tags are named ‘x_result’, ‘x_rel_error’, ‘x_result_total’, ‘x_rel_error_total’ where x is n or p for neutrons or photons.

meshes_have_mats : bool

If false, Meshtally objects will be created without PyNE material material objects.

class pyne.mcnp.PtracReader(filename)[source]

Class to read _binary_ PTRAC files generated by MCNP.

Construct a new Ptrac reader for a given filename, determine the number format and read the file’s headers.

determine_endianness()[source]

Determine the number format (endianness) used in the Ptrac file. For this, the file’s first entry is used. It is always minus one and has a length of 4 bytes.

read_event_line(ptrac_event)[source]

Read an event record and save it to a given PtracParticle instance.

read_headers()[source]

Read and save the MCNP version and problem description from the Ptrac file.

read_next(format, number=1, auto=False, raw_format=False)[source]

Helper method for reading records from the Ptrac file. All binary records consist of the record content’s length in bytes, the content itself and then the length again. format can be one of the struct module’s format characters (i.e. i for an int, f for a float, s for a string). The length of the record can either be hard-coded by setting the number parameter (e.g. to read 10 floats) or determined automatically by setting auto=True. Setting the parameter raw_format to True means that the format string will not be expanded by number, but will be used directly.

read_nps_line()[source]

Read an NPS record and save the type of the next event.

read_variable_ids()[source]

Read the list of variable IDs that each record type in the Ptrac file is comprised of. The variables can vary for different problems. Consult the MCNP manual for details.

write_to_hdf5_table(hdf5_table, print_progress=0)[source]

Writes the events contained in this Ptrac file to a given HDF5 table. The table must already exist and have rows that match the PtracEvent definition. If desired, the number of processed events can be printed to the console each N events by passing the print_progress=N parameter.

class pyne.mcnp.Runtpe(filename)[source]
class pyne.mcnp.Srctp(filename)[source]

This class stores source site data from a ‘srctp’ file written by MCNP. The source sites are stored in the ‘fso’ array in MCNP.

Parameters:
filename : str

Path to Srctp file being worked with.

class pyne.mcnp.SurfSrc(filename, mode='rb')[source]

Enables manipulating both the header and tracklists in surface source files.

Example use cases include adding source particles from other codes, and combining multiple files together. Note that typically additional code will be needed to supplement this class in order to modify the header or track information in a way suitable to the use case.

Parameters:
filename : str

Path to surface source file being read or written.

mode : str, optional

String indicating file opening mode to be used (defaults to ‘rb’).

print_header()[source]

Returns contents of SurfSrc’s header as an informative string.

Returns:
header_string : str

A line-by-line listing of the contents of the SurfSrc’s header.

print_tracklist(max_tracks=None)[source]

Returns tracklists in SurfSrc as a string.

Parameters:
max_tracks : int, optional

Maximum number of tracks to print. Defaults to all tracks.

Returns:
track_data : str

Single string with data for one track on each line.

put_header()[source]

Write the header part of the header to the surface source file

put_summary()[source]

Write the summary part of the header to the surface source file

put_surface_info()[source]

Write the record for each surface to the surface source file

put_table_1()[source]

Write the table1 part of the header to the surface source file

put_table_2()[source]

Write the table2 part of the header to the surface source file

read_header()[source]

Read in the header block data. This block comprises 4 fortran records which we refer to as: header, table1, table2, summary.

read_tracklist()[source]

Reads in track records for individual particles.

update_tracklist(surf_src)[source]

Update tracklist from another surface source. This updates the surface source in-place.

write_header()[source]

Write the first part of the MCNP surface source file. The header content comprises five parts shown below.

write_tracklist()[source]

Write track records for individual particles. Second part of the MCNP surface source file. Tracklist is also known as a ‘phase space’.

class pyne.mcnp.Wwinp[source]

A Wwinp object stores all of the information from a single MCNP WWINP file. Weight window lower bounds are stored on a structured mesh. Only Cartesian mesh WWINP files are supported. Neutron, photon, and simotaneous neutron and photon WWINP files are supported.

Notes

Attribute names are identical to names speficied in WWINP file description in the MCNP5 User’s Guide Volume 3 Appendix J.

Attributes:
ni : number of integers on card 2.

ni = 1 for neutron WWINPs, ni = 2 for photon WWINPs or neutron + photon WWINPs.

nr : int

10 for rectangular, 16 for cylindrical.

ne : list of number of energy groups for neutrons and photons.

If ni = 1 the list is only 1 value long, to represent the number of neutron energy groups

nf : list of numbers

of fine mesh points in the i, j, k dimensions

nft : int

total number of fine mesh points

origin : list of i, j, k

minimums.

nc : list

number of coarse mesh points in the i, j, k dimensions

nwg : int

1 for rectangular, 2 for cylindrical.

cm : list of lists

of coarse mesh points in the i, j, k dimensions. Note the origin is not considered a coarse mesh point (as in MCNP).

fm : list of lists

of number of fine mesh points between the coarses mesh points in the i, j, k dimensions.

e : list of lists

of energy upper bounds for neutrons, photons. If ni = 1, the e will look like [[]]. If ni = 2, e will look like [[], []].

bounds : list of lists

of spacial bounds in the i, j, k dimensions.

mesh : Mesh object

with a structured mesh containing all the neutron and/or photon weight window lower bounds. These tags have the form “ww_X” where X is n or p The mesh has rootSet tags in the form X_e_upper_bounds.

read_mesh(mesh)[source]

This method creates a Wwinp object from a structured mesh object. The mesh must have tags in the form “ww_X” where X is n or p. For every particle there must be a rootSet tag in the form X_e_upper_bounds containing a list of energy upper bounds.

read_wwinp(filename)[source]

This method creates a Wwinp object from the WWINP file <filename>.

write_wwinp(filename)[source]

This method writes a complete WWINP file to <filename>.

class pyne.mcnp.Xsdir(filename)[source]

This class stores the information contained in a single MCNP xsdir file.

Notes

See MCNP5 User’s Guide Volume 3 Appendix K for more information.

Attributes:
f : file handle

The xsdir file.

filename : str

Path to the xsdir file.

directory : str

Path to the directory containing the xsdir file.

datapath : str

The data path specified in the first line of the xsdir file, if it exists.

awr : dict

Maps material ids to their atomic weight ratios.

tables : list

Entries are XsdirTable objects, that appear in the same order as the xsdir table lines.

Parameters:
filename : str

Path to xsdir file.

find_table(name)[source]

Find all tables for a given ZIAD.

Parameters:
name : str

The ZIAD name.

Returns:
tables : list

All XsdirTable objects for a given ZIAD.

nucs()[source]

Provides a set of the valid nuclide ids for nuclides contained in the xsdir.

Returns:
valid_nucs : set

The valid nuclide ids.

read()[source]

Populate the Xsdir object by reading the file.

to_xsdata(filename)[source]

Writes a Serpent xsdata file for all continuous energy xs tables.

Parameters:
filename : str

The output filename.

class pyne.mcnp.XsdirTable[source]

Stores all information that describes a xsdir table entry, which appears as a single line in xsdir file. Attribute names are based off of those found in the MCNP5 User’s Guide Volume 3, appendix K.

Attributes:
name : str

The ZAID and library identifier, delimited by a ‘.’.

awr : float

The atomic mass ratio of the nuclide.

filename : str

The relative path of the file containing the xs table.

access : str

Additional string to specify an access route, such as UNIX directory. This entry is typically 0.

filetype : int

Describes whether the file contains formated (1) or unformated (2) file.

address : int

If filetype is 1, address is the line number of the xsdir table. If filetype is 2, address is the record number.

tablelength : int

Length of the second block of a data table.

recordlength : int

Unused for filetype = 1. For filetype = 2, recordlength is the number of entires per record times the size (in bytes) of each entry.

entries : int

Unused for filetype = 1. For filetype = 2, it is the number of entries per record

temperature : float

Temperature in MeV for neutron data only.

ptable : bool

True if xs table describes continuous energy neutron data with unresolved resonance range probability tables.

to_serpent(directory='')[source]

Converts table to serpent format.

Parameters:
directory : str

The directory where Serpent data is to be stored.

alias

Returns the name of the table entry <ZIAD>.<library id>.

metastable

Returns 1 is xsdir table nuclide is metastable. Returns zero otherwise.

serpent_type

Converts cross section table type to Serpent format: :1: continuous energy (c). :2: dosimetry table (y). :3: termal (t).

zaid

Returns the ZIAD of the nuclide.

pyne.mcnp.mat_from_inp_line(filename, mat_line, densities='None')[source]

This function reads an MCNP material card from a file and returns a Material or Multimaterial object for the material described by the card. This function is used by mats_from_inp().

Parameters:
filename : str

Name of the MCNP input file

mat_line : int

Line number of the material card or interest

densities : list of floats

The densities associated with the material

Returns:
finished_mat : Material or MultiMaterial

A Material object is returned if there is 1 density supplied. If multiple densities are supplied a MultiMaterial is returned.

pyne.mcnp.mats_from_inp(inp)[source]

This function reads an MCNP inp file and returns a mapping of material numbers to material objects.

Parameters:
inp : str

MCNP input file

Returns:
materials : dict

Keys are MCNP material numbers and values are PyNE material objects (for single density materials) and MultiMaterial objects (for multiple density materials).

pyne.mcnp.mesh_to_geom(mesh, frac_type='mass', title_card='Generated from PyNE Mesh')[source]

This function reads a structured Mesh object and returns the geometry portion of an MCNP input file (cells, surfaces, materials), prepended by a title card. The mesh must be axis aligned. Surfaces and cells are written in xyz iteration order (z changing fastest).

Parameters:
mesh : PyNE Mesh object

A structured Mesh object with materials and valid densities.

frac_type : str, optional

Either ‘mass’ or ‘atom’. The type of fraction to use for the material definition.

title_card : str, optional

The MCNP title card to appear at the top of the input file.

Returns:
geom : str

The title, cell, surface, and material cards of an MCNP input file in the proper order.