• 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

80.0
/deeprankcore/features/exposure.py
1
import logging
1✔
2
import numpy as np
1✔
3
import warnings
1✔
4
from Bio.PDB.Atom import PDBConstructionWarning
1✔
5
from Bio.PDB.PDBParser import PDBParser
1✔
6
from Bio.PDB.ResidueDepth import get_surface, residue_depth
1✔
7
from Bio.PDB.HSExposure import HSExposureCA
1✔
8
from deeprankcore.domain import nodestorage as Nfeat
1✔
9
from deeprankcore.molstruct.atom import Atom
1✔
10
from deeprankcore.molstruct.residue import Residue
1✔
11
from deeprankcore.utils.graph import Graph
1✔
12
import sys
1✔
13
import signal
1✔
14

15

16
_log = logging.getLogger(__name__)
1✔
17

18

19
def handle_sigint(sig, frame): # pylint: disable=unused-argument
1✔
20
    print('SIGINT received, terminating.')
×
21
    sys.exit()
×
22

23

24
def handle_timeout(sig, frame): # pylint: disable=unused-argument
1✔
25
    raise TimeoutError('Timed out!')
×
26

27

28
def space_if_none(value):
1✔
29
    if value is None:
1!
30
        return " "
1✔
31

32
    return value
×
33

34

35
def add_features(pdb_path: str, graph: Graph, *args, **kwargs): # pylint: disable=unused-argument
1✔
36

37
    signal.signal(signal.SIGINT, handle_sigint)
1✔
38
    signal.signal(signal.SIGALRM, handle_timeout)
1✔
39

40
    with warnings.catch_warnings(record=PDBConstructionWarning):
1✔
41
        parser = PDBParser()
1✔
42
        structure = parser.get_structure('_tmp', pdb_path)
1✔
43
    
44
    bio_model = structure[0]
1✔
45

46
    try:
1✔
47
        signal.alarm(20)
1✔
48
        surface = get_surface(bio_model)
1✔
49
        signal.alarm(0)
1✔
50
    except TimeoutError as e:
×
51
        raise TimeoutError('Bio.PDB.ResidueDepth.get_surface timed out.') from e
×
52
    else:
53
        hse = HSExposureCA(bio_model)
1✔
54

55
        for node in graph.nodes:
1✔
56

57
            # These can only be calculated per residue, not per atom.
58
            # So for atomic graphs, every atom gets its residue's value.
59
            if isinstance(node.id, Atom):
1!
60
                atom = node.id
×
61
                residue = atom.residue
×
62
            elif isinstance(node.id, Residue):
1!
63
                residue = node.id
1✔
64
            else:
65
                raise TypeError(f"Unexpected node type: {type(node)}")
×
66

67
            bio_residue = bio_model[residue.chain.id][residue.number]
1✔
68
            node.features[Nfeat.RESDEPTH] = residue_depth(bio_residue, surface)
1✔
69

70
            hse_key = (residue.chain.id, (" ", residue.number, space_if_none(residue.insertion_code)))
1✔
71
            if hse_key in hse:
1✔
72
                node.features[Nfeat.HSE] = hse[hse_key]
1✔
73
            else:
74
                node.features[Nfeat.HSE] = np.array((0, 0, 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