• 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/NeighbourFunctions.py
1
# import os
NEW
2
import sys
×
3

4
# import matplotlib.pyplot as plt
5
import MDAnalysis as mda
×
NEW
6
import numpy as np
×
7

8
# from ast import arg
9

10

11
# from numpy import linalg as la
12

13
# import math
14

15
# from CodeEntropy import CustomFunctions as CF
16
# from CodeEntropy import GeometricFunctions as GF
17
# from CodeEntropy import UnitsAndConversions as UAC
18
# from CodeEntropy import LevelFunctions as LF
19
# from CodeEntropy import Utils
20
# from CodeEntropy import Writer
21
# import multiprocessing as mp
22
# from functools import partial
23

24

25
# import pandas as pd
26
# from MDAnalysis.analysis import distances
27

NEW
28
np.set_printoptions(threshold=sys.maxsize)
×
29

30

31
def get_neighbours(molecule_i, reduced_atom):
×
32
    """
33
    Molecules in the coordination shell are obtained using the relative angular distance
34
    (RAD) algorithm, as presented in J.Higham and R. H. Henchman, J. Chem. Phys., 2016,
35
    145, 084108.
36

37
    Input
38
    -----
39
      molecule: DataContainer type with the information on the molecule of interest for
40
      which are finding the neighbours
41
      reduced_atom: MDAnalysis universe object containing the system of interest
42
    Returns
43
    -------
44
      neighbours_dict :  dictionary - dictionary of neighbours for the molecule - should
45
      contain the type of neighbour molecule and the number of neighbour
46
      molecules of that species
47
      neighbours_array: array containing all neighbouring molecules
48
    """
NEW
49
    number_molecules = len(reduced_atom.atoms.fragments)
×
NEW
50
    neighbours_dict = {}
×
NEW
51
    neighbours_array = []
×
52
    # go through molecules to see if they're in the coordination shell of the molecule
53
    # of interest
NEW
54
    for j in range(0, number_molecules):
×
NEW
55
        molecule_j = reduced_atom.atoms.fragments[j]
×
56
        # to avoid adding a molecule as its own neighbour
NEW
57
        if molecule_i != molecule_j:
×
58
            # we have already found a neighbour
NEW
59
            if len(neighbours_array) > 0:
×
NEW
60
                for molecule_k in (
×
61
                    neighbours_array
62
                    # check if every closer molecule that is already in the neighbour
63
                    # list is unblocked
64
                ):
65
                    # distance between the molecule of interest and the molecule
66
                    # that we check if it's a neighbour
NEW
67
                    r_ij = mda.analysis.distances.dist(molecule_i, molecule_j)
×
68
                    # distance between the molecule of interest and the neighbours
69
                    # already identified
NEW
70
                    r_ik = mda.analysis.distances.dist(molecule_i, molecule_k)
×
NEW
71
                    r_jk = mda.analysis.distances.dist(molecule_j, molecule_k)
×
NEW
72
                    cos_theta_jik = (r_ij**2 + r_ik**2 - r_jk**2) / (
×
73
                        2 * r_ij * r_ik
74
                    )  # cosine of the angle subintended at i by j and k
NEW
75
                    if (r_ij) ** (-2) < (r_ik) ** (-2) * cos_theta_jik:
×
NEW
76
                        break  # j is not a neighbour as it is blocked by k
×
77
                    else:
NEW
78
                        neighbours_array.append(molecule_j.atoms.resids[0])
×
NEW
79
                        if molecule_j.smth in neighbours_dict.keys():
×
NEW
80
                            neighbours_dict[molecule_j.atoms.resnames[0]] += 1
×
81
                        else:
NEW
82
                            neighbours_dict[molecule_j.atoms.resnames[0]] = 1
×
83
            else:  # first neighbour
84
                # r_ij = mda.analysis.distances.dist(molecule_i, molecule_j)
85
                # print(r_ij)
NEW
86
                neighbours_array.append(molecule_j.atoms.resids[0])
×
NEW
87
                neighbours_dict[molecule_j.atoms.resnames[0]] = 1
×
NEW
88
    return neighbours_dict, neighbours_array
×
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