3. API Reference: yaslha

3.1. yaslha package

Package to handle SLHA-format files and data.

yaslha.parse(text, input_type='AUTO', parser=None, **kwargs)[source]

Parse a text to return an SLHA object.

yaslha.dump(slha, output_type='SLHA', dumper=None, **kwargs)[source]

Output a dumped string of an SLHA object.

yaslha.parse_file(path, **kwargs)[source]

Parse a file to return an SLHA object.

yaslha.dump_file(data, path, **kwargs)[source]

Write into a file a dumped string of an SLHA object.

3.2. yaslha.slha module

Module of SLHA object class.

class yaslha.slha.SLHA[source]

Bases: object

SLHA object, representing a SLHA-format text.

add_block(obj: Union[Block, InfoBlock, Decay]) → None[source]

Add a block to SLHA file.

The name is automatically detected from the object.

__getitem__(key: Any) → Any[source]

Get values of SLHA object or deeper.

SLHA[str] and SLHA[int] give the specified block and decay block, respectively. For ordinary blocks, further referencing is possible as SLHA[str, *key], while decay blocks refuse such referencing for safety.

get(*key, default: Any = None) → Any[source]

Return the value if exists, or default.

__setitem__(key: Any, value: Any) → None[source]

Set a value of SLHA object or deeper.

__delitem__(key: Any) → None[source]

Delete values of SLHA object or deeper.

normalize(blocks: bool = True, decays: bool = True) → None[source]

Normalize the head-lines so that names/pids match the dict keys.

merge(another: yaslha.slha.SLHA) → None[source]

Merge another SLHA data into this object.

3.3. yaslha.block module

Block-like object of SLHA data.

class yaslha.block.GenericBlock[source]

Bases: typing.Generic

Block-like object containing comments.

comment

Give the interface to comments.

classmethod new(obj: Union[int, str, yaslha.line.DecayHeadLine, yaslha.line.BlockHeadLine]) → Union[yaslha.block.Block, yaslha.block.InfoBlock, yaslha.block.Decay][source]

Create a GenericBlock object according to the argument.

class yaslha.block.AbsBlock(obj: Union[yaslha.line.BlockHeadLine, str])[source]

Bases: yaslha.block.GenericBlock, typing.Generic

Abstract class for SLHA blocks.

name

Return the name of block (always in upper case).

q

Return the Q value.

__getitem__(key: KT) → Union[VT, Sequence[VT]][source]

Return the value corresponding to the key.

__setitem__(key: KT, value: VT) → None[source]

Set the value for the key.

__delitem__(key: KT) → None[source]

Delete the value for the key.

update_line(line: LT) → None[source]

Add the line to the block, overriding if exists.

keys(sort: bool = False) → Iterator[KT][source]

Return the keys.

__iter__(sort: bool = False) → Iterator[KT]

Return the keys.

items(sort: bool = False) → Iterator[Tuple[KT, VT]][source]

Return (key, value) tuples.

class yaslha.block.Block(obj: Union[yaslha.line.BlockHeadLine, str])[source]

Bases: yaslha.block.AbsBlock

SLHA block that has one value for one key.

__getitem__(key: Union[None, int, Sequence[int]]) → float[source]

Return the value corresponding to the key.

__setitem__(key: Union[None, int, Sequence[int]], value: float) → None[source]

Set the value for the key.

__delitem__(key: Union[None, int, Sequence[int]]) → None[source]

Delete the value for the key.

update_line(line: yaslha.line.ValueLine) → None[source]

Add the line to the block, overriding if exists.

merge(another: Union[yaslha.block.Block, yaslha.block.InfoBlock]) → None[source]

Merge another block.

get(*key, default: T) → Union[float, T][source]

Return the value for the key if exists, or default value.

keys(sort: bool = False) → Iterator[Union[None, int, Sequence[int]]][source]

Return the keys.

