Data structure classes

containers

A collection of container classes supporting the PDBx/mmCIF storage model.

A base container class is defined which supports common features of data and definition containers. PDBx data files are organized in sections called data blocks which are mapped to data containers. PDBx dictionaries contain definition sections and data sections which are mapped to definition and data containers respectively.

Data in both PDBx data files and dictionaries are organized in data categories. In the PDBx syntax individual items or data identified by labels of the form ‘_categoryName.attribute_name’. The terms category and attribute in PDBx jargon are analogous table and column in relational data model, or class and attribute in an object oriented data model.

The DataCategory class provides base storage container for instance data and definition meta data.

class pdbx.containers.CifName[source]

Class of utilities for CIF-style data names.

static attribute_part(name) → str[source]

Get the attribute part of the name.

Parameters:name (str) – name
Returns:attribute part of name
static category_part(name) → str[source]

Get the category part of the name.

Parameters:name (str) – name
Returns:category part of name
class pdbx.containers.ContainerBase(name)[source]

Container base class for data and definition objects.

append(obj)[source]

Add the input object to the current object catalog. An existing object of the same name will be overwritten.

Parameters:obj (DataCategory) – input object to catalog
exists(name) → bool[source]

Determine if object name exists in object catalog.

Parameters:name (str) – object name
Returns:whether object exists in object catalog
get_object(name)[source]

Get object from object catalog.

Parameters:name (str) – object name
Returns:object or None
Return type:DataCategory
get_object_name_list() → list[source]

Get list of object names.

Returns:list of DataCategory objects
get_type() → str[source]

Get container type.

Returns:container type
name

Get container name.

Returns:container name
print_it(fobj=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, type_='brief')[source]

Dump information about container to specified file object.

Parameters:
  • fobj (file) – file object for writing
  • type (str) – type of summary (“brief” makes it short)
remove(current_name) → bool[source]

Remove object by name.

Parameters:current_name (str) – name of object to remove
Returns:True on success or False otherwise.
rename(current_name, new_name) → bool[source]

Change the name of an object in place.

Parameters:
  • current_name (str) – old name for object
  • new_name (str) – new name for object
Returns:

indicator of whether renaming was successful

replace(obj)[source]

Replace an existing object with the input object.

Parameters:obj (DataCategory) – input object to catalog
set_name(name)[source]

Set container name.

Parameters:name (str) – container name
set_type(type_)[source]

Set container type.

Parameters:type (str) – container type
class pdbx.containers.DataCategory(name, attribute_name_list=None, row_list=None)[source]

Methods for creating, accessing, formatting PDBx cif data categories.

append(row)[source]

Add row to container.

Parameters:row (list) – row to add
append_attribute(attribute_name)[source]

Add attribute to container.

Parameters:attribute_name (str) – name of attribute to add
append_attribute_extend_rows(attribute_name)[source]

Append attribute and extend rows.

Parameters:attribute_name (str) – name of attribute to add
attribute_count

Get number of attributes.

attribute_list

Get list of attributes.

attribute_list_with_order

Get list of attributes in order.

current_attribute

Get current attribute.

current_row_index

Get current row index.

dump_it(file_=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>)[source]

Dump contents of container.

Parameters:file (file) – file object ready for writing
get_attribute_index(attribute_name) → int[source]

Get index of given attribute.

Parameters:attribute_name (str) – name of attribute
Returns:index of attribute
Raises:IndexError – if attribute not found
get_format_type_list(steps=1) → str[source]

Get a formatted type list.

Parameters:steps (int) – step size for iterating through rows
Returns:formatted type list
get_format_type_list_x

Alternate version of format type list.

get_full_row(index) → list[source]

Return a full row based on the length of the the attribute list.

Parameters:index (int) – index of row to retrieve
Returns:row
get_max_attribute_list_length(steps=1) → int[source]

Get maximum length of attribute value list.

Parameters:steps (int) – step size for iterating through rows
Returns:attribute value list max length
get_row(index) → list[source]

Get specified row.

Parameters:index (int) – row index
Returns:specified row or empty array if row not found.
get_value(attribute_name=None, row_index=None)[source]

Get value for specified attribute and row.

Parameters:
  • attribute_name (str) – attribute name
  • row_index (int) – row index
Returns:

attribute value

Raises:

IndexError – if attribute not found

get_value_formatted(attribute_name=None, row_index=None) → str[source]

Get formatted version of value.

Parameters:
  • attribute_name (str) – attribute name
  • row_index (int) – row index
Returns:

formatted value

get_value_formatted_by_index(attribute_index, row_index) → str[source]

Get value formatted by index.

Parameters:
  • attribute_name (str) – attribute name
  • row_index (int) – row index
Returns:

formatted value

has_attribute(attribute_name) → bool[source]

Indicate whether container has attribute.

invoke_attribute_method(attribute_name, method)[source]

Invoke method of current attribute.

Parameters:
  • attribute_name (str) – attribute name
  • method (str) – name of attribute method
invoke_category_method(method)[source]

Invoke method of current category.

Parameters:method (str) – name of method
item_name_list

List of attribute names as fully qualified item names.

max_attribute_list_length

Get maximum attribute list length.

name

Get container name.

print_it(file_=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>)[source]

Print container information.

Parameters:file (file) – file object ready for writing
remove_row(index) → bool[source]

Remove specified row.

Parameters:index (int) – index of row to remove
Returns:True if successful, False otherwise
rename_attribute(current_attribute_name, new_attribute_name) → bool[source]

Change the name of an attribute in place.

Parameters:
  • current_attribute_name (str) – current attribute name
  • new_attribute_name (str) – new attribute name
Returns:

flag indicating renaming success

replace_substring(old_value, new_value, attribute_name) → bool[source]

Replace substring of value of given attribute.

Parameters:
  • old_value – old attribute value
  • new_value – new attribute value
  • attribute_name (str) – name of attribute to replace
Returns:

Boolean flag indicating success.

replace_value(old_value, new_value, attribute_name) → int[source]

Replace the value of the specified attribute.

Parameters:
  • old_value – old attribute value
  • new_value – new attribute value
  • attribute_name (str) – name of attribute to replace
Returns:

number of replacements

row_count

Get number of rows.

row_list

Get list of rows.

set_value(value, attribute_name=None, row_index=None)[source]

Set value of attribute.

Parameters:
  • value – value of attribute to set
  • attribute_name (str) – name of attribute
  • row_index (int) – index of row
class pdbx.containers.DataCategoryBase(name, attribute_name_list=None, row_list=None)[source]

Base object definition for a data category.

get() → tuple[source]

Get name, attribute name list, and row list.

Returns:tuple of (name, attribute name list, and row list)
set_attribute_name_list(attribute_name_list)[source]

Set attribute name list.

Parameters:attribute_name_list (list) – list of attribute names
set_name(name)[source]

Set name.

Parameters:name (str) – object name to set
set_row_list(row_list)[source]

Set row list.

Parameters:row_list (list) – list of rows
class pdbx.containers.DataContainer(name)[source]

Container class for DataCategory objects.

get_global() → bool[source]

Return global flag.

invoke_data_block_method(method)[source]

Invoke a method for the given data block.

Parameters:method (str) – name of method
set_global()[source]

Set global flag to True.

class pdbx.containers.DefinitionContainer(name)[source]

Container for definitions.

is_attribute() → bool[source]

Determine if container contains item objects.

Returns:indicator of whether item objects are in container
is_category() → bool[source]

Determine if container contains category objects.

Returns:indicator of whether category objects are in container
print_it(file_=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, type_='brief')[source]

Print information about container to file object.

Parameters:
  • file (file) – file object for writing
  • type (str) – type of summary (“brief” makes it short)