pidibble.pdbrecord module¶
- class pidibble.pdbrecord.PDBRecord(input_dict)[source]¶
Bases:
BaseRecordA 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:
- Returns:
A tuple containing the parsed input dictionary, the current key, and the current format.
- Return type:
- 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.
- 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:
- Returns:
A new instance of the PDBRecord class containing the parsed data.
- Return type:
- 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.
- 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.PDBRecordinstances.
- 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:
UserDictA 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.
- class pidibble.pdbrecord.PDBRecordList(initlist=None)[source]¶
Bases:
UserListA class representing a list of PDBRecord instances, inheriting from UserList. It provides methods for parsing and handling multiple PDB records.
- 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:
- 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.
- pidibble.pdbrecord.header_check(record, headers, parse, hold=None)[source]¶
Check if a record is a header line and parse it accordingly.
- 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: