# biotite.structure.io.pdbx.PDBxFile¶

class biotite.structure.io.pdbx.PDBxFile[source]

Bases: biotite.file.TextFile, collections.abc.MutableMapping

This class represents a PDBx/mmCIF file.

The categories of the file can be accessed using the get_category()/set_category() methods. The content of each category is represented by a dictionary. The dictionary contains the entry (e.g. label_entity_id in atom_site) as key. The corresponding values are either strings in non-looped categories, or 1-D numpy arrays of string objects in case of looped categories.

A category can be changed or added using set_category(): If a string-valued dictionary is provided, a non-looped category will be created; if an array-valued dictionary is given, a looped category will be created. In case of arrays, it is important that all arrays have the same size.

Alternatively, The content of this file can also be read/write accessed using dictionary-like indexing: You can either provide a data block and a category or only a category, in which case the first data block is taken.

Notes

This class is also able to detect and parse multiline entries in the file. However, when writing a category no multiline values are used. This could lead to long lines.

This class uses a lazy category dictionary creation: When reading the file only the line positions of all categories are checked. The time consuming task of dictionary creation is done when get_category() is called.

Examples

Read the file and get author names:

>>> import os.path
>>> file = PDBxFile()
>>> author_dict = file.get_category("citation_author", block="1L2Y")
>>> print(author_dict["name"])
['Neidigh, J.W.' 'Fesinmeyer, R.M.' 'Andersen, N.H.']


Dictionary style indexing, no specification of data block:

>>> print(file["citation_author"]["name"])
['Neidigh, J.W.' 'Fesinmeyer, R.M.' 'Andersen, N.H.']


Get the structure from the file:

>>> arr = get_structure(file)
>>> print(type(arr))
<class 'biotite.structure.atoms.AtomArrayStack'>
>>> arr = get_structure(file, model=1)
>>> print(type(arr))
<class 'biotite.structure.atoms.AtomArray'>


Modify atom array and write it back into the file:

>>> arr_mod = rotate(arr, [1,2,3])
>>> set_structure(file, arr_mod)
>>> file.write(os.path.join(path_to_directory, "1l2y_mod.cif"))

read(self, file)[source]

Parse a file (or file-like object) and store the content in this object.

Parameters
file_namefile-like object or str

The file to be read. Alternatively a file path can be supplied.

get_block_names(self)[source]

Get the names of all data blocks in the file.

Returns
blockslist

List of data block names.

get_category(self, category, block=None)[source]

Get the dictionary for a given category.

Parameters
categorystring

The name of the category. The leading underscore is omitted.

blockstring, optional

The name of the data block. Default is the first (and most times only) data block of the file.

This function optionally uses C-extensions.
Returns
category_dictdict or None

A entry keyed dictionary. The corresponding values are strings or ndarrays of strings for non-looped and looped categories, respectively. Returns None, if the data block does not contain the given category.

set_category(self, category, category_dict, block=None)[source]

Set the content of a category.

If the category is already exisiting, all lines corresponding to the category are replaced. Otherwise a new category is created and the lines are appended at the end of the data block.

Parameters
categorystring

The name of the category. The leading underscore is omitted.

category_dictdict

The category content. The dictionary must have strings (subcategories) as keys and strings or ndarrays as values.

blockstring, optional

The name of the data block. Default is the first (and most times only) data block of the file. If the block is not contained in the file yet, a new block is appended at the end of the file..

clear(self)
copy(self)

Create a deep copy of this object.

Returns
copy

A copy of this object.

get(self, key, default=None)
items(self)
keys(self)
pop(self, key, default=<object object at 0x7fc2eac76050>)

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem(self)

as a 2-tuple; but raise KeyError if D is empty.

setdefault(self, key, default=None)
update(*args, **kwds)

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values(self)
write(self, file)

Write the contents of this object into a file (or file-like object).

Parameters
file_namefile-like object or str

The file to be written to. Alternatively a file path can be supplied.