__iter__(sort: bool = False) → Iterator[Union[None, int, Sequence[int]]]

Return the keys.

items(sort: bool = False) → Iterator[Tuple[Union[None, int, Sequence[int]], float]][source]

Return (key, value) tuples.

class yaslha.block.InfoBlock(obj: Union[yaslha.line.BlockHeadLine, str])[source]

Bases: yaslha.block.AbsBlock

SLHA block that may have multiple values for one key.

__getitem__(key: int) → Sequence[str][source]

Return the value corresponding to the key.

__setitem__(key: int, value: Sequence[str]) → None[source]

Set the value for the key.

__delitem__(key: int) → None[source]

Delete the value for the key.

update_line(line: yaslha.line.InfoLine) → None[source]

Add the line to the block, overriding if exists.

append_line(line: yaslha.line.InfoLine) → None[source]

Add the line, appending to the existing one if exists.

append(key: int, value: str) → None[source]

Append the value for the key.

merge(another: Union[yaslha.block.Block, yaslha.block.InfoBlock]) → None[source]

Merge another block.

keys(sort: bool = False) → Iterator[int][source]

Return the keys.

__iter__(sort: bool = False) → Iterator[int]

Return the keys.

items(sort: bool = False) → Iterator[Tuple[int, str]][source]

Return (key, value) tuples.

class yaslha.block.Decay(obj: Union[yaslha.line.DecayHeadLine, int])[source]

Bases: yaslha.block.GenericBlock

Decay block.

br_normalize_threshold = 1e-06
pid

Return the pid of mother particle.

width

Return the total width.

update_line(line: yaslha.line.DecayLine) → None[source]

Add the line to the block, overriding if exists.

br(*key) → float[source]

Return the BR of given channel.

partial_width(*key) → float[source]

Return the width of given channel.

keys(sort: bool = False) → Iterator[Sequence[int]][source]

Return the keys.

__iter__(sort: bool = False) → Iterator[Sequence[int]]

Return the keys.

items_br(sort=False)[source]

Return (key, BR) tuples, sorted by the BR.

items_partial_width(sort=False)[source]

Return (key, width) tuples, sorted by the BR.

normalize(force: bool = False) → None[source]

Normalize the branching ratios.

This method normalize all the branching ratios so that the sum becomes unity or less. In particular, if force is set True, they are normalized so that the sum becomes unity, regardless of the current value.

If force is False and the sum is less than one, the branching ratio is not normalized, assuming that some decay channels are not listed. If force is False and the sum slightly exceeds the unity, the branching ratios are normalized, while if the excess is larger than br_normalize_threshold, ValueError is raised.

set_partial_width(*args) → None[source]

Update the partial width and recalculate BRs of all channels.

remove(*key) → None[source]

Remove the channel and recalculate BRs of all the other channels.

3.4. yaslha.comment module

Module of a class to handle comment interface.

class yaslha.comment.CommentInterface(block: GenericBlock[KTG, CT])[source]

Bases: typing.Generic

Accessor object to the comments in blocks.

pre

Return pre-comment interface.

__getitem__(key: Union[KTG, typing_extensions.Literal['head'][head]]) → Union[CT, str][source]

Return comment.

__setitem__(key: Union[KTG, typing_extensions.Literal['head'][head]], value: Union[CT, str, None]) → None[source]

Set comment.

__call__(key: Union[KTG, typing_extensions.Literal['head'][head]], **kw) → Union[CT, str][source]

Return comment in specified format.

class yaslha.comment.PreCommentInterface(block: GenericBlock[KTG, CT])[source]

Bases: typing.Generic

Accessor object to the pre-line comments in blocks.

__getitem__(key: Union[KTG, typing_extensions.Literal['head'][head]]) → List[str][source]

Return pre-line comment.

__setitem__(key: Union[KTG, typing_extensions.Literal['head'][head]], value: Optional[List[str]]) → None[source]

