montepy.mcnp_problem module#

Classes:

MCNP_Problem(destination)

A class to represent an entire MCNP problem in a semantic way.

class montepy.mcnp_problem.MCNP_Problem(destination)#

Bases: object

A class to represent an entire MCNP problem in a semantic way.

Notes

If a stream is provided. It will not be closed by this function.

Parameters:

destination (io.TextIOBase, str, os.PathLike) – the path to the input file to read, or a readable stream.

Methods:

add_cell_children_to_problem()

Deprecated: Adds the surfaces, materials, and transforms of all cells in this problem to this problem to the

clone()

Creates a complete independent copy of this problem.

parse(input[, append])

Parses the MCNP object given by the string, and links it adds it to this problem.

parse_input([check_input, replace])

Semantically parses the MCNP file provided to the constructor.

remove_duplicate_surfaces(tolerance)

Finds duplicate surfaces in the problem, and remove them.

set_mode(particles)

Sets the mode of problem to the given particles.

write_problem(destination[, overwrite])

Write the problem to a file or writeable object.

write_to_file(file_path[, overwrite])

Writes the problem to a file.

Attributes:

cells

A collection of the Cell objects in this problem.

data_inputs

A list of the DataInput objects in this problem.

input_file

The file name of the original file name this problem was read from.

materials

A collection of the Material objects in this problem.

mcnp_version

The version of MCNP that this is intended for.

message

The Message object at the beginning of the problem if any.

mode

The mode of particles being used for the problem.

original_inputs

A list of the MCNP_Inputs read from the original file.

print_in_data_block

Controls whether or not the specific input gets printed in the cell block or the data block.

surfaces

A collection of the Surface objects in this problem.

title

The Title object for the title.

transforms

The collection of transform objects in this problem.

universes

The Universes object holding all problem universes.

add_cell_children_to_problem()#
Deprecated: Adds the surfaces, materials, and transforms of all cells in this problem to this problem to the

internal lists to allow them to be written to file.

Deprecated since version 1.0.0: This function is no longer needed. When cells are added to problem.cells these children are added as well.

Raises:

DeprecationWarning

clone()#

Creates a complete independent copy of this problem.

Added in version 0.5.0.

Return type:

MCNP_Problem

parse(input: str, append: bool = True) MCNP_Object#

Parses the MCNP object given by the string, and links it adds it to this problem.

This attempts to identify the input type by trying to parse it in the following order:

  1. Data Input

  2. Surface

  3. Cell

This is done mostly for optimization to go from easiest parsing to hardest. This will:

  1. Parse the input

  2. Link it to other objects in the problem. Note: this will raise an error if those objects don’t exist.

  3. Append it to the appropriate collection

Parameters:
  • input (str) – the string describing the input. New lines are allowed but this does not need to meet MCNP line length rules.

  • append (bool) – Whether to append this parsed object to this problem.

Returns:

the parsed object.

Return type:

MCNP_Object

Raises:
parse_input(check_input=False, replace=True)#

Semantically parses the MCNP file provided to the constructor.

Parameters:
  • check_input (bool) – If true, will try to find all errors with input and collect them as warnings to log.

  • replace (bool) – replace all non-ASCII characters with a space (0x20)

remove_duplicate_surfaces(tolerance)#

Finds duplicate surfaces in the problem, and remove them.

Parameters:

tolerance (float) – The amount of relative error to consider two surfaces identical

set_mode(particles)#

Sets the mode of problem to the given particles.

For details see: montepy.data_cards.mode.Mode.set().

Parameters:

particles (list, str) – the particles that the mode will be switched to.

Raises:

ValueError – if string is not a valid particle shorthand.

write_problem(destination, overwrite=False)#

Write the problem to a file or writeable object.

Parameters:
  • destination (io.TextIOBase, str, os.PathLike) – File path or writable object

  • overwrite (bool) – Whether to overwrite ‘destination’ if it is an existing file

write_to_file(file_path, overwrite=False)#

Writes the problem to a file.

Changed in version 0.3.0: The overwrite parameter was added.

Parameters:
  • file_path (str, os.PathLike) – the file path to write this problem to

  • overwrite (bool) – Whether to overwrite the file at ‘new_problem’ if it exists

Raises:
  • IllegalState – if an object in the problem has not been fully initialized.

  • FileExistsError – if a file already exists with the same path.

  • IsADirectoryError – if the path given is actually a directory.

property cells#

A collection of the Cell objects in this problem.

Returns:

a collection of the Cell objects, ordered by the order they were in the input file.

Return type:

Cells

property data_inputs#

A list of the DataInput objects in this problem.

Returns:

a list of the DataCardAbstract objects, ordered by the order they were in the input file.

Return type:

list

property input_file#

The file name of the original file name this problem was read from.

Return type:

MCNP_InputFile

property materials#

A collection of the Material objects in this problem.

Returns:

a colection of the Material objects, ordered by the order they were in the input file.

Return type:

Materials

property mcnp_version#

The version of MCNP that this is intended for.

Notes

MCNP versions prior to 6.2 aren’t fully supported to avoid Export Control Restrictions. Documentation for MCNP 6.2 is public in report: LA-UR-17-29981. All features are based on MCNP 6.2, and may cause other versions of MCNP to break.

The version is a tuple of major, minor, revision. 6.2.0 would be represented as (6, 2, 0)

Return type:

tuple

property message#

The Message object at the beginning of the problem if any.

Return type:

Message

property mode#

The mode of particles being used for the problem.

Return type:

Mode

property original_inputs#

A list of the MCNP_Inputs read from the original file.

This should not be mutated, and should be used as a reference to maintain the structure

Deprecated since version 0.2.0: This will likely be removed soon, and it’s functionality will not be necessary to reproduce.

Returns:

A list of the MCNP_Object objects representing the file as it was read

Return type:

list

property print_in_data_block#

Controls whether or not the specific input gets printed in the cell block or the data block.

This acts like a dictionary. The key is the case insensitive name of the card. For example to enable printing importance data in the data block run:

problem.print_in_data_block["Imp"] = True

Note

The default for this is False, that is to print the data in the cell block if this was not set in the input file or by the user.

Changed in version 1.0.0: Default value changed to False

Return type:

dict[str, bool]

property surfaces#

A collection of the Surface objects in this problem.

Returns:

a collection of the Surface objects, ordered by the order they were in the input file.

Return type:

Surfaces

property title#

The Title object for the title.

Return type:

Title

property transforms#

The collection of transform objects in this problem.

Returns:

a collection of transforms in the problem.

Return type:

Transforms

property universes#

The Universes object holding all problem universes.

Returns:

a collection of universes in the problem.

Return type:

Universes