Skip to content

Converter API#

docksuitex.utils.converter #

Format conversion utilities for DockSuiteX.

convert #

convert(
    input: Union[str, Path, list[Union[str, Path]]],
    output_format: str,
    gen3d: bool = False,
    split: bool = False,
    output_dir: Optional[Union[str, Path]] = None,
    extra_args: Optional[list[str]] = None,
) -> Union[Path, list[Path]]

Convert molecular file(s) from one format to another using Open Babel.

Supports single files, lists of file paths, or a directory path. The output filename is automatically derived by replacing the input extension with the specified output_format.

Parameters:

Name Type Description Default
input str | Path | list

Path to the input file, a list of paths, or a directory containing molecular files.

required
output_format str

The target format identifier (e.g. "sdf", "pdbqt").

required
gen3d bool

Generate 3D coordinates. Essential when converting from SMILES or other 2D/text formats. Defaults to False.

False
split bool

Split multi-molecule/model files into individual files. Appends suffixes (1, 2, 3...) to the output filename. Defaults to False.

False
output_dir str | Path

Directory to save the converted files. If not provided, files are saved in the same directory as the input.

None
extra_args list[str]

Additional command-line arguments passed directly to Open Babel (e.g. ["-h", "--minimize"]).

None

Returns:

Type Description
Union[Path, list[Path]]

Path | list[Path]: Path to the created output file (single input) or a list of paths (batch input).

Raises:

Type Description
FileNotFoundError

If input files or Open Babel executable are missing.

RuntimeError

If the Open Babel conversion fails.

get_supported_formats #

get_supported_formats() -> dict[str, str]

Query Open Babel for all supported file formats.

Returns:

Type Description
dict[str, str]

dict[str, str]: Mapping of format identifier to description.

Raises:

Type Description
FileNotFoundError

If the Open Babel executable is not found.

RuntimeError

If Open Babel fails to list formats.