atomium.mmtf

Contains functions for dealing with the .mmtf file format.

atomium.mmtf.add_atom(d, atoms, group, atom_num, atom_count)[source]

Adds an atom dictionary to a molecule dictionary.

Parameters:
  • d (dict) – the molecule dictionary to update.
  • atoms (list) – the list of half-created atom dictionaries.
  • group (dict) – a .mmtf group dictionary.
  • atom_num (int) – the atom number within the group.
  • atom_count (int) – the total number of processed atoms.
atomium.mmtf.add_het_to_groups(het, group_type_list, group_id_list, group_list, ins_list)[source]

Updates group lists with information from a single Het.

Parameters:
  • het (Het) – the Het to pack.
  • group_type_list (list) – the list of group types.
  • group_id_list (list) – the list of group IDs.
  • group_list (list) – the list of groups.
  • ins_list (list) – the list of insertion codes.
Return type:

tuple

atomium.mmtf.decode_dict(d)[source]

Takes a dictionary that might have bytestring keys, lists of bytestring values, .mmtf binary values, or other weirdness, and returns a dully decoded version of it which is a JSON-valid dictionary.

Parameters:d (dict) – the dictionary to read.
Return type:dict
atomium.mmtf.delta_decode(integers)[source]

Turns a list of integers into a new list of integers where the values in the first are treated as deltas to be applied to the previous value.

Parameters:integers (list) – the integers to decode.
Return type:list
atomium.mmtf.get_atoms_list(mmtf_dict)[source]

Creates a list of atom dictionaries from a .mmtf dictionary by zipping together some of its fields.

Parameters:mmtf_dict (dict) – the .mmtf dictionary to read.
Return type:list
atomium.mmtf.get_chain_ids_and_names(chains, ligands, waters)[source]

Takes lists of chains, ligands and waters, and returns the chain IDs and chain names that should go in the .mmtf file.

Parameters:
  • chains (list) – the chains to pack.
  • ligands (list) – the ligands to pack.
  • waters (list) – the waters to pack.
Return type:

list

atomium.mmtf.get_chain_sequence(mmtf_dict, chain_num)[source]

Gets the chain sequence for a given chain number.

Parameters:
  • mmtf_dict (dict) – the .mmtf dictionary to read.
  • chain_num (int) – the chain number.
Return type:

str

atomium.mmtf.get_entity_list(entities, chains, ligands, waters)[source]

Takes a list of entity objects, as well as the objects they represent, and turns them into a list of .mmtf dictionaries.

Parameters:
  • entities (list) – the entities to pack.
  • chains (list) – the chains to pack.
  • ligands (list) – the ligands to pack.
  • waters (list) – the waters to pack.
Return type:

list

atomium.mmtf.get_groups(chains, ligands, waters)[source]

Creates the relevant lists of group information from chains, ligands and waters.

Parameters:
  • chains (list) – the chains to pack.
  • ligands (list) – the ligands to pack.
  • waters (list) – the waters to pack.
Return type:

tuple

atomium.mmtf.get_groups_per_chain(chains, ligands, waters)[source]

Takes lists of chains, ligands and waters, and returns the chain counts that should go in the .mmtf file.

Parameters:
  • chains (list) – the chains to pack.
  • ligands (list) – the ligands to pack.
  • waters (list) – the waters to pack.
Return type:

list

atomium.mmtf.get_structures(structure)[source]

Takes an atomic structure, and creates a list of chains within it, a list of ligands, a list of waters, a list of relevant atom properties, and a list of entities.

Parameters:structure (AtomStructure) – the structure to unpack.
Return type:tuple
atomium.mmtf.get_type(mmtf_dict, chain_num)[source]

Takes an .mmtf dictionary and a chain number, and works out what type of molecule it corresponds to.

Parameters:
  • mmtf_dict (dict) – the .mmtf dictionary to read.
  • chain_num (int) – the chain number.
Return type:

str

atomium.mmtf.make_chain(mmtf_dict, chain_num)[source]

Creates a chain dictionary

Parameters:
  • mmtf_dict (dict) – the .mmtf dictionary to read.
  • chain_num (int) – the chain number.
Return type:

dict

atomium.mmtf.make_group_id(mmtf_dict, chain_num, g_count)[source]

Creates an atomium residue/molecule ID for a given group.

Parameters:
  • mmtf_dict (dict) – the .mmtf dictionary to read.
  • chain_num (int) – the chain number.
  • g_count (int) – the group number.
Return type:

str

atomium.mmtf.make_molecule(type_, group_name, mmtf_dict, chain_num)[source]

Creates a residue or ligand dictionary.

Parameters:
  • type (str) – ‘polymer’ or ‘non-polymer’.
  • group_name (str) – the name of the molecule.
  • mmtf_dict (dict) – the .mmtf dictionary to read.
  • chain_num (int) – the chain number.
Return type:

dict

atomium.mmtf.mmtf_bytes_to_mmtf_dict(bytestring)[source]

Takes the raw bytestring of a .mmtf file and turns it into a normal, fully decoded JSON dictionary.

Patam bytes bytestring:
 the .mmtf filestring.
Return type:dict
atomium.mmtf.mmtf_dict_to_data_dict(mmtf_dict)[source]

Converts an .mmtf dictionary into an atomium data dictionary, with the same standard layout that the other file formats get converted into.

Parameters:mmtf_dict (dict) – the .mmtf dictionary.
Return type:dict
atomium.mmtf.mmtf_to_data_transfer(mmtf_dict, data_dict, d_cat, d_key, m_key, date=False, first=False, trim=False)[source]

A function for transfering a bit of data from a .mmtf dictionary to a data dictionary, or doing nothing if the data doesn’t exist.

Parameters:
  • mmtf_dict (dict) – the .mmtf dictionary to read.
  • data_dict (dict) – the data dictionary to update.
  • d_cat (str) – the top-level key in the data dictionary.
  • d_key (str) – the data dictionary field to update.
  • m_key (str) – the .mmtf field to read.
  • date (bool) – if True, the value will be converted to a date.
  • first (bool) – if True, the value’s first item will be split used.
  • trim (int) – if given, the value will be rounded by this amount.
atomium.mmtf.parse_binary_field(b)[source]

Some fields in a .mmtf file cannot be unpacked by msgpack and have special .mmtf encoding, as specified in its documentation. This function takes such a field and decodes it.

Parameters:b (bytestring) – the field to parse.
Returns:the parsed result (type varies).
atomium.mmtf.recursive_decode(integers, bits=16)[source]

Turns a list of integers into a new list of integers where the values in the first are merged if it looks like a higher order integer split over two integers.

(Code here adapted from the official python-mmtf package.)

Parameters:integers (list) – the integers to decode.
Return type:list
atomium.mmtf.run_length_decode(integers)[source]

Expands a list of integers where every second integer is a count of the integer before it.

Parameters:integers (list) – the integers to decode.
Return type:list
atomium.mmtf.structure_to_mmtf_string(structure)[source]

Converts a AtomStructure to a .mmtf filestring.

No compression is currently performed.

Parameters:structure (AtomStructure) – the structure to convert.
Return type:bytes
atomium.mmtf.update_models_list(mmtf_dict, data_dict)[source]

Takes a data dictionary and updates its models list with information from a .mmtf dictionary.

Parameters:
  • mmtf_dict (dict) – the .mmtf dictionary to read.
  • data_dict (dict) – the data dictionary to update.