infostrings#
Here we implement the InfoString class, that allows to gather
different parameters from objects and to display them in a tree format.
This is used in the print_info() method that is present in most
classes accross the module.
Examples
Run a simulation with one initial condition vector
from atomsmltr.utils.infostring import InfoString
info = InfoString("PARAMETERS")
info.add_section("First Section")
info.add_element("elem", "param")
info.add_element("x", f"{25.4e-6:.2e}µm")
info.add_element("y", f"{15.8:.2f} mW")
info.add_section("Another section")
info.add_element("elem", "param")
info.add_element("elem2", "param2")
print(info.generate())
This prints :
──────────────
| PARAMETERS |
──────────────
. First Section :
├── elem : param
├── x : 2.54e-05µm
└── y : 15.80 mW
. Another section :
├── elem : param
└── elem2 : param2
- class atomsmltr.utils.infostring.InfoString(title: str)[source]#
Bases:
objectGenerates info strings
- Parameters:
title (str) – the title of the infostring object
- absorb_section(info, target_section: str, new_name: str = None)[source]#
incorporates a section from another infostring object
- Parameters:
info (InfoString) – the infostring object from which we take the section
target_section (str) – name of the section to incorporate
new_name (str, optional) – name of the incorporated section. If None is given we use the name of the original section, by default None
- add_element(name: str, value: str = None, section: str = None)[source]#
adds an element in a given section
- Parameters:
name (str) – name of the element
value (str, optional) – value of the element, by default None
section (str, optional) – name of the section. If None is given, the element is added to the lastly used section, by default None
- add_section(name: str)[source]#
adds a new section for parameters
- Parameters:
name (str) – the section name
- property elements#
the elements inside the infostring object
- Type:
OrderedDict
- generate(display_title=True)[source]#
generates a string from the infostring object
- Parameters:
display_title (bool, optional) – whether to display the title, by default True
- Returns:
out_str – a string with all parameters from the info string
- Return type:
str
- merge(info, prefix='')[source]#
merges an entire infostring
- Parameters:
info (InfoString) – infostring object to merge
prefix (str, optional) – prefix added to the names of the sections incorporated from the merged infostring, by default “”
- rm_element(name: str, section: str = None)[source]#
removes an element from a section
- Parameters:
name (str) – name of the element to remove
section (str, optional) – name of the section. If None is given, the element is removed from the lastly used section, by default None
- property title: str#
titile of the infostring object
- Type:
str