• 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/poseidon/extractData/readFiles.py
1
#!/usr/bin/env python
2

3
import logging
×
4

5
# import math
6
# import operator
7
import sys
×
NEW
8
from collections import defaultdict  # Counter,
×
9
from datetime import datetime
×
10

11
import MDAnalysis
×
NEW
12
import numpy as np
×
13

14
# from CodeEntropy.poseidon.extractData.generalFunctions import *
NEW
15
from CodeEntropy.poseidon.extractData.mainClass import atom_info
×
16

17
# from numpy import linalg as LA
18

19

20
# create nested dict in one go
NEW
21
def nested_dict():
×
NEW
22
    return defaultdict(nested_dict)
×
23

24

25
def populateTopology(container, all_data, waterTuple):
×
26
    """
27
    After reading in topologies using MDAnalysis,
28
    relavant information from topology files are saved into a global
29
    class object. Properties are read in differently depeding on what
30
    file types were read in.
31
    """
32

33
    all_resids = []
×
34
    mol = None
×
35

36
    for tp in container.atoms:
×
37
        bonded_atom_nums = []
×
38
        for b in tp.bonds:
×
39
            for x in b:
×
40
                if x.index != tp.index:
×
41
                    bonded_atom_nums.append(int(x.index))
×
42
                else:
43
                    continue
×
44

45
        try:
×
46
            dihedral_list = []
×
NEW
47
            if tp.mass > 1.1:
×
48
                for dih in tp.dihedrals:
×
49
                    diha_list = []
×
50
                    for di in dih:
×
51
                        if di.mass > 1.1:
×
52
                            diha_list.append(int(di.index))
×
53
                        else:
54
                            break
×
55

56
                    if len(diha_list) == 4:
×
57
                        dihedral_list.append(diha_list)
×
58
                    else:
59
                        continue
×
60
        except AttributeError:
×
61
            dihedral_list = []
×
62

NEW
63
        inf = atom_info(
×
64
            int(tp.index),
65
            tp.name,
66
            tp.mass,
67
            tp.charge,
68
            int(tp.resid),
69
            tp.resname,
70
            bonded_atom_nums,
71
            dihedral_list,
72
        )
73

74
        all_data.append(inf)
×
75

76
    # Get and populate UA and molecule level information
77
    molecule_dict = nested_dict()
×
78
    molecule_resids_dict = nested_dict()
×
79
    for x in range(0, len(all_data)):
×
80
        atom = all_data[x]
×
81
        # print(f"x = {x}")
82
        if atom.mass > 1.1:
×
83
            heavy_bonded = []
×
84
            H_bonded = []
×
85
            for bonded_atom in atom.bonded_to_atom_num:
×
86
                # print(f"bonded_atom = {bonded_atom}")
87
                bonded = all_data[bonded_atom]
×
88
                if bonded.mass > 1.1:
×
89
                    heavy_bonded.append(bonded)
×
90
                elif bonded.mass < 1.1:
×
91
                    H_bonded.append(bonded)
×
92
                else:
93
                    continue
×
94

95
            bonded_atoms_list = [atom] + heavy_bonded + H_bonded
×
96
            atom.bondedUA_H = [len(heavy_bonded), len(H_bonded)]
×
97

98
            if atom.resid not in molecule_dict:
×
99
                molecule_dict[atom.resid] = []
×
100
                molecule_resids_dict[atom.resid] = []
×
101
            if atom.atom_num not in molecule_dict[atom.resid]:
×
102
                molecule_dict[atom.resid].append(atom.atom_num)
×
103
            for bonded2 in heavy_bonded:
×
104
                if bonded2.resid not in molecule_resids_dict[atom.resid]:
×
105
                    molecule_resids_dict[atom.resid].append(bonded2.resid)
×
106
                else:
107
                    continue
×
108

109
    for x in range(0, len(all_data)):
×
110
        atom = all_data[x]
×
111
        if atom.mass > 1.1:
×
112
            atom.molecule_atomNums = sorted(molecule_dict[atom.resid])
×
113
            atom.bonded_to_resids = sorted(molecule_resids_dict[atom.resid])
×
114
        else:
115
            continue
×
116

117

NEW
118
def getCoordsForces(container, all_data, dimensions, frame, startTime, verbosePrint):
×
119
    """
120
    Read in coordinate and force trajectories and populate mainClass.
121
    """
122

123
    t = container.trajectory[frame]
×
124
    dimensions = np.array(t.dimensions[0:3])
×
125
    print(t)
×
126

127
    for x in range(0, len(t)):
×
128
        crds = np.array(t[x])
×
129
        all_data[x].coords = crds
