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

3
# import logging
NEW
4
import math
×
5

6
# import sys
NEW
7
from collections import Counter, defaultdict
×
8

9
import numpy as np
×
10
import pandas as pd
×
11
from numpy import linalg as LA
×
12

13
from CodeEntropy.FunctionCollection import Utils
×
14

15

NEW
16
def nested_dict():
×
NEW
17
    return defaultdict(nested_dict)
×
18

19

20
# create nested dict in one go
21

22

NEW
23
def processEE(
×
24
    num_frames,
25
    totFrames,
26
    Aclass,
27
    solvent,
28
    waterTuple,
29
    temperature,
30
    level,
31
    name,
32
    forceUnits,
33
    verbosePrint,
34
):
35
    """
36
    Populate and process Smix and Sor into global dictionaries
37
    """
38

NEW
39
    verbosePrint("\n\n---ANALYSIS_TYPE_%s---\n" % (name))
×
NEW
40
    verbosePrint("\n\n---ORIENTATIONAL_ENTROPY_CALCULATIONS---\n")
×
NEW
41
    if any(i in solvent for i in waterTuple) is True:
×
NEW
42
        SorCalculation(Aclass, "Sor_test2", level, waterTuple, verbosePrint)
×
43

NEW
44
    verbosePrint("\n\n --UA_VIBRATIONAL_ENTROPY--\n")
×
45
    SvibCalculations(totFrames, Aclass, temperature, forceUnits, verbosePrint)
×
NEW
46
    verbosePrint("\n\n --WM_VIBRATIONAL_ENTROPY--\n")
×
NEW
47
    WMSvibCalculations(Aclass, totFrames, temperature, forceUnits, verbosePrint)
×
48

NEW
49
    verbosePrint("\n\n --WM_CONFORMATIONAL_ENTROPY(DIH)--\n")
×
50
    process_dihedrals(Aclass, verbosePrint)
×
51

NEW
52
    verbosePrint("\n\n--PRINT_ALL_VARIABLES--\n")
×
53
    # solventData, soluteData = saveAllVariables(
54
    #     num_frames, Aclass, level, name, solvent, waterTuple, verbosePrint
55
    # )
NEW
56
    solventData, soluteData = saveAllVariables(
×
57
        num_frames, Aclass, level, name, solvent, waterTuple, verbosePrint
58
    )
59

NEW
60
    if level in ["residLevel_resname", "atomLevel"]:
×
NEW
61
        verbosePrint("\n\n--CONTACTS--\n")
×
62
        # contactMatrix = contactCalculation(Aclass, level, totFrames, verbosePrint)
63
        contactMatrix = contactCalculation(Aclass, level, totFrames, verbosePrint)
×
64

NEW
65
        return {
×
66
            "solventData": solventData,
67
            "soluteData": soluteData,
68
            "contactMatrix": contactMatrix,
69
        }
70

NEW
71
    return {"solventData": solventData, "soluteData": soluteData}
×
72

73

74
def contactCalculation(Aclass, level, totFrames, verbosePrint):
×
75
    """
76
    resid matrix of RAD contacts between resids that are not water and
77
    the nearest non-like to it.
78
    """
79

NEW
80
    verbosePrint("\n*******_RESID_CONTACTS_**********\n")
×
81
    # data = open('resid_contact_matrix_%s.csv' % (level), 'w')
NEW
82
    contact_matrix_name = f"resid_contact_matrix_{level}.csv"
×
NEW
83
    if level == "atomLevel":
×
84
        # data.write('\n'.join(['centre_resid,neighbour_resid,count,'\
85
        #         'centre_resname,neighbour_resname,centre_atom,'\
86
        #         'neighbour_atom'])
87
        #         + '\n')
NEW
88
        Utils.printOut(
×
89
            contact_matrix_name,
90
            "centre_resid,"
91
            "neighbour_resid,"
92
            "count,"
93
            "centre_resname,"
94
            "neighbour_resname,"
95
            "centre_atom,"
96
            "neighbour_atom",
97
        )
NEW
98
        contactMatrix = pd.DataFrame(
×
99
            columns=[
100
                "centre_resid",
101
                "neighbour_resid",
102
                "count",
103
                "centre_resname",
104
                "neighbour_resname",
105
                "centre_atom",
106
                "neighbour_atom",
107
            ]
108
        )
109
    else:
110
        # data.write('\n'.join(['centre_resid,neighbour_resid,count,'\
111
        #         'centre_resname,neighbour_resname'])
112
        #         + '\n')
NEW
113
        Utils.printOut(
×
114
            contact_matrix_name,
115
            "centre_resid,neighbour_resid,count,centre_resname,neighbour_resname",
116
        )
NEW
117
        contactMatrix = pd.DataFrame(
×
118
            columns=[
119
                "centre_resid",
120
                "neighbour_resid",
121
                "count",
122
                "centre_resname",
123
                "neighbour_resname",
124
            ]
125
        )
NEW
126
    for centre_info, neighbour_resid_key in sorted(
×
127
        list(Aclass.resid_contact_matrix_dict.items())
128
    ):
NEW
129
        for neighbour_info, count in sorted(list(neighbour_resid_key.items())):
×
130
            # verbosePrint(centre_info, neighbour_info, count)
131
            if count > 0:
×
NEW
132
                if level == "atomLevel":
×
133
                    centre_atom = centre_info[0]
×
134
                    centre_resname = centre_info[1]
×
135
                    centre_resid = centre_info[2]
×
136
                    neighbour_atom = neighbour_info[0]
×
137
                    neighbour_resname = neighbour_info[1]
×
138
                    neighbour_resid = neighbour_info[2]
×
139
                    count = float(count) / float(totFrames)
×
140
                    # data.write('\n'.join(['%s,%s,%s,%s,%s,%s,%s'
141
                    #         % (centre_resid,
142
                    #         neighbour_resid, count, centre_resname,
143
                    #         neighbour_resname, centre_atom,
144
                    #         neighbour_atom)]) + '\n')
NEW
145
                    Utils.printOut(
×
146
                        contact_matrix_name,
147
                        (
148
                            f"{centre_resid},{neighbour_resid},{count},"
149
                            f"{centre_resname},{neighbour_resname},"
150
                            f"{centre_atom},{neighbour_atom}"
151
                        ),
152
                    )
NEW
153
                    newRowContact = pd.DataFrame(
×
154
                        {
155
                            "centre_resid": centre_resid,
156
                            "neighbour_resid": neighbour_resid,
157
                            "count": count,
158
                            "centre_resname": centre_resname,
159
                            "neighbour_resname": neighbour_resname,
160
                            "centre_atom": centre_atom,
161
                            "neighbour_atom": neighbour_atom,
162
                        },
163
                        index=[0],
164
                    )
NEW
165
                    contactMatrix = pd.concat(
×
166
                        [contactMatrix, newRowContact], ignore_index=True
167
                    )
168
                else:
169
                    centre_resname = centre_info[0]
×
170
                    centre_resid = centre_info[1]
×
171
                    neighbour_resname = neighbour_info[0]
×
172
                    neighbour_resid = neighbour_info[1]
×
173
                    count = float(count) / float(totFrames)
×
174
                    # data.write('\n'.join(['%s,%s,%s,%s,%s' % (centre_resid,
175
                    #         neighbour_resid, count, centre_resname,
176
                    #         neighbour_resname)]) + '\n')
NEW
177
                    Utils.printOut(
×
178
                        contact_matrix_name,
179
                        (
180
                            f"{centre_resid},{neighbour_resid},"
181
                            f"{count},{centre_resname},"
182
                            f"{neighbour_resname}"
183
                        ),
184
                    )
NEW
185
                    newRowContact = pd.DataFrame(
×
186
                        {
187
                            "centre_resid": centre_resid,
188
                            "neighbour_resid": neighbour_resid,
189
                            "count": count,
190
                            "centre_resname": centre_resname,
191
                            "neighbour_resname": neighbour_resname,
192
                        },
193
                        index=[0],
194
                    )
NEW
195
                    contactMatrix = pd.concat(
×
196
                        [contactMatrix, newRowContact], ignore_index=True
197
                    )
198
            else:
199
                continue
×
200

201
    # data.close()
202
    return contactMatrix
×
203

204

205
def SorCalculation(Aclass, methodType, level, waterTuple, verbosePrint):
×
206
    """ """
207

208
    # por_dict = nested_dict()
209
    shells_ppD_ppA_dict = nested_dict()
×
NEW
210
    verbosePrint("\n\n__ORIENTATIONAL_ENTROPY_%s" % (methodType))
×
NEW
211
    num_molecules0 = sum(
×
212
        count
213
        for atomType in Aclass.RADshell_Sor_dict.values()
214
        # for Nc in atomType.values()
215
        for RADshell_num in atomType.values()
216
        for RAD_str in RADshell_num.values()
217
        for ADs in RAD_str.values()
218
        for key, HBcount in ADs.items()
219
        for HB, count in HBcount.items()
220
        if key == "D"
221
    )
NEW
222
    verbosePrint("\nall molecule count:", num_molecules0)
×
NEW
223
    S1 = 0
×
NEW
224
    for nearest, assigned_key in sorted(list(Aclass.RADshell_Sor_dict.items())):
×
NEW
225
        num_molecules1 = sum(
×
226
            count
227
            # for Nc in assigned_key.values()
228
            for RADshell_num in assigned_key.values()
229
            for RAD_str in RADshell_num.values()
230
            for ADs in RAD_str.values()
231
            for AD, HBcount in ADs.items()
232
            for HB, count in HBcount.items()
233
            if AD == "D"
234
        )
235

NEW
236
        nearest_resname = nearest.split("_")[0]
×
NEW
237
        verbosePrint(
×
238
            "\n\nnearest:", nearest, "count:", num_molecules1, "/", num_molecules0
239
        )
240

241
        S2 = 0
×
242
        for assigned, shell_num_key in sorted(list(assigned_key.items())):
×
NEW
243
            num_molecules2 = sum(
×
244
                count
245
                # for RADshell_num in Nc_key.values()
246
                for RAD_str in shell_num_key.values()
247
                for ADs in RAD_str.values()
248
                for AD, HBcount in ADs.items()
249
                for HB, count in HBcount.items()
250
                if AD == "D"
251
            )
252

253
            # assigned_resname = assigned[0].split("_")[0]
NEW
254
            verbosePrint(
×
255
                "\tassigned:", assigned, "count:", num_molecules2, "/", num_molecules1
256
            )
257
            N_H = assigned[1]
×
NEW
258
            verbosePrint("\tN_H", N_H)
×
259
            S4 = 0
×
NEW
260
            for shell_num, RADlist_key in sorted(list(shell_num_key.items())):
×
261

NEW
262
                num_molecules4 = sum(
×
263
                    count
264
                    for ADs in RADlist_key.values()
265
                    for AD, HBcount in ADs.items()
266
                    for HB, count in HBcount.items()
267
                    if AD == "D"
268
                )
269

NEW
270
                verbosePrint(
×
271
                    "\t\t\tshell_num:",
272
                    shell_num[0],
273
                    "count:",
274
                    num_molecules4,
275
                    "/",
276
                    num_molecules2,
277
                )
278
                S5 = 0
×
279
                S_shell = 0
×
280
                ave_pbias_ave = 0
×
281
                ave_Nc_eff = 0
×
282

NEW
283
                for RADlist, AD_key in sorted(list(RADlist_key.items())):
×
NEW
284
                    verbosePrint("\t" * 4, "-----RADshell------")
×
NEW
285
                    num_molecules5 = sum(
×
286
                        count
287
                        for AD, HBcount in AD_key.items()
288
                        for HB, count in HBcount.items()
289
                        if AD == "D"
290
                    )
291

292
                    # dict for p(c) log p(c)
NEW
293
                    if (
×
294
                        methodType == "Sor_test2"
295
                        and level == "moleculeLevel"
296
                        and assigned[0] in waterTuple
297
                        and int(shell_num[0]) == 1
298
                    ):
299
                        newRADlist = []
×
300
                        for n in RADlist:
×
NEW
301
                            if n == "0":
×
302
                                newRADlist.append(nearest_resname)
×
303
                            else:
304
                                newRADlist.append(n)
×
305
                        newRADlist = tuple(sorted(newRADlist))
×
306
                        try:
×
NEW
307
                            if newRADlist not in Aclass.p_coord_dict[len(RADlist)]:
×
NEW
308
                                Aclass.p_coord_dict[len(RADlist)][newRADlist] = 0
×
NEW
309
                            Aclass.p_coord_dict[len(RADlist)][
×
310
                                newRADlist
311
                            ] += num_molecules5
312
                        except AttributeError:
×
313
                            pass
×
314

NEW
315
                    RAD_l = "%s" % (",".join(map(str, RADlist)))
×
NEW
316
                    verbosePrint(
×
317
                        "\t\t\t\tneighbours:",
318
                        RAD_l,
319
                        "Nc:",
320
                        len(RADlist),
321
                        "count:",
322
                        num_molecules5,
323
                        "/",
324
                        num_molecules4,
325
                    )
326
                    S6 = 0
×
327
                    Sor_list = []
×
328
                    pbias_ave = 0
×
329
                    Nc_eff = 0
×
330

NEW
331
                    if methodType == "Sor_test2":
×
332
                        D_values = None
×
333
                        A_values = None
×
NEW
334
                        for AD, values in sorted(list(AD_key.items())):
×
NEW
335
                            if AD == "D":
×
336
                                D_values = values
×
NEW
337
                            if AD == "A":
×
338
                                A_values = values
×
NEW
339
                        verbosePrint("\t" * 4, "* SEPARATE ADs *")
×
NEW
340
                        S7, pbias_ave, Nc_eff, ppD_ppA_dict = RAD_or_entropyCalc_test2(
×
341
                            RADlist,
342
                            D_values,
343
                            A_values,
344
                            N_H,
345
                            shell_num[1],
346
                            num_molecules5,
347
                            nearest_resname,
348
                            waterTuple,
349
                            verbosePrint,
350
                        )
351

352
                        # ppD_ppA_dict population
353
                        for c in range(0, int(num_molecules5)):
×
354
                            for i, pp in ppD_ppA_dict.items():
×
355
                                ppD = pp[0]
×
356
                                ppA = pp[1]
×
NEW
357
                                if (
×
358
                                    i
359
                                    not in shells_ppD_ppA_dict[nearest][assigned][
360
                                        float(shell_num[0])
361
                                    ]
362
                                ):
NEW
363
                                    shells_ppD_ppA_dict[nearest][assigned][
×
364
                                        float(shell_num[0])
365
                                    ][i] = [0, 0, 0]
NEW
366
                                ppD_stored = shells_ppD_ppA_dict[nearest][assigned][
×
367
                                    float(shell_num[0])
368
                                ][i][0]
NEW
369
                                ppA_stored = shells_ppD_ppA_dict[nearest][assigned][
×
370
                                    float(shell_num[0])
371
                                ][i][1]
NEW
372
                                count_stored = shells_ppD_ppA_dict[nearest][assigned][
×
373
                                    float(shell_num[0])
374
                                ][i][2]
375

376
                                count_add = count_stored + 1
×
NEW
377
                                ppD_add = (ppD + ppD_stored * count_stored) / float(
×
378
                                    count_add
379
                                )
NEW
380
                                ppA_add = (ppA + ppA_stored * count_stored) / float(
×
381
                                    count_add
382
                                )
383

NEW
384
                                shells_ppD_ppA_dict[nearest][assigned][
×
385
                                    float(shell_num[0])
386
                                ][i][0] = ppD_add
NEW
387
                                shells_ppD_ppA_dict[nearest][assigned][
×
388
                                    float(shell_num[0])
389
                                ][i][1] = ppA_add
NEW
390
                                shells_ppD_ppA_dict[nearest][assigned][
×
391
                                    float(shell_num[0])
392
                                ][i][2] = count_add
393

NEW
394
                        Sor_list.append([S7, "DA"])
×
NEW
395
                        verbosePrint("\t\t\t\tS7_DA = ", round(S7, 3))
×
396

397
                    Sor_list = sorted(Sor_list)
×
398
                    verbosePrint()
×
NEW
399
                    verbosePrint("\t" * 4, "*** Sor-list:")
×
400
                    c = 0
×
401
                    for s, label in Sor_list:
×
402
                        c += 1
×
403
                        if c == 1:
×
NEW
404
                            verbosePrint(
×
405
                                "\t" * 4, round(s, 3), label, "<-- selected Sor"
406
                            )
407
                        else:
NEW
408
                            verbosePrint("\t" * 4, round(s, 3), label)
×
409
                    # use smallest Sor as selected value
NEW
410
                    S6 += Sor_list[0][0] * float(num_molecules5) / float(num_molecules4)
×
NEW
411
                    S_shell += (
×
412
                        Sor_list[0][0] * float(num_molecules5) / float(num_molecules4)
413
                    )
NEW
414
                    ave_pbias_ave += (
×
415
                        pbias_ave * float(num_molecules5) / float(num_molecules4)
416
                    )
417

NEW
418
                    ave_Nc_eff += Nc_eff * float(num_molecules5) / float(num_molecules4)
×
419

NEW
420
                    if methodType == "Sor_test2":
×
NEW
421
                        Aclass.Sor_reference_dict[nearest][assigned[0]][
×
422
                            str(shell_num[0])
423
                        ][RADlist] = (Sor_list[0][0] * 8.314)
424
                        # print(RADlist, Sor_list[0][0] * 8.314)
425

NEW
426
                    verbosePrint("\t\t\t\tS6 = ", round(S6, 3))
×
427
                    verbosePrint()
×
NEW
428
                    S5 += S6 * float(num_molecules4) / float(num_molecules2)
×
429

NEW
430
                Aclass.allVariables_dict[nearest][assigned][float(shell_num[0])][
×
431
                    "%s" % (methodType)
432
                ] = (S_shell * 8.314, num_molecules4)
433

NEW
434
                """
×
435
                if methodType == 'Sor_test2':
436
                    Aclass.allVariables_dict[nearest][assigned]\
437
                            [float(shell_num[0])]\
438
                            ['pbias_ave_%s' % (methodType)] = \
439
                            ave_pbias_ave, num_molecules4
440

441
                    Aclass.allVariables_dict[nearest][assigned]\
442
                            [float(shell_num[0])]\
443
                            ['Nc_eff_%s' % (methodType)] = \
444
                            ave_Nc_eff, num_molecules4
445
                """
446

NEW
447
                verbosePrint("\t\t\tS5 = ", round(S5, 3))
×
NEW
448
                S4 += S5 * float(num_molecules4) / float(num_molecules2)
×
449

NEW
450
            verbosePrint("\t\tS4 = ", round(S4, 3))
×
NEW
451
            S2 += S4 * float(num_molecules1) / float(num_molecules0)
×
452

NEW
453
        verbosePrint("\tS2 = ", round(S2, 3))
×
454
        S1 += S2
