biotite.structure.io.mmtf.MMTFFile

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

Bases: biotite.file.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 value is an encoded array, the value automatically decoded. Decoded arrays are always returned as ndarray instances.

Examples

>>> import os.path
>>> mmtf_file = MMTFFile()
>>> mmtf_file.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']
read(self, file)[source]

Parse a MMTF file.

Parameters
filefile-like object or str

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

write(self, 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.

get_codec(self, 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(self, 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(self, 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.

set_array(self, key, array, codec, param=0)[source]
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)