×
130
        frcs = np.array(t.forces[x])
×
131
        all_data[x].forces = frcs
×
132

NEW
133
    verbosePrint("COORDS-FORCES")
×
134
    verbosePrint(datetime.now() - startTime)
×
NEW
135
    sys.stdout.flush()
×
136

137
    return all_data, dimensions
×
138

139

140
# #Energy is not needed
141
# def populateEnergy(container, all_data, dimensions, frame, startTime,
142
#         verbosePrint):
143
#     '''
144
#     read in energies from lammps input file.
145
#     '''
146

147
#     for e in container.trajectory:
148
#         if e.frame == frame:
149
#             dimensions = np.array(e.dimensions[0:3])
150
#             for x in range(0, len(e)):
151
#                 energy = np.array(e.velocities[x])
152
#                 all_data[x].PKenergy = [energy[0], energy[1]]
153
#             break
154
#         else:
155
#             continue
156

157

158
#     verbosePrint('ENERGIES')
159
#     verbosePrint(datetime.now() - startTime)
160
#     sys.stdout.flush()
161

162

163
# def UAEnergyGroup(all_data):
164
#     '''
165
#     For energy on each atom, group together for each UA
166
#     and sum
167
#     '''
168

169
#     for x in range(0, len(all_data)):
170
#         atom = all_data[x]
171
#         if atom.mass > 1.1:
172
#             heavy_bonded = []
173
#             H_bonded = []
174
#             for bonded_atom in atom.bonded_to_atom_num:
175
#                 bonded = all_data[bonded_atom]
176
#                 if bonded.mass > 1.1:
177
#                     heavy_bonded.append(bonded)
178
#                 elif bonded.mass < 1.1:
179
#                     H_bonded.append(bonded)
180
#                 else:
181
#                     continue
182

183
#             bonded_atoms_list = [atom] + heavy_bonded + H_bonded
184
#             atom.bondedUA_H = [len(heavy_bonded), len(H_bonded)]
185
#             UA_atoms_list = [atom] + H_bonded
186

187
#             UA_PE_list = []
188
#             UA_KE_list = []
189
#             for A in UA_atoms_list:
190
#                 if A.PKenergy != None:
191
#                     UA_PE_list.append(A.PKenergy[0])
192
#                     UA_KE_list.append(A.PKenergy[1])
193
#                 else:
194
#                     continue
195

196
#             if len(UA_PE_list) != 0:
197
#                 UA_PE = round(sum(UA_PE_list), 3)
198
#                 UA_KE = round(sum(UA_KE_list), 3)
199
#                 atom.UA_PKenergy = [UA_PE, UA_KE]
200

201

NEW
202
def getDistArray(
×
203
    atom,
204
    all_data,
205
    traj,
206
    max_cutoff,
207
    dimensions,
208
    neighbour_coords,
209
    startTime,
210
    verbosePrint,
211
):
212
    """
213
    Find the NN list of an atom
214
    Important to use coords directly from MDAnalysis to run NN calc
215
    """
216

217
    atom_coords = traj[atom.atom_num]
×
218

219
    # added a small min cutoff to stop zero distance
NEW
220
    array1, array2 = MDAnalysis.lib.distances.capped_distance(
×
221
        atom_coords,
222
        neighbour_coords,
223
        max_cutoff=max_cutoff,
224
        min_cutoff=None,
225
        box=traj.dimensions,
226
        method=None,
227
        return_distances=True,
228
    )
229

230
    try:
×
NEW
231
        array1, array2 = zip(*sorted(zip(array2, array1), key=lambda x: x[0]))
×
232

233
    except ValueError:
×
NEW
234
        logging.error(
×
235
            "Bad Arrays for Coordinate/ Atom Number " "Nearest Neighbour Assignments"
236
        )
237

238
    atomNumList = []
×
239
    allAtomList = []
×
240
    for atoms, dist in zip(array2, array1):
×
241
        near = atoms[1]
×
242
        atom_num = all_data[near].atom_num
×
243
        atom_resid = all_data[near].resid
×
244
        atom_mass = all_data[near].mass
×
245
        allAtomList.append((near, dist))
×
246

247
        # atom_resid != all_data[x].resid removed for quartz
248
        # surface that is all the same resid.
NEW
249
        if (
×
250
            atom_num != atom.atom_num
251
            and atom_num not in atom.bonded_to_atom_num
252
            and float(atom_mass) > 1.1
253
        ):
254
            atomNumList.append((near, dist))
×
255
        else:
256
            continue
×
257

258
    atom.nearest_sorted_array = atomNumList
×
259
    atom.nearest_all_atom_array = allAtomList
×
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