File: __init__.py

package info (click to toggle)
python-mmcif-pdbx 2.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 10,000 kB
  • sloc: python: 1,389; makefile: 25
file content (61 lines) | stat: -rw-r--r-- 1,881 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""PDBx/mmCIF Python dictionary resources.

All of the code in this repository is original based on
http://mmcif.wwpdb.org/. Specifically, this code is directly derived from the
`pdbx code <http://mmcif.wwpdb.org/docs/sw-examples/python/src/pdbx.tar.gz>`_
linked from
`PDBx Python Parser Examples and Tutorial
<http://mmcif.wwpdb.org/docs/sw-examples/python/html/>`_.

See `PDBx Python Parser Examples and Tutorial
<http://mmcif.wwpdb.org/docs/sw-examples/python/html/>`_ for more information
about this package, including examples.
"""

# import pdbx.reader
import io
from .reader import PdbxReader
from .writer import PdbxWriter
from .errors import PdbxSyntaxError, PdbxError  # noqa: F401
from .containers import DataCategory, DataContainer  # noqa: F401
from ._version import __version__  # noqa: F401


def load(fobj) -> list:
    """Parse a CIF file.

    :param file fobj:  file object ready for reading
    :returns:  a list of :class:`~pdbx.containers.DataContainer` objects
    """
    data = []
    PdbxReader(fobj).read(data)
    return data


def loads(text) -> list:
    """Parse a CIF string.

    :param str s:  string with CIF data
    :returns: a list of :class:`~pdbx.containers.DataContainer` objects
    """
    return load(io.StringIO(text))


def dump(datacontainers, fobj):
    """Write a list of objects to a CIF file.

    :param list datacontainers:  a list of :class:`~pdbx.containers.DataContainer` objects # noqa E501
    :param file fobj:  a file object ready for writing
    """
    PdbxWriter(fobj).write(datacontainers)


def dumps(datacontainers) -> str:
    """Serialize a list of objects to a CIF-formatted string.

    :param list datacontainers:  list of :class:`~pdbx.containers.DataContainer` objects # noqa E501
    :returns:  CIF-formatted string
    """
    fobj = io.StringIO()
    dump(datacontainers, fobj)
    return fobj.getvalue()