×
NEW
455
    verbosePrint("S1 = ", round(S1, 3))
×
456

NEW
457
    if methodType == "Sor_test2":
×
NEW
458
        verbosePrint("\n\n__ppX_ORIENTATIONAL_ENTROPY_%s" % (methodType))
×
NEW
459
        verbosePrint("nearest,assigned,shell_num,i,ppD,ppA,count")
×
460
        for nearest, assigned_key in sorted(list(shells_ppD_ppA_dict.items())):
×
461
            for assigned, shell_num_key in sorted(list(assigned_key.items())):
×
462
                for shell_num, i_key in sorted(list(shell_num_key.items())):
×
463
                    for i, pp in sorted(list(i_key.items())):
×
464
                        ppD, ppA, count = pp[0], pp[1], pp[2]
×
NEW
465
                        verbosePrint(
×
466
                            "%s,%s,%s,%s,%s,%s,%s"
467
                            % (
468
                                nearest,
469
                                assigned[0],
470
                                int(shell_num),
471
                                i,
472
                                round(ppD, 5),
473
                                round(ppA, 5),
474
                                count,
475
                            )
476
                        )
477

478

NEW
479
def RAD_or_entropyCalc_test2(
×
480
    shell,
481
    shellD,
482
    shellA,
483
    N_H,
484
    shell_num,
485
    referenceCount,
486
    nearest,
487
    waterTuple,
488
    verbosePrint,
489
):
490
    """
491
    ***** S_or
492
    """
493

494
    # get info about shell
NEW
495
    shellCount = Counter([str(N) for N in shell])
×
496
    # count constituents in shell
497
    Nc = sum(shellCount.values())
×
498
    Nc_solvent_only = 0
×
499
    for n in shell:
×
NEW
500
        if n == "X":
×
501
            Nc_solvent_only += 1
×
502
        else:
503
            try:
×
504
                n = int(n)
×
505
                if n != 0:
×
506
                    Nc_solvent_only += 1
×
507
                else:
508
                    continue
×
509
            except ValueError:
×
510
                pass
×
511

512
    soluteA_pi, soluteD_pi = None, None
×
513
    pA_degen_dict, pD_degen_dict = None, None
×
NEW
514
    for AD, shellDs in [["A", shellA], ["D", shellD]]:
×
NEW
515
        verbosePrint("\t" * 5, "__%s__" % (AD))
×
516
        # get info about shell
NEW
517
        shellCount = Counter([str(N) for N in shell])
×
518
        # count constituents in shell
519
        Dcount = Counter([tuple(Ds) for Ds in shellDs])
×
520
        num_orients = len(shellDs)
×
521

522
        solute_donor = False
×
523
        solvent_donor = False
×
524

525
        for ds in shellDs:
×
526
            for d in ds:
×
527
                try:
×
528
                    d = int(d)
×
529
                    if d == 0:
×
530
                        solute_donor = True
×
531
                    else:
532
                        continue
×
533
                except ValueError:
×
NEW
534
                    if d in ["X", "H"]:
×
535
                        solvent_donor = True
×
536
                    else:
537
                        solute_donor = True
×
538

539
        # pi only, degeneracy info for each orientation type observed
540
        i_counts_dict = {}
×
541
        tot_i_count = 0
×
542
        for donors, count in Dcount.items():
×
543
            for i in donors:
×
544
                if i not in i_counts_dict:
×
NEW
545
                    i_counts_dict[i] = 0
×
546
                i_counts_dict[i] += count
×
547
                tot_i_count += count
×
548

NEW
549
        verbosePrint("\t" * 5, "--i--")
×
550
        for i, count in i_counts_dict.items():
×
NEW
551
            verbosePrint("\t" * 5, i, count)
×
NEW
552
        verbosePrint("\t" * 5, "sum i counts:", tot_i_count)
×
553

554
        pi_degen_dict = {}
×
555
        solute_pis = 0
×
556
        largest_pi = 0
×
557
        ww_Ds = 0
×
558
        for i, count in i_counts_dict.items():
×
559
            degeneracy = shellCount[i]
×
560
            if degeneracy == 0:
×
561
                degeneracy = 1
×
562
            pi = (float(count) / float(tot_i_count)) / float(degeneracy)
×
563
            pi_degen_dict[i] = [pi, degeneracy, count]
×
NEW
564
            verbosePrint(
×
565
                "\t" * 6,
566
                "pi",
567
                i,
568
                round(pi, 4),
569
                "degen:",
570
                degeneracy,
571
                "pi_d:",
572
                round((pi * degeneracy), 4),
573
            )
574
            # verbosePrint(i, pi)
575
            if pi * degeneracy > largest_pi:
×
576
                largest_pi = pi * degeneracy
×
577

578
            solute_pi, solvent_pi = False, False
×
579
            try:
×
580
                i = int(i)
×
581
                if i == 0 and nearest not in waterTuple:
×
582
                    solute_pi = True
×
583
                else:
584
                    ww_Ds += count
×
585
                    continue
×
586
            except ValueError:
×
NEW
587
                if i in ["X", "H"]:
×
588
                    solvent_pi = True
×
589
                    ww_Ds += count
×
590
                else:
591
                    solute_pi = True
×
NEW
592
            if solute_pi is True:
×
593
                solute_pis += pi * degeneracy
×
594

595
        # calculate number of observed orientations
596
        # pi_max = max(map(lambda x: x[0], pi_degen_dict.values()))
597
        # verbosePrint('\t'*6, 'pi_max', round(pi_max, 5))
598

599
        # verbosePrint(ww_Ds, referenceCount)
600
        # per_w_Ds = ww_Ds / float(referenceCount)
601

NEW
602
        if AD == "A":
×
603
            pA_degen_dict = pi_degen_dict
×
NEW
604
        if AD == "D":
×
605
            pD_degen_dict = pi_degen_dict
×
606

607
        # pij, degeneracy info for each orientation type observed
NEW
608
        verbosePrint("\t" * 5, "--ij--")
×
609
        pij_degen_dict = {}
×
610
        for donors, count in Dcount.items():
×
NEW
611
            verbosePrint("\t" * 5, donors, count)
×
612
            donor_constituents = Counter([str(dc) for dc in donors])
×
613
            degeneracy = 1
×
614
            sum_weight = 0
×
615
            for dc, count2 in donor_constituents.items():
×
616
                if count2 == N_H and N_H != 1:
×
617
                    degeneracy = 0
×
NEW
618
                    for num in range(shellCount[dc] - (N_H - 1), 0, -1):
×
619
                        degeneracy += num
×
620
                if N_H == 1:
×
621
                    degeneracy = shellCount[dc]
×
622
                if count2 != N_H and N_H != 1:
×
623
                    degeneracy *= shellCount[dc]
×
624

625
            if degeneracy == 0:
×
626
                degeneracy = 1
×
627
            pij = (float(count) / float(num_orients)) / float(degeneracy)
×
628
            pij_degen_dict[donors] = [pij, degeneracy, sum_weight]
×
629

NEW
630
        verbosePrint("\t" * 5, "sum pair counts:", num_orients)
×
631

632
        solute_pijs = 0
×
633
        largest_pij = 0
×
634
        for donors, pij in pij_degen_dict.items():
×
NEW
635
            verbosePrint(
×
636
                "\t" * 6,
637
                "pij",
638
                donors,
639
                round(pij[0], 4),
640
                "degen:",
641
                pij[1],
642
                "pij_d:",
643
                round((pij[0] * pij[1]), 4),
644
            )
645
            solute_pij, solvent_pij = False, False
×
646
            for d in donors:
×
647
                try:
×
648
                    d = int(d)
×
649
                    if d == 0:
×
650
                        solute_pij = True
×
651
                    else:
652
                        continue
×
653
                except ValueError:
×
NEW
654
                    if d in ["X", "H"]:
×
655
                        solvent_pij = True
×
656
                    else:
657
                        solute_pij = True
×
NEW
658
            if solute_pij is True:
×
659
                solute_pijs += pij[0] * pij[1]
×
660

661
            if pij[0] * pij[1] > largest_pij:
×
662
                largest_pij = pij[0] * pij[1]
×
663

664
        # calculate number of observed orientations
665
        pij_max = max(map(lambda x: x[0], pij_degen_dict.values()))
×
NEW
666
        verbosePrint("\t" * 6, "pij_max", round(pij_max, 5))
×
667

668
        por_list = []
×
669
        omega_obs = 0
×
670
        for donors, pij in pij_degen_dict.items():
×
671
            om = (float(pij[0]) / float(pij_max)) * pij[1]
×
672
            por_list.append((donors, om))
×
673
            omega_obs += om
×
674

NEW
675
        if AD == "D":
×
676
            soluteD_pi = solute_pis
×
NEW
677
        if AD == "A":
×
678
            soluteA_pi = solute_pis
×
679

NEW
680
        verbosePrint("\t" * 6, "solute_donor", solute_donor)
×
NEW
681
        verbosePrint("\t" * 6, "Nc, Nc_solvent_only", Nc, Nc_solvent_only)
×
NEW
682
        verbosePrint("\t" * 6, "solute_pijs", round(solute_pijs, 3))
×
NEW
683
        verbosePrint("\t" * 6, "solute_pis", round(solute_pis, 3))
×
NEW
684
        verbosePrint("\t" * 6, "largest_pij", round(largest_pij, 3))
×
NEW
685
        verbosePrint("\t" * 6, "largest_pi", round(largest_pi, 3))
×
686

687
    S = 0
×
688
    ppD_ppA_dict = {}
×
689
    pbias_ave = 0
×
690
    Nc_eff = 0
