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

3
import math
×
4

5
# import os
NEW
6
import sys
×
7

NEW
8
from CodeEntropy.poseidon.analysis.classes import variables_dicts
×
NEW
9
from CodeEntropy.poseidon.analysis.populateEE import (
×
10
    SconfPopulation,
11
    SorPopulation,
12
    SvibPopulation,
13
    contactPopulation,
14
    contactPopulationUA,
15
)
16

17
# from collections import Counter
18

19
# import numpy as np
20
# import psutil
21

22

NEW
23
def classPopulation(
×
24
    atomList,
25
    entropyEnergy,
26
    level_list,
27
    count,
28
    atom_count,
29
    num_atoms,
30
    waterTuple,
31
    temperature,
32
    solvent,
33
    EEclass,
34
    EEclass_residLevel_resname,
35
    EEclass_soluteContacts,
36
    EEclass_atomLevel,
37
    weighting_info,
38
    verbosePrint,
39
):
40
    """
41
    For each flag, populate dictionaries accordingly
42
    The objects read in are used for this.
43
    """
44

45
    # Smix_methods
46
    step_list = None
×
47

48
    #
NEW
49
    if count == 1:
×
50

51
        # initiate classes for each flag
52

53
        if entropyEnergy:
×
54
            EEclass = variables_dicts(True)
×
55
            EEclass_residLevel_resname = variables_dicts(True)
×
56
            EEclass_soluteContacts = variables_dicts(True)
×
57
            EEclass_atomLevel = variables_dicts(True)
×
58

NEW
59
        if weighting_info is not None:
×
NEW
60
            if EEclass is None:
×
61
                EEclass = variables_dicts(True)
×
62
            EEclass.weighting_list = weighting_info[0]
×
63
            EEclass.weighting_chunks = weighting_info[1]
×
64

65
    #
66

NEW
67
    for i in atomList:  # iterate through each atom
×
68
        # only need to change this if list order changes (and below)
69
        atom_count += 1
×
NEW
70
        globalFrame = math.ceil(atom_count / float(num_atoms))  # round UP
×
NEW
71
        frame = i[0]  # not used
×
NEW
72
        cumulative_steps = ["All"]
×
NEW
73
        if step_list is not None:
×
74
            for n in range(1, len(step_list)):
×
75
                step = step_list[n]
×
76
                if int(globalFrame) <= step:
×
77
                    cumulative_step = str(step)
×
78
                    # print(globalFrame, cumulative_step)
79
                    cumulative_steps.append(cumulative_step)
×
80

81
        atom_name = i[1]
×
82
        atom_num = i[2]
×
83
        atom_resname = i[3]
×
84
        atom_resid = i[4]
×
85
        N_H = i[5][1]
×
86
        # molecule_atoms = i[6] #heavy atoms only
NEW
87
        molecule_size = len(i[6])  # heavy atoms only
×
88
        try:
×
89
            nearest_atomName = i[7][0]
×
90
            nearest_resname = i[7][1]
×
91
            nearest_resid = i[7][2]
×
92
            # dist = float(i[7][3])
93
            # dist = round(float(i[7][3]), 1)
94
        except IndexError:
×
NEW
95
            nearest_atomName = "unassigned"
×
NEW
96
            nearest_resname = "unassigned"
×
97
            nearest_resid = 0
×
98
            # dist = 0
99
        RADshell_num = i[8]
×
NEW
100
        if RADshell_num is not None:
×
NEW
101
            RADshell_num = "0"  # unassigned to a nearest
×
102
        RAD_list = sorted(i[9][0])
×
103
        As = i[9][1]
×
104
        Ds = i[9][2]
×
105
        # Svib_Ecalcs
NEW
106
        MweightedForces = i[10]  # array
×
NEW
107
        MweightedTorques = i[11]  # array
×
108
        PE = None
×
109
        KE = None
×
NEW
110
        if i[12] is not None:
×
111
            PE = i[12][0]
×
112
            KE = i[12][1]
×
113

114
        UAweightedForces = i[13]
×
115
        UAweightedTorques = i[14]
×
116
        # FT POPULATION
117
        try:
×
118
            dihedral_phi_list = i[15]
×
119
            Ndih = len(i[15])
×
120
        except (IndexError, TypeError):
×
121
            dihedral_phi_list
×
122
            Ndih = None
×
123
        try:
×
124
            molecule_UA_F = i[16]
