pidibble.pdbrecord module

class pidibble.pdbrecord.PDBRecord(input_dict)[source]

Bases: BaseRecord

A class representing a PDB record, inheriting from baserecord.BaseRecord. It provides methods for parsing and handling PDB records, including embedded records and tokens.

classmethod base_parse(current_key, pdbrecordline: str, current_format: dict, typemap: dict)[source]

Parse a PDB record line based on the provided format and type mapping.

This method handles the parsing of the PDB record line according to the specified format. It extracts fields, subrecords, allowed values, and concatenated fields based on the format and type mapping provided. It also checks for subrecords and handles them accordingly.

Parameters:
  • current_key (str) – The key for the current record being parsed.

  • pdbrecordline (str) – The line from the PDB file to be parsed.

  • current_format (dict) – The format dictionary defining the structure of the PDB record.

  • typemap (dict) – A dictionary mapping field names to their types.

Returns:

A tuple containing the parsed input dictionary, the current key, and the current format.

Return type:

tuple

continuation = '0'
continue_record(other, record_format, **kwargs)[source]

Continue a PDBRecord instance with another PDBRecord instance. This method merges the attributes of the other PDBRecord instance into the current instance, handling continuation fields and concatenating values as necessary.

Parameters:
  • other (PDBRecord) – The other PDBRecord instance to merge with.

  • record_format (dict) – The format dictionary defining the structure of the PDB record.

  • kwargs (dict, optional) – Additional keyword arguments, such as ‘all_fields’ to specify whether to include all fields.

  • all_fields (bool, optional) – If True, all fields from the record format will be considered for continuation. If False, only the fields specified in the record format will be considered.

Returns:

This method modifies the current instance in place.

Return type:

None

get_token(key)[source]

Retrieve a token value from the PDBRecord instance based on the provided key.

Parameters:

key (str) – The key for the token to retrieve.

Returns:

The value of the token if found, or None if the token does not exist.

Return type:

str or None

classmethod newrecord(base_key: str, pdbrecordline: str, record_format: dict, typemap: dict)[source]

Create a new PDBRecord instance from a PDB record line and its format. This method parses the PDB record line according to the specified format and type mapping, and returns a new instance of the PDBRecord class with the parsed data.

Parameters:
  • base_key (str) – The base key for the PDB record.

  • pdbrecordline (str) – The line from the PDB file to be parsed.

  • record_format (dict) – The format dictionary defining the structure of the PDB record.

  • typemap (dict) – A dictionary mapping field names to their types.

Returns:

A new instance of the PDBRecord class containing the parsed data.

Return type:

PDBRecord

parse_embedded(format_dict, typemap)[source]

Parse embedded records within the PDBRecord instance based on the record format. This method checks if the record format contains embedded records and parses them accordingly.

Parameters:
  • format_dict (dict) – A dictionary mapping field names to their formats.

  • typemap (dict) – A dictionary mapping field names to their types.

parse_tables(typemap)[source]

Parse tables from the PDBRecord instance based on the record format. This method checks if the record format contains table formats and parses them accordingly.

Parameters:

typemap (dict) – A dictionary mapping field names to their types.

Returns:

  • None. This method modifies the PDBRecord instance in place, adding a tables attribute

  • that contains the parsed tables, where each table is a list of pdbrecord.PDBRecord instances.

parse_tokens(typemap)[source]

Parse tokens from the PDBRecord instance based on the record format. This method checks if the record format contains token formats and parses them accordingly.

Parameters:

typemap (dict) – A dictionary mapping field names to their types.

Returns:

This method modifies the PDBRecord instance in place, adding a tokengroups attribute that contains the parsed tokens grouped by their labels.

Return type:

None

class pidibble.pdbrecord.PDBRecordDict(*args, **kwargs)[source]

Bases: UserDict

A class representing a dictionary of PDBRecord or PDBRecordList instances, inheriting from UserDict. It provides methods for parsing and handling multiple PDB records stored in a dictionary.

setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D[source]
update([E, ]**F) None.  Update D from mapping/iterable E and F.[source]

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

class pidibble.pdbrecord.PDBRecordList(initlist=None)[source]

Bases: UserList

A class representing a list of PDBRecord instances, inheriting from UserList. It provides methods for parsing and handling multiple PDB records.

append(item)[source]

S.append(value) – append value to the end of the sequence

extend(other)[source]

S.extend(iterable) – extend sequence by appending elements from the iterable

insert(index, item)[source]

S.insert(index, value) – insert value before index

pidibble.pdbrecord.capture_record(rec, fmt, typemap, key, hdrs, hh, th, divno, rh)[source]

Capture a record from the PDB file and create a new PDBRecord instance. This function checks if the record is a continuation of an existing record or a new record. If it is a continuation, it updates the existing record. If it is a new record, it creates a new PDBRecord instance and adds it to the record holder.

Parameters:
  • rec (str) – The record line to capture.

  • fmt (dict) – The format dictionary defining the structure of the PDB record.

  • typemap (dict) – A dictionary mapping field names to their types.

  • key (str) – The key for the current record being captured.

  • hdrs (dict) – A dictionary containing header formats and their specifications.

  • hh (list) – A list to hold the header values.

  • th (dict) – A dictionary to hold the tokens.

  • divno (int) – The current division number.

  • rh (dict) – A dictionary to hold the records, where keys are record keys and values are PDBRecord instances.

Returns:

True if a new division was detected, False otherwise.

Return type:

bool

pidibble.pdbrecord.gather_token(k, v, hold=None)[source]

Gather a token into a holder dictionary. If the key already exists in the holder, it appends the value to the list.

Parameters:
  • k (str) – The key for the token.

  • v (str) – The value of the token.

  • hold (dict, optional) – A dictionary to hold the tokens. Defaults to an empty dictionary.

pidibble.pdbrecord.header_check(record, headers, parse, hold=None)[source]

Check if a record is a header line and parse it accordingly.

Parameters:
  • record (str) – The record line to check.

  • headers (dict) – A dictionary containing header formats and their specifications.

  • parse (function) – A function to parse the header line.

  • hold (list, optional) – A list to hold the parsed header values. Defaults to an empty list.

pidibble.pdbrecord.header_or_token(rec, d, hdrs, tp, htp, th, hh)[source]

Check if a record is a token or a header line and parse it accordingly. This function checks if the record can be tokenized or if it matches a header format. If it matches a header format, it updates the header holder. If it is a token, it gathers the token into the token holder.

Parameters:
  • rec (str) – The record line to check.

  • d (str) – The delimiter used to separate tokens in the record.

  • hdrs (dict) – A dictionary containing header formats and their specifications.

  • tp (function) – A function to parse the token line.

  • htp (function) – A function to parse the header line.

  • th (dict) – A dictionary to hold the tokens.

  • hh (list) – A list to hold the header values.

Returns:

True if the record was parsed as a token or header, False otherwise.

Return type:

bool

class pidibble.pdbrecord.tokengroup(tokname, tokval, determinant=True)[source]

Bases: object

A class to represent a group of tokens with a label and a method to add tokens.

add_token(tokname, tokval)[source]

Add a token to the token group.

Parameters:
  • tokname (str) – The name of the token.

  • tokval (str) – The value of the token.