molecupy.pdb.pdbfile (PDB File)

This module is used to provide a container to the PDB file itself and its records - but not the data contained within them.

class molecupy.pdb.pdbfile.PdbRecord(text, pdb_file=None)[source]

Represents the lines, or ‘records’ in a PDB file.

Indexing a PdbRecord will get the equivalent slice of the record text, only stripped, and converted to int or float if possible. Empty sub-strings will return None.

Parameters:
  • text (str) – The raw text of the record.
  • pdb_file (PdbFile) – Optional: a PdbFile that the record should be associated with.
get_as_string(start, end)[source]

Indexing a record will automatically convert the value to an integer or float if it can - using this method instead will force it to return a string.

Parameters:
  • start (int) – The start of the subsection.
  • end (int) – The end of the subsection.
Return type:

str

number()[source]

The record’s line number in its associated PdbFile. If there is no file associated, this will return None.

Return type:int
name(name=None)[source]

The record’s name (the first six characters). If a string value is supplied, the name will be set to the new value, and the text will also be updated.

Parameters:name (str) – (optional) A new name to change to.
Return type:str
content(content=None)[source]

The record’s text exlcuding the first six characters. If a string value is supplied, the content will be set to the new value, and the text will also be updated.

Parameters:content (str) – (optional) A new content to change to.
Return type:str
text(text=None)[source]

The record’s text, extended to 80 characters. If a string value is supplied, the text will be set to the new value, and the name and content will also be updated.

Parameters:text (str) – (optional) A new text to change to.
Return type:str
pdb_file(pdb_file=None)[source]

The PdbFile that the record is associated with. This method can update the associated file by passing a PdbFile to it.

Parameters:pdb_file (PdbFile) – (optional) A new PdbFile to set.
Return type:PdbFile
class molecupy.pdb.pdbfile.PdbFile(file_string='')[source]

A PDB File - a representation of the file itself, with no processing of the data it contains (other than reading record names from the start of each line).

Parameters:file_string (str) – The raw text of a PDB file.
source()[source]

The object from which this PdbFile was created.

records()[source]

A list of PdbRecord objects.

Returns:list of PdbRecord objects.
get_record_by_name(record_name)[source]

Gets the first PdbRecord of a given name.

Parameters:record_name (str) – record name to search by.
Return type:PdbRecord or None if there is no match.
get_records_by_name(record_name)[source]

Gets all PdbRecord objects of a given name.

Parameters:record_name (str) – record name to search by.
Returns:list of PdbRecord objects.
add_record(record)[source]

Adds a PdbRecord to the end of the list of records.

Parameters:record (PdbRecord) – The PdbRecord to add.
remove_record(record)[source]

Removes a PdbRecord from the list of records.

Parameters:record (PdbRecord) – The PdbRecord to remove.
convert_to_string()[source]

Converts the PdbFile to a string, that can be written to file.

to_pdb_data_file()[source]

Converts the PdbFile to a PdbDataFile.