biotite.structure.io.mmtf.MMTFFile

class biotite.structure.io.mmtf.MMTFFile[source]

Bases: biotite.File, collections.abc.MutableMapping

This class represents a MMTF file.

When reading a file, the MessagePack unpacker is used to create a dictionary of the file content. This dictionary is accessed by indexing the MMTFFile instance directly with the dictionary keys. If the dictionary value is an encoded array, the value automatically decoded. Decoded arrays are always returned as ndarray instances.

Examples

>>> import os.path
>>> mmtf_file = MMTFFile.read(os.path.join(path_to_structures, "1l2y.mmtf"))
>>> print(mmtf_file["title"])
NMR Structure of Trp-Cage Miniprotein Construct TC5b
>>> print(mmtf_file["chainNameList"])
['A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A'
 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A'
 'A' 'A']
clear() None.  Remove all items from D.
copy()

Create a deep copy of this object.

Returns
copy

A copy of this object.

get(k[, d]) D[k] if k in D, else d.  d defaults to None.
get_codec(key)[source]

Obtain the codec ID of an MMTF encoded value.

Parameters
keystr

The key for the potentially encoded value.

Returns
codecint or None

The codec ID. None if the value is not encoded.

get_length(key)[source]

Obtain the length of an MMTF encoded value.

Parameters
keystr

The key for the potentially encoded value.

Returns
codecint or None

The length of the bytes array. None if the value is not encoded.

get_param(key)[source]

Obtain the parameter of an MMTF encoded value.

Parameters
keystr

The key for the potentially encoded value.

Returns
codecint or None

The parameter of the encoded value. None if the value is not encoded.

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
pop(k[, d]) v, remove specified key and return the corresponding value.

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

popitem() (k, v), remove and return some (key, value) pair

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

classmethod read(file)[source]

Read a MMTF file.

Parameters
filefile-like object or str

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

Returns
file_objectMMTFFile

The parsed file.

set_array(key, array, codec, param=0)[source]
setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D
update([E, ]**F) None.  Update D from mapping/iterable E and F.

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() an object providing a view on D's values
write(file)[source]

Write contents into a MMTF file.

Parameters
filefile-like object or str

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