×
691
    if Nc != 0:
×
692
        pbias_list = []
×
693
        for i, N_i in shellCount.items():
×
694
            pD_i, pA_i = 0, 0
×
695
            pD_count, pA_count, pbias = 0, 0, 0
×
696
            if i in pA_degen_dict:
×
697
                pA_i = pA_degen_dict[i][0] * pA_degen_dict[i][1]
×
698
                pA_count = pA_degen_dict[i][2]
×
699

700
            if i in pD_degen_dict:
×
701
                pD_i = pD_degen_dict[i][0] * pD_degen_dict[i][1]
×
702
                pD_count = pD_degen_dict[i][2]
×
703

NEW
704
            verbosePrint(
×
705
                "\t" * 5,
706
                "i",
707
                i,
708
                "N_i",
709
                N_i,
710
                "pA_count",
711
                round(pA_count, 5),
712
                "pD_count",
713
                round(pD_count, 5),
714
            )
NEW
715
            if pD_count != 0 and pA_count != 0:
×
716
                ppD_i = pD_i / float(pD_i + pA_i)
×
717
                ppA_i = pA_i / float(pD_i + pA_i)
×
718
                N_i_eff = ppD_i * ppA_i / float(0.25) * N_i
×
719
                Nc_eff += N_i_eff
×
720
                pbias = ppD_i * ppA_i
×
721
                for x in range(0, N_i):
×
722
                    pbias_list.append(pbias)
×
NEW
723
                verbosePrint(
×
724
                    "\t" * 6,
725
                    "i",
726
                    i,
727
                    "N_i",
728
                    N_i,
729
                    "ppA_i",
730
                    round(ppA_i, 5),
731
                    "ppD_i",
732
                    round(ppD_i, 5),
733
                    "N_i_eff",
734
                    round(N_i_eff, 5),
735
                    "pbias_i",
736
                    round(pbias, 5),
737
                )
738

739
                ppD_ppA_dict[i] = [ppD_i, ppA_i]
×
740
            else:
741
                for x in range(0, N_i):
×
742
                    pbias_list.append(pbias)
×
743
                if pD_count == 0 and pA_count != 0:
×
744
                    ppD_ppA_dict[i] = [0, 1]
×
745
                if pD_count != 0 and pA_count == 0:
×
746
                    ppD_ppA_dict[i] = [1, 0]
×
747
                if pD_count == 0 and pA_count == 0:
×
748
                    ppD_ppA_dict[i] = [0, 0]
×
749

NEW
750
        verbosePrint("\t" * 5, "Nc_eff", round(Nc_eff, 5))
×
751

752
        pbias_ave = 0
×
753
        if len(pbias_list) != 0:
×
754
            pbias_ave = sum(pbias_list) / float(len(pbias_list))
×
755

NEW
756
        verbosePrint("\t" * 5, "pbias_ave", round(pbias_ave, 5))
×
757
        if Nc_eff != 0:
×
NEW
758
            S = np.log((Nc_eff) ** (3 / float(2)) * np.pi**0.5 * pbias_ave / 2)
×
NEW
759
        verbosePrint("\t" * 5, "S3 (test2)", round(S, 5))
×
760

761
        if S < 0:
×
762
            S = 0
×
763

764
    return S, pbias_ave, Nc_eff, ppD_ppA_dict
×
765

766

767
def forceUnitConversion(forceUnits):
×
768
    """
769
    Amber = kcal / mol/ Ang / m^2
770
    Gromacs = kJ / mol / nm / m^2
771
    """
772

773
    # for amber
NEW
774
    force_half = 0.5**2
×
NEW
775
    cal_J = 4184**2
×
NEW
776
    pmol_pmolec = 6.02214086e23**2
×
NEW
777
    A_m = 1e-10**2
×
778
    A = 1e-10
×
779
    gmol_kg = 6.02214086e26
×
780

781
    #
NEW
782
    if forceUnits != "kJ":
×
783
        # top = force_half*cal_J*gmol_kg
784
        top = cal_J * gmol_kg
×
785
        bottom = pmol_pmolec * A_m
×
786
        constant = float(top) / float(bottom)
×
787
    #
788

789
    #
NEW
790
    if forceUnits == "kJ":
×
791
        # for gromacs
792
        nm_m = 1e-9**2
×
793
        nm = 1e-9
×
NEW
794
        kJ_J = 1000**2  # sqrd as force is sqred
×
795
        top = kJ_J * gmol_kg
×
796
        bottom = pmol_pmolec * nm_m
×
797
        constant = float(top) / float(bottom)
×
798
        # constant = 1000
799
    #
800

801
    return constant
×
802

803

804
def SvibCalculations(totFrames, Aclass, temperature, forceUnits, verbosePrint):
×
805
    """
806
    Get rotated forces^2 and torques^2 matrices from allMoleculeList and
807
    group into types.
808
    Then for each molecule type (Nc and extended RAD shell), calc S_vib.
809

810
    Units:
811
    force: Lammps = Kcal/mole-Angstrom, Amber = kcal/mol-Angstrom,
812
        SI = kg.m/s^2 = N
813
    energy: Lammps = Kcal/mole, Amber = Kcal/mole, SI = kg.m^2/s^2 = J(/mol)
814
    covert Kcal/mole to KJ/mole by * 4.184
815

816
    cal to mol = * 4.184
817

818
    240.663461 = (1000/6.022E+23)/(1.38E-23*0.5) to get T from KE (kJ/mol)
819
    """
820

821
    constant = forceUnitConversion(forceUnits)
×
822

823
    for nearest, key2 in Aclass.RADshell_dict.items():
×
NEW
824
        verbosePrint("\nnearest", nearest)
×
825
        for assigned, key3 in key2.items():
×
NEW
826
            verbosePrint("\tassigned", assigned)
×
827

828
            for RADshell_num, values in key3.items():
×
829
                RADshell_num = float(RADshell_num)
×
NEW
830
                verbosePrint("\n\t\tRADshell_num", RADshell_num, "count", values[5])
×
831
                forces = values[0]
×
832
                torques = values[1]
×
833
                pe = values[2]
×
834
                ke = values[3]
×
835
                Temp = values[4]
×
836
                count = values[5]
×
837
                weight = values[6]
×
838
                weightNorm = weight / float(totFrames)
×
839
                countNorm = count / float(totFrames)
×
840
                zpe = 0
×
841

NEW
842
                Strans_qm, Srot_qm, pe_mean, ke_mean, zpe, T = 0, 0, 0, 0, 0, None
×
843

844
                # setting temp here
NEW
845
                T = temperature
×
846

847
                try:
×
848
                    force_sqrd_SI = np.multiply(forces, constant)
×
849
                    Strans_qm, zpe_trans, eigenvalues = Svib_calc(
×
850
                        force_sqrd_SI, T, cov=False, out=False, outputEigenValues=True
851
                    )
852
                    zpe = zpe_trans
×
853
                    verbosePrint(
×
854
                        "\n\t\t\tave forces:\n\t\t\t%s"
855
                        "\n\t\t\t%s\n\t\t\t%s"
856
                        % (force_sqrd_SI[0], force_sqrd_SI[1], force_sqrd_SI[2]),
857
                        "\n\t\t\tStrans",
858
                        Strans_qm,
859
                    )
860

NEW
861
                    verbosePrint("\n\t\t\teigenvalues:\n\t\t\t%s" % (eigenvalues))
×
862

863
                    torque_sqrd_SI = np.multiply(torques, constant)
×
864
                    Srot_qm, zpe_rot, eigenvalues = Svib_calc(
×
865
                        torque_sqrd_SI, T, cov=False, out=False, outputEigenValues=True
866
                    )
867
                    zpe += zpe_rot
×
868
                    verbosePrint(
×
869
                        "\n\t\t\tave torques:\n\t\t\t%s"
870
                        "\n\t\t\t%s\n\t\t\t%s"
871
                        % (torque_sqrd_SI[0], torque_sqrd_SI[1], torque_sqrd_SI[2]),
872
                        "\n\t\t\tSrot",
873
                        Srot_qm,
874
                    )
875

NEW
876
                    verbosePrint("\n\t\t\teigenvalues:\n\t\t\t%s" % (eigenvalues))
×
877

NEW
878
                except (TypeError, ValueError):  # force is a zero
×
879
                    pass
×
880

NEW
881
                pe = pe * 4.184  # kcal to kJ
×
NEW
882
                verbosePrint("\n\t\t\tave pe: ", pe)
×
883
                ke = ke * 4.184
×
NEW
884
                verbosePrint("\n\t\t\tave ke: ", ke)
×
885

NEW
886
                if Strans_qm is not None:
×
887
                    Strans_qm = Strans_qm * 8.314
×
NEW
888
                if Strans_qm is None:
×
889
                    Strans_qm = 0
×
NEW
890
                if Srot_qm is not None:
×
891
                    Srot_qm = Srot_qm * 8.314
×
NEW
892
                if Srot_qm is None:
×
893
                    Srot_qm = 0
×
894

NEW
895
                Aclass.allVariables_dict[nearest][assigned][RADshell_num]["Strans"] = (
×
896
                    Strans_qm,
897
                    count,
898
                )
NEW
899
                Aclass.allVariables_dict[nearest][assigned][RADshell_num]["Srot"] = (
×
900
                    Srot_qm,
901
                    count,
902
                )
903
                if pe != 0 and ke != 0:
×
NEW
904
                    Aclass.allVariables_dict[nearest][assigned][RADshell_num]["PE"] = (
×
905
                        pe,
906
                        count,
907
                    )
NEW
908
                    Aclass.allVariables_dict[nearest][assigned][RADshell_num]["KE"] = (
×
909
                        ke,
910
                        count,
911
                    )
NEW
912
                Aclass.allVariables_dict[nearest][assigned][RADshell_num]["count"] = (
×
913
                    countNorm,
914
                    count,
915
                )
916

917

918
def Svib_calc(matrix_SI, T, cov, out, *args, **kwargs):
×
919
    """
920
    Calculate Svib from matrix with SI units.
921
    """
922

NEW
923
    outputEigenValues = kwargs.get("outputEigenValues", False)
×
NEW
924
    eigenvalues = kwargs.get("eigenvalues", False)
×
925

926
    kB = 1.38064852e-23
×
927
    # if T == None:
928
    # T = 298 #over-write inputted T for now
NEW
929
    T = float(T)  # uses input T
×
NEW
930
    h = 1.0545718e-34  # value of hbar
×
931
    # h = 6.62607004e-34
932
    c = 30000000000
×
NEW
933
    NA = 6.022e23
×
934
    # print(T)
935

936
    # verbosePrint(matrix_SI)
937

NEW
938
    if eigenvalues is False:
×
NEW
939
        if cov is True:
×
940
            eigenvalues, eigenvectors = LA.eig(matrix_SI)
×
NEW
941
        if cov is False:
×
NEW
942
            eigenvalues = matrix_SI.diagonal()  # do this for diagonal only
×
943
            # CHECK
944

NEW
945
    if out is True:
×
NEW
946
        if cov is True:
×
NEW
947
            print(
×
948
                "\n\t\t\teigenvectors:\n\t\t\t%s\n\t\t\t%s\n\t\t\t%s"
949
                % (eigenvectors[0], eigenvectors[1], eigenvectors[2]),
950
                "\n\t\t\teigenvalues:\n\t\t\t%s" % (eigenvalues),
951
            )
NEW
952
        if cov is False:
×
NEW
953
            print("\n\t\t\teigenvalues:\n\t\t\t%s" % (eigenvalues))
×
954

955
    frequencies = []
×
956
    fraction = []
×
957
    sums = []
×
958
    ZPE = []
×
959
    for value in eigenvalues:
×
NEW
960
        w = value / (kB * T)
×
961
        # print('w = ', (w))
962
        # Need to avoid square root of negative number -> NaN results
963
        # If w is positive no problems
964
        if w > 0:
×
NEW
965
            w = w**0.5
×
966
        # If w is very close to zero but on the negative side, we think this is noise
967
        # and using zero should be fine.
968
        elif w > -0.0001:
×
969
            w = 0
×
970
        else:
971
            raise ValueError("Cannot take square root of negative number")
×
972
        frequencies.append(w)
×
973
        zpe = 0.5 * w * h * NA
×
974
        ZPE.append(zpe)
×
975

976
    for freq in frequencies:
×
977
        # this is for qm
NEW
978
        interim = (h * freq) / (kB * T)
×
979
        fraction.append(interim)
×
980

981
    for value in fraction:
×
982
        # verbosePrint(value)
983
        if value != 0:
×
984
            try:
×
NEW
985
                mid = math.exp(value) - 1
×
NEW
986
                mid2 = math.log(1 - math.exp(-value))
×
NEW
987
                mid3 = value / mid - mid2
×
988
                sums.append(mid3)
×
989
            except (ValueError, TypeError, OverflowError):
×
990
                sums.append(0)
×
991
        else:
992
            sums.append(0)
×
993

994
    S_qm = sum(sums)
×
995
    ZPE_qm = sum(ZPE)
×
996
    # Svib_qm = NA * kB * S_qm
997
    Svib_qm = S_qm
×
998

NEW
999
    if outputEigenValues is True:
×
1000
        return Svib_qm, ZPE_qm, eigenvalues
×
1001
    else:
1002
        return Svib_qm, ZPE_qm
×
1003

1004

NEW
1005
def WMSvibCalculations(Aclass, totFrames, temperature, forceUnits, verbosePrint):
×
1006
    """
1007
    Get forces and torques for molecule and UA levels with
1008
    shells as x
1009
    """
1010

NEW
1011
    for nearest, resname_Ndih_key in sorted(list(Aclass.WM_FT_shell_dict.items())):
×
NEW
1012
        if "Any" in nearest:
×
NEW
1013
            verbosePrint("\n\n\n***** NEAREST: %s *****" % (nearest))
×
NEW
1014
            for resname_Ndih, shellNum_key in sorted(list(resname_Ndih_key.items())):
×
1015
                resname = resname_Ndih[0]
×
NEW
1016
                for RADshellDist, values in sorted(list(shellNum_key.items())):
×
NEW
1017
                    verbosePrint(
×
1018
                        "\n\n\n***** SHELL_NUM or DIST: %s *****" % (RADshellDist)
1019
                    )
1020
                    RADshellDist = float(RADshellDist)
×
1021
                    count = values[7]
×
1022
                    # countNorm = count / float(totFrames)
NEW
1023
                    Svib_qm, Strans_qm, Srot_qm, Strans_qm_UA, Srot_qm_UA, T_mean = (
×
1024
                        process_FT(
1025
                            Aclass,
1026
                            nearest,
1027
                            resname_Ndih,
1028
                            values,
1029
                            temperature,
1030
                            forceUnits,
1031
                            verbosePrint,
1032
                        )
1033
                    )
1034

NEW
1035
                    Aclass.allVariables_dict[nearest][resname][RADshellDist][
×
1036
                        "WM_Strans"
1037
                    ] = (Strans_qm * 8.314, count)
NEW
1038
                    Aclass.allVariables_dict[nearest][resname][RADshellDist][
×
1039
                        "WM_Srot"
1040
                    ] = (Srot_qm * 8.314, count)
NEW
1041
                    Aclass.allVariables_dict[nearest][resname][RADshellDist][
×
1042
                        "WM_UA_Strans"
1043
                    ] = (Strans_qm_UA * 8.314, count)
NEW
1044
                    Aclass.allVariables_dict[nearest][resname][RADshellDist][
×
1045
                        "WM_UA_Srot"
1046
                    ] = (Srot_qm_UA * 8.314, count)
1047

1048

NEW
1049
def process_FT(
×
1050
    Aclass, nearest, resname_Ndih, values, temperature, forceUnits, verbosePrint
1051
):
1052
    """
1053
    Get forces and torques for molecule and UA levels  - global
1054
    """
1055

1056
    WM_eigenvalues = []
×
1057
    WM_UA_eigenvalues = []
×
1058

1059
    resname = resname_Ndih[0][0]
×
1060
    Ndih = resname_Ndih[1]
×
1061
    forces = values[0]
×
1062
    torques = values[1]
×
1063
    pe = values[2]
×
1064
    ke = values[3]
×
1065
    T = values[4]
×
1066
    UAs_forces = values[5]
×
1067
    UAs_torques = values[6]
×
1068
    count = values[7]
×
1069

NEW
1070
    verbosePrint("\n\n\t***** MOLECULE LEVEL: %s *****" % (resname), "count:", count)
×
NEW
1071
    verbosePrint("\t\t--WM", resname)
×
1072

NEW
1073
    Strans_qm, Srot_qm, pe_mean, ke_mean, zpe, T_mean, eigenvalues = FT_S(
×
1074
        forces, torques, pe, ke, forceUnits, temperature, verbosePrint, print_out=False
1075
    )
NEW
1076
    verbosePrint("\n\t\t\tTmean", T_mean, "\n")
×
1077

1078
    for ev in eigenvalues:
×
1079
        e = ev + [resname]
×
1080
        WM_eigenvalues.append(e)
×
1081

NEW
1082
    if not isinstance(UAs_forces, int) and not isinstance(UAs_torques, int):
×
NEW
1083
        verbosePrint("\t\t--WM_UAs", resname)
×
NEW
1084
        Strans_qm, Srot_qm, pe_mean, ke_mean, zpe, T_mean, eigenvalues = FT_S(
×
1085
            UAs_forces,
1086
            UAs_torques,
1087
            pe,
1088
            ke,
1089
            forceUnits,
1090
            temperature,
1091
            verbosePrint,
1092
            print_out=False,
1093
        )
NEW
1094
        verbosePrint("\n\t\t\tTmean", T_mean, "\n")
×
1095

1096
        for ev in eigenvalues:
×
1097
            e = ev + [resname]
×
1098
            WM_UA_eigenvalues.append(e)
×
1099

1100
    # if T_mean != None:
1101
    # temperature = T_mean
1102

NEW
1103
    verbosePrint("\t" * 2, "--WM eigenvalues")
×
1104
    WM_force_eigenvalues = []
×
1105
    WM_torque_eigenvalues = []
×
1106
    WM_eigenvalues.sort(key=lambda x: x[0])
×
1107
    for ev in WM_eigenvalues:
×
NEW
1108
        verbosePrint("\t" * 3, ev)
×
NEW
1109
        if ev[1] == "force":
×
1110
            WM_force_eigenvalues.append(ev[0])
×
NEW
1111
        elif ev[1] == "torque":
×
1112
            WM_torque_eigenvalues.append(ev[0])
×
1113
        else:
1114
            continue
×
1115

1116
    WM_eigenvalues1 = sorted(list(map(lambda x: x[0], WM_eigenvalues)))
×
NEW
1117
    Svib_qm, zpe_trans = Svib_calc(
×
1118
        None, temperature, cov=True, out=False, eigenvalues=WM_eigenvalues1
1119
    )
NEW
1120
    verbosePrint("\n\t\t\tSvib WM", Svib_qm)
×
1121

NEW
1122
    Strans_qm, zpe_trans = Svib_calc(
×
1123
        None, temperature, cov=True, out=False, eigenvalues=WM_force_eigenvalues
1124
    )
NEW
1125
    verbosePrint("\n\t\t\tStrans WM", Strans_qm)
×
1126

NEW
1127
    Srot_qm, zpe_trans = Svib_calc(
×
1128
        None, temperature, cov=True, out=False, eigenvalues=WM_torque_eigenvalues
1129
    )
NEW
1130
    verbosePrint("\n\t\t\tSrot WM", Srot_qm)
×
1131

1132
    verbosePrint()
×
1133

NEW
1134
    verbosePrint("\t" * 2, "--WM_UAs eigenvalues")
×
1135
    WM_UA_eigenvalues.sort(key=lambda x: x[0])
×
1136
    for ev in WM_UA_eigenvalues:
×
NEW
1137
        verbosePrint("\t" * 3, ev)
×
1138

1139
    verbosePrint()
×
NEW
1140
    verbosePrint("\t***** WM_UA LEVEL: %s *****" % (resname))
×
1141

1142
    force_eigenvalues = []
×
1143
    torque_eigenvalues = []
×
1144
    for ev in WM_UA_eigenvalues:
×
NEW
1145
        if ev[1] == "force":
×
1146
            force_eigenvalues.append(ev[0])
×
NEW
1147
        elif ev[1] == "torque":
×
1148
            torque_eigenvalues.append(ev[0])
×
1149
        else:
1150
            continue
×
1151

1152
    torque_eigenvalues = sorted(torque_eigenvalues)
×
1153
    force_eigenvalues = sorted(force_eigenvalues)
×
1154

NEW
1155
    verbosePrint("\n\t\t--All WM_UA torque eigenvalues:")
×
1156
    for ev in torque_eigenvalues:
×
NEW
1157
        verbosePrint("\t" * 3, ev)
×
1158

NEW
1159
    verbosePrint("\n\t\t--All WM_UA force eigenvalues:")
×
1160
    for ev in force_eigenvalues:
×
NEW
1161
        verbosePrint("\t" * 3, ev)
×
1162

NEW
1163
    force_eigenvalues = force_eigenvalues[6:]
×
1164
    # remove 6 smallest eigenvals
1165
    # these correspond to WM level evs
NEW
1166
    if Ndih is not None:  # halve Ndih largest remaining eigenvals
×
NEW
1167
        verbosePrint("\n\t\tNdih: %s" % (Ndih))
×
NEW
1168
        N_ev = np.array(force_eigenvalues[0:Ndih])
×
1169
        # lowest Ndih evs are 1/2
1170
        N_ev_halved = []
×
1171
        for ev_type in N_ev:
×
1172
            ev_half = float(ev_type) / float(4)
×
1173
            N_ev_halved.append(ev_half)
×
1174

1175
        force_eigenvalues = N_ev_halved + force_eigenvalues[Ndih:]
×
1176

NEW
1177
    verbosePrint("\n\t\t--(-6) WM_UA torque eigenvalues:")
×
1178
    for ev in torque_eigenvalues:
×
NEW
1179
        verbosePrint("\t" * 3, ev)
×
1180

NEW
1181
    verbosePrint("\n\t\t--(-6) WM_UA forces eigenvalues")
×
1182
    for ev in force_eigenvalues:
×
NEW
1183
        verbosePrint("\t" * 3, ev)
×
1184

1185
    # WM_UA_eigenvalues = sorted(list(map(lambda x: x[0],
1186
    # WM_UA_eigenvalues)))
NEW
1187
    Strans_qm_UA, zpe_trans_UA = Svib_calc(
×
1188
        None, temperature, cov=True, out=False, eigenvalues=force_eigenvalues
1189
    )
1190

NEW
1191
    verbosePrint("\n\t\t\tStrans WM_UA", Strans_qm_UA)
×
1192

NEW
1193
    Srot_qm_UA, zpe_trans_UA = Svib_calc(
×
1194
        None, temperature, cov=True, out=False, eigenvalues=torque_eigenvalues
1195
    )
1196

NEW
1197
    verbosePrint("\n\t\t\tSrot WM_UA", Srot_qm_UA)
×
1198

1199
    #
1200

1201
    return Svib_qm, Strans_qm, Srot_qm, Strans_qm_UA, Srot_qm_UA, T_mean
×
1202

1203

NEW
1204
def FT_S(forces, torques, pe, ke, forceUnits, temperature, verbosePrint, print_out):
×
1205
    """ """
1206

1207
    constant = forceUnitConversion(forceUnits)
×
1208
    forces = np.array(forces)
×
1209
    torques = np.array(torques)
×
1210
    pe = np.array(pe)
×
1211
    ke = np.array(ke)
×
1212

NEW
1213
    Strans_qm, Srot_qm, pe_mean, ke_mean, zpe, T_mean = None, None, None, None, 0, None
×
1214

1215
    # setting temp here
1216
    T_mean = temperature
×
1217

1218
    DOF = 0
×
NEW
1219
    if not isinstance(forces, int):
×
1220
        for f in forces[0]:
×
1221
            if f != 0:
×
1222
                DOF += 1
×
1223
            else:
1224
                continue
×
1225

NEW
1226
    if not isinstance(torques, int):
×
1227
        for t in torques[0]:
×
1228
            if t != 0:
×
1229
                DOF += 1
×
1230
            else:
1231
                continue
×
1232

1233
    eigenvalues_list = []
×
1234

NEW
1235
    if not isinstance(forces, int):
×
1236
        force_sqrd_SI = np.multiply(forces, constant)
×
NEW
1237
        Strans_qm, zpe_trans, eigenvalues = Svib_calc(
×
1238
            force_sqrd_SI, T_mean, cov=True, out=False, outputEigenValues=True
1239
        )
1240
        zpe = zpe_trans
×
NEW
1241
        if print_out is True:
×
NEW
1242
            verbosePrint("\n\t\t\tave forces:")
×
1243
            for FF in force_sqrd_SI:
×
NEW
1244
                verbosePrint("\n\t\t\t%s" % (FF))
×
1245

NEW
1246
        verbosePrint("\n\t\t\tStrans", Strans_qm)
×
1247

1248
        for ev in eigenvalues:
×
NEW
1249
            eigenvalues_list.append([ev, "force"])
×
1250

NEW
1251
    if not isinstance(torques, int):
×
1252
        torque_sqrd_SI = np.multiply(torques, constant)
×
NEW
1253
        Srot_qm, zpe_rot, eigenvalues = Svib_calc(
×
1254
            torque_sqrd_SI, T_mean, cov=True, out=False, outputEigenValues=True
1255
        )
1256
        zpe += zpe_rot
×
NEW
1257
        if print_out is True:
×
NEW
1258
            verbosePrint("\n\t\t\tave torques:")
×
1259
            for TT in torque_sqrd_SI:
×
NEW
1260
                verbosePrint("\n\t\t\t%s" % (TT))
×
NEW
1261
        verbosePrint("\n\t\t\tSrot", Srot_qm)
×
1262

1263
        for ev in eigenvalues:
×
NEW
1264
            eigenvalues_list.append([ev, "torque"])
×
1265

1266
    pe_mean = np.mean(pe) * 4.184
×
NEW
1267
    verbosePrint("\n\t\t\tave pe: ", pe_mean)
×
1268

1269
    ke_mean = np.mean(ke) * 4.184
×
NEW
1270
    verbosePrint("\n\t\t\tave ke: ", ke_mean)
×
1271
    if DOF != 0:
×
1272
        T_mean = float(ke_mean) / float(DOF) * 240.663461
×
1273
    else:
1274
        T_mean = float(ke_mean) * 240.663461
×
1275

NEW
1276
    return Strans_qm, Srot_qm, pe_mean, ke_mean, zpe, T_mean, eigenvalues_list
×
1277

1278

1279
def process_dihedrals(Aclass, verbosePrint):
×
1280
    """ """
1281

1282
    if len(Aclass.adaptive_dih_dict) != 0:
×
1283

1284
        # adaptive dihedrals
NEW
1285
        verbosePrint("\nAdaptive Dihedrals p ln p\n")
×
NEW
1286
        for nearest, assigned_key in sorted(list(Aclass.adaptive_dih_dict.items())):
×
NEW
1287
            for assigned, shell_num_key in sorted(list(assigned_key.items())):
×
1288
                # assigned_count = 0
NEW
1289
                for shell_num, dih_atoms_key in sorted(list(shell_num_key.items())):
×
1290
                    verbosePrint(nearest, assigned, shell_num)
×
1291
                    sum_S = 0
×
1292
                    shell_count = 0
×
1293
                    dih_count = 0
×
NEW
1294
                    for dih_atoms, phi_key in sorted(list(dih_atoms_key.items())):
×
1295
                        verbosePrint(dih_atoms)
×
1296
                        dih_count += 1
×
1297
                        phi_count_list = []
×
1298
                        max_list = []
×
1299
                        for phi, count in sorted(list(phi_key.items())):
×
1300
                            phi_count_list.append([phi, count])
×
NEW
1301
                            shell_count += count / float(len(dih_atoms_key.keys()))
×
NEW
1302
                        N = len(phi_count_list) - 1
×
1303
                        # verbosePrint(phi_count_list)
1304
                        same_dict = nested_dict()
×
NEW
1305
                        for x in range(0, N + 1):
×
1306
                            if phi_count_list[x][1] != 0:
×
1307
                                if x == 0:
×
NEW
1308
                                    if (
×
1309
                                        phi_count_list[x + 1][1] <= phi_count_list[x][1]
1310
                                        and phi_count_list[N][1] <= phi_count_list[x][1]
1311
                                    ):
1312
                                        max_list.append(phi_count_list[x])
×
1313
                                    else:
1314
                                        continue
×
1315
                                elif x == N:
×
NEW
1316
                                    if (
×
1317
                                        phi_count_list[x - 1][1] <= phi_count_list[x][1]
1318
                                        and phi_count_list[0][1] <= phi_count_list[x][1]
1319
                                    ):
1320
                                        max_list.append(phi_count_list[x])
×
1321
                                    else:
1322
                                        continue
×
1323
                                else:
NEW
1324
                                    if (
×
1325
                                        phi_count_list[x - 1][1] <= phi_count_list[x][1]
1326
                                        and phi_count_list[x + 1][1]
1327
                                        <= phi_count_list[x][1]
1328
                                    ):
1329
                                        max_list.append(phi_count_list[x])
×
1330
                                    else:
1331
                                        continue
×
1332
                            else:
1333
                                continue
×
1334

1335
                        refined_max_list = []
×
1336
                        excluded = []
×
1337

1338
                        for max_count in max_list:
×
1339
                            for max_count2 in max_list:
×
NEW
1340
                                if (
×
1341
                                    max_count != max_count2
1342
                                    and len(max_list) > 1
1343
                                    and max_count not in refined_max_list
1344
                                ):
1345
                                    diff = max_count[0] - max_count2[0]
×
1346

1347
                                    normDeg = diff % 360
×
NEW
1348
                                    diff2 = min(360 - normDeg, normDeg)
×
1349
                                    # if less than 30 degrees difference
1350
                                    # then only pick the largest degree to be
1351
                                    # binned the other gets excluded
1352
                                    if diff2 < 60:
×
1353
                                        if max_count[1] == max_count2[1]:
×
NEW
1354
                                            if (
×
1355
                                                max_count[0] > max_count2[0]
1356
                                                and max_count not in refined_max_list
1357
                                            ):
NEW
1358
                                                refined_max_list.append(max_count)
×
1359
                                                excluded.append(max_count2)
×
1360
                                            else:
1361
                                                continue
×
1362
                                        elif max_count[1] > max_count2[1]:
×
NEW
1363
                                            if max_count not in refined_max_list:
×
NEW
1364
                                                refined_max_list.append(max_count)
×
1365
                                            else:
1366
                                                continue
×
1367
                                        else:
1368
                                            continue
×
NEW
1369
                                elif (
×
1370
                                    max_count == max_count2
1371
                                    and len(max_list) == 1
1372
                                    and max_count not in refined_max_list
1373
                                ):
1374
                                    refined_max_list.append(max_count)
×
1375
                                else:
1376
                                    continue
×
1377

1378
                        for max_count in max_list:
×
1379
                            for max_count2 in max_list:
×
NEW
1380
                                if (
×
1381
                                    max_count != max_count2
1382
                                    and len(max_list) > 1
1383
                                    and max_count not in refined_max_list
1384
                                ):
1385
                                    diff = max_count[0] - max_count2[0]
×
1386
                                    normDeg = diff % 360
×
NEW
1387
                                    diff2 = min(360 - normDeg, normDeg)
×
NEW
1388
                                    if (
×
1389
                                        diff2 >= 60
1390
                                        and max_count not in refined_max_list
1391
                                        and max_count not in excluded
1392
                                    ):
1393
                                        refined_max_list.append(max_count)
×
1394

1395
                        refined_max_dict = {}
×
1396
                        for max_count in refined_max_list:
×
1397
                            refined_max_dict[max_count[0]] = max_count[1]
×
1398
                        max_phis = list(refined_max_dict.keys())
×
1399
                        for phi, count in phi_count_list:
×
1400
                            if phi not in refined_max_dict and count != 0:
×
1401
                                smallest_diff = 999
×
1402
                                closest_phi = None
×
1403
                                for maxPhi in max_phis:
×
1404
                                    diff = phi - maxPhi
×
1405
                                    normDeg = diff % 360
×
NEW
1406
                                    diff2 = min(360 - normDeg, normDeg)
×
1407
                                    if diff2 < smallest_diff:
×
1408
                                        smallest_diff = diff2
×
1409
                                        closest_phi = maxPhi
×
1410
                                refined_max_dict[closest_phi] += count
×
1411

1412
                        # p ln p calcs finally!
NEW
1413
                        sum_count = sum(
×
1414
                            count for phi, count in refined_max_dict.items()
1415
                        )
1416
                        topo_S = 0
×
1417
                        for phi, count in refined_max_dict.items():
×
1418
                            p = count / float(sum_count)
×
1419
                            S = -p * np.log(p) * 8.314
×
1420
                            topo_S += S
×
NEW
1421
                            verbosePrint("\t", phi, count, p, S)
×
NEW
1422
                        verbosePrint("\t\t", topo_S)
×
1423
                        verbosePrint()
×
1424
                        sum_S += topo_S
×
1425

NEW
1426
                    Aclass.allVariables_dict[nearest][
×
1427
                        (assigned[0], assigned[3], assigned[4])
1428
                    ][float(shell_num)]["conf_AE"] = sum_S, int(round(shell_count, 0))
NEW
1429
                    verbosePrint("\nS_adaptive", sum_S, "N_dih:", dih_count, assigned)
×
NEW
1430
                    verbosePrint()
×
1431

1432

NEW
1433
def saveAllVariables(
×
1434
    num_frames, Aclass, level, name, solvent, waterTuple, verbosePrint
1435
):
1436
    """ """
1437

NEW
1438
    frames = ""
×
NEW
1439
    if num_frames is not None:
×
1440
        frames = num_frames
×
NEW
1441
    solventDataName = f"solventVariables{frames}{name}_{level}.csv"
×
1442
    # data = open('solventVariables%s%s_%s.csv' % (frames, name, level), 'w')
1443
    # data.write(
1444
    #         '\n'.join(['nearest,assigned,shell_num,variable,value,count'])
1445
    #         + '\n')
NEW
1446
    Utils.printOut(solventDataName, "nearest,assigned,shell_num,variable,value,count")
×
NEW
1447
    solventData = pd.DataFrame(
×
1448
        columns=["nearest", "assigned", "shell_num", "variable", "value", "count"]
1449
    )
1450

NEW
1451
    soluteDataName = f"soluteVariables{frames}{name}_{level}.csv"
×
1452
    # data2 = open('soluteVariables%s%s_%s.csv' %
1453
    #         (frames, name, level), 'w')
1454
    # data2.write('\n'.join(['resName,variable,value,count'])
1455
    #         + '\n')
NEW
1456
    Utils.printOut(soluteDataName, "resName,variable,value,count")
×
1457

NEW
1458
    soluteData = pd.DataFrame(columns=["resName", "variable", "value", "count"])
×
1459

NEW
1460
    if level == "res_atomLevel":
×
1461
        reduced_dict = nested_dict()
×
NEW
1462
        for nearest, assigned_key in sorted(list(Aclass.allVariables_dict.items())):
×
NEW
1463
            nearest = nearest.split("_")[0]
×
1464
            for assigned, shellNum_key in sorted(list(assigned_key.items())):
×
NEW
1465
                assigned = assigned[0].split("_")[0]
×
1466
                if assigned in waterTuple:
×
NEW
1467
                    for shellNum, variable_key in sorted(list(shellNum_key.items())):
×
1468
                        tot_count = 0
×
NEW
1469
                        for nearest2, assigned2_key in Aclass.allVariables_dict.items():
×
NEW
1470
                            for assigned2, shellNum2_key in assigned2_key.items():
×
NEW
1471
                                for shellNum2, variable2_key in shellNum2_key.items():
×
NEW
1472
                                    for variable2, count in variable2_key.items():
×
NEW
1473
                                        nearest3 = nearest2.split("_")[0]
×
NEW
1474
                                        assigned3 = assigned2[0].split("_")[0]
×
NEW
1475
                                        if (
×
1476
                                            nearest3 == nearest
1477
                                            and assigned3 == assigned
1478
                                            and shellNum2 == shellNum
1479
                                            and variable2 == "count"
1480
                                        ):
1481
                                            tot_count += count[1]
×
1482
                                        else:
1483
                                            continue
×
1484
                        for variable, value in variable_key.items():
×
NEW
1485
                            if (
×
1486
                                variable
1487
                                not in reduced_dict[nearest][assigned][shellNum]
1488
                                and value[0] is not None
1489
                            ):
NEW
1490
                                reduced_dict[nearest][assigned][shellNum][variable] = [
×
1491
                                    0,
1492
                                    0,
1493
                                ]
NEW
1494
                            reduced_dict[nearest][assigned][shellNum][variable][0] += (
×
1495
                                value[0] * value[1] / float(tot_count)
1496
                            )
NEW
1497
                            reduced_dict[nearest][assigned][shellNum][variable][
×
1498
                                1
1499
                            ] += int(round(value[1], 0))
1500
                else:
1501
                    continue
×
1502

NEW
1503
        for nearest, assigned_key in sorted(list(reduced_dict.items())):
×
1504
            for assigned, shellNum_key in sorted(list(assigned_key.items())):
×
NEW
1505
                for shellNum, variable_key in sorted(list(shellNum_key.items())):
×
1506
                    for variable, value in variable_key.items():
×
NEW
1507
                        if (
×
1508
                            value[0] is not None
1509
                            and assigned in solvent
1510
                            and shellNum == 1
1511
                        ):
1512
                            # data.write('\n'.join(['%s,%s,%s,%s,%s,%s' %
1513
                            #         (nearest,
1514
                            #         assigned, shellNum, variable, value[0],
1515
                            #         value[1])]) + '\n')
NEW
1516
                            Utils.printOut(
×
1517
                                solventDataName,
1518
                                (
1519
                                    f"{nearest},{assigned},"
1520
                                    f"{shellNum},{variable},"
1521
                                    f"{value[0]},{value[1]}"
1522
                                ),
1523
                            )
NEW
1524
                            newRowSolvent = pd.DataFrame(
×
1525
                                {
1526
                                    "nearest": nearest,
1527
                                    "assigned": assigned,
1528
                                    "shell_num": shellNum,
1529
                                    "variable": variable,
1530
                                    "value": value[0],
1531
                                    "count": value[1],
1532
                                },
1533
                                index=[0],
1534
                            )
NEW
1535
                            solventData = pd.concat(
×
1536
                                [solventData, newRowSolvent], ignore_index=True
1537
                            )
1538
                        else:
1539
                            continue
×
1540

1541
        # for solute only
1542
        PE_KE_dict = nested_dict()
×
NEW
1543
        for nearest, assigned_key in sorted(list(Aclass.allVariables_dict.items())):
×
1544
            for assigned, shellNum_key in sorted(list(assigned_key.items())):
×
1545
                assigned = list(assigned)
×
NEW
1546
                if "_" in assigned[0]:
×
NEW
1547
                    assigned[0] = assigned[0].split("_")[0]
×
NEW
1548
                for shellNum, variable_key in sorted(list(shellNum_key.items())):
×
1549
                    for variable, value in variable_key.items():
×
1550
                        if assigned[0] not in solvent and shellNum != 0:
×
NEW
1551
                            if variable in ["PE", "KE"] and value[0] is not None:
×
NEW
1552
                                new_var = "WM_%s" % (variable)
×
NEW
1553
                                if new_var not in PE_KE_dict[nearest][assigned[0]]:
×
NEW
1554
                                    PE_KE_dict[nearest][assigned[0]][new_var] = [0, 0]
×
NEW
1555
                                PE_KE_dict[nearest][assigned[0]][new_var][0] += value[0]
×
NEW
1556
                                PE_KE_dict[nearest][assigned[0]][new_var][1] = value[1]
×
1557

NEW
1558
                            if "WM_" in variable or variable == "conf_AE":
×
1559
                                # data2.write('\n'.join(['%s,%s,%s,%s' %
1560
                                #         (assigned[0],
1561
                                #         variable, value[0],
1562
                                #         int(round(value[1], 0)))]) + '\n')
NEW
1563
                                Utils.printOut(
×
1564
                                    soluteDataName,
1565
                                    (
1566
                                        f"{assigned[0]},{variable},{value[0]},"
1567
                                        f"{int(round(value[1], 0))}"
1568
                                    ),
1569
                                )
NEW
1570
                                newRowSolute = pd.DataFrame(
×
1571
                                    {
1572
                                        "resName": assigned[0],
1573
                                        "variable": variable,
1574
                                        "value": value[0],
1575
                                        "count": int(round(value[1], 0)),
1576
                                    },
1577
                                    index=[0],
1578
                                )
NEW
1579
                                soluteData = pd.concat(
×
1580
                                    [soluteData, newRowSolute], ignore_index=True
1581
                                )
1582
                        else:
1583
                            continue
×
1584

NEW
1585
        for nearest, assigned_key in sorted(list(PE_KE_dict.items())):
×
1586
            for assigned, variable_key in sorted(list(assigned_key.items())):
×
1587
                for variable, value in sorted(list(variable_key.items())):
×
1588
                    # data2.write('\n'.join(['%s,%s,%s,%s' %
1589
                    #         (assigned,
1590
                    #         variable, value[0],
1591
                    #         value[1])]) + '\n')
NEW
1592
                    Utils.printOut(
×
1593
                        soluteDataName,
1594
                        f"{assigned[0]},{variable},{value[0]},{value[1]}",
1595
                    )
NEW
1596
                    newRowSolute = pd.DataFrame(
×
1597
                        {
1598
                            "resName": assigned,
1599
                            "variable": variable,
1600
                            "value": value[0],
1601
                            "count": value[1],
1602
                        },
1603
                        index=[0],
1604
                    )
NEW
1605
                    soluteData = pd.concat(
×
1606
                        [soluteData, newRowSolute], ignore_index=True
1607
                    )
1608
        #
1609

1610
    else:
NEW
1611
        for nearest, assigned_key in sorted(list(Aclass.allVariables_dict.items())):
×
1612
            for assigned, shellNum_key in sorted(list(assigned_key.items())):
×
NEW
1613
                for shellNum, variable_key in sorted(list(shellNum_key.items())):
×
1614
                    for variable, value in variable_key.items():
×
NEW
1615
                        if (
×
1616
                            assigned[0] in solvent
1617
                            and shellNum == 1
1618
                            and value[0] is not None
1619
                        ):
1620
                            # data.write('\n'.join(['%s,%s,%s,%s,%s,%s' %
1621
                            #         (nearest,
1622
                            #         assigned[0], shellNum,
1623
                            #         variable, value[0],
1624
                            #         int(round(value[1], 0)))]) + '\n')
NEW
1625
                            Utils.printOut(
×
1626
                                solventDataName,
1627
                                (
1628
                                    f"{nearest},{assigned[0]},"
1629
                                    f"{shellNum},{variable},",
1630
                                    f"{value[0]},{int(round(value[1], 0))}",
1631
                                ),
1632
                            )
NEW
1633
                            newRowSolvent = pd.DataFrame(
×
1634
                                {
1635
                                    "nearest": nearest,
1636
                                    "assigned": assigned[0],
1637
                                    "shell_num": shellNum,
1638
                                    "variable": variable,
1639
                                    "value": value[0],
1640
                                    "count": int(round(value[1], 0)),
1641
                                },
1642
                                index=[0],
1643
                            )
NEW
1644
                            solventData = pd.concat(
×
1645
                                [solventData, newRowSolvent], ignore_index=True
1646
                            )
1647
                        else:
1648
                            continue
×
1649

1650
        #
1651
        # for solute only
1652
        PE_KE_dict = nested_dict()
×
NEW
1653
        for nearest, assigned_key in sorted(list(Aclass.allVariables_dict.items())):
×
1654
            for assigned, shellNum_key in sorted(list(assigned_key.items())):
×
NEW
1655
                for shellNum, variable_key in sorted(list(shellNum_key.items())):
×
1656
                    for variable, value in variable_key.items():
×
1657
                        if assigned[0] not in solvent and shellNum != 0:
×
NEW
1658
                            if variable in ["PE", "KE"] and value[0] is not None:
×
NEW
1659
                                new_var = "WM_%s" % (variable)
×
NEW
1660
                                if new_var not in PE_KE_dict[nearest][assigned[0]]:
×
NEW
1661
                                    PE_KE_dict[nearest][assigned[0]][new_var] = [0, 0]
×
NEW
1662
                                PE_KE_dict[nearest][assigned[0]][new_var][0] += value[0]
×
NEW
1663
                                PE_KE_dict[nearest][assigned[0]][new_var][1] = value[1]
×
1664

NEW
1665
                            if "WM_" in variable or variable == "conf_AE":
×
1666
                                # data2.write('\n'.join(['%s,%s,%s,%s' %
1667
                                #         (assigned[0],
1668
                                #         variable, value[0],
1669
                                #         int(round(value[1], 0)))]) + '\n')
NEW
1670
                                Utils.printOut(
×
1671
                                    soluteDataName,
1672
                                    (
1673
                                        f"{assigned[0]},{variable},"
1674
                                        f"{value[0]},{int(round(value[1], 0))}"
1675
                                    ),
1676
                                )
NEW
1677
                                newRowSolute = pd.DataFrame(
×
1678
                                    {
1679
                                        "resName": assigned[0],
1680
                                        "variable": variable,
1681
                                        "value": value[0],
1682
                                        "count": int(round(value[1], 0)),
1683
                                    },
1684
                                    index=[0],
1685
                                )
NEW
1686
                                soluteData = pd.concat(
×
1687
                                    [soluteData, newRowSolute], ignore_index=True
1688
                                )
1689

1690
                        else:
1691
                            continue
×
1692

NEW
1693
        for nearest, assigned_key in sorted(list(PE_KE_dict.items())):
×
1694
            for assigned, variable_key in sorted(list(assigned_key.items())):
×
1695
                for variable, value in sorted(list(variable_key.items())):
×
1696
                    # data2.write('\n'.join(['%s,%s,%s,%s' %
1697
                    #         (assigned,
1698
                    #         variable, value[0],
1699
                    #         value[1])]) + '\n')
NEW
1700
                    Utils.printOut(
×
1701
                        soluteDataName, f"{assigned},{variable},{value[0]},{value[1]}"
1702
                    )
NEW
1703
                    newRowSolute = pd.DataFrame(
×
1704
                        {
1705
                            "resName": assigned[0],
1706
                            "variable": variable,
1707
                            "value": value[0],
1708
                            "count": int(round(value[1], 0)),
1709
                        },
1710
                        index=[0],
1711
                    )
NEW
1712
                    soluteData = pd.concat(
×
1713
                        [soluteData, newRowSolute], ignore_index=True
1714
                    )
1715
        #
1716

1717
    # data.close()
1718
    # data2.close()
1719
    return (solventData, soluteData)
×
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