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

CCPBioSim / CodeEntropy / 13726590978

07 Mar 2025 06:07PM UTC coverage: 1.726%. First build
13726590978

push

github

web-flow
Merge pull request #45 from CCPBioSim/39-implement-ci-pipeline-pre-commit-hooks

Implement CI pipeline pre-commit hooks

27 of 1135 new or added lines in 23 files covered. (2.38%)

53 of 3071 relevant lines covered (1.73%)

0.05 hits per line

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

0.0
/CodeEntropy/MDAUniverseHelper.py
1
import pickle
×
2

NEW
3
import MDAnalysis as mda
×
4
from MDAnalysis.analysis.base import AnalysisFromFunction
×
5
from MDAnalysis.coordinates.memory import MemoryReader
×
6

7

8
def new_U_select_frame(u, start=None, end=None, step=1):
×
9
    """Create a reduced universe by dropping frames according to user selection
10

11
    Parameters
12
    ----------
13
    u : MDAnalyse.Universe
14
        A Universe object will all topology, dihedrals,coordinates and force information
15
    start : int or None, Optional, default: None
16
        Frame id to start analysis. Default None will start from frame 0
17
    end : int or None, Optional, default: None
18
        Frame id to end analysis. Default None will end at last frame
19
    step : int, Optional, default: 1
20
        Steps between frame.
21

22
    Returns
23
    -------
24
        u2 : MDAnalysis.Universe
25
            reduced universe
26
    """
NEW
27
    if start is None:
×
28
        start = 0
×
NEW
29
    if end is None:
×
30
        end = len(u.trajectory)
×
NEW
31
    select_atom = u.select_atoms("all", updating=True)
×
NEW
32
    coordinates = (
×
33
        AnalysisFromFunction(lambda ag: ag.positions.copy(), select_atom)
34
        .run()
35
        .results["timeseries"][start:end:step]
36
    )
NEW
37
    forces = (
×
38
        AnalysisFromFunction(lambda ag: ag.forces.copy(), select_atom)
39
        .run()
40
        .results["timeseries"][start:end:step]
41
    )
NEW
42
    dimensions = (
×
43
        AnalysisFromFunction(lambda ag: ag.dimensions.copy(), select_atom)
44
        .run()
45
        .results["timeseries"][start:end:step]
46
    )
47
    u2 = mda.Merge(select_atom)
×
NEW
48
    u2.load_new(coordinates, format=MemoryReader, forces=forces, dimensions=dimensions)
×
49
    return u2
×
50

51

NEW
52
def new_U_select_atom(u, select_string="all"):
×
53
    """Create a reduced universe by dropping atoms according to user selection
54

55
    Parameters
56
    ----------
57
    u : MDAnalyse.Universe
58
        A Universe object will all topology, dihedrals,coordinates and force information
59
    select_string : str, Optional, default: 'all'
60
        MDAnalysis.select_atoms selection string.
61

62
    Returns
63
    -------
64
        u2 : MDAnalysis.Universe
65
            reduced universe
66

67
    """
68
    select_atom = u.select_atoms(select_string, updating=True)
×
NEW
69
    coordinates = (
×
70
        AnalysisFromFunction(lambda ag: ag.positions.copy(), select_atom)
71
        .run()
72
        .results["timeseries"]
73
    )
NEW
74
    forces = (
×
75
        AnalysisFromFunction(lambda ag: ag.forces.copy(), select_atom)
76
        .run()
77
        .results["timeseries"]
78
    )
NEW
79
    dimensions = (
×
80
        AnalysisFromFunction(lambda ag: ag.dimensions.copy(), select_atom)
81
        .run()
82
        .results["timeseries"]
83
    )
84
    u2 = mda.Merge(select_atom)
×
85
    u2.load_new(coordinates, format=MemoryReader, forces=forces, dimensions=dimensions)
×
NEW
86
    return u2
×
87

88

NEW
89
def write_universe(u, name="default"):
×
90
    """Write a universe to working directories as pickle
91

92
    Parameters
93
    ----------
94
    u : MDAnalyse.Universe
95
        A Universe object will all topology, dihedrals,coordinates and force information
96
    name : str, Optional. default: 'default'
97
        The name of file with sub file name .pkl
98

99
    Returns
100
    -------
101
        name : str
102
            filename of saved universe
103
    """
104
    filename = f"{name}.pkl"
×
105
    pickle.dump(u, open(filename, "wb"))
×
106
    return name
×
107

108

109
def read_universe(path):
×
110
    """read a universe to working directories as pickle
111

112
    Parameters
113
    ----------
114
    path : str
115
        The path to file.
116

117
    Returns
118
    -------
119
        u : MDAnalysis.Universe
120
            A Universe object will all topology, dihedrals,coordinates and force
121
            information.
122
    """
123
    u = pickle.load(open(path, "rb"))
×
124
    return u
×
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

© 2026 Coveralls, Inc