waterEntropy 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Jas Kalayan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,58 @@
1
+ Metadata-Version: 2.4
2
+ Name: waterEntropy
3
+ Version: 1.0.0
4
+ Summary: Python package for calculating interfacial water entropy from molecular dynamics simulations.
5
+ Keywords: water,entropy,molecular dynamics,forces
6
+ Author-email: Jas Kalayan <jas.kalayan@stfc.ac.uk>
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ Classifier: Programming Language :: Python
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Natural Language :: English
13
+ Classifier: Development Status :: 3 - Alpha
14
+ License-File: LICENSE
15
+ Requires-Dist: mdanalysis==2.7.0
16
+ Requires-Dist: numpy==1.26.2
17
+ Requires-Dist: sphinx ; extra == "docs"
18
+ Requires-Dist: sphinx_rtd_theme ; extra == "docs"
19
+ Requires-Dist: sphinxcontrib-contentui ; extra == "docs"
20
+ Requires-Dist: sphinxcontrib-details-directive ; extra == "docs"
21
+ Requires-Dist: sphinx_copybutton ; extra == "docs"
22
+ Requires-Dist: furo ; extra == "docs"
23
+ Requires-Dist: markupsafe<2.1 ; extra == "docs"
24
+ Requires-Dist: pre-commit==3.7.1 ; extra == "pre-commit"
25
+ Requires-Dist: pylint==3.2.5 ; extra == "pre-commit"
26
+ Requires-Dist: pgtest==1.3.2 ; extra == "testing"
27
+ Requires-Dist: wheel==0.43.0 ; extra == "testing"
28
+ Requires-Dist: coverage[toml] ; extra == "testing"
29
+ Requires-Dist: pytest==8.2.2 ; extra == "testing"
30
+ Requires-Dist: pytest-cov==5.0.0 ; extra == "testing"
31
+ Requires-Dist: pytest-sugar==1.0.0 ; extra == "testing"
32
+ Project-URL: Source, https://github.com/jkalayan/waterEntropy
33
+ Provides-Extra: docs
34
+ Provides-Extra: pre-commit
35
+ Provides-Extra: testing
36
+
37
+ [![Documentation Status](https://readthedocs.org/projects/waterentropy/badge/?version=latest)](https://waterentropy.readthedocs.io/en/latest/?badge=latest)
38
+ [![Coverage Status](https://coveralls.io/repos/github/jkalayan/waterEntropy/badge.svg?branch=main)](https://coveralls.io/github/jkalayan/waterEntropy?branch=main)
39
+
40
+ # waterEntropy
41
+ The Python package for calculating interfacial water entropy from molecular dynamics simulations.
42
+
43
+ <p align="center">
44
+ <img src="docs/source/images/waterentropy_logo_grey.png" width="500px" />
45
+ </p>
46
+
47
+ ## Documentation
48
+
49
+ See [here](https://waterentropy.readthedocs.io/en/latest/) for documentation for users and developers.
50
+
51
+ ## License
52
+
53
+ MIT
54
+
55
+ ## Contact
56
+
57
+ - jas.kalayan@stfc.ac.uk
58
+
@@ -0,0 +1,21 @@
1
+ [![Documentation Status](https://readthedocs.org/projects/waterentropy/badge/?version=latest)](https://waterentropy.readthedocs.io/en/latest/?badge=latest)
2
+ [![Coverage Status](https://coveralls.io/repos/github/jkalayan/waterEntropy/badge.svg?branch=main)](https://coveralls.io/github/jkalayan/waterEntropy?branch=main)
3
+
4
+ # waterEntropy
5
+ The Python package for calculating interfacial water entropy from molecular dynamics simulations.
6
+
7
+ <p align="center">
8
+ <img src="docs/source/images/waterentropy_logo_grey.png" width="500px" />
9
+ </p>
10
+
11
+ ## Documentation
12
+
13
+ See [here](https://waterentropy.readthedocs.io/en/latest/) for documentation for users and developers.
14
+
15
+ ## License
16
+
17
+ MIT
18
+
19
+ ## Contact
20
+
21
+ - jas.kalayan@stfc.ac.uk
@@ -0,0 +1,124 @@
1
+ [build-system]
2
+ # build the package with [flit](https://flit.readthedocs.io)
3
+ requires = ["flit_core >=3.4,<4"]
4
+ build-backend = "flit_core.buildapi"
5
+
6
+ [project]
7
+ # See https://www.python.org/dev/peps/pep-0621/
8
+ name = "waterEntropy"
9
+ dynamic = ["version"] # read from waterEntropy/__init__.py
10
+ description = "Python package for calculating interfacial water entropy from molecular dynamics simulations."
11
+ authors = [{name = "Jas Kalayan", email = "jas.kalayan@stfc.ac.uk"}]
12
+ readme = "README.md"
13
+ license = {file = "LICENSE"}
14
+ classifiers = [
15
+ "Programming Language :: Python",
16
+ "Intended Audience :: Science/Research",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Natural Language :: English",
19
+ "Development Status :: 3 - Alpha",
20
+ ]
21
+ keywords = ["water", "entropy", "molecular dynamics", "forces"]
22
+ requires-python = ">=3.8"
23
+ dependencies = [
24
+ "mdanalysis==2.7.0",
25
+ "numpy==1.26.2",
26
+ ]
27
+
28
+ [project.urls]
29
+ Source = "https://github.com/jkalayan/waterEntropy"
30
+
31
+ [project.optional-dependencies]
32
+ testing = [
33
+ "pgtest==1.3.2",
34
+ "wheel==0.43.0",
35
+ "coverage[toml]",
36
+ "pytest==8.2.2",
37
+ "pytest-cov==5.0.0",
38
+ "pytest-sugar==1.0.0"
39
+ ]
40
+ pre-commit = [
41
+ "pre-commit==3.7.1",
42
+ "pylint==3.2.5"
43
+ ]
44
+ docs = [
45
+ "sphinx",
46
+ "sphinx_rtd_theme",
47
+ "sphinxcontrib-contentui",
48
+ "sphinxcontrib-details-directive",
49
+ "sphinx_copybutton",
50
+ "furo",
51
+ "markupsafe<2.1"
52
+ ]
53
+
54
+ [project.scripts]
55
+ waterEntropy = "waterEntropy.cli.runWaterEntropy:main"
56
+
57
+ #[project.entry-points."waterEntropy.neighbours"]
58
+ #"gromacs.pdb2gmx" = "waterEntropy.neighbours.RAD:RAD"
59
+
60
+ #[project.entry-points."aiida.calculations"]
61
+ #"gromacs.pdb2gmx" = "aiida_gromacs.calculations.pdb2gmx:Pdb2gmxCalculation"
62
+
63
+ #[project.entry-points."aiida.parsers"]
64
+ #"gromacs.pdb2gmx" = "aiida_gromacs.parsers.pdb2gmx:Pdb2gmxParser"
65
+
66
+ #[project.entry-points."aiida.workflows"]
67
+ #"gromacs.setup" = "aiida_gromacs.workflows.simsetup:SetupWorkChain"
68
+
69
+ #[project.entry-points."aiida.cmdline.data"]
70
+ #"provenance" = "aiida_gromacs.commands.provenance:provenance"
71
+
72
+ [tool.flit.module]
73
+ name = "waterEntropy"
74
+
75
+ [tool.pylint.format]
76
+ max-line-length = 125
77
+
78
+ [tool.pylint.messages_control]
79
+ disable = [
80
+ "too-many-ancestors",
81
+ "invalid-name",
82
+ "duplicate-code",
83
+ ]
84
+
85
+ [tool.pytest.ini_options]
86
+ # Configuration for [pytest](https://docs.pytest.org)
87
+ python_files = "test_*.py example_*.py"
88
+ filterwarnings = [
89
+ "ignore::DeprecationWarning:plumpy:",
90
+ "ignore::DeprecationWarning:yaml:",
91
+ ]
92
+
93
+ [tool.coverage.run]
94
+ # Configuration of [coverage.py](https://coverage.readthedocs.io)
95
+ # reporting which lines of your plugin are covered by tests
96
+ source=["waterEntropy"]
97
+
98
+ [tool.isort]
99
+ # Configuration of [isort](https://isort.readthedocs.io)
100
+ line_length = 120
101
+ force_sort_within_sections = true
102
+ sections = ['FUTURE', 'STDLIB', 'THIRDPARTY', 'FIRSTPARTY', 'LOCALFOLDER']
103
+ extend_skip = [".tpr", ".gro", ".pdb", ".top", ".mdp"]
104
+
105
+ [tool.tox]
106
+ legacy_tox_ini = """
107
+ [tox]
108
+ envlist = py38
109
+ [testenv]
110
+ usedevelop=True
111
+ [testenv:py{38,39,310,311}]
112
+ description = Run the test suite against a python version
113
+ extras = testing
114
+ commands = pytest {posargs}
115
+ [testenv:pre-commit]
116
+ description = Run the pre-commit checks
117
+ extras = pre-commit
118
+ commands = pre-commit run {posargs}
119
+ [testenv:docs]
120
+ description = Build the documentation
121
+ extras = docs
122
+ commands = sphinx-build -nW --keep-going -b html {posargs} docs/source docs/build/html
123
+ commands_post = echo "open file://{toxinidir}/docs/build/html/index.html"
124
+ """
@@ -0,0 +1,6 @@
1
+ """calculate water entropy near heterogeneous interfaces"""
2
+
3
+ # Add imports here
4
+ # from waterEntropy.neighbours.force_torque import *
5
+
6
+ __version__ = "1.0.0"
@@ -0,0 +1,169 @@
1
+ """
2
+ These functions calculate hydrogen bonding within a shell.
3
+ """
4
+
5
+ import numpy as np
6
+
7
+ import waterEntropy.analysis.RAD as RADShell
8
+ import waterEntropy.maths.trig as Trig
9
+ from waterEntropy.utils.helpers import nested_dict
10
+
11
+
12
+ class HBCollection:
13
+ """
14
+ Class for hydrogen bond donors and their acceptors
15
+ """
16
+
17
+ def __init__(self):
18
+ self.donating_to = (
19
+ nested_dict()
20
+ ) # structure: UA_idx[donating_idx] = accepting_idx
21
+ self.accepting_from = (
22
+ nested_dict()
23
+ ) # structure: UA_idx[accepting_idx] = [donating_idx1,]
24
+
25
+ def add_data(self, UA_idx: int, donator_idx: int, acceptor_idx: int):
26
+ """
27
+ For a given donator index, save its acceptor index in the donating_to
28
+ dictionary. And for that acceptor, save the donator index as a list in
29
+ the accepting from dictionary.
30
+
31
+ :param self: class instance
32
+ :param UA_idx: atom index of the UA of the bonded donating hydrogen
33
+ :param donator_idx: atom index of the donator bonded to the UA
34
+ :param acceptor_idx: atom index of the UA accepting the
35
+ hydrogen bond in the coordination shell
36
+ """
37
+ if donator_idx not in self.donating_to[UA_idx]:
38
+ self.donating_to[UA_idx][donator_idx] = acceptor_idx
39
+ if acceptor_idx not in self.accepting_from:
40
+ self.accepting_from[acceptor_idx] = []
41
+ if donator_idx not in self.accepting_from[acceptor_idx]:
42
+ self.accepting_from[acceptor_idx].append(donator_idx)
43
+
44
+ def find_donators(self, UA_idx: int):
45
+ """
46
+ Find the donators for a given residue, this returns a dict where the
47
+ key is the accepting atom index and the value is a list of the atom
48
+ indices that donate to it.
49
+
50
+ :param cls: class instance
51
+ :param UA_idx: atom index of UA being donated to
52
+ """
53
+ return self.accepting_from.get(UA_idx, None)
54
+
55
+ def find_acceptor(self, UA_idx: int):
56
+ """
57
+ Find the acceptors for a given resid, this returns a dictionary where
58
+ the key is the donator index and the value is the acceptor index
59
+
60
+ :param cls: class instance
61
+ :param UA_idx: atom index of UA accepting HBs
62
+ """
63
+ return self.donating_to.get(UA_idx, None)
64
+
65
+
66
+ def get_HB_terms(heavy_atom, donator, acceptor, DA_distance, dimensions):
67
+ """
68
+ Get two terms for calculating the hydrogen bond between a donator and
69
+ potential acceptor in a coordination shell.
70
+ For a hydrogen bond to form, the following criteria need to be met:
71
+
72
+ 1. Angle between heavy atom bonded to donator (X), the donator (D) and
73
+ the acceptor (A) is over 90 degrees
74
+
75
+ 2. The relative charge is most negative over all other neighbours in a
76
+ coordination shell
77
+
78
+ :param heavy_atom: the mdanalysis instance for the heavy atom bonded to
79
+ the donator
80
+ :param donator: the mdanalysis instance for the donator
81
+ :param acceptor: the mdanalysis instance for the possible acceptor
82
+ :param DA_distance: the distance between donor and acceptor
83
+ :param dimensions: the dimensions of the simulation box
84
+ """
85
+ relative_charge = (float(donator.charge) * float(acceptor.charge)) / float(
86
+ DA_distance**2
87
+ )
88
+ cosine_angle = Trig.get_angle(
89
+ heavy_atom.position, donator.position, acceptor.position, dimensions
90
+ )
91
+ XDA_angle = np.degrees(np.arccos(cosine_angle))
92
+
93
+ return relative_charge, XDA_angle
94
+
95
+
96
+ def get_shell_HB_acceptors(shell, system, HBs: HBCollection):
97
+ # pylint: disable=too-many-locals
98
+ """
99
+ Find the hydrogen bond acceptors for the central UA hydrogens that are
100
+ electropositive. The assumption is made that hydrogen bonding can only
101
+ occur inside the coordination shell, this is needed for shell neighbour
102
+ labelling used in orientational entropy calculations
103
+
104
+ :param shell: the instance for containing coordination shell neighbours
105
+ :param system: mdanalysis instance of all atoms in current frame
106
+ :param HBs: instance of HBCollection class
107
+ """
108
+ X_idx = shell.atom_idx # shell central heavy atom
109
+ heavy_atom = system.atoms[X_idx]
110
+ # 1. iterate over atoms bonded to atom X
111
+ for i in heavy_atom.bonds:
112
+ D_idx = i.indices[1]
113
+ bonded = system.atoms[D_idx]
114
+ # 2. find hydrogen atoms bonded to heavy atom with positive charge
115
+ if bonded.mass < 1.1 and bonded.mass > 1.0 and bonded.charge > 0:
116
+ donator = system.atoms[D_idx]
117
+ # 3. set starting hydrogen bond term and possible acceptor to a large number
118
+ # the acceptor that gives the lowest relative charge is the acceptor
119
+ current_relative_charge = 99
120
+ current_acceptor = False
121
+ # 4. get shell neighbours ordered by ascending distance
122
+ sorted_indices, sorted_distances = Trig.get_shell_neighbour_selection(
123
+ shell, donator, system
124
+ )
125
+ for A_idx, DA_distance in zip(sorted_indices, sorted_distances):
126
+ # 5. check if neighbouring atom in shell is an acceptor,
127
+ # if so override current possible acceptor
128
+ acceptor = system.atoms[A_idx]
129
+ if not current_acceptor:
130
+ current_acceptor = acceptor
131
+ relative_charge, XDA_angle = get_HB_terms(
132
+ heavy_atom, donator, acceptor, DA_distance, system.dimensions[:3]
133
+ )
134
+ # 6. Check if an atom is a possible hydrogen bond acceptor
135
+ if relative_charge < current_relative_charge and float(XDA_angle) > 90:
136
+ current_relative_charge = relative_charge
137
+ current_acceptor = acceptor
138
+ # 7. create a new object for hydrogen bonding in a RAD shell
139
+ HBs.add_data(X_idx, D_idx, current_acceptor.index)
140
+
141
+
142
+ def get_shell_HBs(shell, system, HBs: HBCollection, shells: RADShell.ShellCollection):
143
+ """
144
+ For a given UA and its coordination shell neighbours, find what the central
145
+ UA donates to and accepts from in its shell.
146
+
147
+ :param shell: the instance for class waterEntropy.neighbours.RAD.RAD
148
+ containing coordination shell neighbours
149
+ :param system: mdanalysis instance of all atoms in current frame
150
+ :param HBs: HBCollection instance
151
+ :param shells: ShellCollection instance
152
+ """
153
+ # 1. first check that HB donations haven't already been found
154
+ donates_to = HBs.find_acceptor(shell.atom_idx)
155
+ if not donates_to:
156
+ get_shell_HB_acceptors(shell, system, HBs)
157
+ donates_to = HBs.find_acceptor(shell.atom_idx)
158
+ # 2. now iterate through shell and find shells of shell neighbours
159
+ for n_idx in shell.UA_shell:
160
+ neighbour_shell = shells.find_shell(n_idx)
161
+ if not neighbour_shell:
162
+ neighbour_shell = RADShell.get_RAD_shell(
163
+ system.atoms[n_idx], system, shells
164
+ )
165
+ # 3. find what each shell neighbour donates to in their shell
166
+ neighbour_donates_to = HBs.find_acceptor(n_idx)
167
+ if not neighbour_donates_to:
168
+ get_shell_HB_acceptors(neighbour_shell, system, HBs)
169
+ neighbour_donates_to = HBs.find_acceptor(n_idx)
@@ -0,0 +1,199 @@
1
+ """
2
+ Store the labelled neighbours that are donated to and accepted from the central
3
+ atom in a shell. Shells with the same neighbours are grouped together and
4
+ along with the counts for donating to and accepting from each neighbour type.
5
+ These labelled HB neighbours are used to calculate orientational
6
+ entropy of water molecules.
7
+ """
8
+
9
+ from waterEntropy.analysis.HB import HBCollection
10
+ from waterEntropy.analysis.shells import ShellCollection
11
+ from waterEntropy.utils.helpers import nested_dict
12
+ import waterEntropy.utils.selections as Selections
13
+
14
+
15
+ class HBLabelCollection:
16
+ """
17
+ Labelled shell counts used for Sorient.
18
+ The counts are placed into two dictionaries used for statistics later,
19
+ the structure of these two dictionaries are as follows:
20
+
21
+ dict1 = {"resname": {("labelled_shell"): {"shell_count": 0,
22
+ "donates_to": {"labelled_donators": 0,},
23
+ "accepts_from": {"labelled_acceptors": 0,}
24
+ }}}
25
+ dict2 = {"nearest_resid": {"resname":
26
+ {("labelled_shell"): {"shell_count": 0,
27
+ "donates_to": {"labelled_donators": 0,},
28
+ "accepts_from": {"labelled_acceptors": 0,}
29
+ }}}
30
+ """
31
+
32
+ def __init__(self):
33
+ self.labelled_shell_counts = nested_dict() # save shell instances in here
34
+ self.resid_labelled_shell_counts = nested_dict() # save shell instances in here
35
+
36
+ def add_data(self, resid, resname, labelled_shell, donates_to, accepts_from):
37
+ # pylint: disable=too-many-arguments
38
+ """Add data to class dictionaries"""
39
+ self.add_shell_counts(resid, resname, labelled_shell)
40
+ self.add_donates_to(resid, resname, labelled_shell, donates_to)
41
+ self.add_accepts_from(resid, resname, labelled_shell, accepts_from)
42
+
43
+ def add_shell_counts(self, resid, resname, labelled_shell):
44
+ """
45
+ Add a labelled shell to a dictionary that keeps track of the counts
46
+ for each labelled shell type with constituents alpha-numerically
47
+ ordered
48
+
49
+ :param self: class instance
50
+ :param resid: residue id of nearest nonlike atom in the labelled shell
51
+ :param resname: residue name of nearest nonlike atom in the labelled shell
52
+ :param labelled_shell: coordination shell with labelled neighbours
53
+ """
54
+ labelled_shell = tuple(sorted(labelled_shell))
55
+ if "shell_count" not in self.labelled_shell_counts[resname][labelled_shell]:
56
+ self.labelled_shell_counts[resname][labelled_shell]["shell_count"] = 1
57
+ else:
58
+ self.labelled_shell_counts[resname][labelled_shell]["shell_count"] += 1
59
+
60
+ if (
61
+ "shell_count"
62
+ not in self.resid_labelled_shell_counts[resid][resname][labelled_shell]
63
+ ):
64
+ self.resid_labelled_shell_counts[resid][resname][labelled_shell][
65
+ "shell_count"
66
+ ] = 1
67
+ else:
68
+ self.resid_labelled_shell_counts[resid][resname][labelled_shell][
69
+ "shell_count"
70
+ ] += 1
71
+
72
+ def add_donates_to(self, resid, resname, labelled_shell, donates_to):
73
+ """
74
+ Add a labelled neighbours donated to in a dictionary that keeps
75
+ track of the counts for each labelled shell type with
76
+ constituents alpha-numerically ordered
77
+
78
+ :param self: class instance
79
+ :param resid: residue id of nearest nonlike atom in the labelled shell
80
+ :param resname: residue name of nearest nonlike atom in the labelled shell
81
+ :param labelled_shell: coordination shell with labelled neighbours
82
+ :param donates_to: list of labelled neighbours that are donated to
83
+ """
84
+ labelled_shell = tuple(sorted(labelled_shell))
85
+ # donates_to = tuple(sorted(donates_to))
86
+ for a in donates_to:
87
+ if (
88
+ a
89
+ not in self.labelled_shell_counts[resname][labelled_shell]["donates_to"]
90
+ ):
91
+ self.labelled_shell_counts[resname][labelled_shell]["donates_to"][a] = 1
92
+ else:
93
+ self.labelled_shell_counts[resname][labelled_shell]["donates_to"][
94
+ a
95
+ ] += 1
96
+
97
+ if (
98
+ a
99
+ not in self.resid_labelled_shell_counts[resid][resname][labelled_shell][
100
+ "donates_to"
101
+ ]
102
+ ):
103
+ self.resid_labelled_shell_counts[resid][resname][labelled_shell][
104
+ "donates_to"
105
+ ][a] = 1
106
+ else:
107
+ self.resid_labelled_shell_counts[resid][resname][labelled_shell][
108
+ "donates_to"
109
+ ][a] += 1
110
+
111
+ def add_accepts_from(self, resid, resname, labelled_shell, accepts_from):
112
+ """
113
+ Add a labelled neighbours accepted from to in a dictionary that keeps
114
+ track of the counts for each labelled shell type with
115
+ constituents alpha-numerically ordered
116
+
117
+ :param self: class instance
118
+ :param resid: residue id of nearest nonlike atom in the labelled shell
119
+ :param resname: residue name of nearest nonlike atom in the labelled shell
120
+ :param labelled_shell: coordination shell with labelled neighbours
121
+ :param accepts_from: list of labelled neighbours that are accepted_from
122
+ """
123
+ labelled_shell = tuple(sorted(labelled_shell))
124
+ for d in accepts_from:
125
+ if (
126
+ d
127
+ not in self.labelled_shell_counts[resname][labelled_shell][
128
+ "accepts_from"
129
+ ]
130
+ ):
131
+ self.labelled_shell_counts[resname][labelled_shell]["accepts_from"][
132
+ d
133
+ ] = 1
134
+ else:
135
+ self.labelled_shell_counts[resname][labelled_shell]["accepts_from"][
136
+ d
137
+ ] += 1
138
+
139
+ if (
140
+ d
141
+ not in self.resid_labelled_shell_counts[resid][resname][labelled_shell][
142
+ "accepts_from"
143
+ ]
144
+ ):
145
+ self.resid_labelled_shell_counts[resid][resname][labelled_shell][
146
+ "accepts_from"
147
+ ][d] = 1
148
+ else:
149
+ self.resid_labelled_shell_counts[resid][resname][labelled_shell][
150
+ "accepts_from"
151
+ ][d] += 1
152
+
153
+
154
+ def get_HB_labels(atom_idx: int, system, HBs: HBCollection, shells: ShellCollection):
155
+ """
156
+ For a given central atom, get what UAs it donates and accepts from, then
157
+ find what shell labels these correspond to. Update the shells class
158
+ instance with this information
159
+
160
+ :param atom_idx: atom index to find HB labels for
161
+ :param system: mdanalysis instance of all atoms in current frame
162
+ :param HBs: HBCollection class instance
163
+ :param shells: ShellCollection class instance
164
+ """
165
+ shell = shells.find_shell(atom_idx)
166
+ accepts_from_labels = []
167
+ donates_to_labels = []
168
+ if shell:
169
+ # 1.check if HB donating to and accepting from have previously
170
+ # been found
171
+ if shell.labels:
172
+ # 2. Find what UAs the central atom donates to and accepts from
173
+ # with the HBs class instance
174
+ donates_to = HBs.find_acceptor(atom_idx)
175
+ accepts_from = HBs.find_donators(atom_idx)
176
+ if accepts_from:
177
+ for d_idx in accepts_from:
178
+ # 3. check if UA being accepted from is in shell of
179
+ # central UA and add label to list
180
+ bonded_UA = Selections.find_bonded_heavy_atom(d_idx, system)
181
+ if bonded_UA.index in shell.UA_shell:
182
+ shell_idx = shell.UA_shell.index(bonded_UA.index)
183
+ accepts_from_labels.append(shell.labels[shell_idx])
184
+ else:
185
+ # don't add donating neighbour if not in central UA
186
+ # shell
187
+ continue
188
+
189
+ if donates_to:
190
+ # 4. iterate through acceptors and add labels
191
+ for d_idx, a_idx in donates_to.items():
192
+ acceptor = system.atoms[a_idx]
193
+ if acceptor.mass < 1.1:
194
+ acceptor = Selections.find_bonded_heavy_atom(a_idx, system)
195
+ shell_idx = shell.UA_shell.index(acceptor.index)
196
+ donates_to_labels.append(shell.labels[shell_idx])
197
+ # 5. Add labelled neighbours to shells instance
198
+ shell.donates_to_labels = donates_to_labels
199
+ shell.accepts_from_labels = accepts_from_labels