Skip to content

AutoParser

AutoParser is the main entry point for parsing chemical files. It automatically selects the appropriate parser based on the file extension.

The Entrypoint of MolOP

参数:

名称 类型 描述 默认
file_path str

use regax to match files.

必需
total_charge int | None

forced charge of the molecule, if not given, will use the charge written in the file or 0.

None
total_multiplicity int | None

forced multiplicity of the molecule, if not given, will use the charge written in the file or 1.

None
n_jobs int

number of jobs to use, if -1, use cpu with default max number.

-1
only_extract_structure bool

if True, only extract the structure, else extract the whole file.

False
only_last_frame bool

if True, only extract the last frame, else extract all frames.

False
release_file_content bool

if True, release the file content after parsing, else keep the file content in memory.

True
parser_detection str

if “auto”, use the file extension to detect the parser, else use the given format id.

'auto'

返回:

类型 描述
FileBatchModelDisk[FileDiskObj]

FileBatchParserDisk

How to use

Python
from molop import AutoParser

parser = AutoParser("/path/to/file")  # return FileBatchParserDisk with singlefile_parser
parser = AutoParser("/path/to/files/*.log")  # return FileBatchParserDisk
源代码位于: src/molop/io/__init__.py
Python
def AutoParser(
    file_path: str,
    *,
    total_charge: int | None = None,
    total_multiplicity: int | None = None,
    n_jobs: int = -1,
    only_extract_structure=False,
    only_last_frame=False,
    release_file_content: bool = True,
    parser_detection: str = "auto",
) -> FileBatchModelDisk["FileDiskObj"]:
    """
    The Entrypoint of MolOP

    Parameters:
        file_path (str):
            use regax to match files.
        total_charge (int | None):
            forced charge of the molecule, if not given, will use the charge written in the file or 0.
        total_multiplicity (int | None):
            forced multiplicity of the molecule, if not given, will use the charge written in the file or 1.
        n_jobs (int):
            number of jobs to use, if -1, use cpu with default max number.
        only_extract_structure (bool):
            if True, only extract the structure, else extract the whole file.
        only_last_frame (bool):
            if True, only extract the last frame, else extract all frames.
        release_file_content (bool):
            if True, release the file content after parsing, else keep the file content in memory.
        parser_detection (str):
            if "auto", use the file extension to detect the parser, else use the given format id.

    Returns:
        FileBatchParserDisk

    How to use
    ----------
    ```python
    from molop import AutoParser

    parser = AutoParser("/path/to/file")  # return FileBatchParserDisk with singlefile_parser
    parser = AutoParser("/path/to/files/*.log")  # return FileBatchParserDisk
    ```
    """
    if os.path.isfile(file_path) and os.path.exists(file_path):
        files = [file_path]
    else:
        base_path, pattern = split_path_pattern(file_path)
        files = [str(p) for p in base_path.glob(pattern)]
    return FileBatchParserDisk(n_jobs=n_jobs).parse(
        files,
        total_charge=total_charge,
        total_multiplicity=total_multiplicity,
        only_extract_structure=only_extract_structure,
        only_last_frame=only_last_frame,
        release_file_content=release_file_content,
        parser_detection=parser_detection,
    )