Decorators and metaclasses used by atomium structures.

class atomium.base.StructureClass[source]

A metaclass which can be applied to structure class. It will override the instantation behaviour so that all methods that belong to a preset list (‘atoms’, ‘chains’ etc.) will have the query() decorator applied and a copy with the getone() decorator applied.


Return a type’s method resolution order.

class atomium.base.StructureSet(*args)[source]

A data structure for holding structures. It stores them internally as a dictionary where they keys are IDs (to allow rapid lookup by ID) and the values are all structures with that ID (to allow for duplicate IDs).

Two structure sets can be added together, but they are immutable - the structures they have when they are made is the structures they will always have.

They’re basically sets optimised to lookup things by ID.

Parameters:args (*) – the structures that will make up the StructureSet.

Gets a structure by ID. If an ID points to multiple structures, just one will be returned.

Returns:some structure.

Returns the IDs of the StructureSet.

Return type:set

Returns the structures of the StructureSet.

Return type:list
atomium.base.attribute_matches_value(attribute, value, components)[source]

Checks if an attribute value matches a given value. The components given will determine whether an exact match is sought, or whether a more complex criterion is used.

  • attribute – the value of an object’s attribute.
  • value – the value to match against.
  • components (list) – the components of the original key.
Return type:


atomium.base.filter_objects(objects, key, value)[source]

Takes a StructureSet of objects, and filters them on object properties.

They key can be an attribute of the object, or a complex double-underscore separated chain of attributes.

  • objects (StructreSet) – the dictionary of objects - the keys are unimportant.
  • key (str) – the attribute to search. This can be an attribute of the object, or attr__regex, or attr__gt etc.
  • value – the value that the attribute must have.
Return type:


atomium.base.get_object_attribute_from_filter(obj, components)[source]

Gets the object’s value of some attribute based on a list of key components.

  • obj – the object with attributes.
  • components (list) – the components of the original key.

the value

atomium.base.get_object_from_filter(obj, components)[source]

Gets the object whose attributes are actually being queried, which may be a different object if there is a chain.

  • obj – the intial object.
  • components (list) – the components of the original key.

the relevant object


A decorator which can be applied to any function which returns an iterable. It produces a function which just gets the first item in that iterable.

In atomium, various classes define methods like atoms, residues, etc. - this decorator can make a function like atom, residue which takes all the same params but just returns one object.

Parameters:func – the function to modify.
Return type:function
atomium.base.query(func, tuple_=False)[source]

A decorator which can be applied to any function which returns a StructureSet and which takes no other parameters other than self. It will query the returned objects by any keyword argument, or use a positional argument to search by ID.

  • func – the function to modify.
  • tuple (bool) – if True, objects will be returned in a tuple not a set.
Return type: