From dc6dc547bd04751bc95263ba491be2609375f2e9 Mon Sep 17 00:00:00 2001 From: Nathan Baker Date: Sun, 28 Feb 2021 09:24:39 -0800 Subject: [PATCH 1/2] Change many attributes to properties and improve documentation. Fixes #5. --- docs/changelog.rst | 6 +- old_pdb/annotation.py | 426 +++++++++++----------- old_pdb/bookkeeping.py | 62 ++-- old_pdb/coordinates.py | 168 ++++----- old_pdb/crystallography.py | 26 +- old_pdb/heterogen.py | 65 ++-- old_pdb/pdb_entry.py | 722 ++++++++++++++++++++++++++++--------- old_pdb/primary.py | 229 ++++++------ old_pdb/secondary.py | 421 ++++++++++----------- tests/read_test.py | 7 +- 10 files changed, 1269 insertions(+), 863 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 67ecbf5..365ab60 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,10 +4,12 @@ Change log ========== -Current version -=============== +1.0.0 +===== * Fixed readthedocs.io rendering of documentation (`#3 `_) +* Changed several attributes to properties, per (`#5 `_) +* Improved documentation of attributes (as properties) 0.0.1 ===== diff --git a/old_pdb/annotation.py b/old_pdb/annotation.py index 1e07d8f..961ca47 100644 --- a/old_pdb/annotation.py +++ b/old_pdb/annotation.py @@ -18,17 +18,17 @@ class Author(BaseRecord): The AUTHOR record contains the names of the people responsible for the contents of the entry. - +---------+--------------+--------------+-------------------------------+ - | COLUMNS | DATA TYPE | FIELD | DEFINITION | - +=========+==============+==============+===============================+ - | 1-6 | Record name | "AUTHOR" | | - +---------+--------------+--------------+-------------------------------+ - | 9-10 | Continuation | continuation | Allows concatenation of | - | | | | multiple records. | - +---------+--------------+--------------+-------------------------------+ - | 11-79 | List | authorList | List of the author names, | - | | | | separated by commas. | - +---------+--------------+--------------+-------------------------------+ + +---------+--------------+---------------+-------------------------------+ + | COLUMNS | DATA TYPE | FIELD | DEFINITION | + +=========+==============+===============+===============================+ + | 1-6 | Record name | "AUTHOR" | | + +---------+--------------+---------------+-------------------------------+ + | 9-10 | Continuation | continuation | Allows concatenation of | + | | | | multiple records. | + +---------+--------------+---------------+-------------------------------+ + | 11-79 | List | author_list | List of the author names, | + | | | | separated by commas. | + +---------+--------------+---------------+-------------------------------+ """ def __init__(self): @@ -68,7 +68,7 @@ class Caveat(BaseRecord): | 9-10 | Continuation | continuation | Allows concatenation of | | | | | multiple records. | +---------+--------------+--------------+---------------------------------+ - | 12-15 | IDcode | idCode | PDB ID code of this entry. | + | 12-15 | IDcode | id_code | PDB ID code of this entry. | +---------+--------------+--------------+---------------------------------+ | 20-79 | String | comment | Free text giving the reason for | | | | | the CAVEAT. | @@ -217,11 +217,11 @@ class Header(BaseRecord): +---------+-------------+----------------+--------------------------------+ | 11-50 | String(40) | classification | Classifies the molecule(s). | +---------+-------------+----------------+--------------------------------+ - | 51-59 | Date | depDate | Deposition date. This is the | + | 51-59 | Date | dep_date | Deposition date. This is the | | | | | date the coordinates were | | | | | received at the PDB. | +---------+-------------+----------------+--------------------------------+ - | 63-66 | IDcode | idCode | This identifier is unique | + | 63-66 | IDcode | id_code | This identifier is unique | | | | | within the PDB. | +---------+-------------+----------------+--------------------------------+ """ @@ -301,7 +301,7 @@ class Keywords(BaseRecord): | 9-10 | Continuation | continuation | Allows concatenation of records | | | | | if necessary. | +---------+--------------+--------------+---------------------------------+ - | 11-79 | List | keywds | Comma-separated list of | + | 11-79 | List | keywords | Comma-separated list of | | | | | keywords relevant to the entry. | +---------+--------------+--------------+---------------------------------+ """ @@ -381,46 +381,46 @@ class Obsolete(BaseRecord): The format allows for the case of multiple new entries replacing one existing entry. - +---------+--------------+--------------+--------------------------------+ - | COLUMNS | DATA TYPE | FIELD | DEFINITION | - +=========+==============+==============+================================+ - | 1-6 | Record name | "OBSLTE" | | - +---------+--------------+--------------+--------------------------------+ - | 9-10 | Continuation | continuation | Allows concatenation of | - | | | | multiple records | - +---------+--------------+--------------+--------------------------------+ - | 12-20 | Date | repDate | Date that this entry was | - | | | | replaced. | - +---------+--------------+--------------+--------------------------------+ - | 22-25 | IDcode | idCode | ID code of this entry. | - +---------+--------------+--------------+--------------------------------+ - | 32-35 | IDcode | rIdCode | ID code of entry that replaced | - | | | | this one. | - +---------+--------------+--------------+--------------------------------+ - | 37-40 | IDcode | rIdCode | ID code of entry that replaced | - | | | | this one. | - +---------+--------------+--------------+--------------------------------+ - | 42-45 | IDcode | rIdCode | ID code of entry that replaced | - | | | | this one. | - +---------+--------------+--------------+--------------------------------+ - | 47-50 | IDcode | rIdCode | ID code of entry that replaced | - | | | | this one. | - +---------+--------------+--------------+--------------------------------+ - | 52-55 | IDcode | rIdCode | ID code of entry that replaced | - | | | | this one. | - +---------+--------------+--------------+--------------------------------+ - | 57-60 | IDcode | rIdCode | ID code of entry that replaced | - | | | | this one. | - +---------+--------------+--------------+--------------------------------+ - | 62-65 | IDcode | rIdCode | ID code of entry that replaced | - | | | | this one. | - +---------+--------------+--------------+--------------------------------+ - | 67-70 | IDcode | rIdCode | ID code of entry that replaced | - | | | | this one. | - +---------+--------------+--------------+--------------------------------+ - | 72-75 | IDcode | rIdCode | ID code of entry that replaced | - | | | | this one. | - +---------+--------------+--------------+--------------------------------+ + +---------+--------------+---------------------+--------------------------+ + | COLUMNS | DATA TYPE | FIELD | DEFINITION | + +=========+==============+=====================+==========================+ + | 1-6 | Record name | "OBSLTE" | | + +---------+--------------+---------------------+--------------------------+ + | 9-10 | Continuation | continuation | Allows concatenation of | + | | | | multiple records | + +---------+--------------+---------------------+--------------------------+ + | 12-20 | Date | replace_date | Date that this entry was | + | | | | replaced. | + +---------+--------------+---------------------+--------------------------+ + | 22-25 | IDcode | id_code | ID code of this entry. | + +---------+--------------+---------------------+--------------------------+ + | 32-35 | IDcode | replace_id_codes[0] | ID of entry replacing | + | | | | this one. | + +---------+--------------+---------------------+--------------------------+ + | 37-40 | IDcode | replace_id_codes[1] | ID of entry replacing | + | | | | this one. | + +---------+--------------+---------------------+--------------------------+ + | 42-45 | IDcode | replace_id_codes[2] | ID of entry replacing | + | | | | this one. | + +---------+--------------+---------------------+--------------------------+ + | 47-50 | IDcode | replace_id_codes[3] | ID of entry replacing | + | | | | this one. | + +---------+--------------+---------------------+--------------------------+ + | 52-55 | IDcode | replace_id_codes[4] | ID of entry replacing | + | | | | this one. | + +---------+--------------+---------------------+--------------------------+ + | 57-60 | IDcode | replace_id_codes[5] | ID of entry replacing | + | | | | this one. | + +---------+--------------+---------------------+--------------------------+ + | 62-65 | IDcode | replace_id_codes[6] | ID of entry replacing | + | | | | this one. | + +---------+--------------+---------------------+--------------------------+ + | 67-70 | IDcode | replace_id_codes[7] | ID of entry replacing | + | | | | this one. | + +---------+--------------+---------------------+--------------------------+ + | 72-75 | IDcode | replace_id_codes[8] | ID of entry replacing | + | | | | this one. | + +---------+--------------+---------------------+--------------------------+ """ def __init__(self): @@ -515,38 +515,38 @@ def __str__(self): class Revision(BaseRecord): """Class to store contents of a single REVDAT modification. - +---------+--------------+--------------+---------------------------------+ - | COLUMNS | DATA TYPE | FIELD | DEFINITION | - +=========+==============+==============+=================================+ - | 1-6 | Record name | "REVDAT" | | - +---------+--------------+--------------+---------------------------------+ - | 8-10 | Integer | modNum | Modification number. | - +---------+--------------+--------------+---------------------------------+ - | 11-12 | Continuation | continuation | Allows concatenation of | - | | | | multiple records. | - +---------+--------------+--------------+---------------------------------+ - | 14-22 | Date | modDate | Date of modification (or | - | | | | for new entries) in DD-MMM-YY | - | | | | format. This is not repeated on | - | | | | continued lines. | - +---------+--------------+--------------+---------------------------------+ - | 24-27 | IDCode | modId | ID code of this entry. This is | - | | | | not repeated on continuation | - | | | | lines. | - +---------+--------------+--------------+---------------------------------+ - | 32 | Integer | modType | An integer identifying the type | - | | | | of modification. For all | - | | | | revisions, the modification | - | | | | type is listed as 1 | - +---------+--------------+--------------+---------------------------------+ - | 40-45 | LString(6) | record | Modification detail. | - +---------+--------------+--------------+---------------------------------+ - | 47-52 | LString(6) | record | Modification detail. | - +---------+--------------+--------------+---------------------------------+ - | 54-59 | LString(6) | record | Modification detail. | - +---------+--------------+--------------+---------------------------------+ - | 61-66 | LString(6) | record | Modification detail. | - +---------+--------------+--------------+---------------------------------+ + +---------+--------------+-------------------+---------------------------------+ + | COLUMNS | DATA TYPE | FIELD | DEFINITION | + +=========+==============+===================+=================================+ + | 1-6 | Record name | "REVDAT" | | + +---------+--------------+-------------------+---------------------------------+ + | 8-10 | Integer | modification_num | Modification number. | + +---------+--------------+-------------------+---------------------------------+ + | 11-12 | Continuation | continuation | Allows concatenation of | + | | | | multiple records. | + +---------+--------------+-------------------+---------------------------------+ + | 14-22 | Date | modification_date | Date of modification (or | + | | | | for new entries) in DD-MMM-YY | + | | | | format. This is not repeated on | + | | | | continued lines. | + +---------+--------------+-------------------+---------------------------------+ + | 24-27 | IDCode | modification_id | ID code of this entry. This is | + | | | | not repeated on continuation | + | | | | lines. | + +---------+--------------+-------------------+---------------------------------+ + | 32 | Integer | modification_type | An integer identifying the type | + | | | | of modification. For all | + | | | | revisions, the modification | + | | | | type is listed as 1 | + +---------+--------------+-------------------+---------------------------------+ + | 40-45 | LString(6) | record | Modification detail. | + +---------+--------------+-------------------+---------------------------------+ + | 47-52 | LString(6) | record | Modification detail. | + +---------+--------------+-------------------+---------------------------------+ + | 54-59 | LString(6) | record | Modification detail. | + +---------+--------------+-------------------+---------------------------------+ + | 61-66 | LString(6) | record | Modification detail. | + +---------+--------------+-------------------+---------------------------------+ """ def __init__(self): @@ -648,7 +648,20 @@ class RevisionData(BaseRecord): def __init__(self): super().__init__() - self.revisions = OrderedDict() + self._revisions = OrderedDict() + + @property + def revisions(self) -> OrderedDict: + """Get revisions. + + :returns: dictionary with modifiction numbers as keys and + :class:`Revision` objects as values + """ + return self._revisions + + @revisions.setter + def revisions(self, value): + self._revisions = value def parse_line(self, line): """Parse PDB-format line. @@ -657,15 +670,15 @@ def parse_line(self, line): """ super().parse_line(line) mod_num = int(line[7:10].strip()) - revision = self.revisions.get(mod_num, Revision()) + revision = self._revisions.get(mod_num, Revision()) revision.parse_line(line) - self.revisions[mod_num] = revision + self._revisions[mod_num] = revision def __str__(self): strings = [] curr_mod = None continuation = 1 - for mod_num, revision in self.revisions.items(): + for mod_num, revision in self._revisions.items(): string = str(revision) if mod_num == curr_mod: continuation += 1 @@ -683,67 +696,66 @@ class Site(BaseRecord): The SITE records supply the identification of groups comprising important sites in the macromolecule. - +---------+--------------+----------+-------------------------------------+ - | COLUMNS | DATA TYPE | FIELD | DEFINITION | - +=========+==============+==========+=====================================+ - | 1-6 | Record name | "SITE " | | - +---------+--------------+----------+-------------------------------------+ - | 8-10 | Integer | seqNum | Sequence number. | - +---------+--------------+----------+-------------------------------------+ - | 12-14 | LString(3) | siteID | Site name. | - +---------+--------------+----------+-------------------------------------+ - | 16-17 | Integer | numRes | Number of residues that compose the | - +---------+--------------+----------+-------------------------------------+ - | | | | site. | - +---------+--------------+----------+-------------------------------------+ - | 19-21 | Residue name | resName1 | Residue name for first residue that | - | | | | creates the site. | - +---------+--------------+----------+-------------------------------------+ - | 23 | Character | chainID1 | Chain identifier for first residue | - | | | | of site. | - +---------+--------------+----------+-------------------------------------+ - | 24-27 | Integer | seq1 | Residue sequence number for first | - | | | | residue of the site. | - +---------+--------------+----------+-------------------------------------+ - | 28 | AChar | iCode1 | Insertion code for first residue of | - | | | | the site. | - +---------+--------------+----------+-------------------------------------+ - | 30-32 | Residue name | resName2 | Residue name for second residue | - | | | | that creates the site. | - +---------+--------------+----------+-------------------------------------+ - | 34 | Character | chainID2 | Chain identifier for second residue | - | | | | of the site. | - +---------+--------------+----------+-------------------------------------+ - | 35-38 | Integer | seq2 | Residue sequence number for second | - | | | | residue of the site. | - +---------+--------------+----------+-------------------------------------+ - | 39 | AChar | iCode2 | Insertion code for second residue | - | | | | of the site. | - +---------+--------------+----------+-------------------------------------+ - | 41-43 | Residue name | resName3 | Residue name for third residue that | - | | | | creates the site. | - +---------+--------------+----------+-------------------------------------+ - | 45 | Character | chainID3 | Chain identifier for third residue | - | | | | of the site. | - +---------+--------------+----------+-------------------------------------+ - | 46-49 | Integer | seq3 | Residue sequence number for third | - | | | | residue of the site. | - +---------+--------------+----------+-------------------------------------+ - | 50 | AChar | iCode3 | Insertion code for third residue of | - | | | | the site. | - +---------+--------------+----------+-------------------------------------+ - | 52-54 | Residue name | resName4 | Residue name for fourth residue | - | | | | that creates the site. | - +---------+--------------+----------+-------------------------------------+ - | 56 | Character | chainID4 | Chain identifier for fourth residue | - | | | | of the site. | - +---------+--------------+----------+-------------------------------------+ - | 57-60 | Integer | seq4 | Residue sequence number for fourth | - | | | | residue of the site. | - +---------+--------------+----------+-------------------------------------+ - | 61 | AChar | iCode4 | Insertion code for fourth residue | - | | | | of the site. | - +---------+--------------+----------+-------------------------------------+ + +---------+--------------+-----------+------------------------------------+ + | COLUMNS | DATA TYPE | FIELD | DEFINITION | + +=========+==============+===========+====================================+ + | 1-6 | Record name | "SITE " | | + +---------+--------------+-----------+------------------------------------+ + | 8-10 | Integer | seq_num | Sequence number. | + +---------+--------------+-----------+------------------------------------+ + | 12-14 | LString(3) | site_id | Site name. | + +---------+--------------+-----------+------------------------------------+ + | 16-17 | Integer | num_res | Number of residues that compose | + | | | | the site. | + +---------+--------------+-----------+------------------------------------+ + | 19-21 | Residue name | res_name1 | Residue name for first residue | + | | | | that creates the site. | + +---------+--------------+-----------+------------------------------------+ + | 23 | Character | chain_id1 | Chain identifier for first residue | + | | | | of site. | + +---------+--------------+-----------+------------------------------------+ + | 24-27 | Integer | seq1 | Residue sequence number for first | + | | | | residue of the site. | + +---------+--------------+-----------+------------------------------------+ + | 28 | AChar | ins_code1 | Insertion code for first residue | + | | | | of the site. | + +---------+--------------+-----------+------------------------------------+ + | 30-32 | Residue name | res_name2 | Residue name for second residue | + | | | | that creates the site. | + +---------+--------------+-----------+------------------------------------+ + | 34 | Character | chain_id2 | Chain identifier for second | + | | | | residue of the site. | + +---------+--------------+-----------+------------------------------------+ + | 35-38 | Integer | seq2 | Residue sequence number for second | + | | | | residue of the site. | + +---------+--------------+-----------+------------------------------------+ + | 39 | AChar | ins_code2 | Insertion code for second residue | + | | | | of the site. | + +---------+--------------+-----------+------------------------------------+ + | 41-43 | Residue name | res_name3 | Residue name for third residue | + | | | | that creates the site. | + +---------+--------------+-----------+------------------------------------+ + | 45 | Character | chain_id3 | Chain identifier for third residue | + | | | | of the site. | + +---------+--------------+-----------+------------------------------------+ + | 46-49 | Integer | seq3 | Residue sequence number for third | + | | | | residue of the site. | + +---------+--------------+-----------+------------------------------------+ + | 50 | AChar | ins_code3 | Insertion code for third residue | + | | | | of the site. | + +---------+--------------+-----------+------------------------------------+ + | 52-54 | Residue name | res_name4 | Residue name for fourth residue | + | | | | that creates the site. | + +---------+--------------+-----------+------------------------------------+ + | 56 | Character | chain_id4 | Chain identifier for fourth | + | | | | residue of the site. | + +---------+--------------+-----------+------------------------------------+ + | 57-60 | Integer | seq4 | Residue sequence number for fourth | + | | | | residue of the site. | + +---------+--------------+-----------+------------------------------------+ + | 61 | AChar | ins_code4 | Insertion code for fourth residue | + | | | | of the site. | + +---------+--------------+-----------+------------------------------------+ """ def __init__(self): @@ -821,13 +833,13 @@ class NumModels(BaseRecord): The NUMMDL record indicates total number of models in a PDB entry. - +---------+-------------+-------------+-----------------------------------+ - | COLUMNS | DATA TYPE | FIELD | DEFINITION | - +=========+=============+=============+===================================+ - | 1-6 | Record name | "NUMMDL" | | - +---------+-------------+-------------+-----------------------------------+ - | 11-14 | Integer | modelNumber | Number of models. | - +---------+-------------+-------------+-----------------------------------+ + +---------+-------------+--------------+----------------------------------+ + | COLUMNS | DATA TYPE | FIELD | DEFINITION | + +=========+=============+==============+==================================+ + | 1-6 | Record name | "NUMMDL" | | + +---------+-------------+--------------+----------------------------------+ + | 11-14 | Integer | model_number | Number of models. | + +---------+-------------+--------------+----------------------------------+ """ def __init__(self): @@ -863,7 +875,7 @@ class Source(BaseRecord): | 8-10 | Continuation | continuation | Allows concatenation of | | | | | multiple records. | +---------+---------------+--------------+--------------------------------+ - | 11-79 | Specification | srcName | Identifies the source of the | + | 11-79 | Specification | source | Identifies the source of the | | | List | | macromolecule in a token: | | | | | value format. | +---------+---------------+--------------+--------------------------------+ @@ -908,33 +920,33 @@ class Split(BaseRecord): | 9-10 | Continuation | continuation | Allows concatenation of | | | | | multiple records. | +---------+--------------+--------------+---------------------------------+ - | 12-15 | IDcode | idCode | ID code of related entry. | + | 12-15 | IDcode | id_codes[0] | ID code of related entry. | +---------+--------------+--------------+---------------------------------+ - | 17-20 | IDcode | idCode | ID code of related entry. | + | 17-20 | IDcode | id_codes[1] | ID code of related entry. | +---------+--------------+--------------+---------------------------------+ - | 22-25 | IDcode | idCode | ID code of related entry. | + | 22-25 | IDcode | id_codes[2] | ID code of related entry. | +---------+--------------+--------------+---------------------------------+ - | 27-30 | IDcode | idCode | ID code of related entry. | + | 27-30 | IDcode | id_codes[3] | ID code of related entry. | +---------+--------------+--------------+---------------------------------+ - | 32-35 | IDcode | idCode | ID code of related entry. | + | 32-35 | IDcode | id_codes[4] | ID code of related entry. | +---------+--------------+--------------+---------------------------------+ - | 37-40 | IDcode | idCode | ID code of related entry. | + | 37-40 | IDcode | id_codes[5] | ID code of related entry. | +---------+--------------+--------------+---------------------------------+ - | 42-45 | IDcode | idCode | ID code of related entry. | + | 42-45 | IDcode | id_codes[6] | ID code of related entry. | +---------+--------------+--------------+---------------------------------+ - | 47-50 | IDcode | idCode | ID code of related entry. | + | 47-50 | IDcode | id_codes[7] | ID code of related entry. | +---------+--------------+--------------+---------------------------------+ - | 52-55 | IDcode | idCode | ID code of related entry. | + | 52-55 | IDcode | id_codes[8] | ID code of related entry. | +---------+--------------+--------------+---------------------------------+ - | 57-60 | IDcode | idCode | ID code of related entry. | + | 57-60 | IDcode | id_codes[9] | ID code of related entry. | +---------+--------------+--------------+---------------------------------+ - | 62-65 | IDcode | idCode | ID code of related entry. | + | 62-65 | IDcode | id_codes[10] | ID code of related entry. | +---------+--------------+--------------+---------------------------------+ - | 67-70 | IDcode | idCode | ID code of related entry. | + | 67-70 | IDcode | id_codes[11] | ID code of related entry. | +---------+--------------+--------------+---------------------------------+ - | 72-75 | IDcode | idCode | ID code of related entry. | + | 72-75 | IDcode | id_codes[12] | ID code of related entry. | +---------+--------------+--------------+---------------------------------+ - | 77-80 | IDcode | idCode | ID code of related entry. | + | 77-80 | IDcode | id_codes[13] | ID code of related entry. | +---------+--------------+--------------+---------------------------------+ """ @@ -982,39 +994,39 @@ class Supersedes(BaseRecord): release set. One entry may replace many. It is PDB policy that only the principal investigator of a structure has the authority to withdraw it. - +---------+--------------+--------------+---------------------------------+ - | COLUMNS | DATA TYPE | FIELD | DEFINITION | - +=========+==============+==============+=================================+ - | 1-6 | Record name | "SPRSDE" | | - +---------+--------------+--------------+---------------------------------+ - | 9-10 | Continuation | continuation | Allows for multiple ID codes. | - +---------+--------------+--------------+---------------------------------+ - | 12-20 | Date | sprsdeDate | Date this entry superseded the | - | | | | listed entries. This field is | - | | | | not copied on continuations. | - +---------+--------------+--------------+---------------------------------+ - | 22-25 | IDcode | idCode | ID code of this entry. This | - | | | | field is not copied on | - | | | | continuations. | - +---------+--------------+--------------+---------------------------------+ - | 32-35 | IDcode | sIdCode | ID code of a superseded entry. | - +---------+--------------+--------------+---------------------------------+ - | 37-40 | IDcode | sIdCode | ID code of a superseded entry. | - +---------+--------------+--------------+---------------------------------+ - | 42-45 | IDcode | sIdCode | ID code of a superseded entry. | - +---------+--------------+--------------+---------------------------------+ - | 47-50 | IDcode | sIdCode | ID code of a superseded entry. | - +---------+--------------+--------------+---------------------------------+ - | 52-55 | IDcode | sIdCode | ID code of a superseded entry. | - +---------+--------------+--------------+---------------------------------+ - | 57-60 | IDcode | sIdCode | ID code of a superseded entry. | - +---------+--------------+--------------+---------------------------------+ - | 62-65 | IDcode | sIdCode | ID code of a superseded entry. | - +---------+--------------+--------------+---------------------------------+ - | 67-70 | IDcode | sIdCode | ID code of a superseded entry. | - +---------+--------------+--------------+---------------------------------+ - | 72-75 | IDcode | sIdCode | ID code of a superseded entry. | - +---------+--------------+--------------+---------------------------------+ + +---------+--------------+----------------+-------------------------------+ + | COLUMNS | DATA TYPE | FIELD | DEFINITION | + +=========+==============+================+===============================+ + | 1-6 | Record name | "SPRSDE" | | + +---------+--------------+----------------+-------------------------------+ + | 9-10 | Continuation | continuation | Allows for multiple ID codes. | + +---------+--------------+----------------+-------------------------------+ + | 12-20 | Date | super_date | Date entry superseded the | + | | | | listed entries. This field is | + | | | | not copied on continuations. | + +---------+--------------+----------------+-------------------------------+ + | 22-25 | IDcode | id_code | ID code of this entry. This | + | | | | field is not copied on | + | | | | continuations. | + +---------+--------------+----------------+-------------------------------+ + | 32-35 | IDcode | super_id_codes | ID code of superseded entry. | + +---------+--------------+----------------+-------------------------------+ + | 37-40 | IDcode | super_id_codes | ID code of superseded entry. | + +---------+--------------+----------------+-------------------------------+ + | 42-45 | IDcode | super_id_codes | ID code of superseded entry. | + +---------+--------------+----------------+-------------------------------+ + | 47-50 | IDcode | super_id_codes | ID code of superseded entry. | + +---------+--------------+----------------+-------------------------------+ + | 52-55 | IDcode | super_id_codes | ID code of superseded entry. | + +---------+--------------+----------------+-------------------------------+ + | 57-60 | IDcode | super_id_codes | ID code of superseded entry. | + +---------+--------------+----------------+-------------------------------+ + | 62-65 | IDcode | super_id_codes | ID code of superseded entry. | + +---------+--------------+----------------+-------------------------------+ + | 67-70 | IDcode | super_id_codes | ID code of superseded entry. | + +---------+--------------+----------------+-------------------------------+ + | 72-75 | IDcode | super_id_codes | ID code of superseded entry. | + +---------+--------------+----------------+-------------------------------+ """ def __init__(self): diff --git a/old_pdb/bookkeeping.py b/old_pdb/bookkeeping.py index 5b8026b..a1dab6a 100644 --- a/old_pdb/bookkeeping.py +++ b/old_pdb/bookkeeping.py @@ -75,37 +75,37 @@ class Master(BaseRecord): It lists the number of lines in the coordinate entry or file for selected record types. - +---------+-------------+-----------+-------------------------------------+ - | COLUMNS | DATA TYPE | FIELD | DEFINITION | - +=========+=============+===========+=====================================+ - | 1-6 | Record name | "MASTER" | | - +---------+-------------+-----------+-------------------------------------+ - | 11-15 | Integer | numRemark | Number of REMARK records | - +---------+-------------+-----------+-------------------------------------+ - | 16-20 | Integer | "0" | | - +---------+-------------+-----------+-------------------------------------+ - | 21-25 | Integer | numHet | Number of HET records | - +---------+-------------+-----------+-------------------------------------+ - | 26-30 | Integer | numHelix | Number of HELIX records | - +---------+-------------+-----------+-------------------------------------+ - | 31-35 | Integer | numSheet | Number of SHEET records | - +---------+-------------+-----------+-------------------------------------+ - | 36-40 | Integer | numTurn | deprecated | - +---------+-------------+-----------+-------------------------------------+ - | 41-45 | Integer | numSite | Number of SITE records | - +---------+-------------+-----------+-------------------------------------+ - | 46-50 | Integer | numXform | Number of coordinate transformation | - | | | | records (ORIGX+SCALE+MTRIX) | - +---------+-------------+-----------+-------------------------------------+ - | 51-55 | Integer | numCoord | Number of atomic coordinate records | - | | | | records (ATOM+HETATM) | - +---------+-------------+-----------+-------------------------------------+ - | 56-60 | Integer | numTer | Number of TER records | - +---------+-------------+-----------+-------------------------------------+ - | 61-65 | Integer | numConect | Number of CONECT records | - +---------+-------------+-----------+-------------------------------------+ - | 66-70 | Integer | numSeq | Number of SEQRES records | - +---------+-------------+-----------+-------------------------------------+ + +---------+-------------+------------+------------------------------------+ + | COLUMNS | DATA TYPE | FIELD | DEFINITION | + +=========+=============+============+====================================+ + | 1-6 | Record name | "MASTER" | | + +---------+-------------+------------+------------------------------------+ + | 11-15 | Integer | num_remark | Number of REMARK records | + +---------+-------------+------------+------------------------------------+ + | 16-20 | Integer | "0" | | + +---------+-------------+------------+------------------------------------+ + | 21-25 | Integer | num_het | Number of HET records | + +---------+-------------+------------+------------------------------------+ + | 26-30 | Integer | num_helix | Number of HELIX records | + +---------+-------------+------------+------------------------------------+ + | 31-35 | Integer | num_sheet | Number of SHEET records | + +---------+-------------+------------+------------------------------------+ + | 36-40 | Integer | num_turn | deprecated | + +---------+-------------+------------+------------------------------------+ + | 41-45 | Integer | num_site | Number of SITE records | + +---------+-------------+------------+------------------------------------+ + | 46-50 | Integer | num_xform | Number of coordinate transform | + | | | | records (ORIGX+SCALE+MTRIX) | + +---------+-------------+------------+------------------------------------+ + | 51-55 | Integer | num_coord | Number of atomic coordinate | + | | | | records (ATOM+HETATM) | + +---------+-------------+------------+------------------------------------+ + | 56-60 | Integer | num_ter | Number of TER records | + +---------+-------------+------------+------------------------------------+ + | 61-65 | Integer | num_conect | Number of CONECT records | + +---------+-------------+------------+------------------------------------+ + | 66-70 | Integer | num_seq | Number of SEQRES records | + +---------+-------------+------------+------------------------------------+ """ def __init__(self): diff --git a/old_pdb/coordinates.py b/old_pdb/coordinates.py index a18c604..82a99a7 100644 --- a/old_pdb/coordinates.py +++ b/old_pdb/coordinates.py @@ -150,42 +150,42 @@ class Atom(BaseRecord): always present on each ATOM record; segment identifier and charge are optional. - +---------+--------------+------------+-----------------------------------+ - | COLUMNS | DATA TYPE | FIELD | DEFINITION | - +=========+==============+============+===================================+ - | 1-6 | Record name | "ATOM " | | - +---------+--------------+------------+-----------------------------------+ - | 7-11 | Integer | serial | Atom serial number. | - +---------+--------------+------------+-----------------------------------+ - | 13-16 | Atom | name | Atom name. | - +---------+--------------+------------+-----------------------------------+ - | 17 | Character | altLoc | Alternate location indicator. | - +---------+--------------+------------+-----------------------------------+ - | 18-20 | Residue name | resName | Residue name. | - +---------+--------------+------------+-----------------------------------+ - | 22 | Character | chainID | Chain identifier. | - +---------+--------------+------------+-----------------------------------+ - | 23-26 | Integer | resSeq | Residue sequence number. | - +---------+--------------+------------+-----------------------------------+ - | 27 | AChar | iCode | Code for insertion of residues. | - +---------+--------------+------------+-----------------------------------+ - | 31-38 | Real(8.3) | x | Orthogonal coordinates for X in | - | | | | Angstroms. | - +---------+--------------+------------+-----------------------------------+ - | 39-46 | Real(8.3) | y | Orthogonal coordinates for Y in | - | | | | Angstroms. | - +---------+--------------+------------+-----------------------------------+ - | 47-54 | Real(8.3) | z | Orthogonal coordinates for Z in | - | | | | Angstroms. | - +---------+--------------+------------+-----------------------------------+ - | 55-60 | Real(6.2) | occupancy | Occupancy. | - +---------+--------------+------------+-----------------------------------+ - | 61-66 | Real(6.2) | tempFactor | Temperature factor. | - +---------+--------------+------------+-----------------------------------+ - | 77-78 | LString(2) | element | Element symbol, right-justified. | - +---------+--------------+------------+-----------------------------------+ - | 79-80 | LString(2) | charge | Charge on the atom. | - +---------+--------------+------------+-----------------------------------+ + +---------+--------------+-------------+----------------------------------+ + | COLUMNS | DATA TYPE | FIELD | DEFINITION | + +=========+==============+=============+==================================+ + | 1-6 | Record name | "ATOM " | | + +---------+--------------+-------------+----------------------------------+ + | 7-11 | Integer | serial | Atom serial number. | + +---------+--------------+-------------+----------------------------------+ + | 13-16 | Atom | name | Atom name. | + +---------+--------------+-------------+----------------------------------+ + | 17 | Character | alt_loc | Alternate location indicator. | + +---------+--------------+-------------+----------------------------------+ + | 18-20 | Residue name | res_name | Residue name. | + +---------+--------------+-------------+----------------------------------+ + | 22 | Character | chain_id | Chain identifier. | + +---------+--------------+-------------+----------------------------------+ + | 23-26 | Integer | res_seq | Residue sequence number. | + +---------+--------------+-------------+----------------------------------+ + | 27 | AChar | ins_code | Code for insertion of residues. | + +---------+--------------+-------------+----------------------------------+ + | 31-38 | Real(8.3) | x | Orthogonal coordinates for X in | + | | | | Angstroms. | + +---------+--------------+-------------+----------------------------------+ + | 39-46 | Real(8.3) | y | Orthogonal coordinates for Y in | + | | | | Angstroms. | + +---------+--------------+-------------+----------------------------------+ + | 47-54 | Real(8.3) | z | Orthogonal coordinates for Z in | + | | | | Angstroms. | + +---------+--------------+-------------+----------------------------------+ + | 55-60 | Real(6.2) | occupancy | Occupancy. | + +---------+--------------+-------------+----------------------------------+ + | 61-66 | Real(6.2) | temp_factor | Temperature factor. | + +---------+--------------+-------------+----------------------------------+ + | 77-78 | LString(2) | element | Element symbol, right-justified. | + +---------+--------------+-------------+----------------------------------+ + | 79-80 | LString(2) | charge | Charge on the atom. | + +---------+--------------+-------------+----------------------------------+ """ def __init__(self): @@ -255,27 +255,27 @@ class TemperatureFactor(BaseRecord): +---------+--------------+----------+-------------------------------------+ | 13-16 | Atom | name | Atom name. | +---------+--------------+----------+-------------------------------------+ - | 17 | Character | altLoc | Alternate location indicator | + | 17 | Character | alt_loc | Alternate location indicator | +---------+--------------+----------+-------------------------------------+ - | 18-20 | Residue name | resName | Residue name. | + | 18-20 | Residue name | res_name | Residue name. | +---------+--------------+----------+-------------------------------------+ - | 22 | Character | chainID | Chain identifier. | + | 22 | Character | chain_id | Chain identifier. | +---------+--------------+----------+-------------------------------------+ - | 23-26 | Integer | resSeq | Residue sequence number. | + | 23-26 | Integer | res_seq | Residue sequence number. | +---------+--------------+----------+-------------------------------------+ - | 27 | AChar | iCode | Insertion code. | + | 27 | AChar | ins_code | Insertion code. | +---------+--------------+----------+-------------------------------------+ - | 29-35 | Integer | u[0][0] | U(1,1) | + | 29-35 | Integer | u00 | U(1,1) | +---------+--------------+----------+-------------------------------------+ - | 36-42 | Integer | u[1][1] | U(2,2) | + | 36-42 | Integer | u11 | U(2,2) | +---------+--------------+----------+-------------------------------------+ - | 43-49 | Integer | u[2][2] | U(3,3) | + | 43-49 | Integer | u22 | U(3,3) | +---------+--------------+----------+-------------------------------------+ - | 50-56 | Integer | u[0][1] | U(1,2) | + | 50-56 | Integer | u01 | U(1,2) | +---------+--------------+----------+-------------------------------------+ - | 57-63 | Integer | u[0][2] | U(1,3) | + | 57-63 | Integer | u02 | U(1,3) | +---------+--------------+----------+-------------------------------------+ - | 64-70 | Integer | u[1][2] | U(2,3) | + | 64-70 | Integer | u12 | U(2,3) | +---------+--------------+----------+-------------------------------------+ | 77-78 | LString(2) | element | Element symbol, right-justified. | +---------+--------------+----------+-------------------------------------+ @@ -348,13 +348,13 @@ class ChainTerminus(BaseRecord): +---------+--------------+----------+-------------------------------------+ | 7-11 | Integer | serial | Serial number. | +---------+--------------+----------+-------------------------------------+ - | 18-20 | Residue name | resName | Residue name. | + | 18-20 | Residue name | res_name | Residue name. | +---------+--------------+----------+-------------------------------------+ - | 22 | Character | chainID | Chain identifier. | + | 22 | Character | chain_id | Chain identifier. | +---------+--------------+----------+-------------------------------------+ - | 23-26 | Integer | resSeq | Residue sequence number. | + | 23-26 | Integer | res_seq | Residue sequence number. | +---------+--------------+----------+-------------------------------------+ - | 27 | AChar | iCode | Insertion code. | + | 27 | AChar | ins_code | Insertion code. | +---------+--------------+----------+-------------------------------------+ """ @@ -397,39 +397,39 @@ class HeterogenAtom(BaseRecord): within "non-standard" groups. These records are used for water molecules and atoms presented in HET groups. - +---------+--------------+------------+-----------------------------------+ - | COLUMNS | DATA TYPE | FIELD | DEFINITION | - +=========+==============+============+===================================+ - | 1-6 | Record name | "HETATM" | | - +---------+--------------+------------+-----------------------------------+ - | 7-11 | Integer | serial | Atom serial number. | - +---------+--------------+------------+-----------------------------------+ - | 13-16 | Atom | name | Atom name. | - +---------+--------------+------------+-----------------------------------+ - | 17 | Character | altLoc | Alternate location indicator. | - +---------+--------------+------------+-----------------------------------+ - | 18-20 | Residue name | resName | Residue name. | - +---------+--------------+------------+-----------------------------------+ - | 22 | Character | chainID | Chain identifier. | - +---------+--------------+------------+-----------------------------------+ - | 23-26 | Integer | resSeq | Residue sequence number. | - +---------+--------------+------------+-----------------------------------+ - | 27 | AChar | iCode | Code for insertion of residues. | - +---------+--------------+------------+-----------------------------------+ - | 31-38 | Real(8.3) | x | Orthogonal coordinates for X. | - +---------+--------------+------------+-----------------------------------+ - | 39-46 | Real(8.3) | y | Orthogonal coordinates for Y. | - +---------+--------------+------------+-----------------------------------+ - | 47-54 | Real(8.3) | z | Orthogonal coordinates for Z. | - +---------+--------------+------------+-----------------------------------+ - | 55-60 | Real(6.2) | occupancy | Occupancy. | - +---------+--------------+------------+-----------------------------------+ - | 61-66 | Real(6.2) | tempFactor | Temperature factor. | - +---------+--------------+------------+-----------------------------------+ - | 77-78 | LString(2) | element | Element symbol; right-justified. | - +---------+--------------+------------+-----------------------------------+ - | 79-80 | LString(2) | charge | Charge on the atom. | - +---------+--------------+------------+-----------------------------------+ + +---------+--------------+-------------+----------------------------------+ + | COLUMNS | DATA TYPE | FIELD | DEFINITION | + +=========+==============+=============+==================================+ + | 1-6 | Record name | "HETATM" | | + +---------+--------------+-------------+----------------------------------+ + | 7-11 | Integer | serial | Atom serial number. | + +---------+--------------+-------------+----------------------------------+ + | 13-16 | Atom | name | Atom name. | + +---------+--------------+-------------+----------------------------------+ + | 17 | Character | alt_loc | Alternate location indicator. | + +---------+--------------+-------------+----------------------------------+ + | 18-20 | Residue name | res_name | Residue name. | + +---------+--------------+-------------+----------------------------------+ + | 22 | Character | chain_id | Chain identifier. | + +---------+--------------+-------------+----------------------------------+ + | 23-26 | Integer | res_seq | Residue sequence number. | + +---------+--------------+-------------+----------------------------------+ + | 27 | AChar | ins_code | Code for insertion of residues. | + +---------+--------------+-------------+----------------------------------+ + | 31-38 | Real(8.3) | x | Orthogonal coordinates for X. | + +---------+--------------+-------------+----------------------------------+ + | 39-46 | Real(8.3) | y | Orthogonal coordinates for Y. | + +---------+--------------+-------------+----------------------------------+ + | 47-54 | Real(8.3) | z | Orthogonal coordinates for Z. | + +---------+--------------+-------------+----------------------------------+ + | 55-60 | Real(6.2) | occupancy | Occupancy. | + +---------+--------------+-------------+----------------------------------+ + | 61-66 | Real(6.2) | temp_factor | Temperature factor. | + +---------+--------------+-------------+----------------------------------+ + | 77-78 | LString(2) | element | Element symbol; right-justified. | + +---------+--------------+-------------+----------------------------------+ + | 79-80 | LString(2) | charge | Charge on the atom. | + +---------+--------------+-------------+----------------------------------+ """ def __init__(self): diff --git a/old_pdb/crystallography.py b/old_pdb/crystallography.py index 4a20ca7..875ccd7 100644 --- a/old_pdb/crystallography.py +++ b/old_pdb/crystallography.py @@ -24,13 +24,13 @@ class FractionalTransform(BaseRecord): +=========+=============+========================+========================+ | 1 - 6 | Record name | "SCALEn" n=1, 2, or 3 | | +---------+-------------+------------------------+------------------------+ - | 11 - 20 | Real(10.6) | s[n][1] | Sn1 | + | 11 - 20 | Real(10.6) | sn1 | Sn1 | +---------+-------------+------------------------+------------------------+ - | 21 - 30 | Real(10.6) | s[n][2] | Sn2 | + | 21 - 30 | Real(10.6) | sn2 | Sn2 | +---------+-------------+------------------------+------------------------+ - | 31 - 40 | Real(10.6) | s[n][3] | Sn3 | + | 31 - 40 | Real(10.6) | sn3 | Sn3 | +---------+-------------+------------------------+------------------------+ - | 46 - 55 | Real(10.5) | u[n] | Un | + | 46 - 55 | Real(10.5) | unif | Un | +---------+-------------+------------------------+------------------------+ """ @@ -76,13 +76,13 @@ class OriginalTransform(BaseRecord): +=========+=============+==========+======================================+ | 1-6 | Record name | "ORIGXn" | n=1, 2, or 3 | +---------+-------------+----------+--------------------------------------+ - | 11-20 | Real(10.6) | o[n][1] | On1 | + | 11-20 | Real(10.6) | on1 | On1 | +---------+-------------+----------+--------------------------------------+ - | 21-30 | Real(10.6) | o[n][2] | On2 | + | 21-30 | Real(10.6) | on2 | On2 | +---------+-------------+----------+--------------------------------------+ - | 31-40 | Real(10.6) | o[n][3] | On3 | + | 31-40 | Real(10.6) | on3 | On3 | +---------+-------------+----------+--------------------------------------+ - | 46-55 | Real(10.5) | t[n] | Tn | + | 46-55 | Real(10.5) | tn | Tn | +---------+-------------+----------+--------------------------------------+ """ @@ -129,15 +129,15 @@ class NoncrystalTransform(BaseRecord): +---------+-------------+----------+--------------------------------------+ | 8-10 | Integer | serial | Serial number. | +---------+-------------+----------+--------------------------------------+ - | 11-20 | Real(10.6) | m[n][1] | Mn1 | + | 11-20 | Real(10.6) | mn1 | Mn1 | +---------+-------------+----------+--------------------------------------+ - | 21-30 | Real(10.6) | m[n][2] | Mn2 | + | 21-30 | Real(10.6) | mn2 | Mn2 | +---------+-------------+----------+--------------------------------------+ - | 31-40 | Real(10.6) | m[n][3] | Mn3 | + | 31-40 | Real(10.6) | mn3 | Mn3 | +---------+-------------+----------+--------------------------------------+ - | 46-55 | Real(10.5) | v[n] | Vn | + | 46-55 | Real(10.5) | vn | Vn | +---------+-------------+----------+--------------------------------------+ - | 60 | Integer | iGiven | 1 if coordinates for the | + | 60 | Integer | i_given | 1 if coordinates for the | | | | | representations which are | | | | | approximately related by the | | | | | transformations of the molecule are | diff --git a/old_pdb/heterogen.py b/old_pdb/heterogen.py index d3894a6..0a98f47 100644 --- a/old_pdb/heterogen.py +++ b/old_pdb/heterogen.py @@ -29,24 +29,24 @@ class Heterogen(BaseRecord): Het records also describe heterogens for which the chemical identity is unknown, in which case the group is assigned the hetatm_id UNK. - +---------+-------------+-------------+-----------------------------------+ - | COLUMNS | DATA TYPE | FIELD | DEFINITION | - +=========+=============+=============+===================================+ - | 1-6 | Record name | "HET " | | - +---------+-------------+-------------+-----------------------------------+ - | 8-10 | LString(3) | hetID | Het identifier, right-justified. | - +---------+-------------+-------------+-----------------------------------+ - | 13 | Character | ChainID | Chain identifier. | - +---------+-------------+-------------+-----------------------------------+ - | 14-17 | Integer | seqNum | Sequence number. | - +---------+-------------+-------------+-----------------------------------+ - | 18 | AChar | iCode | Insertion code. | - +---------+-------------+-------------+-----------------------------------+ - | 21-25 | Integer | numHetAtoms | Number of HETATM records for the | - | | | | group present in the entry. | - +---------+-------------+-------------+-----------------------------------+ - | 31-70 | String | text | Text describing Het group. | - +---------+-------------+-------------+-----------------------------------+ + +---------+-------------+---------------+---------------------------------+ + | COLUMNS | DATA TYPE | FIELD | DEFINITION | + +=========+=============+===============+=================================+ + | 1-6 | Record name | "HET " | | + +---------+-------------+---------------+---------------------------------+ + | 8-10 | LString(3) | het_id | Identifier, right-justified. | + +---------+-------------+---------------+---------------------------------+ + | 13 | Character | chain_id | Chain identifier. | + +---------+-------------+---------------+---------------------------------+ + | 14-17 | Integer | seq_num | Sequence number. | + +---------+-------------+---------------+---------------------------------+ + | 18 | AChar | ins_code | Insertion code. | + +---------+-------------+---------------+---------------------------------+ + | 21-25 | Integer | num_het_atoms | Number of HETATM records for | + | | | | the group present in the entry. | + +---------+-------------+---------------+---------------------------------+ + | 31-70 | String | text | Text describing Het group. | + +---------+-------------+---------------+---------------------------------+ """ def __init__(self): @@ -92,7 +92,7 @@ class HeterogenName(BaseRecord): | 9-10 | Continuation | continuation | Allows concatenation of | | | | | multiple records. | +---------+--------------+--------------+---------------------------------+ - | 12-14 | LString(3) | hetID | Het identifier, right- | + | 12-14 | LString(3) | het_id | Het identifier, right- | | | | | justified. | +---------+--------------+--------------+---------------------------------+ | 16-70 | String | text | Chemical name. | @@ -145,10 +145,10 @@ class HeterogenSynonym(BaseRecord): | 9-10 | Continuation | continuation | Allows concatenation of | | | | | multiple records. | +----------+--------------+--------------+--------------------------------+ - | 12-14 | LString(3) | hetID | Het identifier, right- | + | 12-14 | LString(3) | het_id | Het identifier, right- | | | | | justified. | +----------+--------------+--------------+--------------------------------+ - | 16-70 | SList | hetSynonyms | List of synonyms. | + | 16-70 | SList | synonyms | List of synonyms. | +----------+--------------+--------------+--------------------------------+ """ @@ -201,7 +201,20 @@ class Formula(BaseRecord): def __init__(self): super().__init__() - self.components = OrderedDict() + self._components = OrderedDict() + + @property + def components(self) -> dict: + """Formulae for components. + + :returns: dictionary with component numbers as keys and values that + consist of tuples of the hetatom ID and the formula text. + """ + return self._components + + @components.setter + def components(self, value): + self._components = value def parse_line(self, line): """Parse PDB-format line. @@ -210,15 +223,15 @@ def parse_line(self, line): """ super().parse_line(line) component_num = int(line[8:10].strip()) - if component_num not in self.components: - self.components[component_num] = [] + if component_num not in self._components: + self._components[component_num] = [] hetatm_id = line[12:15].strip() text = line[18:70].rstrip() - self.components[component_num].append((hetatm_id, text)) + self._components[component_num].append((hetatm_id, text)) def __str__(self): strings = [] - for component_num, component_list in self.components.items(): + for component_num, component_list in self._components.items(): for hetatm_id, text in component_list: string = ( f"FORMUL {component_num:>2} {hetatm_id:>3} {text:52}" diff --git a/old_pdb/pdb_entry.py b/old_pdb/pdb_entry.py index 6610615..67c627b 100644 --- a/old_pdb/pdb_entry.py +++ b/old_pdb/pdb_entry.py @@ -6,6 +6,9 @@ .. codeauthor:: Nathan Baker """ +from old_pdb.primary import DatabaseReference +from old_pdb.secondary import Helix +from old_pdb.heterogen import HeterogenSynonym import logging from . import annotation, primary, heterogen, secondary, coordinates from . import crystallography, bookkeeping @@ -23,52 +26,415 @@ class Entry: def __init__(self): # Title section - self.header = None - self.obsolete = None - self.title = None - self.split = None - self.caveat = None - self.compound = None - self.source = None - self.keywords = None - self.experimental_data = None - self.num_models = None - self.model_type = None - self.author = None - self.revision_data = None - self.supersedes = None - self.journal = [] - self.remark = [] + self._header = None + self._obsolete = None + self._title = None + self._split = None + self._caveat = None + self._compound = None + self._source = None + self._keyword = None + self._experimental_data = None + self._num_model = None + self._model_type = None + self._author = None + self._revision_data = None + self._supersedes = None + self._journal = [] + self._remark = [] # Primary structure section - self.database_reference = [] - self.sequence_differences = [] - self.sequence_residues = None - self.modified_residues = [] + self._database_reference = [] + self._sequence_difference = [] + self._sequence_residue = None + self._modified_residue = [] # Heterogen section - self.heterogen = [] - self.heterogen_name = None - self.heterogen_synonyms = None - self.heterogen_formula = None + self._heterogen = [] + self._heterogen_name = None + self._heterogen_synonym = None + self._heterogen_formula = None # Secondary structure section - self.helix = [] - self.sheet = [] + self._helix = [] + self._sheet = [] # Connectivity annotation section - self.disulfide_bond = [] - self.link = [] - self.cis_peptide = [] + self._disulfide_bond = [] + self._link = [] + self._cis_peptide = [] # Miscellaneous section self.site = [] # Crystallographic and coordinate transformation section - self.unit_cell = None - self.orig_transform = [] - self.frac_transform = [] - self.noncrystal_transform = [] + self._unit_cell = None + self._orig_transform = [] + self._frac_transform = [] + self._noncrystal_transform = [] # Coordinate section - self.model = [] + self._model = [] # Connectivity section - self.connect = [] + self._connect = [] # Bookeeping section - self.master = None + self._master = None + + @property + def header(self) -> annotation.Header: + """:class:`.annotation.Header` HEADER record.""" + if self._header is None: + self._header = annotation.Header() + return self._header + + @header.setter + def header(self, value): + self._header = value + + @property + def obsolete(self) -> annotation.Obsolete: + """:class:`.annotation.Obsolete` OBSLTE record.""" + if self._obsolete is None: + self._obsolete = annotation.Obsolete() + return self._obsolete + + @obsolete.setter + def obsolete(self, value): + self._obsolete = value + + @property + def title(self) -> annotation.Title: + """:class:`.annotation.Title` TITLE record.""" + if self._title is None: + self._title = annotation.Title() + return self._title + + @title.setter + def title(self, value): + self._title = value + + @property + def split(self) -> annotation.Split: + """:class:`.annotation.Split` SPLIT record.""" + if self._split is None: + self._split = annotation.Split() + return self._split + + @split.setter + def split(self, value): + self._split = value + + @property + def caveat(self) -> annotation.Caveat: + """:class:`.annotation.Caveat` CAVEAT record.""" + if self._caveat is None: + self._caveat = annotation.Caveat() + return self._caveat + + @caveat.setter + def caveat(self, value): + self._caveat = value + + @property + def compound(self) -> annotation.Compound: + """:class:`.annotation.Compound` COMPND record.""" + if self._compound is None: + self._compound = annotation.Compound() + return self._compound + + @compound.setter + def compound(self, value): + self._compound = value + + @property + def source(self) -> annotation.Source: + """:class:`.annotation.Source` SOURCE record.""" + if self._source is None: + self._source = annotation.Source() + return self._source + + @source.setter + def source(self, value): + self._source = value + + @property + def keyword(self) -> annotation.Keywords: + """:class:`.annotation.Keywords` KEYWDS record.""" + if self._keyword is None: + self._keyword = annotation.Keywords() + return self._keyword + + @keyword.setter + def keyword(self, value): + self._keyword = value + + @property + def experimental_data(self) -> annotation.ExperimentalData: + """:class:`.annotation.ExperimentalData` EXPDTA record.""" + if self._experimental_data is None: + self._experimental_data = annotation.ExperimentalData() + return self._experimental_data + + @experimental_data.setter + def experimental_data(self, value): + self._experimental_data = value + + @property + def num_model(self) -> annotation.NumModels: + """:class:`.annotation.NumModels` NUMMDL record.""" + if self._num_model is None: + _LOGGER.error("Creating new NumModel") + self._num_model = annotation.NumModels() + return self._num_model + + @num_model.setter + def num_model(self, value): + self._num_model = value + + @property + def model_type(self) -> annotation.ModelType: + """:class:`.annotation.ModelType` MDLTYP record.""" + if self._model_type is None: + self._model_type = annotation.ModelType() + return self._model_type + + @model_type.setter + def model_type(self, value): + self._model_type = value + + @property + def author(self) -> annotation.Author: + """:class:`.annotation.Author` AUTHOR record.""" + if self._author is None: + self._author = annotation.Author() + return self._author + + @author.setter + def setter(self, value): + self._setter = value + + @property + def revision_data(self) -> annotation.RevisionData: + """:class:`.annotation.RevisionData` REVDAT record.""" + if self._revision_data is None: + self._revision_data = annotation.RevisionData() + return self._revision_data + + @revision_data.setter + def revision_data(self, value): + self._revision_data = value + + @property + def supersedes(self) -> annotation.Supersedes: + """:class:`.annotation.Supersedes` SPRSDE record.""" + if self._supersedes is None: + self._supersedes = annotation.Supersedes() + return self._supersedes + + @supersedes.setter + def supersedes(self, value): + self._supersedes = value + + @property + def journal(self) -> annotation.Journal: + """:class:`.annotation.Journal` JRNL record.""" + if self._journal is None: + self._journal = annotation.Journal() + return self._journal + + @journal.setter + def journal(self, value): + self._journal = value + + @property + def remark(self) -> list: + """List of :class:`annotation.Remark` REMARK records.""" + return self._remark + + @remark.setter + def remark(self, value): + self._remark = value + + @property + def database_reference(self) -> list: + """List of :class:`primary.DatabaseReference` DBREF records.""" + return self._database_reference + + @database_reference.setter + def database_reference(self, value): + self._database_reference = value + + @property + def sequence_difference(self) -> list: + """List of :class:`primary.SequenceDifferences` SEQADV records.""" + return self._sequence_difference + + @sequence_difference.setter + def sequence_difference(self, value): + self._sequence_difference = value + + @property + def sequence_residue(self) -> list: + """List of :class:`.primary.SequenceResidues` SEQRES records.""" + return self._sequence_residue + + @sequence_residue.setter + def sequence_residue(self, value): + self._sequence_residue = value + + @property + def modified_residue(self) -> list: + """List of :class:`.primary.ModifiedResidue` MODRES records.""" + return self._modified_residue + + @modified_residue.setter + def modified_residue(self, value): + self._modified_residue = value + + @property + def heterogen(self) -> list: + """List of :class:`.heterogen.Heterogen` HET records.""" + return self._heterogen + + @heterogen.setter + def heterogen(self, value): + self._heterogen = value + + @property + def heterogen_name(self) -> list: + """List of :class:`.heterogen.HeterogenName` HETNAM records.""" + if self._heterogen_name is None: + self._heterogen_name = heterogen.HeterogenName() + return self._heterogen_name + + @heterogen_name.setter + def heterogen_name(self, value): + self._heterogen_name = value + + @property + def heterogen_synonym(self): + """:class:`.heterogen.HeterogenSynonym` HETSYN record.""" + if self._heterogen_synonym is None: + self._heterogen_synonym = heterogen.HeterogenSynonym() + return self._heterogen_synonym + + @heterogen_synonym.setter + def heterogen_synonym(self, value): + self._heterogen_synonym = value + + @property + def heterogen_formula(self): + """:class:`heterogen.Formula` FORMUL record.""" + if self._heterogen_formula is None: + self._heterogen_formula = heterogen.Formula() + + @heterogen_formula.setter + def heterogen_formula(self, value): + self._heterogen_formula = value + + @property + def helix(self) -> list: + """List of :class:`.secondary.Helix` HELIX records.""" + return self._helix + + @helix.setter + def helix(self, value): + self._helix = value + + @property + def sheet(self) -> list: + """List of :class:`.secondary.Sheet` SHEET records.""" + return self._sheet + + @sheet.setter + def sheet(self, value): + self._sheet = value + + @property + def disulfide_bond(self) -> list: + """List of :class:`.secondary.DisulfideBond` SSBOND records.""" + return self._disulfide_bond + + @disulfide_bond.setter + def disulfide_bond(self, value): + self._disulfide_bond = value + + @property + def link(self) -> list: + """List of :class:`.secondary.Link` LINK records.""" + return self._link + + @link.setter + def link(self, value): + self._link = value + + @property + def cis_peptide(self) -> list: + """List of :class:`.secondary.CisPeptide` CISPEP records.""" + return self._cis_peptide + + @cis_peptide.setter + def cis_peptide(self, value): + self._cis_peptide = value + + @property + def unit_cell(self) -> crystallography.UnitCell: + """:class:`.crystallography.UnitCell` CRYST1 record.""" + if self._unit_cell is None: + self._unit_cell = crystallography.UnitCell() + return self._unit_cell + + @unit_cell.setter + def unit_cell(self, value): + self._unit_cell = value + + @property + def original_transform(self) -> list: + """List of :class:`.crystallography.OriginalTransform` ORIGX + records.""" + return self._orig_transform + + @original_transform.setter + def original_transform(self, value): + self._orig_transform = value + + @property + def frac_transform(self) -> list: + """List of :class:`crystallography.FractionalTransform` SCALEn + records.""" + return self._frac_transform + + @frac_transform.setter + def frac_transform(self, value): + self._frac_transform = value + + @property + def noncrystal_transform(self) -> list: + """List of :class:`.crystallography.NoncrystalTransform` MTRIXn + records.""" + return self._noncrystal_transform + + @noncrystal_transform.setter + def noncrystal_transform(self, value): + self._noncrystal_transform = value + + @property + def model(self) -> list: + """List of :class:`.coordinates.Model` MODEL records.""" + return self._model + + @model.setter + def model(self, value): + self._model = value + + @property + def connect(self) -> list: + """List of :class:`.bookkeeping.Connection` CONECT records.""" + return self._connect + + @connect.setter + def connect(self, value): + self._connect = value + + @property + def master(self) -> bookkeeping.Master: + """:class:`.bookkeeping.Master` MASTER record.""" + if self._master is not None: + self._master = bookkeeping.Master() + return self._master def find_residue(self, chain_id, residue_id, model_num=1) -> list: """Find a specific residue. @@ -76,9 +442,9 @@ def find_residue(self, chain_id, residue_id, model_num=1) -> list: :param str chain_id: chain ID to find :param int residue_id: residue ID to find :param int model_num: model number to use - :returns: list of :class:`coordinates.Atom`-like objects + :returns: list of :class:`.coordinates.Atom`-like objects """ - model = self.model[model_num - 1] + model = self._model[model_num - 1] atoms = [] for atom in model.all_atoms: if (atom.chain_id == chain_id) and (atom.res_seq == residue_id): @@ -109,8 +475,8 @@ def find_atom_by_name( def annotate_link(self, record) -> secondary.Link: """Annotate LINK to indicate whether the named atoms are elements. - Creates two new Boolean attributes in record: is_element1 and - is_element2. + Creates two new Boolean attributes in record: ``is_element1`` and + ``is_element2``. :param secondary.Link record: record to annotate :returns: annotated record @@ -137,56 +503,56 @@ def __str__(self): # Title section for record in ( [ - self.header, - self.obsolete, - self.title, - self.split, - self.caveat, - self.compound, - self.source, - self.keywords, - self.experimental_data, - self.num_models, - self.model_type, + self._header, + self._obsolete, + self._title, + self._split, + self._caveat, + self._compound, + self._source, + self._keyword, + self._experimental_data, + self._num_model, + self._model_type, self.author, ] - + [self.revision_data] - + [self.supersedes] - + self.journal - + self.remark + + [self._revision_data] + + [self._supersedes] + + self._journal + + self._remark ): if record is not None: strings.append(str(record)) # Primary structure section for record in ( - self.database_reference - + self.sequence_differences - + [self.sequence_residues] - + self.modified_residues + self._database_reference + + self._sequence_difference + + [self._sequence_residue] + + self._modified_residue ): if record is not None: strings.append(str(record)) # Heterogen section - for record in self.heterogen + [ - self.heterogen_name, - self.heterogen_synonyms, - self.heterogen_formula, + for record in self._heterogen + [ + self._heterogen_name, + self._heterogen_synonym, + self._heterogen_formula, ]: if record is not None: strings.append(str(record)) # Secondary structure section - for record in self.helix + self.sheet: + for record in self._helix + self._sheet: if record is not None: strings.append(str(record)) # Connectivity annotation section - for record in self.disulfide_bond: + for record in self._disulfide_bond: if record is not None: strings.append(str(record)) - for record in self.link: + for record in self._link: record = self.annotate_link(record) if record is not None: strings.append(str(record)) - for record in self.cis_peptide: + for record in self._cis_peptide: if record is not None: strings.append(str(record)) # Miscellaneous section @@ -195,26 +561,26 @@ def __str__(self): strings.append(str(record)) # Crystallographic and coordinate transformation section for record in ( - [self.unit_cell] - + self.orig_transform - + self.frac_transform - + self.noncrystal_transform + [self._unit_cell] + + self._orig_transform + + self._frac_transform + + self._noncrystal_transform ): if record is not None: strings.append(str(record)) # Coordinate section - for record in self.model: + for record in self._model: if record is not None: strings.append(str(record)) - if len(self.model) > 1: + if len(self._model) > 1: strings.append("ENDMDL") # Connectivity section - for record in self.connect: + for record in self._connect: if record is not None: strings.append(str(record)) # Bookkeeping section - if self.master is not None: - strings.append(str(self.master)) + if self._master is not None: + strings.append(str(self._master)) strings.append("END ") return "\n".join(strings) @@ -237,183 +603,183 @@ def parse_line(self, line): """ name = line[0:6].strip() if name == "HEADER": - if self.header: - err = f"HEADER already exists:\n{self.header}" + if self._header: + err = f"HEADER already exists:\n{self._header}" raise ValueError(err) - self.header = annotation.Header() - self.header.parse_line(line) + self._header = annotation.Header() + self._header.parse_line(line) elif name == "OBSLTE": - if not self.obsolete: - self.obsolete = annotation.Obsolete() - self.obsolete.parse_line(line) + if not self._obsolete: + self._obsolete = annotation.Obsolete() + self._obsolete.parse_line(line) elif name == "TITLE": - if not self.title: - self.title = annotation.Title() - self.title.parse_line(line) + if not self._title: + self._title = annotation.Title() + self._title.parse_line(line) elif name == "SPLIT": - if not self.split: - self.split = annotation.Split() - self.split.parse_line(line) + if not self._split: + self._split = annotation.Split() + self._split.parse_line(line) elif name == "CAVEAT": - if not self.caveat: - self.caveat = annotation.Caveat() - self.caveat.parse_line(line) + if not self._caveat: + self._caveat = annotation.Caveat() + self._caveat.parse_line(line) elif name == "COMPND": - if not self.compound: - self.compound = annotation.Compound() - self.compound.parse_line(line) + if not self._compound: + self._compound = annotation.Compound() + self._compound.parse_line(line) elif name == "SOURCE": - if not self.source: - self.source = annotation.Source() - self.source.parse_line(line) + if not self._source: + self._source = annotation.Source() + self._source.parse_line(line) elif name == "KEYWDS": - if not self.keywords: - self.keywords = annotation.Keywords() - self.keywords.parse_line(line) + if not self._keyword: + self._keyword = annotation.Keywords() + self._keyword.parse_line(line) elif name == "EXPDTA": - if not self.experimental_data: - self.experimental_data = annotation.ExperimentalData() - self.experimental_data.parse_line(line) + if not self._experimental_data: + self._experimental_data = annotation.ExperimentalData() + self._experimental_data.parse_line(line) elif name == "NUMMDL": - if self.num_models is not None: - err = f"NUMMDL already exists:\n{self.num_models}" + if self._num_model is not None: + err = f"NUMMDL already exists:\n{self._num_model}" raise ValueError(err) - self.num_models = annotation.NumModels() - self.num_models.parse_line(line) + self._num_model = annotation.NumModels() + self._num_model.parse_line(line) elif name == "MDLTYP": - if not self.model_type: - self.model_type = annotation.ModelType() - self.model_type.parse_line(line) + if not self._model_type: + self._model_type = annotation.ModelType() + self._model_type.parse_line(line) elif name == "AUTHOR": if not self.author: self.author = annotation.Author() self.author.parse_line(line) elif name == "REVDAT": - if not self.revision_data: - self.revision_data = annotation.RevisionData() - self.revision_data.parse_line(line) + if not self._revision_data: + self._revision_data = annotation.RevisionData() + self._revision_data.parse_line(line) elif name == "SPRSDE": - if not self.supersedes: - self.supersedes = annotation.Supersedes() - self.supersedes.parse_line(line) + if not self._supersedes: + self._supersedes = annotation.Supersedes() + self._supersedes.parse_line(line) elif name == "JRNL": journal = annotation.Journal() journal.parse_line(line) - self.journal.append(journal) + self._journal.append(journal) elif name == "REMARK": remark = annotation.Remark() remark.parse_line(line) - self.remark.append(remark) + self._remark.append(remark) elif name == "DBREF": database = primary.DatabaseReference() database.parse_line(line) - self.database_reference.append(database) + self._database_reference.append(database) elif name == "DBREF1": database = primary.DatabaseReference1() database.parse_line(line) - self.database_reference.append(database) + self._database_reference.append(database) elif name == "DBREF2": database = primary.DatabaseReference2() database.parse_line(line) - self.database_reference.append(database) + self._database_reference.append(database) elif name == "SEQADV": seqadv = primary.SequenceDifferences() seqadv.parse_line(line) - self.sequence_differences.append(seqadv) + self._sequence_difference.append(seqadv) elif name == "SEQRES": - if not self.sequence_residues: - self.sequence_residues = primary.SequenceResidues() - self.sequence_residues.parse_line(line) + if not self._sequence_residue: + self._sequence_residue = primary.SequenceResidues() + self._sequence_residue.parse_line(line) elif name == "HET": het = heterogen.Heterogen() het.parse_line(line) - self.heterogen.append(het) + self._heterogen.append(het) elif name == "HETNAM": - if not self.heterogen_name: - self.heterogen_name = heterogen.HeterogenName() - self.heterogen_name.parse_line(line) + if not self._heterogen_name: + self._heterogen_name = heterogen.HeterogenName() + self._heterogen_name.parse_line(line) elif name == "HETSYN": - if not self.heterogen_synonyms: - self.heterogen_synonyms = heterogen.HeterogenSynonym() - self.heterogen_synonyms.parse_line(line) + if not self._heterogen_synonym: + self._heterogen_synonym = heterogen.HeterogenSynonym() + self._heterogen_synonym.parse_line(line) elif name == "FORMUL": - if not self.heterogen_formula: - self.heterogen_formula = heterogen.Formula() - self.heterogen_formula.parse_line(line) + if not self._heterogen_formula: + self._heterogen_formula = heterogen.Formula() + self._heterogen_formula.parse_line(line) elif name == "HELIX": helix = secondary.Helix() helix.parse_line(line) - self.helix.append(helix) + self._helix.append(helix) elif name == "SHEET": sheet = secondary.Sheet() sheet.parse_line(line) - self.sheet.append(sheet) + self._sheet.append(sheet) elif name == "SSBOND": bond = secondary.DisulfideBond() bond.parse_line(line) - self.disulfide_bond.append(bond) + self._disulfide_bond.append(bond) elif name == "LINK": link = secondary.Link() link.parse_line(line) - self.link.append(link) + self._link.append(link) elif name == "CISPEP": pep = secondary.CisPeptide() pep.parse_line(line) - self.cis_peptide.append(pep) + self._cis_peptide.append(pep) elif name == "SITE": site = annotation.Site() site.parse_line(line) self.site.append(site) elif name == "CRYST1": - if self.unit_cell is not None: - err = f"CRYST1 already exists:\n{self.unit_cell}" + if self._unit_cell is not None: + err = f"CRYST1 already exists:\n{self._unit_cell}" raise ValueError(err) - self.unit_cell = crystallography.UnitCell() - self.unit_cell.parse_line(line) + self._unit_cell = crystallography.UnitCell() + self._unit_cell.parse_line(line) elif name in ["ORIGX1", "ORIGX2", "ORIGX3"]: n = int(name[5]) orig = crystallography.OriginalTransform(n) orig.parse_line(line) - self.orig_transform.append(orig) - if len(self.orig_transform) > 3: - err = f"Too many ({len(self.orig_transform)}) transforms." + self._orig_transform.append(orig) + if len(self._orig_transform) > 3: + err = f"Too many ({len(self._orig_transform)}) transforms." raise ValueError(err) elif name in ["SCALE1", "SCALE2", "SCALE3"]: n = int(name[5]) scale = crystallography.FractionalTransform(n) scale.parse_line(line) - self.frac_transform.append(scale) - if len(self.frac_transform) > 3: - err = f"Too many ({len(self.frac_transform)}) transforms." + self._frac_transform.append(scale) + if len(self._frac_transform) > 3: + err = f"Too many ({len(self._frac_transform)}) transforms." raise ValueError(err) elif name in ["MTRIX1", "MTRIX2", "MTRIX3"]: n = int(name[5]) matrix = crystallography.NoncrystalTransform(n) matrix.parse_line(line) - self.noncrystal_transform.append(matrix) - if len(self.noncrystal_transform) > 3: + self._noncrystal_transform.append(matrix) + if len(self._noncrystal_transform) > 3: err = ( - f"Too many ({len(self.noncrystal_transform)}) transforms." + f"Too many ({len(self._noncrystal_transform)}) transforms." ) raise ValueError(err) elif name == "MODEL": model = coordinates.Model() model.parse_line(line) - self.model.append(model) + self._model.append(model) elif name in ["ATOM", "ANISOU", "TER", "HETATM"]: - if len(self.model) == 0: - self.model = [coordinates.Model()] - self.model[-1].parse_line(line) + if len(self._model) == 0: + self._model = [coordinates.Model()] + self._model[-1].parse_line(line) elif name == "CONECT": connect = bookkeeping.Connection() connect.parse_line(line) - self.connect.append(connect) + self._connect.append(connect) elif name == "MASTER": - if self.master: + if self._master: err = f"MASTER record already exists. Got: {line}." raise ValueError(err) - self.master = bookkeeping.Master() - self.master.parse_line(line) + self._master = bookkeeping.Master() + self._master.parse_line(line) elif name in ["ENDMDL", "END"]: pass else: @@ -426,9 +792,9 @@ def num_transforms(self) -> int: :returns: number of ORGIXn + SCALEn + MTRIXn """ return ( - len(self.orig_transform) - + len(self.frac_transform) - + len(self.noncrystal_transform) + len(self._orig_transform) + + len(self._frac_transform) + + len(self._noncrystal_transform) ) def num_atoms(self, heavy_only=True) -> int: @@ -436,23 +802,23 @@ def num_atoms(self, heavy_only=True) -> int: :param bool heavy_only: exclude hydrogen atoms from count """ - return self.model[0].num_atoms(heavy_only) + return self._model[0].num_atoms(heavy_only) def num_chains(self) -> int: """Number of chains in entry.""" - return self.model[0].num_chains() + return self._model[0].num_chains() def num_residues(self, count_hetatm=False) -> int: """Number of residues in entry. :param bool count_hetam: include heterogen residues in count """ - return self.model[0].num_residues(count_hetatm) + return self._model[0].num_residues(count_hetatm) def num_ter(self) -> int: """Number of TER records in entry.""" num = 0 - for model in self.model: + for model in self._model: num += model.num_ter() return num @@ -461,24 +827,24 @@ def check_master(self): :raises AssertionError: if checks fail """ - master = self.master + master = self._master for field, expected, test in [ ( "model", - self.num_models.model_number - if self.num_models is not None + self._num_model.model_number + if self._num_model is not None else 1, - len(self.model), + len(self._model), ), - ("REMARK", master.num_remark, len(self.remark)), - ("HETATM", master.num_het, len(self.heterogen)), - ("HELIX", master.num_helix, len(self.helix)), - ("SHEET", master.num_sheet, len(self.sheet)), + ("REMARK", master.num_remark, len(self._remark)), + ("HETATM", master.num_het, len(self._heterogen)), + ("HELIX", master.num_helix, len(self._helix)), + ("SHEET", master.num_sheet, len(self._sheet)), ("SITE", master.num_site, len(self.site)), ("transform", master.num_xform, self.num_transforms()), ("coordinate", master.num_coord, self.num_atoms()), ("TER", master.num_ter, self.num_ter()), - ("CONECT", master.num_conect, len(self.connect)), + ("CONECT", master.num_conect, len(self._connect)), ]: test_str = ( f"MASTER indicates {expected} {field} records; found {test}." diff --git a/old_pdb/primary.py b/old_pdb/primary.py index df79041..f86e5a0 100644 --- a/old_pdb/primary.py +++ b/old_pdb/primary.py @@ -4,7 +4,6 @@ .. codeauthor:: Yong Huang .. codeauthor:: Nathan Baker """ -from itertools import chain import logging from collections import OrderedDict from .general import BaseRecord, grouper @@ -19,48 +18,49 @@ class DatabaseReference(BaseRecord): The DBREF record provides cross-reference links between PDB sequences (what appears in SEQRES record) and a corresponding database sequence. - +---------+-------------+-------------+-----------------------------------+ - | COLUMNS | DATA TYPE | FIELD | DEFINITION | - +=========+=============+=============+===================================+ - | 1-6 | Record name | "DBREF " | | - +---------+-------------+-------------+-----------------------------------+ - | 8-11 | IDcode | idCode | ID code of this entry. | - +---------+-------------+-------------+-----------------------------------+ - | 13 | Character | chainID | Chain identifier. | - +---------+-------------+-------------+-----------------------------------+ - | 15-18 | Integer | seqBegin | Initial sequence number of the | - | | | | PDB sequence segment. | - +---------+-------------+-------------+-----------------------------------+ - | 19 | AChar | insertBegin | Initial insertion code of the | - | | | | PDB sequence segment. | - +---------+-------------+-------------+-----------------------------------+ - | 21-24 | Integer | seqEnd | Ending sequence number of the PDB | - | | | | sequence segment. | - +---------+-------------+-------------+-----------------------------------+ - | 25 | AChar | insertEnd | Ending insertion code of the PDB | - | | | | sequence segment. | - +---------+-------------+-------------+-----------------------------------+ - | 27-32 | LString | database | Sequence database name. | - +---------+-------------+-------------+-----------------------------------+ - | 34-41 | LString | dbAccession | Sequence database accession code. | - +---------+-------------+-------------+-----------------------------------+ - | 43-54 | LString | dbIdCode | Sequence database identification | - | | | | code. | - +---------+-------------+-------------+-----------------------------------+ - | 56-60 | Integer | dbseqBegin | Initial sequence number of the | - | | | | database seqment. | - +---------+-------------+-------------+-----------------------------------+ - | 61 | AChar | idbnsBeg | Insertion code of initial residue | - | | | | the segment, if PDB is the | - | | | | reference. | - +---------+-------------+-------------+-----------------------------------+ - | 63-67 | Integer | dbseqEnd | Ending sequence number of the | - | | | | segment. | - +---------+-------------+-------------+-----------------------------------+ - | 68 | AChar | dbinsEnd | Insertion code of the ending of | - | | | | the segment, if PDB is the | - | | | | reference. | - +---------+-------------+-------------+-----------------------------------+ + +---------+-------------+--------------------+-----------------------------+ + | COLUMNS | DATA TYPE | FIELD | DEFINITION | + +=========+=============+====================+=============================+ + | 1-6 | Record name | "DBREF " | | + +---------+-------------+--------------------+-----------------------------+ + | 8-11 | IDcode | id_code | ID code of this entry. | + +---------+-------------+--------------------+-----------------------------+ + | 13 | Character | chain_id | Chain identifier. | + +---------+-------------+--------------------+-----------------------------+ + | 15-18 | Integer | seq_begin | Initial sequence number of | + | | | | PDB sequence segment. | + +---------+-------------+--------------------+-----------------------------+ + | 19 | AChar | ins_begin | Initial insertion code of | + | | | | PDB sequence segment. | + +---------+-------------+--------------------+-----------------------------+ + | 21-24 | Integer | seq_end | Ending sequence number of | + | | | | PDB sequence segment. | + +---------+-------------+--------------------+-----------------------------+ + | 25 | AChar | ins_end | Ending insertion code of | + | | | | PDB sequence segment. | + +---------+-------------+--------------------+-----------------------------+ + | 27-32 | LString | database | Sequence database name. | + +---------+-------------+--------------------+-----------------------------+ + | 34-41 | LString | database_accession | Sequence database accession | + | | | | code. | + +---------+-------------+--------------------+-----------------------------+ + | 43-54 | LString | database_id_code | Sequence database id | + | | | | code. | + +---------+-------------+--------------------+-----------------------------+ + | 56-60 | Integer | database_seq_begin | Initial sequence number of | + | | | | database seqment. | + +---------+-------------+--------------------+-----------------------------+ + | 61 | AChar | database_ins_begin | Insertion code of initial | + | | | | residue segment, if PDB is | + | | | | reference. | + +---------+-------------+--------------------+-----------------------------+ + | 63-67 | Integer | database_seq_end | Ending sequence number of | + | | | | segment. | + +---------+-------------+--------------------+-----------------------------+ + | 68 | AChar | database_ins_end | Insertion code of the | + | | | | the segment end, if PDB is | + | | | | reference. | + +---------+-------------+--------------------+-----------------------------+ """ def __init__(self): @@ -124,27 +124,27 @@ class DatabaseReference1(BaseRecord): +=========+=============+=============+===================================+ | 1-6 | Record name | "DBREF1" | | +---------+-------------+-------------+-----------------------------------+ - | 8-11 | IDcode | idCode | ID code of this entry. | + | 8-11 | IDcode | id_code | ID code of this entry. | +---------+-------------+-------------+-----------------------------------+ - | 13 | Character | chainID | Chain identifier. | + | 13 | Character | chain_id | Chain identifier. | +---------+-------------+-------------+-----------------------------------+ - | 15-18 | Integer | seqBegin | Initial sequence number of the | + | 15-18 | Integer | seq_begin | Initial sequence number of the | | | | | PDB sequence segment, right | | | | | justified. | +---------+-------------+-------------+-----------------------------------+ - | 19 | AChar | insertBegin | Initial insertion code of the PDB | + | 19 | AChar | ins_begin | Initial insertion code of the PDB | | | | | sequence segment. | +---------+-------------+-------------+-----------------------------------+ - | 21-24 | Integer | seqEnd | Ending sequence number of the PDB | + | 21-24 | Integer | seq_end | Ending sequence number of the PDB | | | | | sequence segment, right | | | | | justified. | +---------+-------------+-------------+-----------------------------------+ - | 25 | AChar | insertEnd | Ending insertion code of the PDB | + | 25 | AChar | ins_end | Ending insertion code of the PDB | | | | | sequence segment. | +---------+-------------+-------------+-----------------------------------+ | 27-32 | LString | database | Sequence database name. | +---------+-------------+-------------+-----------------------------------+ - | 48-67 | LString | dbIdCode | Sequence database identification | + | 48-67 | LString | db_id_code | Sequence database identification | | | | | code, left justified. | +---------+-------------+-------------+-----------------------------------+ """ @@ -158,7 +158,7 @@ def __init__(self): self.seq_end = None self.ins_end = None self.database = None - self.db_ins_code = None + self.db_id_code = None def parse_line(self, line): """Parse PDB-format line. @@ -173,13 +173,13 @@ def parse_line(self, line): self.seq_end = int(line[20:24]) self.ins_end = line[24].strip() self.database = line[26:32].strip() - self.db_ins_code = line[47:67].strip() + self.db_id_code = line[47:67].strip() def __str__(self): return ( f"DBREF1 {self.id_code:4} {self.chain_id:1} {self.seq_begin:4}" f"{self.ins_begin:1} {self.seq_end:4}{self.ins_end:1}" - f" {self.database:6} {self.db_ins_code:20}" + f" {self.database:6} {self.db_id_code:20}" ) @@ -192,26 +192,26 @@ class DatabaseReference2(BaseRecord): This includes some GenBank sequence numbering (greater than 5 characters) and UNIMES accession numbers (greater than 12 characters). - +---------+-------------+-------------+-----------------------------------+ - | COLUMNS | DATA TYPE | FIELD | DEFINITION | - +=========+=============+=============+===================================+ - | 1-6 | Record name | "DBREF2" | | - +---------+-------------+-------------+-----------------------------------+ - | 8-11 | IDcode | idCode | ID code of this entry. | - +---------+-------------+-------------+-----------------------------------+ - | 13 | Character | chainID | Chain identifier. | - +---------+-------------+-------------+-----------------------------------+ - | 19-40 | LString | dbAccession | Sequence database accession code, | - | | | | left justified. | - +---------+-------------+-------------+-----------------------------------+ - | 46-55 | Integer | seqBegin | Initial sequence number of the | - | | | | Database segment, right | - | | | | justified. | - +---------+-------------+-------------+-----------------------------------+ - | 58-67 | Integer | seqEnd | Ending sequence number of the | - | | | | Database segment, right | - | | | | justified. | - +---------+-------------+-------------+-----------------------------------+ + +---------+-------------+--------------+----------------------------------+ + | COLUMNS | DATA TYPE | FIELD | DEFINITION | + +=========+=============+==============+==================================+ + | 1-6 | Record name | "DBREF2" | | + +---------+-------------+--------------+----------------------------------+ + | 8-11 | IDcode | id_code | ID code of this entry. | + +---------+-------------+--------------+----------------------------------+ + | 13 | Character | chain_id | Chain identifier. | + +---------+-------------+--------------+----------------------------------+ + | 19-40 | LString | db_accession | Sequence database accession code | + | | | | left justified. | + +---------+-------------+--------------+----------------------------------+ + | 46-55 | Integer | seq_begin | Initial sequence number of the | + | | | | Database segment, right | + | | | | justified. | + +---------+-------------+--------------+----------------------------------+ + | 58-67 | Integer | seq_end | Ending sequence number of the | + | | | | Database segment, right | + | | | | justified. | + +---------+-------------+--------------+----------------------------------+ """ def __init__(self): @@ -250,26 +250,26 @@ class ModifiedResidue(BaseRecord): Included are a mapping between residue names given in a PDB entry and standard residues. - +---------+--------------+----------+-------------------------------------+ - | COLUMNS | DATA TYPE | FIELD | DEFINITION | - +=========+==============+==========+=====================================+ - | 1-6 | Record name | "MODRES" | | - +---------+--------------+----------+-------------------------------------+ - | 8-11 | IDcode | idCode | ID code of this entry. | - +---------+--------------+----------+-------------------------------------+ - | 13-15 | Residue name | resName | Residue name used in this entry. | - +---------+--------------+----------+-------------------------------------+ - | 17 | Character | chainID | Chain identifier. | - +---------+--------------+----------+-------------------------------------+ - | 19-22 | Integer | seqNum | Sequence number. | - +---------+--------------+----------+-------------------------------------+ - | 23 | AChar | iCode | Insertion code. | - +---------+--------------+----------+-------------------------------------+ - | 25-27 | Residue name | stdRes | Standard residue name. | - +---------+--------------+----------+-------------------------------------+ - | 30-70 | String | comment | Description of the residue | - | | | | modification. | - +---------+--------------+----------+-------------------------------------+ + +---------+--------------+--------------+---------------------------------+ + | COLUMNS | DATA TYPE | FIELD | DEFINITION | + +=========+==============+==============+=================================+ + | 1-6 | Record name | "MODRES" | | + +---------+--------------+--------------+---------------------------------+ + | 8-11 | IDcode | id_code | ID code of this entry. | + +---------+--------------+--------------+---------------------------------+ + | 13-15 | Residue name | res_name | Residue name used in this entry | + +---------+--------------+--------------+---------------------------------+ + | 17 | Character | chain_id | Chain identifier. | + +---------+--------------+--------------+---------------------------------+ + | 19-22 | Integer | seq_num | Sequence number. | + +---------+--------------+--------------+---------------------------------+ + | 23 | AChar | ins_code | Insertion code. | + +---------+--------------+--------------+---------------------------------+ + | 25-27 | Residue name | standard_res | Standard residue name. | + +---------+--------------+--------------+---------------------------------+ + | 30-70 | String | comment | Description of the residue | + | | | | modification. | + +---------+--------------+--------------+---------------------------------+ """ def __init__(self): @@ -320,25 +320,25 @@ class SequenceDifferences(BaseRecord): +=========+==============+=============+==================================+ | 1-6 | Record name | "SEQADV" | | +---------+--------------+-------------+----------------------------------+ - | 8-11 | IDcode | idCode | ID code of this entry. | + | 8-11 | IDcode | id_code | ID code of this entry. | +---------+--------------+-------------+----------------------------------+ - | 13-15 | Residue name | resName | Name of the PDB residue in | + | 13-15 | Residue name | res_name | Name of the PDB residue in | | | | | conflict. | +---------+--------------+-------------+----------------------------------+ - | 17 | Character | chainID | PDB chain identifier. | + | 17 | Character | chain_id | PDB chain identifier. | +---------+--------------+-------------+----------------------------------+ - | 19-22 | Integer | seqNum | PDB sequence number. | + | 19-22 | Integer | seq_num | PDB sequence number. | +---------+--------------+-------------+----------------------------------+ - | 23 | AChar | iCode | PDB insertion code. | + | 23 | AChar | ins_code | PDB insertion code. | +---------+--------------+-------------+----------------------------------+ | 25-28 | LString | database | | +---------+--------------+-------------+----------------------------------+ - | 30-38 | LString | dbAccession | Sequence database accession | + | 30-38 | LString | db_id_code | Sequence database accession | | | | | number. | +---------+--------------+-------------+----------------------------------+ - | 40-42 | Residue name | dbRes | Sequence database residue name. | + | 40-42 | Residue name | db_res | Sequence database residue name. | +---------+--------------+-------------+----------------------------------+ - | 44-48 | Integer | dbSeq | Sequence database sequence | + | 44-48 | Integer | db_seq | Sequence database sequence | | | | | number. | +---------+--------------+-------------+----------------------------------+ | 50-70 | LString | conflict | Conflict comment. | @@ -445,9 +445,22 @@ class SequenceResidues(BaseRecord): def __init__(self): super().__init__() - self.residues = OrderedDict() + self._residues = OrderedDict() self.num_residues = {} + @property + def residues(self) -> dict: + """Dictionary of residues indexed by chain id. + + :returns: dictionary with chain IDs as keys and lists of residue names + as values. + """ + return self._residues + + @residues.setter + def residues(self, value): + self._residues = value + def parse_line(self, line): """Parse PDB-format line. @@ -455,13 +468,13 @@ def parse_line(self, line): """ super().parse_line(line) chain_id = line[11].strip() - if chain_id not in self.residues: - self.residues[chain_id] = [] - self.num_residues [chain_id]= int(line[13:17]) + if chain_id not in self._residues: + self._residues[chain_id] = [] + self.num_residues[chain_id] = int(line[13:17]) start = 19 end = 22 while True: - self.residues[chain_id].append(line[start:end].strip()) + self._residues[chain_id].append(line[start:end].strip()) start += 4 end += 4 if start > 68: @@ -469,11 +482,11 @@ def parse_line(self, line): def num_chains(self) -> int: """Number of chains in sequence.""" - return len(self.residues) + return len(self._residues) def __str__(self): strings = [] - for chain_id, residues in self.residues.items(): + for chain_id, residues in self._residues.items(): for ichunk, chunk in enumerate(grouper(residues, 13)): serial_num = ichunk + 1 string = f"SEQRES {serial_num:>3} {chain_id:1} " diff --git a/old_pdb/secondary.py b/old_pdb/secondary.py index 6105b9a..1ed1587 100644 --- a/old_pdb/secondary.py +++ b/old_pdb/secondary.py @@ -18,33 +18,33 @@ class CisPeptide(BaseRecord): the cis conformation. This record replaces the use of footnote records to list cis peptides. - +---------+-------------+----------+--------------------------------------+ - | COLUMNS | DATA TYPE | FIELD | DEFINITION | - +=========+=============+==========+======================================+ - | 1-6 | Record name | "CISPEP" | | - +---------+-------------+----------+--------------------------------------+ - | 8-10 | Integer | serNum | Record serial number. | - +---------+-------------+----------+--------------------------------------+ - | 12-14 | LString(3) | pep1 | Residue name. | - +---------+-------------+----------+--------------------------------------+ - | 16 | Character | chainID1 | Chain identifier. | - +---------+-------------+----------+--------------------------------------+ - | 18-21 | Integer | seqNum1 | Residue sequence number. | - +---------+-------------+----------+--------------------------------------+ - | 22 | AChar | icode1 | Insertion code. | - +---------+-------------+----------+--------------------------------------+ - | 26-28 | LString(3) | pep2 | Residue name. | - +---------+-------------+----------+--------------------------------------+ - | 30 | Character | chainID2 | Chain identifier. | - +---------+-------------+----------+--------------------------------------+ - | 32-35 | Integer | seqNum2 | Residue sequence number. | - +---------+-------------+----------+--------------------------------------+ - | 36 | AChar | icode2 | Insertion code. | - +---------+-------------+----------+--------------------------------------+ - | 44-46 | Integer | modNum | Identifies the specific model. | - +---------+-------------+----------+--------------------------------------+ - | 54-59 | Real(6.2) | measure | Angle measurement in degrees. | - +---------+-------------+----------+--------------------------------------+ + +---------+-------------+-----------+-------------------------------------+ + | COLUMNS | DATA TYPE | FIELD | DEFINITION | + +=========+=============+===========+=====================================+ + | 1-6 | Record name | "CISPEP" | | + +---------+-------------+-----------+-------------------------------------+ + | 8-10 | Integer | ser_num | Record serial number. | + +---------+-------------+-----------+-------------------------------------+ + | 12-14 | LString(3) | pep1 | Residue name. | + +---------+-------------+-----------+-------------------------------------+ + | 16 | Character | chain_id1 | Chain identifier. | + +---------+-------------+-----------+-------------------------------------+ + | 18-21 | Integer | seq_num1 | Residue sequence number. | + +---------+-------------+-----------+-------------------------------------+ + | 22 | AChar | icode1 | Insertion code. | + +---------+-------------+-----------+-------------------------------------+ + | 26-28 | LString(3) | pep2 | Residue name. | + +---------+-------------+-----------+-------------------------------------+ + | 30 | Character | chain_id2 | Chain identifier. | + +---------+-------------+-----------+-------------------------------------+ + | 32-35 | Integer | seq_num2 | Residue sequence number. | + +---------+-------------+-----------+-------------------------------------+ + | 36 | AChar | icode2 | Insertion code. | + +---------+-------------+-----------+-------------------------------------+ + | 44-46 | Integer | mod_num | Identifies the specific model. | + +---------+-------------+-----------+-------------------------------------+ + | 54-59 | Real(6.2) | measure | Angle measurement in degrees. | + +---------+-------------+-----------+-------------------------------------+ """ def __init__(self): @@ -95,35 +95,35 @@ class DisulfideBond(BaseRecord): polypeptide structures by identifying the two residues involved in the bond. - +---------+-------------+----------+--------------------------------------+ - | COLUMNS | DATA TYPE | FIELD | DEFINITION | - +=========+=============+==========+======================================+ - | 1-6 | Record name | "SSBOND" | | - +---------+-------------+----------+--------------------------------------+ - | 8-10 | Integer | serNum | Serial number. | - +---------+-------------+----------+--------------------------------------+ - | 12-14 | LString(3) | "CYS" | Residue name. | - +---------+-------------+----------+--------------------------------------+ - | 16 | Character | chainID1 | Chain identifier. | - +---------+-------------+----------+--------------------------------------+ - | 18-21 | Integer | seqNum1 | Residue sequence number. | - +---------+-------------+----------+--------------------------------------+ - | 22 | AChar | icode1 | Insertion code. | - +---------+-------------+----------+--------------------------------------+ - | 26-28 | LString(3) | "CYS" | Residue name. | - +---------+-------------+----------+--------------------------------------+ - | 30 | Character | chainID2 | Chain identifier. | - +---------+-------------+----------+--------------------------------------+ - | 32-35 | Integer | seqNum2 | Residue sequence number. | - +---------+-------------+----------+--------------------------------------+ - | 36 | AChar | icode2 | Insertion code. | - +---------+-------------+----------+--------------------------------------+ - | 60-65 | SymOP | sym1 | Symmetry operator for residue 1. | - +---------+-------------+----------+--------------------------------------+ - | 67-72 | SymOP | sym2 | Symmetry operator for residue 2. | - +---------+-------------+----------+--------------------------------------+ - | 74-78 | Real(5.2) | Length | Disulfide bond distance | - +---------+-------------+----------+--------------------------------------+ + +---------+-------------+-----------+-------------------------------------+ + | COLUMNS | DATA TYPE | FIELD | DEFINITION | + +=========+=============+===========+=====================================+ + | 1-6 | Record name | "SSBOND" | | + +---------+-------------+-----------+-------------------------------------+ + | 8-10 | Integer | ser_num | Serial number. | + +---------+-------------+-----------+-------------------------------------+ + | 12-14 | LString(3) | "CYS" | Residue name. | + +---------+-------------+-----------+-------------------------------------+ + | 16 | Character | chain_id1 | Chain identifier. | + +---------+-------------+-----------+-------------------------------------+ + | 18-21 | Integer | seq_num1 | Residue sequence number. | + +---------+-------------+-----------+-------------------------------------+ + | 22 | AChar | icode1 | Insertion code. | + +---------+-------------+-----------+-------------------------------------+ + | 26-28 | LString(3) | "CYS" | Residue name. | + +---------+-------------+-----------+-------------------------------------+ + | 30 | Character | chain_id2 | Chain identifier. | + +---------+-------------+-----------+-------------------------------------+ + | 32-35 | Integer | seq_num2 | Residue sequence number. | + +---------+-------------+-----------+-------------------------------------+ + | 36 | AChar | icode2 | Insertion code. | + +---------+-------------+-----------+-------------------------------------+ + | 60-65 | SymOP | sym1 | Symmetry operator for residue 1. | + +---------+-------------+-----------+-------------------------------------+ + | 67-72 | SymOP | sym2 | Symmetry operator for residue 2. | + +---------+-------------+-----------+-------------------------------------+ + | 74-78 | Real(5.2) | length | Disulfide bond distance | + +---------+-------------+-----------+-------------------------------------+ """ def __init__(self): @@ -172,49 +172,49 @@ class Helix(BaseRecord): molecule. Helices are both named and numbered. The residues where the helix begins and ends are noted, as well as the total length. - +---------+--------------+-------------+----------------------------------+ - | COLUMNS | DATA TYPE | FIELD | DEFINITION | - +=========+==============+=============+==================================+ - | 1-6 | Record name | "HELIX " | | - +---------+--------------+-------------+----------------------------------+ - | 8-10 | Integer | serNum | Serial number of the helix. This | - | | | | starts at 1 and increases | - | | | | incrementally. | - +---------+--------------+-------------+----------------------------------+ - | 12-14 | LString(3) | helixID | Helix identifier. In addition to | - | | | | a serial number, each helix is | - | | | | given an alphanumeric character | - | | | | helix identifier. | - +---------+--------------+-------------+----------------------------------+ - | 16-18 | Residue name | initResName | Name of the initial residue. | - +---------+--------------+-------------+----------------------------------+ - | 20 | Character | initChainID | Chain identifier for the chain | - | | | | containing this helix. | - +---------+--------------+-------------+----------------------------------+ - | 22-25 | Integer | initSeqNum | Sequence number of the initial | - | | | | residue. | - +---------+--------------+-------------+----------------------------------+ - | 26 | AChar | initICode | Insertion code of the initial | - | | | | residue. | - +---------+--------------+-------------+----------------------------------+ - | 28-30 | Residue name | endResName | Name of the terminal residue of | - | | | | the helix. | - +---------+--------------+-------------+----------------------------------+ - | 32 | Character | endChainID | Chain identifier for the chain | - | | | | containing this helix. | - +---------+--------------+-------------+----------------------------------+ - | 34-37 | Integer | endSeqNum | Sequence number of the terminal | - | | | | residue. | - +---------+--------------+-------------+----------------------------------+ - | 38 | AChar | endICode | Insertion code of the terminal | - | | | | residue. | - +---------+--------------+-------------+----------------------------------+ - | 39-40 | Integer | helixClass | Helix class (see below). | - +---------+--------------+-------------+----------------------------------+ - | 41-70 | String | comment | Comment about this helix. | - +---------+--------------+-------------+----------------------------------+ - | 72-76 | Integer | length | Length of this helix. | - +---------+--------------+-------------+----------------------------------+ + +---------+--------------+---------------+--------------------------------+ + | COLUMNS | DATA TYPE | FIELD | DEFINITION | + +=========+==============+===============+================================+ + | 1-6 | Record name | "HELIX " | | + +---------+--------------+---------------+--------------------------------+ + | 8-10 | Integer | serNum | Serial number of the helix. | + | | | | starts at 1 and increases | + | | | | incrementally. | + +---------+--------------+---------------+--------------------------------+ + | 12-14 | LString(3) | helix_id | Helix identifier. In addition | + | | | | to a serial number, each helix | + | | | | is given an alphanumeric | + | | | | helix identifier. | + +---------+--------------+---------------+--------------------------------+ + | 16-18 | Residue name | init_res_name | Name of the initial residue. | + +---------+--------------+---------------+--------------------------------+ + | 20 | Character | init_chain_id | Chain identifier for the chain | + | | | | containing this helix. | + +---------+--------------+---------------+--------------------------------+ + | 22-25 | Integer | init_seq_num | Sequence number of the initial | + | | | | residue. | + +---------+--------------+---------------+--------------------------------+ + | 26 | AChar | init_i_code | Insertion code of the initial | + | | | | residue. | + +---------+--------------+---------------+--------------------------------+ + | 28-30 | Residue name | end_res_name | Name of the terminal residue | + | | | | of the helix. | + +---------+--------------+---------------+--------------------------------+ + | 32 | Character | end_chain_id | Chain identifier for the chain | + | | | | containing this helix. | + +---------+--------------+---------------+--------------------------------+ + | 34-37 | Integer | end_seq_num | Sequence number of the | + | | | | terminal residue. | + +---------+--------------+---------------+--------------------------------+ + | 38 | AChar | end_i_code | Insertion code of the terminal | + | | | | residue. | + +---------+--------------+---------------+--------------------------------+ + | 39-40 | Integer | helix_class | Helix class (see below). | + +---------+--------------+---------------+--------------------------------+ + | 41-70 | String | comment | Comment about this helix. | + +---------+--------------+---------------+--------------------------------+ + | 72-76 | Integer | length | Length of this helix. | + +---------+--------------+---------------+--------------------------------+ """ def __init__(self): @@ -280,41 +280,41 @@ class Link(BaseRecord): .. todo:: Clean up output using element/atom information and formatting - +---------+--------------+----------+-------------------------------------+ - | COLUMNS | DATA TYPE | FIELD | DEFINITION | - +=========+==============+==========+=====================================+ - | 1-6 | Record name | "LINK " | | - +---------+--------------+----------+-------------------------------------+ - | 13-16 | Atom | name1 | Atom name. | - +---------+--------------+----------+-------------------------------------+ - | 17 | Character | altLoc1 | Alternate location indicator. | - +---------+--------------+----------+-------------------------------------+ - | 18-20 | Residue name | resName1 | Residue name. | - +---------+--------------+----------+-------------------------------------+ - | 22 | Character | chainID1 | Chain identifier. | - +---------+--------------+----------+-------------------------------------+ - | 23-26 | Integer | resSeq1 | Residue sequence number. | - +---------+--------------+----------+-------------------------------------+ - | 27 | AChar | iCode1 | Insertion code. | - +---------+--------------+----------+-------------------------------------+ - | 43-46 | Atom | name2 | Atom name. | - +---------+--------------+----------+-------------------------------------+ - | 47 | Character | altLoc2 | Alternate location indicator. | - +---------+--------------+----------+-------------------------------------+ - | 48-50 | Residue name | resName2 | Residue name. | - +---------+--------------+----------+-------------------------------------+ - | 52 | Character | chainID2 | Chain identifier. | - +---------+--------------+----------+-------------------------------------+ - | 53-56 | Integer | resSeq2 | Residue sequence number. | - +---------+--------------+----------+-------------------------------------+ - | 57 | AChar | iCode2 | Insertion code. | - +---------+--------------+----------+-------------------------------------+ - | 60-65 | SymOP | sym1 | Symmetry operator atom 1. | - +---------+--------------+----------+-------------------------------------+ - | 67-72 | SymOP | sym2 | Symmetry operator atom 2. | - +---------+--------------+----------+-------------------------------------+ - | 74-78 | Real(5.2) | Length | Link distance | - +---------+--------------+----------+-------------------------------------+ + +---------+--------------+-----------+------------------------------------+ + | COLUMNS | DATA TYPE | FIELD | DEFINITION | + +=========+==============+===========+====================================+ + | 1-6 | Record name | "LINK " | | + +---------+--------------+-----------+------------------------------------+ + | 13-16 | Atom | name1 | Atom name. | + +---------+--------------+-----------+------------------------------------+ + | 17 | Character | alt_loc1 | Alternate location indicator. | + +---------+--------------+-----------+------------------------------------+ + | 18-20 | Residue name | res_name1 | Residue name. | + +---------+--------------+-----------+------------------------------------+ + | 22 | Character | chain_id | Chain identifier. | + +---------+--------------+-----------+------------------------------------+ + | 23-26 | Integer | res_seq1 | Residue sequence number. | + +---------+--------------+-----------+------------------------------------+ + | 27 | AChar | ins_code1 | Insertion code. | + +---------+--------------+-----------+------------------------------------+ + | 43-46 | Atom | name2 | Atom name. | + +---------+--------------+-----------+------------------------------------+ + | 47 | Character | alt_loc2 | Alternate location indicator. | + +---------+--------------+-----------+------------------------------------+ + | 48-50 | Residue name | res_name2 | Residue name. | + +---------+--------------+-----------+------------------------------------+ + | 52 | Character | chain_id | Chain identifier. | + +---------+--------------+-----------+------------------------------------+ + | 53-56 | Integer | res_seq2 | Residue sequence number. | + +---------+--------------+-----------+------------------------------------+ + | 57 | AChar | ins_code2 | Insertion code. | + +---------+--------------+-----------+------------------------------------+ + | 60-65 | SymOP | sym1 | Symmetry operator atom 1. | + +---------+--------------+-----------+------------------------------------+ + | 67-72 | SymOP | sym2 | Symmetry operator atom 2. | + +---------+--------------+-----------+------------------------------------+ + | 74-78 | Real(5.2) | Length | Link distance | + +---------+--------------+-----------+------------------------------------+ """ def __init__(self): @@ -399,76 +399,77 @@ class Sheet(BaseRecord): molecule. Sheets are both named and numbered. The residues where the sheet begins and ends are noted. - +---------+--------------+-------------+----------------------------------+ - | COLUMNS | DATA TYPE | FIELD | DEFINITION | - +=========+==============+=============+==================================+ - | 1-6 | Record name | "SHEET " | | - +---------+--------------+-------------+----------------------------------+ - | 8-10 | Integer | strand | Strand number which starts at 1 | - | | | | for each strand within a sheet | - | | | | and increases by one. | - +---------+--------------+-------------+----------------------------------+ - | 12-14 | LString(3) | sheetID | Sheet identifier. | - +---------+--------------+-------------+----------------------------------+ - | 15-16 | Integer | numStrands | Number of strands in sheet. | - +---------+--------------+-------------+----------------------------------+ - | 18-20 | Residue name | initResName | Residue name of initial residue. | - +---------+--------------+-------------+----------------------------------+ - | 22 | Character | initChainID | Chain identifier of initial | - | | | | residue in strand. | - +---------+--------------+-------------+----------------------------------+ - | 23-26 | Integer | initSeqNum | Sequence number of initial | - | | | | residue in strand. | - +---------+--------------+-------------+----------------------------------+ - | 27 | AChar | initICode | Insertion code of initial | - | | | | residue in strand. | - +---------+--------------+-------------+----------------------------------+ - | 29-31 | Residue name | endResName | Residue name of terminal residue | - +---------+--------------+-------------+----------------------------------+ - | 33 | Character | endChainID | Chain identifier of terminal | - | | | | residue | - +---------+--------------+-------------+----------------------------------+ - | 34-37 | Integer | endSeqNum | Sequence number of terminal | - | | | | residue. | - +---------+--------------+-------------+----------------------------------+ - | 38 | AChar | endICode | Insertion code of terminal | - | | | | residue. | - +---------+--------------+-------------+----------------------------------+ - | 39-40 | Integer | sense | Sense of strand with respect to | - | | | | previous strand in the sheet. 0 | - | | | | if first strand, 1 if parallel, | - | | | | and -1 if anti-parallel. | - +---------+--------------+-------------+----------------------------------+ - | 42-45 | Atom | curAtom | Registration. Atom name in | - | | | | curent strand. | - +---------+--------------+-------------+----------------------------------+ - | 46-48 | Residue name | curResName | Registration. Residue name in | - | | | | current strand | - +---------+--------------+-------------+----------------------------------+ - | 50 | Character | curChainId | Registration. Chain identifier | - | | | | in current strand. | - +---------+--------------+-------------+----------------------------------+ - | 51-54 | Integer | curResSeq | Registration. Residue sequence | - | | | | number in current strand. | - +---------+--------------+-------------+----------------------------------+ - | 55 | AChar | curICode | Registration. Insertion code in | - | | | | current strand. | - +---------+--------------+-------------+----------------------------------+ - | 57-60 | Atom | prevAtom | Registration. Atom name in | - | | | | previous strand. | - +---------+--------------+-------------+----------------------------------+ - | 61-63 | Residue name | prevResName | Registration. Residue name in | - | | | | previous strand. | - +---------+--------------+-------------+----------------------------------+ - | 65 | Character | prevChainId | Registration. Chain identifier | - | | | | in previous strand. | - +---------+--------------+-------------+----------------------------------+ - | 66-69 | Integer | prevResSeq | Registration. Residue sequence | - | | | | number in previous strand. | - +---------+--------------+-------------+----------------------------------+ - | 70 | AChar | prevICode | Registration. Insertion code in | - | | | | previous strand. | - +---------+--------------+-------------+----------------------------------+ + +---------+--------------+---------------+--------------------------------+ + | COLUMNS | DATA TYPE | FIELD | DEFINITION | + +=========+==============+===============+================================+ + | 1-6 | Record name | "SHEET " | | + +---------+--------------+---------------+--------------------------------+ + | 8-10 | Integer | strand | Strand number which starts at | + | | | | 1 for each strand within a | + | | | | sheet and increases by one. | + +---------+--------------+---------------+--------------------------------+ + | 12-14 | LString(3) | sheet_id | Sheet identifier. | + +---------+--------------+---------------+--------------------------------+ + | 15-16 | Integer | num_strands | Number of strands in sheet. | + +---------+--------------+---------------+--------------------------------+ + | 18-20 | Residue name | init_res_name | Name of initial residue. | + +---------+--------------+---------------+--------------------------------+ + | 22 | Character | init_chain_id | Chain identifier of initial | + | | | | residue in strand. | + +---------+--------------+---------------+--------------------------------+ + | 23-26 | Integer | init_seq_num | Sequence number of initial | + | | | | residue in strand. | + +---------+--------------+---------------+--------------------------------+ + | 27 | AChar | init_ins_code | Insertion code of initial | + | | | | residue in strand. | + +---------+--------------+---------------+--------------------------------+ + | 29-31 | Residue name | end_res_name | Name of terminal residue | + +---------+--------------+---------------+--------------------------------+ + | 33 | Character | end_chain_id | Chain identifier of terminal | + | | | | residue | + +---------+--------------+---------------+--------------------------------+ + | 34-37 | Integer | end_seq_num | Sequence number of terminal | + | | | | residue. | + +---------+--------------+---------------+--------------------------------+ + | 38 | AChar | end_ins_code | Insertion code of terminal | + | | | | residue. | + +---------+--------------+---------------+--------------------------------+ + | 39-40 | Integer | sense | Sense of strand with respect | + | | | | to previous strand in the | + | | | | sheet. 0 if first strand, 1 if | + | | | | parallel, and -1 if | + | | | | anti-parallel. | + +---------+--------------+---------------+--------------------------------+ + | 42-45 | Atom | cur_atom | Registration. Atom name in | + | | | | current strand. | + +---------+--------------+---------------+--------------------------------+ + | 46-48 | Residue name | cur_res_name | Registration. Residue name in | + | | | | current strand | + +---------+--------------+---------------+--------------------------------+ + | 50 | Character | cur_chain_id | Registration. Chain identifier | + | | | | in current strand. | + +---------+--------------+---------------+--------------------------------+ + | 51-54 | Integer | cur_res_seq | Registration. Residue sequence | + | | | | number in current strand. | + +---------+--------------+---------------+--------------------------------+ + | 55 | AChar | cur_ins_code | Registration. Insertion code | + | | | | in current strand. | + +---------+--------------+---------------+--------------------------------+ + | 57-60 | Atom | prev_atom | Registration. Atom name in | + | | | | previous strand. | + +---------+--------------+---------------+--------------------------------+ + | 61-63 | Residue name | prev_res_name | Registration. Residue name in | + | | | | previous strand. | + +---------+--------------+---------------+--------------------------------+ + | 65 | Character | prev_chain_id | Registration. Chain identifier | + | | | | in previous strand. | + +---------+--------------+---------------+--------------------------------+ + | 66-69 | Integer | prev_res_seq | Registration. Residue sequence | + | | | | number in previous strand. | + +---------+--------------+---------------+--------------------------------+ + | 70 | AChar | prev_ins_code | Registration. Insertion code | + | | | | in previous strand. | + +---------+--------------+---------------+--------------------------------+ """ def __init__(self): @@ -479,11 +480,11 @@ def __init__(self): self.init_res_name = None self.init_chain_id = None self.init_seq_num = None - self.init_i_code = None + self.init_ins_code = None self.end_res_name = None self.end_chain_id = None self.end_seq_num = None - self.end_i_code = None + self.end_ins_code = None self.sense = None self.cur_atom = "" self.curr_res_name = "" @@ -508,11 +509,11 @@ def parse_line(self, line): self.init_res_name = line[17:20].strip() self.init_chain_id = line[21].strip() self.init_seq_num = int(line[22:26].strip()) - self.init_i_code = line[26].strip() + self.init_ins_code = line[26].strip() self.end_res_name = line[28:31].strip() self.end_chain_id = line[32].strip() self.end_seq_num = int(line[33:37].strip()) - self.end_i_code = line[37].strip() + self.end_ins_code = line[37].strip() self.sense = int(line[38:40].strip()) self.cur_atom = line[41:45].strip() self.curr_res_name = line[45:48].strip() @@ -538,8 +539,8 @@ def __str__(self): string = ( f"SHEET {self.strand:3} {self.sheet_id:>3}{self.num_strands:2}" f" {self.init_res_name:3} {self.init_chain_id:1}" - f"{self.init_seq_num:4}{self.init_i_code:1} {self.end_res_name:3}" - f" {self.end_chain_id:1}{self.end_seq_num:4}{self.end_i_code:1}" + f"{self.init_seq_num:4}{self.init_ins_code:1} {self.end_res_name:3}" + f" {self.end_chain_id:1}{self.end_seq_num:4}{self.end_ins_code:1}" f"{self.sense:2}" ) if len(self.cur_atom) == 1: diff --git a/tests/read_test.py b/tests/read_test.py index d5e3365..824d1c7 100644 --- a/tests/read_test.py +++ b/tests/read_test.py @@ -21,8 +21,7 @@ def test_pdb(pdb_id): assert entry.num_atoms() == test_row["Num_heavy_atoms"] assert entry.num_residues() == test_row["Num_residues"] assert entry.num_chains() == test_row["Num_chains"] - if entry.num_models: - assert entry.num_models.model_number == test_row["Num_models"] - else: - assert test_row["Num_models"] == 1 + num_model = test_row["Num_models"] + if num_model > 1: + assert entry.num_model.model_number == test_row["Num_models"] assert len(entry.model) == test_row["Num_models"] From 0df7aa587ca2c8f1b9755d548600f66abb12494d Mon Sep 17 00:00:00 2001 From: Nathan Baker Date: Sun, 28 Feb 2021 09:27:32 -0800 Subject: [PATCH 2/2] Update version number. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ccf4256..45485c0 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ setuptools.setup( name="old_pdb", - version="0.0.1", + version="2.0.0", description=( "This code reads and writes the old Protein Data Bank format." ),