×
125
            molecule_UA_T = i[17]
×
126
        except IndexError:
×
127
            Ndih = None
×
128
            molecule_UA_F = []
×
129
            molecule_UA_T = []
×
NEW
130
        RAD_nAtoms = i[18]  # closest atom in each RADshell and distance
×
131

132
        RAD_str = tuple(sorted(RAD_list))
×
133

134
        # toggle between shells or distances as x variable
135
        RADshell_num_dist = str(RADshell_num)
×
136

137
        # group all solute types together for easier analysis
NEW
138
        if atom_resname not in solvent and RADshell_num != "0":
×
NEW
139
            nearest_resname = "Any"
×
NEW
140
            RADshell_num_dist = "1"
×
141

142
        # find out weighting of each frame if simulation is biased
143
        weight = 1
×
NEW
144
        if weighting_info is not None:
×
NEW
145
            if EEclass.weighting_list is not None:
×
146
                weight = getWeight(EEclass, globalFrame)
×
147

148
        for level in level_list:
×
149

150
            nearest_resname_list = []
×
NEW
151
            atom_resnameLevel, nearest_resname_list, waterTuple = levelSelection(
×
152
                level,
153
                atom_resname,
154
                atom_resid,
155
                nearest_resname,
156
                nearest_resname_list,
157
                atom_name,
158
                nearest_atomName,
159
                nearest_resid,
160
                RAD_nAtoms,
161
                waterTuple,
162
            )
163

164
            for nearest_resnameLevel in nearest_resname_list:
×
165

NEW
166
                if "Any" in nearest_resnameLevel:
×
NEW
167
                    nearest_resnameLevel = "Any"
×
168

NEW
169
                if level in [None, "moleculeLevel"]:
×
170

171
                    if entropyEnergy:
×
172

NEW
173
                        SorPopulation(
×
174
                            EEclass,
175
                            atom_name,
176
                            atom_resnameLevel,
177
                            nearest_resnameLevel,
178
                            RAD_str,
179
                            RADshell_num,
180
                            RADshell_num_dist,
181
                            waterTuple,
182
                            N_H,
183
                            As,
184
                            Ds,
185
                            weight,
186
                        )
187

NEW
188
                        SvibPopulation(
×
189
                            EEclass,
190
                            level,
191
                            atom_name,
192
                            atom_resnameLevel,
193
                            N_H,
194
                            atom_num,
195
                            nearest_resnameLevel,
196
                            RADshell_num_dist,
197
                            waterTuple,
198
                            UAweightedForces,
199
                            UAweightedTorques,
200
                            PE,
201
                            KE,
202
                            MweightedForces,
203
                            MweightedTorques,
204
                            Ndih,
205
                            molecule_UA_F,
206
                            molecule_UA_T,
207
                            weight,
208
                        )
209

NEW
210
                        SconfPopulation(
×
211
                            EEclass,
212
                            nearest_resnameLevel,
213
                            atom_name,
214
                            atom_resnameLevel,
215
                            N_H,
216
                            dihedral_phi_list,
217
                            molecule_size,
218
                            RADshell_num_dist,
219
                            weight,
220
                        )
221

NEW
222
                if level in ["residLevel_resname"]:
×
223
                    if entropyEnergy:
×
224

NEW
225
                        contactPopulation(
×
226
                            EEclass_residLevel_resname,
227
                            RAD_nAtoms,
228
                            atom_resnameLevel,
229
                            atom_resid,
230
                            waterTuple,
231
                            weight,
232
                        )
233

NEW
234
                        SorPopulation(
×
235
                            EEclass_residLevel_resname,
236
                            atom_name,
237
                            atom_resnameLevel,
238
                            nearest_resnameLevel,
239
                            RAD_str,
240
                            RADshell_num,
241
                            RADshell_num_dist,
242
                            waterTuple,
243
                            N_H,
244
                            As,
245
                            Ds,
246
                            weight,
247
                        )
248

NEW
249
                        SvibPopulation(
×
250
                            EEclass_residLevel_resname,
251
                            level,
252
                            atom_name,
253
                            atom_resnameLevel,
254
                            N_H,
255
                            atom_num,
256
                            nearest_resnameLevel,
257
                            RADshell_num_dist,
258
                            waterTuple,
259
                            UAweightedForces,
260
                            UAweightedTorques,
261
                            PE,
262
                            KE,
263
                            MweightedForces,
264
                            MweightedTorques,
265
                            Ndih,
266
                            molecule_UA_F,
267
                            molecule_UA_T,
268
                            weight,
269
                        )
