montepy.data_inputs.importance module

class montepy.data_inputs.importance.Importance(input=None, in_cell_block=False, key=None, value=None)

Bases: CellModifierInput

A data input that sets the importance for a cell(s).

Parameters:
  • input (Input) – the Input object representing this data input

  • in_cell_block (bool) – if this card came from the cell block of an input file.

  • key (str) – the key from the key-value pair in a cell

  • value (SyntaxNode) – the value syntax tree from the key-value pair in a cell

property all

Setter for setting importance for all particle types in the problem at once.

Parameters:

importance (float) – the importance to set all particles to.

Returns:

None

Return type:

None

property allowed_keywords

The allowed keywords for this class of MCNP_Card.

The allowed keywords that would appear in the parameters block. For instance for cells the keywords IMP and VOL are allowed. The allowed keywords need to be in upper case.

Deprecated since version 0.2.0: This is no longer needed. Instead this is specified in montepy.input_parser.tokens.MCNP_Lexer._KEYWORDS().

Returns:

A set of the allowed keywords. If there are none this should return the empty set.

Return type:

set

property alpha_particle

Importance for particles of type alpha_particle

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property anti_cascade

Importance for particles of type anti_cascade

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property anti_electron_neutrino

Importance for particles of type anti_electron_neutrino

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property anti_lambda_baryon

Importance for particles of type anti_lambda_baryon

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property anti_muon_neutrino

Importance for particles of type anti_muon_neutrino

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property anti_negative_sigma_baryon

Importance for particles of type anti_negative_sigma_baryon

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property anti_neutron

Importance for particles of type anti_neutron

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property anti_omega

Importance for particles of type anti_omega

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property anti_positive_sigma_baryon

Importance for particles of type anti_positive_sigma_baryon

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property anti_proton

Importance for particles of type anti_proton

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property cascade

Importance for particles of type cascade

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property class_prefix

The text part of the card identifier.

For example: for a material the prefix is m

this must be lower case

Deprecated since version 0.2.0: This has been moved to _class_prefix()

Returns:

the string of the prefix that identifies a card of this class.

Return type:

str

Raises:

DeprecationWarning – always raised.

property classifier

The syntax tree object holding the data classifier.

For example this would container information like M4, or F104:n.

Returns:

the classifier for this data_input.

Return type:

ClassifierNode

property comments

The comments associated with this input if any.

This includes all C comments before this card that aren’t part of another card, and any comments that are inside this card.

Returns:

a list of the comments associated with this comment.

Return type:

list

static compress_jump_values(values)

Takes a list of strings and jump values and combines repeated jump values.

e.g., 1 1 J J 3 J becomes 1 1 2J 3 J

Deprecated since version 0.2.0: This should be automatically handled by the syntax tree instead.

Parameters:

values (list) – a list of string and Jump values to try to compress

Returns:

a list of MCNP word strings that have jump compression

Return type:

list

Raises:

DeprecationWarning – raised always.

static compress_repeat_values(values, threshold=1e-06)

Takes a list of floats, and tries to compress it using repeats.

E.g., 1 1 1 1 would compress to 1 3R

Deprecated since version 0.2.0: This should be automatically handled by the syntax tree instead.

Parameters:
  • values (list) – a list of float values to try to compress

  • threshold (float) – the minimum threshold to consider two values different

Returns:

a list of MCNP word strings that have repeat compression

Return type:

list

Raises:

DeprecationWarning – always raised.

property data

The syntax tree actually holding the data.

Returns:

The syntax tree with the information.

Return type:

ListNode

property deuteron

Importance for particles of type deuteron

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property electron

Importance for particles of type electron

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property electron_neutrino

Importance for particles of type electron_neutrino

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

format_for_mcnp_input(mcnp_version, has_following=False)

Creates a string representation of this MCNP_Object that can be written to file.

Parameters:

mcnp_version (tuple) – The tuple for the MCNP version that must be exported to.

Returns:

a list of strings for the lines that this input will occupy.

Return type:

list

property has_changed_print_style

returns true if the printing style for this modifier has changed from cell block to data block, or vice versa.

Deprecated since version 0.2.0: This property is no longer needed and overly complex.

Returns:

true if the printing style for this modifier has changed

Return type:

bool

Raises:

DeprecationWarning – raised always.

property has_classifier

Whether or not this class supports particle classifiers.

For example: kcode doesn’t allow particle types but tallies do allow it e.g., f7:n

  • 0 : not allowed

  • 1 : is optional

  • 2 : is mandatory

Deprecated since version 0.2.0: This has been moved to _has_classifier()

Returns:

True if this class particle classifiers

Return type:

int

Raises:

DeprecationWarning – always raised.

property has_information

For a cell instance of montepy.data_cards.cell_modifier.CellModifierCard returns True iff there is information here worth printing out.

e.g., a manually set volume for a cell

Returns:

True if this instance has information worth printing.

Return type:

bool

property has_number

Whether or not this class supports numbering.

For example: kcode doesn’t allow numbers but tallies do allow it e.g., f7

Deprecated since version 0.2.0: This has been moved to _has_number()

Returns:

True if this class allows numbers

Return type:

bool

Raises:

DeprecationWarning – always raised.

property heavy_ion

Importance for particles of type heavy_ion

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property helion

Importance for particles of type helion

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property in_cell_block

True if this object represents an input from the cell block section of a file.

Return type:

bool

property kaon_long

Importance for particles of type kaon_long

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property kaon_short

Importance for particles of type kaon_short

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property lambda_baryon

Importance for particles of type lambda_baryon

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property leading_comments

Any comments that come before the beginning of the input proper.

Added in version 0.2.0.

Returns:

the leading comments.

Return type:

list

Links the input to the parent problem for this input.

This is done so that inputs can find links to other objects.

Parameters:

problem (MCNP_Problem) – The problem to link this input to.

merge(other)

Merges the data from another card of same type into this one.

Parameters:

other (CellModifierInput) – The other object to merge into this object.

Raises:

MalformedInputError – if two objects cannot be merged.

property muon_neutrino

Importance for particles of type muon_neutrino

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property negative_cascade

Importance for particles of type negative_cascade

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property negative_kaon

Importance for particles of type negative_kaon

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property negative_muon

Importance for particles of type negative_muon

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property negative_pion

Importance for particles of type negative_pion

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property negative_sigma_baryon

Importance for particles of type negative_sigma_baryon

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property neutral_pion

Importance for particles of type neutral_pion

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property neutron

Importance for particles of type neutron

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property omega_baryon

Importance for particles of type omega_baryon

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property parameters

A dictionary of the additional parameters for the object.

e.g.: 1 0 -1 u=1 imp:n=0.5 has the parameters {"U": "1", "IMP:N": "0.5"}

Returns:

a dictionary of the key-value pairs of the parameters.

Rytpe:

dict

property particle_classifiers

The particle class part of the card identifier as a parsed list.

This is parsed from the input that was read.

For example: the classifier for F7:n is :n, and imp:n,p is :n,p This will be parsed as a list: [<Particle.NEUTRON: 'N'>, <Particle.PHOTON: 'P'>].

Returns:

the particles listed in the input if any. Otherwise None

Return type:

list

property photon

Importance for particles of type photon

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property positive_cascade

Importance for particles of type positive_cascade

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property positive_kaon

Importance for particles of type positive_kaon

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property positive_muon

Importance for particles of type positive_muon

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property positive_pion

Importance for particles of type positive_pion

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property positive_sigma_baryon

Importance for particles of type positive_sigma_baryon

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property positron

Importance for particles of type positron

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

property prefix

The text part of the card identifier parsed from the input.

For example: for a material like: m20 the prefix is ‘m’ this will always be lower case.

Returns:

The prefix read from the input

Return type:

str

property prefix_modifier

The modifier to a name prefix that was parsed from the input.

For example: for a transform: *tr5 the modifier is *

Returns:

the prefix modifier that was parsed if any. None if otherwise.

Return type:

str

property proton

Importance for particles of type proton

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

push_to_cells()

After being linked to the problem update all cells attributes with this data.

This needs to also check that none of the cells had data provided in the cell block (check that set_in_cell_block isn’t set). Use self._check_redundant_definitions to do this.

Raises:

MalformedInputError – When data are given in the cell block and the data block.

property set_in_cell_block

True if this data were set in the cell block in the input

property trailing_comment

The trailing comments and padding of an input.

Generally this will be blank as these will be moved to be a leading comment for the next input.

Returns:

the trailing c style comments and intermixed padding (e.g., new lines)

Return type:

list

property triton

Importance for particles of type triton

Can only be set if this particle is used in the problem mode.

Parameters:

importance – The importance to set this to.

Returns:

the importance for the particle type. If not set, defaults to 0.

Return type:

float

Raises:

ParticleTypeNotInProblem – raised if this particle is accessed while not in the problem mode.

update_pointers(data_inputs)

Connects data inputs to each other

Parameters:

data_inputs (list) – a list of the data inputs in the problem

Returns:

True iff this input should be removed from problem.data_inputs

Return type:

bool, None

validate()

Validates that the object is in a usable state.

Raises:

IllegalState if any condition exists that make the object incomplete.

property words

The words from the input file for this card.

Warning

Deprecated since version 0.2.0: This has been replaced by the syntax tree data structure.

Raises:

DeprecationWarning – Access the syntax tree instead.

static wrap_string_for_mcnp(string, mcnp_version, is_first_line)

Wraps the list of the words to be a well formed MCNP input.

multi-line inputs will be handled by using the indentation format, and not the “&” method.

Parameters:
  • string (str) – A long string with new lines in it, that needs to be chunked appropriately for MCNP inputs

  • mcnp_version (tuple) – the tuple for the MCNP that must be formatted for.

  • is_first_line (bool) – If true this will be the beginning of an MCNP input. The first line will not be indented.

Returns:

A list of strings that can be written to an input file, one item to a line.

Return type:

list

static wrap_words_for_mcnp(words, mcnp_version, is_first_line)

Wraps the list of the words to be a well formed MCNP input.

multi-line cards will be handled by using the indentation format, and not the “&” method.

Deprecated since version 0.2.0: The concept of words is deprecated, and should be handled by syntax trees now.

Parameters:
  • words (list) – A list of the “words” or data-grams that needed to added to this card. Each word will be separated by at least one space.

  • mcnp_version (tuple) – the tuple for the MCNP that must be formatted for.

  • is_first_line (bool) – If true this will be the beginning of an MCNP card. The first line will not be indented.

Returns:

A list of strings that can be written to an input file, one item to a line.

Return type:

list

Raises:

DeprecationWarning – raised always.