Set pre-line comment.

__call__(key: Union[KTG, typing_extensions.Literal['head'][head]], **kw) → List[str][source]

Return pre-line comment in specified format.

3.5. yaslha.line module

Module to describe each type of lines.

The line hierarchy is given by:

  • AbsLine - BlockHeadLine - DecayHeadLine - InfoLine - ValueLine

    • NoIndexLine
    • OneIndexLine
    • TwoIndexLine
    • ThreeIndexLine
    • DecayLine
    • CommentLine
class yaslha.line.LineOutputOption[source]

Bases: object

Class to hold all the options on dumping lines.

class yaslha.line.AbsLine(**kwargs)[source]

Bases: object

Abstract class for SLHA-line like objects.

output_option = <yaslha.line.LineOutputOption object>
classmethod pattern() → Pattern[str][source]

Return a regexp pattern matching a SLHA line for the type.

classmethod construct(line: str) → Optional[LT][source]

Construct an object from a line if it maches the pattern.

to_slha(option: Optional[yaslha.line.LineOutputOption] = None) → List[str][source]

Return the lines for SLHA-format, including pre-comments.

dump() → List[Union[str, float]][source]

Return a list representing the line.

classmethod from_dump(dump: Sequence[Any], **kw) → LT[source]

Return an object from dumped value.

class yaslha.line.BlockHeadLine(name, q=None, comment=None)[source]

Bases: yaslha.line.AbsLine

Line for block header.

name

Return name in upper case.

class yaslha.line.DecayHeadLine(pid: Union[str, int], width: Union[str, float], comment: Optional[str] = None)[source]

Bases: yaslha.line.AbsLine

A line with format ('DECAY',1x,I9,3x,1P,E16.8,0P,3x,'#',1x,A).

class yaslha.line.InfoLine(key, value, comment=None)[source]

Bases: yaslha.line.AbsLine

Class for lines of INFO blocks.

An info-block line is given by format(1x,I5,3x,A), which is not exclusive and matches other patterns. This class accept multi-lines, and thus values are List[str] and comments are multi-lined string, internally kept as List[str].

class yaslha.line.ValueLine(key: Union[None, int, Sequence[int]], value: Union[str, float], comment: Optional[str] = None)[source]

Bases: yaslha.line.AbsLine

Abstract class for value lines in ordinary blocks.

classmethod new(key: Union[None, int, Sequence[int]], value: Union[str, float], comment: Optional[str] = None) → LT2[source]

Construct line object according to the type of key.

The resulting object is an instance of a subclass of ValueLine but not DecayLine.

class yaslha.line.NoIndexLine(value, comment=None)[source]

Bases: yaslha.line.ValueLine

A line with format(9x, 1P, E16.8, 0P, 3x, '#', 1x, A).

class yaslha.line.OneIndexLine(i, value, comment=None)[source]

Bases: yaslha.line.ValueLine

A line with format(1x,I5,3x,1P,E16.8,0P,3x,'#',1x,A).

class yaslha.line.TwoIndexLine(i1, i2, value, comment=None)[source]

Bases: yaslha.line.ValueLine

A line with format(1x,I2,1x,I2,3x,1P,E16.8,0P,3x,'#',1x,A).

class yaslha.line.ThreeIndexLine(i1, i2, i3, value, comment=None)[source]

Bases: yaslha.line.ValueLine

A line with format(1x,I2,1x,I2,1x,I2,3x,1P,E16.8,0P,3x,'#',1x,A).

class yaslha.line.DecayLine(br, channel, nda=None, comment=None)[source]

Bases: yaslha.line.ValueLine

A decay line (3x,1P,E16.8,0P,3x,I2,3x,N (I9,1x),2x,'#',1x,A).

br

Return the branching ratio.

class yaslha.line.CommentLine(comment: Optional[str] = None)[source]

Bases: yaslha.line.AbsLine

Comment line.

This object is prepared for compatibility and not intended to be inserted in blocks or decay-blocks; therefore dumping methods are not implemented.

3.6. yaslha.parser module

Parsers for SLHA package.

Parsers for SLHA-format, JSON-format, and YAML-format are provided.

class yaslha.parser.SLHAParser(**kw)[source]

Bases: object

SLHA-format file parser.

parse(text: str) → yaslha.slha.SLHA[source]

Parse SLHA format text and return SLHA object.

3.7. yaslha.dumper module

Dumpers to write SLHA data in various format.

class yaslha.dumper.BlocksOrder[source]

Bases: enum.Enum

Options for block ordering.

DEFAULT = 0
KEEP = 1
ABC = 2
class yaslha.dumper.ValuesOrder[source]

Bases: enum.Enum

Options for value ordering.

DEFAULT = 0
KEEP = 1
SORTED = 2
class yaslha.dumper.CommentsPreserve[source]

Bases: enum.Enum

Options for comment handling.

NONE = 0
TAIL = 1
ALL = 2
keep_line

Return if to keep line-level comments.

keep_tail

Return if to keep tail comments of value lines.

class yaslha.dumper.AbsDumper(**kw)[source]

Bases: object

Abstract class for YASLHA dumpers.

config(k: str) → Any[source]

Get a current value of configuration.

set_config(k: str, v: Any) → None[source]

Set configuration.

dump(slha: yaslha.slha.SLHA) → str[source]

Return dumped string of an SLHA object.

class yaslha.dumper.SLHADumper(**kw)[source]

Bases: yaslha.dumper.AbsDumper

A dumper class for SLHA output.

config(k: str) → Any[source]

Get a current value of configuration.

set_config(k: str, v: Any) → None[source]

Set configuration.

dump(slha: yaslha.slha.SLHA) → str[source]

Return SLHA-format text of an SLHA object.

dump_block(block, document_block=False)[source]

Return SLHA-format text of a block.

class yaslha.dumper.AbsMarshalDumper(**kw)[source]

Bases: yaslha.dumper.AbsDumper

An abstract class for dumpers handling marshaled data.

SCHEME_VERSION = 3
config(k: str) → Any[source]

Get a current value of configuration.

set_config(k: str, v: Any) → None[source]

Set configuration.

marshal(slha)[source]

Return Mashaled object of an SLHA object.

marshal_block(block: Union[yaslha.block.Block, yaslha.block.InfoBlock, yaslha.block.Decay]) → Mapping[str, Any][source]

Return marshaled object of a block.

class yaslha.dumper.YAMLDumper(**kw)[source]

Bases: yaslha.dumper.AbsMarshalDumper

A dumper for YAML output.

dump(slha: yaslha.slha.SLHA) → str[source]

Return YAML-format text of an SLHA object.

class yaslha.dumper.JSONDumper(**kw)[source]

Bases: yaslha.dumper.AbsMarshalDumper

A dumper for JSON output.

dump(slha: yaslha.slha.SLHA) → str[source]

Return JSON-format text of an SLHA object.

3.8. yaslha.script module

Scripts of this package.

3.9. yaslha.config module

Configuration handlers.

class yaslha.config.SectionWrapper(data: configparser.SectionProxy)[source]

Bases: object

A wrapper class of configparser.SectionProxy.

get_enum(key: str, enum_class: Type[EnumType]) → EnumType[source]

Get an item as an Enum-class object.

get_list(key: str) → List[str][source]

Get a List[str] object.

class yaslha.config.Config[source]

Bases: configparser.ConfigParser

Dictionary to store the configurations.

3.10. yaslha.utility module

Utility module.

yaslha.utility.sort_blocks_default(block_names: Sequence[str]) → List[str][source]

Sort block names according to specified order.

yaslha.utility.sort_pids_default(pids: Sequence[T]) → List[Union[T, int]][source]

Sort block names according to specified order.