Read-Write#
Read and write complexes as a list of their atoms.
- toponetx.readwrite.atomlist.generate_atomlist(domain: CellComplex | SimplicialComplex) Generator[str, None, None] [source]#
Generate an atom list from a complex.
The list of atoms is truncated to only contain maximal atoms and atoms with user-defined attributes. All other atoms are implicitly contained already. For cell complexes, e add a special rank attribute to cells of cardinality 2 that have rank 2 to differentiate them from edges.
- Parameters:
- domainCellComplex or SimplicialComplex
The complex to be converted to an atom list.
- Yields:
- str
One line of the atom list, which corresponds to one atom of the complex together with its attributes.
Examples
Generate a list of atoms from a simplicial complex:
>>> SC = tnx.SimplicialComplex() >>> SC.add_simplex((1,), weight=1.0) >>> SC.add_simplex((1, 2, 3), weight=4.0) >>> list(tnx.generate_atomlist(SC)) ["1 {'weight': 1.0}", "1 2 3 {'weight': 4.0}"]
Generate a list of atoms from a cell complex:
>>> CC = tnx.CellComplex() >>> CC.add_cell((1, 2, 3), rank=2, weight=4.0) >>> list(tnx.generate_atomlist(CC)) ["1 2 3 {'weight': 4.0}"]
- toponetx.readwrite.atomlist.load_from_atomlist(filepath: str, complex_type: Literal['cell'], nodetype=None, encoding='utf-8') CellComplex [source]#
- toponetx.readwrite.atomlist.load_from_atomlist(filepath: str, complex_type: Literal['simplicial'], nodetype=None, encoding='utf-8') SimplicialComplex
Load a complex from an atom list.
- Parameters:
- pathfile or str
File or filename to read. If a file is provided, it must be opened in rb mode. Filenames ending in .gz or .bz2 will be uncompressed.
- complex_type{“cell”, “simplicial”}
The type of complex that should be constructed based on the atom list.
- nodetypecallable, optional
Convert node data from strings to the specified type.
- encodingstr, default=”utf-8”
Specify which encoding to use when reading file.
- Returns:
- CellComplex or SimplicialComplex
The complex that was loaded from the atom list.
- Raises:
- ValueError
If the complex type is unknown.
- toponetx.readwrite.atomlist.parse_atomlist(lines: Iterable[str], complex_type: Literal['cell'], nodetype=None) CellComplex [source]#
- toponetx.readwrite.atomlist.parse_atomlist(lines: Iterable[str], complex_type: Literal['simplicial'], nodetype=None) SimplicialComplex
Parse an atom list.
- Parameters:
- linesiterable of str
List of lines.
- complex_type{“cell”, “simplicial”}
Complex type.
- nodetypecallable, optional
Node type.
- Returns:
- CellComplex or SimplicialComplex
The complex that was parsed from the atom list.
- Raises:
- ValueError
If the complex type is unknown.
- toponetx.readwrite.atomlist.write_atomlist(domain: CellComplex | SimplicialComplex, path, encoding='utf-8') None [source]#
Write an atom list to a file.
- Parameters:
- domainCellComplex or SimplicialComplex
The complex to be converted to an atom list.
- pathfile or str
File or filename to write. If a file is provided, it must be opened in wb mode. Filenames ending in .gz or .bz2 will be compressed.
- encodingstr, default=”utf-8”
Specify which encoding to use when writing file.
- Raises:
- TypeError
If the domain is not a cell or simplicial complex.
Read and write complexes as pickled objects.