270

NEW
271
                        SconfPopulation(
×
272
                            EEclass_residLevel_resname,
273
                            nearest_resnameLevel,
274
                            atom_name,
275
                            atom_resnameLevel,
276
                            N_H,
277
                            dihedral_phi_list,
278
                            molecule_size,
279
                            RADshell_num_dist,
280
                            weight,
281
                        )
282

NEW
283
                if level in ["soluteContacts"]:
×
284

285
                    if entropyEnergy:
×
NEW
286
                        SorPopulation(
×
287
                            EEclass_soluteContacts,
288
                            atom_name,
289
                            atom_resnameLevel,
290
                            nearest_resnameLevel,
291
                            RAD_str,
292
                            RADshell_num,
293
                            RADshell_num_dist,
294
                            waterTuple,
295
                            N_H,
296
                            As,
297
                            Ds,
298
                            weight,
299
                        )
300

NEW
301
                        SvibPopulation(
×
302
                            EEclass_soluteContacts,
303
                            level,
304
                            atom_name,
305
                            atom_resnameLevel,
306
                            N_H,
307
                            atom_num,
308
                            nearest_resnameLevel,
309
                            RADshell_num_dist,
310
                            waterTuple,
311
                            UAweightedForces,
312
                            UAweightedTorques,
313
                            PE,
314
                            KE,
315
                            MweightedForces,
316
                            MweightedTorques,
317
                            Ndih,
318
                            molecule_UA_F,
319
                            molecule_UA_T,
320
                            weight,
321
                        )
322

NEW
323
                        SconfPopulation(
×
324
                            EEclass_soluteContacts,
325
                            nearest_resnameLevel,
326
                            atom_name,
327
                            atom_resnameLevel,
328
                            N_H,
329
                            dihedral_phi_list,
330
                            molecule_size,
331
                            RADshell_num_dist,
332
                            weight,
333
                        )
334

NEW
335
                if level in ["atomLevel"]:
×
336

337
                    if entropyEnergy:
×
338

NEW
339
                        contactPopulationUA(
×
340
                            EEclass_atomLevel,
341
                            RAD_nAtoms,
342
                            atom_name,
343
                            atom_resnameLevel,
344
                            atom_resid,
345
                            waterTuple,
346
                            weight,
347
                        )
348

NEW
349
                        SorPopulation(
×
350
                            EEclass_atomLevel,
351
                            atom_name,
352
                            atom_resnameLevel,
353
                            nearest_resnameLevel,
354
                            RAD_str,
355
                            RADshell_num,
356
                            RADshell_num_dist,
357
                            waterTuple,
358
                            N_H,
359
                            As,
360
                            Ds,
361
                            weight,
362
                        )
363

NEW
364
                        SvibPopulation(
×
365
                            EEclass_atomLevel,
366
                            level,
367
                            atom_name,
368
                            atom_resnameLevel,
369
                            N_H,
370
                            atom_num,
371
                            nearest_resnameLevel,
372
                            RADshell_num_dist,
373
                            waterTuple,
374
                            UAweightedForces,
375
                            UAweightedTorques,
376
                            PE,
377
                            KE,
378
                            MweightedForces,
379
                            MweightedTorques,
380
                            Ndih,
381
                            molecule_UA_F,
382
                            molecule_UA_T,
383
                            weight,
384
                        )
385

NEW
386
                        SconfPopulation(
×
387
                            EEclass_atomLevel,
388
                            nearest_resnameLevel,
389
                            atom_name,
390
                            atom_resnameLevel,
391
                            N_H,
392
                            dihedral_phi_list,
393
                            molecule_size,
394
                            RADshell_num_dist,
395
                            weight,
396
                        )
397

NEW
398
    sys.stdout.flush()
×
399

NEW
400
    return (
×
401
        EEclass,
402
        EEclass_residLevel_resname,
403
        EEclass_soluteContacts,
404
        EEclass_atomLevel,
405
        atom_count,
406
    )
407

408

409
def getWeight(EEclass, globalFrame):
×
410
    """
411
    Find out what the weighting is for a given simualtion frame
412
    """
413

414
    # chunk = int(EEclass.weighting_chunks)
415
    weighting_list = EEclass.weighting_list
×
416

