Importance#
- class montepy.data_inputs.importance.Importance(input: Input | str = None, in_cell_block: bool = False, key: str = None, value: SyntaxNode = None, *, problem: MCNP_Problem = None, jit_parse: bool = True, **kwargs)#
Bases:
CellModifierInputA data input that sets the importance for a cell(s).
Changed in version 1.5.0: Added
jit_parseparameter- Parameters:
input (
Input|str) – the Input object representing this data inputin_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 cellvalue (
SyntaxNode) – the value syntax tree from the key-value pair in a celljit_parse (
bool) – Parse the object just-in-time, when the information is actually needed, if True.problem (montepy.MCNP_Problem)
Methods:
Checks that data wasn't given in data block and the cell block.
The text part of the input identifier.
After data has been pushed to cells, delete internal data to avoid inadvertent editing.
Gets a list of the ValueNodes that hold the information for all cells.
Deletes trailing comments from an object when it has been moved to another object.
Formats the syntax tree for printing in an input file.
_generate_default_node(value_type, default)Generates a "default" or blank ValueNode.
Generate default syntax trees that can be exported once the object is not in an illegal state.
_grab_beginning_comment(new_padding[, last_obj])Whether or not this class supports particle classifiers.
Whether or not this class supports numbering.
Initialize the object to a base state, before any parsing.
Takes the information from syntax tree and link it to the internal attributes.
Updates values in the syntax tree when in the cell block.
_update_values([in_middle])Method to update values in syntax tree with new values.
clone()Create a new independent instance of this object.
format_for_mcnp_input(mcnp_version[, ...])Creates a string representation of this MCNP_Object that can be written to file.
Fully parses this object, and disable just-in-time parsing for it.
items()Returns a generator of the particle and the importance value for all importances set for this cell.
keys()Returns a generator of all of the particles that have set values for this importance.
link_to_problem(problem, *[, deepcopy])Links the input to the parent problem for this input.
mcnp_str([mcnp_version])Returns a string of this input as it would appear in an MCNP input file.
merge(other)Merges the data from another card of same type into this one.
After being linked to the problem update all cells attributes with this data.
search(search)Searches this input for the given string, or compiled regular expression.
validate()Validates that the object is in a usable state.
values()Returns a generator of the importance values set for this cell in the order in which they were set.
wrap_string_for_mcnp(string, mcnp_version, ...)Wraps the list of the words to be a well formed MCNP input.
Attributes:
Determines if this object has information that is worth printing in the input file.
The ValueNode that holds the information for this instance, that should be included in the data block.
Setter for setting importance for all particle types in the problem at once.
Importance for particles of type alpha_particle
Importance for particles of type anti_cascade
Importance for particles of type anti_electron_neutrino
Importance for particles of type anti_lambda_baryon
Importance for particles of type anti_muon_neutrino
Importance for particles of type anti_negative_sigma_baryon
Importance for particles of type anti_neutron
Importance for particles of type anti_omega
Importance for particles of type anti_positive_sigma_baryon
Importance for particles of type anti_proton
Importance for particles of type cascade
The syntax tree object holding the data classifier.
The comments associated with this input if any.
The syntax tree actually holding the data.
Importance for particles of type deuteron
Importance for particles of type electron
Importance for particles of type electron_neutrino
Whether this has been fully parsed, or is just JIT parsed.
For a cell instance of
montepy.data_inputs.cell_modifier.CellModifierInputreturns True iff there is information here worth printing out.Importance for particles of type heavy_ion
Importance for particles of type helion
True if this object represents an input from the cell block section of a file.
Importance for particles of type kaon_long
Importance for particles of type kaon_short
Importance for particles of type lambda_baryon
Any comments that come before the beginning of the input proper.
Importance for particles of type muon_neutrino
Importance for particles of type negative_cascade
Importance for particles of type negative_kaon
Importance for particles of type negative_muon
Importance for particles of type negative_pion
Importance for particles of type negative_sigma_baryon
Importance for particles of type neutral_pion
Importance for particles of type neutron
Importance for particles of type omega_baryon
A dictionary of the additional parameters for the object.
The particle class part of the input identifier as a parsed list.
Importance for particles of type photon
Importance for particles of type positive_cascade
Importance for particles of type positive_kaon
Importance for particles of type positive_muon
Importance for particles of type positive_pion
Importance for particles of type positive_sigma_baryon
Importance for particles of type positron
The text part of the input identifier parsed from the input.
The modifier to a name prefix that was parsed from the input.
Importance for particles of type proton
True if this data were set in the cell block in the input
The trailing comments and padding of an input.
Importance for particles of type triton
- static _class_prefix()#
The text part of the input identifier.
For example: for a material the prefix is
mthis must be lower case
- Returns:
the string of the prefix that identifies a input of this class.
- Return type:
- static _generate_default_node(value_type: Type, default: str, padding: str = ' ', never_pad: bool = False)#
Generates a “default” or blank ValueNode.
None is generally a safe default value to provide.
Changed in version 1.0.0: Added
never_padargument.- Parameters:
value_type (
Type) – the data type for the ValueNode.default (
str) – the default value to provide (type needs to agree with value_type)padding (
str) – the string to provide to the PaddingNode. If None no PaddingNode will be added.never_pad (
bool) – Whether to never add trailing padding. True means extra padding is suppressed.
- Returns:
a new ValueNode with the requested information.
- Return type:
- static _has_classifier()#
Whether or not this class supports particle classifiers.
For example:
kcodedoesn’t allow particle types but tallies do allow it e.g.,f7:n0 : not allowed
1 : is optional
2 : is mandatory
- Returns:
True if this class particle classifiers
- Return type:
- static _has_number()#
Whether or not this class supports numbering.
For example:
kcodedoesn’t allow numbers but tallies do allow it e.g.,f7- Returns:
True if this class allows numbers
- Return type:
- static wrap_string_for_mcnp(string: str, mcnp_version: montepy.types.VersionType, is_first_line: bool, suppress_blank_end: bool = True) list[str]#
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 inputsmcnp_version (
tuple[Integral,Integral,Integral]) – 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.suppress_blank_end (
bool) – Whether or not to suppress any blank lines that would be added to the end. Good for anywhere but cell modifiers in the cell block.
- Returns:
A list of strings that can be written to an input file, one item to a line.
- Return type:
- _check_redundant_definitions()#
Checks that data wasn’t given in data block and the cell block.
- _clear_data()#
After data has been pushed to cells, delete internal data to avoid inadvertent editing.
This is only called on data-block instances of this object.
- _collect_new_values()#
Gets a list of the ValueNodes that hold the information for all cells.
This will be a list in the same order as
montepy.MCNP_Problem.cells.
- _delete_trailing_comment()#
Deletes trailing comments from an object when it has been moved to another object.
- _format_tree()#
Formats the syntax tree for printing in an input file.
By default this runs
self._tree.format().- Returns:
a string of the text to write out to the input file (not wrapped yet for MCNP).
- Return type:
- _generate_default_tree()#
Generate default syntax trees that can be exported once the object is not in an illegal state.
For leaves generally use
self._generate_default_nod(<type, None). Save the tree to self._tree- Parameters:
**kwargs (dict) – Allows passing additional arguments through __init__ as
**kwargs
- _grab_beginning_comment(new_padding, last_obj=None)#
- _init_blank()#
Initialize the object to a base state, before any parsing.
This should not setup the syntax tree though.
- _parse_tree()#
Takes the information from syntax tree and link it to the internal attributes.
Use self._tree for this.
- _update_cell_values()#
Updates values in the syntax tree when in the cell block.
- _update_values(in_middle=False)#
Method to update values in syntax tree with new values.
Generally when
make_prop_val_node()this is not necessary to do, but whenmake_prop_pointer()is used it is necessary. The most common need is to update a value based on the number for an object pointed at, e.g., the material number in a cell definition.
- clone() MCNP_Object#
Create a new independent instance of this object.
- Returns:
a new instance identical to this object.
- Return type:
- format_for_mcnp_input(mcnp_version: montepy.types.VersionType, has_following: bool = False, always_print: bool = False) list[str]#
Creates a string representation of this MCNP_Object that can be written to file.
- Parameters:
mcnp_version (
tuple[Integral,Integral,Integral]) – The tuple for the MCNP version that must be exported to.has_following (
bool) – If true this is followed by another input, and a new line will be inserted if this ends in a comment.always_print (
bool) – If true this will always produce a result irrespective ofprint_in_data_block.
- Returns:
a list of strings for the lines that this input will occupy.
- Return type:
- full_parse()#
Fully parses this object, and disable just-in-time parsing for it.
- Returns:
The object will be mutated and fully parsed.
- Return type:
None
- items() Generator[tuple[Particle, float], None, None]#
Returns a generator of the particle and the importance value for all importances set for this cell.
Added in version 1.4.0.
- keys() Generator[Particle, None, None]#
Returns a generator of all of the particles that have set values for this importance.
Added in version 1.4.0.
- link_to_problem(problem, *, deepcopy: bool = False)#
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.
deepcopy (
bool) – If this is occuring during a problem level deepcopy
- mcnp_str(mcnp_version: montepy.types.VersionType = None) str#
Returns a string of this input as it would appear in an MCNP input file.
..versionadded:: 1.0.0
- merge(other: Importance)#
Merges the data from another card of same type into this one.
- Parameters:
other (
Importance) – The other object to merge into this object.- Raises:
MalformedInputError – if two objects cannot be merged.
- 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_blockisn’t set). Useself._check_redundant_definitionsto do this.- Raises:
MalformedInputError – When data are given in the cell block and the data block.
- search(search: str | Pattern) bool#
Searches this input for the given string, or compiled regular expression.
- validate()#
Validates that the object is in a usable state.
- values() Generator[float, None, None]#
Returns a generator of the importance values set for this cell in the order in which they were set.
Added in version 1.4.0.
- property _is_worth_printing: bool#
Determines if this object has information that is worth printing in the input file.
Uses the
has_information()property for all applicable cell(s)- Returns:
True if this object should be included in the output
- Return type:
- property _problem: MCNP_Problem#
- property _tree_value#
The ValueNode that holds the information for this instance, that should be included in the data block.
- Returns:
The ValueNode to update the data-block syntax tree with.
- Return type:
- 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 alpha_particle#
Importance for particles of type alpha_particle
Can only be set if this particle is used 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.
- 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.
- 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.
- 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.
- 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.
- property anti_neutron#
Importance for particles of type anti_neutron
Can only be set if this particle is used 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.
- 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.
- property anti_proton#
Importance for particles of type anti_proton
Can only be set if this particle is used 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.
- property classifier#
The syntax tree object holding the data classifier.
For example this would container information like
M4, orF104:n.- Returns:
the classifier for this data_input.
- Return type:
- property comments: list[PaddingNode]#
The comments associated with this input if any.
This includes all
Ccomments 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:
- property data: ListNode#
The syntax tree actually holding the data.
- Returns:
The syntax tree with the information.
- Return type:
- property deuteron#
Importance for particles of type deuteron
Can only be set if this particle is used 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.
- property electron_neutrino#
Importance for particles of type electron_neutrino
Can only be set if this particle is used in the problem mode.
- property full_parsed#
Whether this has been fully parsed, or is just JIT parsed.
- Returns:
True iff this is fully parsed, False means this is still just-in-time parsed.
- Return type:
- property has_information#
For a cell instance of
montepy.data_inputs.cell_modifier.CellModifierInputreturns 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:
- property heavy_ion#
Importance for particles of type heavy_ion
Can only be set if this particle is used 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.
- property in_cell_block: bool#
True if this object represents an input from the cell block section of a file.
- Return type:
- property kaon_long#
Importance for particles of type kaon_long
Can only be set if this particle is used 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.
- property lambda_baryon#
Importance for particles of type lambda_baryon
Can only be set if this particle is used in the problem mode.
- property leading_comments: list[PaddingNode]#
Any comments that come before the beginning of the input proper.
- Returns:
the leading comments.
- Return type:
- property muon_neutrino#
Importance for particles of type muon_neutrino
Can only be set if this particle is used 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.
- property negative_kaon#
Importance for particles of type negative_kaon
Can only be set if this particle is used 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.
- property negative_pion#
Importance for particles of type negative_pion
Can only be set if this particle is used 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.
- property neutral_pion#
Importance for particles of type neutral_pion
Can only be set if this particle is used 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.
- property omega_baryon#
Importance for particles of type omega_baryon
Can only be set if this particle is used in the problem mode.
- property parameters: dict[str, str]#
A dictionary of the additional parameters for the object.
e.g.:
1 0 -1 u=1 imp:n=0.5has the parameters{"U": "1", "IMP:N": "0.5"}
- property particle_classifiers: list[Particle]#
The particle class part of the input identifier as a parsed list.
This is parsed from the input that was read.
For example: the classifier for
F7:nis:n, andimp:n,pis:n,pThis 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[montepy.Particle]
- property photon#
Importance for particles of type photon
Can only be set if this particle is used 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.
- property positive_kaon#
Importance for particles of type positive_kaon
Can only be set if this particle is used 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.
- property positive_pion#
Importance for particles of type positive_pion
Can only be set if this particle is used 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.
- property positron#
Importance for particles of type positron
Can only be set if this particle is used in the problem mode.
- property prefix: str#
The text part of the input identifier parsed from the input.
For example: for a material like:
m20the prefix ism. this will always be lower case. Can also be called the mnemonic.- Returns:
The prefix read from the input
- Return type:
- property prefix_modifier: str#
The modifier to a name prefix that was parsed from the input.
For example: for a transform:
*tr5the modifier is*- Returns:
the prefix modifier that was parsed if any. None if otherwise.
- Return type:
- property proton#
Importance for particles of type proton
Can only be set if this particle is used in the problem mode.
- property trailing_comment: CommentNode#
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
cstyle comments and intermixed padding (e.g., new lines)- Return type: