Skip to content

Utilities

qcio.json_dumps

json_dumps(
    obj: BaseModel | list[BaseModel],
    exclude_unset: bool = True,
    **model_dump_kwargs,
) -> str

Serialization helper for lists of pydantic objects.

Parameters:

Name Type Description Default
obj BaseModel | list[BaseModel]

The object to serialize. Either a single pydantic object or a list of pydantic objects.

required
exclude_unset bool

Whether to exclude unset fields from the serialized output.

True
**model_dump_kwargs

Additional keyword arguments to pass to model_dump.

{}
Source code in src/qcio/utils.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def json_dumps(
    obj: BaseModel | list[BaseModel],
    exclude_unset: bool = True,
    **model_dump_kwargs,
) -> str:
    """Serialization helper for lists of pydantic objects.

    Args:
        obj: The object to serialize. Either a single pydantic object or a list of pydantic
            objects.
        exclude_unset: Whether to exclude unset fields from the serialized output.
        **model_dump_kwargs: Additional keyword arguments to pass to model_dump.
    """
    if isinstance(obj, list):
        return json.dumps(
            [
                o.model_dump(exclude_unset=exclude_unset, **model_dump_kwargs)
                for o in obj
            ]
        )
    return obj.model_dump_json(exclude_unset=exclude_unset, **model_dump_kwargs)

qcio.to_multi_xyz

to_multi_xyz(structures: Iterable[Structure]) -> str

Create a multi-structure XYZ string from a list of structures.

Parameters:

Name Type Description Default
structures Iterable[Structure]

An Iterable of Structure objects.

required

Returns:

Type Description
str

The multi-structure XYZ string.

Source code in src/qcio/models/utils.py
89
90
91
92
93
94
95
96
97
98
def to_multi_xyz(structures: Iterable["Structure"]) -> str:
    """Create a multi-structure XYZ string from a list of structures.

    Args:
        structures: An Iterable of Structure objects.

    Returns:
        The multi-structure XYZ string.
    """
    return "".join(struct.to_xyz() for struct in structures)