|
9 | 9 | import re |
10 | 10 | from contextlib import suppress |
11 | 11 | from datetime import datetime |
12 | | -from typing import TYPE_CHECKING |
13 | 12 |
|
14 | 13 | import numpy as np |
15 | 14 | from biotite.structure.io.pdbx import BinaryCIFBlock, BinaryCIFCategory, CIFBlock, CIFCategory |
16 | 15 |
|
17 | 16 | from atomworks.common import exists |
18 | 17 |
|
19 | | -if TYPE_CHECKING: |
20 | | - import pandas as pd |
21 | | - |
22 | 18 | logger = logging.getLogger("atomworks.io") |
23 | 19 |
|
24 | 20 |
|
25 | | -def category_to_df( |
26 | | - cif_block_or_category: CIFBlock | BinaryCIFBlock | CIFCategory | BinaryCIFCategory, category: str | None = None |
27 | | -) -> pd.DataFrame | None: |
28 | | - """Convert CIF component to pandas DataFrame. |
29 | | -
|
30 | | - Accepts either ``(CIFBlock, category_name)`` or ``(CIFCategory)`` directly. |
31 | | - Supports both text CIF and binary CIF (BinaryCIF) formats. |
32 | | -
|
33 | | - Args: |
34 | | - cif_block_or_category: :py:class:`~biotite.structure.io.pdbx.CIFBlock`, |
35 | | - :py:class:`~biotite.structure.io.pdbx.BinaryCIFBlock`, or |
36 | | - :py:class:`~biotite.structure.io.pdbx.CIFCategory` | :py:class:`~biotite.structure.io.pdbx.BinaryCIFCategory` |
37 | | - category: Category name when passing CIFBlock/BinaryCIFBlock, omit when passing CIFCategory |
38 | | -
|
39 | | - Returns: |
40 | | - DataFrame containing the category data, or None if category doesn't exist (CIFBlock mode only) |
41 | | - """ |
42 | | - import pandas as pd |
43 | | - |
44 | | - # Check for both CIFBlock and BinaryCIFBlock |
45 | | - if isinstance(cif_block_or_category, CIFBlock | BinaryCIFBlock): |
46 | | - # Extract category from CIFBlock or BinaryCIFBlock |
47 | | - cif_block = cif_block_or_category |
48 | | - if category in cif_block: |
49 | | - return pd.DataFrame(category_to_dict(cif_block, category)) |
50 | | - return None |
51 | | - else: |
52 | | - # Convert CIFCategory directly |
53 | | - category_obj = cif_block_or_category |
54 | | - return pd.DataFrame(category_to_dict(category_obj)) |
55 | | - |
56 | | - |
57 | 21 | def category_to_dict( |
58 | 22 | cif_block_or_category: CIFBlock | BinaryCIFBlock | CIFCategory | BinaryCIFCategory, category: str | None = None |
59 | 23 | ) -> dict[str, np.ndarray]: |
|
0 commit comments