NEW
417
    index = globalFrame - 1
×
418
    try:
×
419
        weight = float(weighting_list[index])
×
420
        # print('weight: %s' % (weight))
421
    except (IndexError, ValueError):
×
422
        weight = 1
×
423

424
    # print(globalFrame, index, weight)
425

426
    return weight
×
427

428

429
def stripNumbers(atom_name, atom_resname):
×
430
    """ """
431

NEW
432
    atom_name_letters = "".join([i for i in atom_name if not i.isdigit()])
×
433
    if atom_name != atom_resname:
×
434
        atom_name_letters = atom_name_letters[0]
×
NEW
435
    atom_resname = "%s_%s" % (atom_resname, atom_name_letters)
×
436

437
    return atom_resname
×
438

439

NEW
440
def levelSelection(
×
441
    level,
442
    atom_resname,
443
    atom_resid,
444
    nearest_resname,
445
    nearest_resname_list,
446
    atom_name,
447
    nearest_atomName,
448
    nearest_resid,
449
    RAD_nAtoms,
450
    waterTuple,
451
):
452
    """
453
    Depending on what level of analysis we want to do, dictionaries are
454
    populated according to how the nearest and assigned are defined.
455

456
    For example, we may want to analyse molecule types, the atoms
457
    in each molecule, molecules by residue number or multiple solutes
458
    in a RAD shell as a list of nearest molecules.
459
    """
460

461
    # keep as molecule
NEW
462
    if level == "moleculeLevel" or level is None:
×
463
        atom_resname = atom_resname
×
464
        nearest_resname_list = [nearest_resname]
×
465

466
    # use resname_atomName for both nearest and assigned
NEW
467
    if level == "atomLevel":  # res_atomLevel
×
468
        #
469
        water = False
×
470
        if atom_resname in waterTuple:
×
471
            water = True
×
472
        atom_resname = stripNumbers(atom_name, atom_resname)
×
473
        if atom_resname not in waterTuple and water:
×
474
            waterTuple.append(atom_resname)
×
NEW
475
        nearest_resname_list = [stripNumbers(nearest_atomName, nearest_resname)]
×
476

477
        #
478

NEW
479
    """
×
480
    ###Inclusion of atom names, no edits
481
    if level == 'atomLevel':
482
        atom_resname = ('%s_%s' % (atom_resname, atom_name))
483
        nearest_resname_list = [('%s_%s' % (nearest_resname,
484
                nearest_atomName))]
485
    """
486

487
    # Inclusion of molecule resid
NEW
488
    if level == "residLevel_resname":
×
489
        atom_resname = atom_resname
×
490
        if atom_resname not in waterTuple:
×
NEW
491
            atom_resname = "%s_%s" % (atom_resname, atom_resid)
×
NEW
492
        nearest_resname_list = ["%s_%s" % (nearest_resname, nearest_resid)]
×
493
        # print(atom_resname, nearest_resname_list)
494

495
    # Inclusion of molecule resid
NEW
496
    if level == "residLevel_atom":
×
NEW
497
        atom_resname = "%s_%s" % (atom_resname, atom_name)
×
NEW
498
        nearest_resname_list = ["%s_%s" % (nearest_resname, nearest_resid)]
×
499

NEW
500
    if level == "soluteContacts":
×
501
        atom_resname = atom_resname
×
502
        if atom_resname in waterTuple:
×
NEW
503
            if RAD_nAtoms is not None:
×
504
                name_id_list = []
×
505
                for nInfo in RAD_nAtoms:
×
506
                    nResid = nInfo[1]
×
507
                    nResname = nInfo[2]
×
508

509
                    if nResname not in waterTuple:
×
NEW
510
                        name_id = "%s_%s" % (nResname, nResid)
×
511
                        name_id_list.append(name_id)
×
512

513
                name_id_list = sorted(name_id_list)
×
514

515
                if len(name_id_list) > 1:
×
516
                    for solute in name_id_list:
×
517
                        list2 = name_id_list[:]
×
518
                        list2.remove(solute)
×
519
                        for solute2 in list2:
×
NEW
520
                            if (
×
521
                                "%s_%s" % (solute, solute2)
522
                            ) not in nearest_resname_list:
523
                                nearest_resname_list.append(
×
524
                                    ("%s_%s" % (solute, solute2))
525
                                )
526

527
    return atom_resname, nearest_resname_list, waterTuple
×
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