• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DeepRank / deeprank-core / 4075652401

pending completion
4075652401

Pull #330

github

GitHub
Merge 45ea1393e into d73e8c34f
Pull Request #330: fix: data generation threading locked

1046 of 1331 branches covered (78.59%)

Branch coverage included in aggregate %.

36 of 36 new or added lines in 2 files covered. (100.0%)

2949 of 3482 relevant lines covered (84.69%)

0.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.11
/deeprankcore/molstruct/residue.py
1
from typing import Optional
1✔
2
import numpy as np
1✔
3
from deeprankcore.molstruct.structure import Chain
1✔
4
from deeprankcore.molstruct.aminoacid import AminoAcid
1✔
5
from deeprankcore.utils.pssmdata import PssmRow
1✔
6

7

8
class Residue:
1✔
9
    "represents a pdb residue"
10

11
    def __init__(
1✔
12
        self,
13
        chain: Chain,
14
        number: int,
15
        amino_acid: Optional[AminoAcid] = None,
16
        insertion_code: Optional[str] = None,
17
    ):
18
        """
19
        Args:
20
            chain(deeprank chain object): the chain that this residue belongs to
21
            number(int): the residue number
22
            amino_acid(deeprank amino acid, optional): the residue's amino acid (if it's part of a protein)
23
            insertion_code(str, optional): the pdb insertion code, if any
24
        """
25

26
        self._chain = chain
1✔
27
        self._number = number
1✔
28
        self._amino_acid = amino_acid
1✔
29
        self._insertion_code = insertion_code
1✔
30
        self._atoms = []
1✔
31

32
    def __eq__(self, other) -> bool:
1✔
33
        return (
1✔
34
            isinstance(self, type(other))
35
            and self._chain == other._chain
36
            and self._number == other._number
37
            and self._insertion_code == other._insertion_code
38
        )
39

40
    def __hash__(self) -> hash:
1✔
41
        return hash((self._chain, self._number, self._insertion_code))
1✔
42

43
    def get_pssm(self) -> PssmRow:
1✔
44
        """ if the residue's chain has pssm info linked to it,
45
            then return the part that belongs to this residue
46
        """
47

48
        pssm = self._chain.pssm
1✔
49
        if pssm is None:
1!
50
            raise ValueError(f"pssm not set on {self._chain}")
×
51

52
        return pssm[self]
1✔
53

54
    @property
1✔
55
    def number(self) -> int:
1✔
56
        return self._number
1✔
57

58
    @property
1✔
59
    def chain(self):
1✔
60
        return self._chain
1✔
61

62
    @property
1✔
63
    def amino_acid(self) -> AminoAcid:
1✔
64
        return self._amino_acid
1✔
65

66
    @property
1✔
67
    def atoms(self):
1✔
68
        return self._atoms
1✔
69

70
    @property
1✔
71
    def number_string(self) -> str:
1✔
72
        "contains both the number and the insertion code (if any)"
73

74
        if self._insertion_code is not None:
1!
75
            return f"{self._number}{self._insertion_code}"
×
76

77
        return str(self._number)
1✔
78

79
    @property
1✔
80
    def insertion_code(self) -> str:
1✔
81
        return self._insertion_code
1✔
82

83
    def add_atom(self, atom):
1✔
84
        self._atoms.append(atom)
1✔
85

86
    def __repr__(self) -> str:
1✔
87
        return f"{self._chain} {self.number_string}"
1✔
88

89
    @property
1✔
90
    def position(self) -> np.array:
1✔
91
        return np.mean([atom.position for atom in self._atoms], axis=0)
1✔
92

93

94
def get_residue_center(residue: Residue) -> np.ndarray:
1✔
95
    """
96
    Chooses a center position for a residue, based on the atoms it has:
97
    1. find beta carbon, if present
98
    2. find alpha carbon, if present
99
    3. else take the mean of the atom positions
100
    """
101

102
    betas = [atom for atom in residue.atoms if atom.name == "CB"]
1✔
103
    if len(betas) > 0:
1✔
104
        return betas[0].position
1✔
105

106
    alphas = [atom for atom in residue.atoms if atom.name == "CA"]
1✔
107
    if len(alphas) > 0:
1✔
108
        return alphas[0].position
1✔
109

110
    if len(residue.atoms) == 0:
1!
111
        raise ValueError(f"cannot get the center position from {residue}, because it has no atoms")
×
112

113
    return np.mean([atom.position for atom in residue.atoms], axis=0)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc