atomium.base

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.

mro()

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.
get(id)[source]

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

Returns:some structure.
ids

Returns the IDs of the StructureSet.

Return type:set
structures

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.

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

bool

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.

Parameters:
  • 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:

dict

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.

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

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.

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

the relevant object

atomium.base.getone(func)[source]

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.

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

function