Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishy7777 committed Feb 4, 2025
1 parent 2548cfe commit 276d3fc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package/MDAnalysis/analysis/polymer.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ class PersistenceLength(AnalysisBase):
C(n) = \langle \cos\theta_{i, i+n} \rangle =
\langle \mathbf{a_i} \cdot \mathbf{a_{i+n}} \rangle
where :math:`a_i` and :math:`a_{i+n}` are unit vectors
along the bonds. (Because for two vectors :math:`\mathbf{a}` and :math:`\mathbf{b}`,
along the bonds. (Because for two vectors :math:`\mathbf{a}` and :math:`\mathbf{b}`,
:math:`\mathbf{a} \cdot \mathbf{b} = |\mathbf{a}| |\mathbf{b}| \cos{\alpha}`,
where :math:`\alpha` is the angle between the two vectors.)
Expand Down
28 changes: 22 additions & 6 deletions package/MDAnalysis/core/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,25 +1106,41 @@ class WaterSelection(Selection):
.. versionadded:: 2.9.0
"""
token = 'water'

token = "water"

# Recognized water resnames
water_res = {
'H2O', 'HOH', 'OH2', 'HHO', 'OHH',
'T3P', 'T4P', 'T5P', 'SOL', 'WAT',
'TIP', 'TIP2', 'TIP3', 'TIP4'
"H2O",
"HOH",
"OH2",
"HHO",
"OHH",
"T3P",
"T4P",
"T5P",
"SOL",
"WAT",
"TIP",
"TIP2",
"TIP3",
"TIP4",
}

def _apply(self, group):
resnames = group.universe._topology.resnames
nmidx = resnames.nmidx[group.resindices]

matches = [ix for (nm, ix) in resnames.namedict.items()
if nm in self.water_res]
matches = [
ix
for (nm, ix) in resnames.namedict.items()
if nm in self.water_res
]
mask = np.isin(nmidx, matches)

return group[mask]


class BackboneSelection(ProteinSelection):
"""A BackboneSelection contains all atoms with name 'N', 'CA', 'C', 'O'.
Expand Down
12 changes: 6 additions & 6 deletions testsuite/MDAnalysisTests/coordinates/test_xdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,10 +984,12 @@ def test_persistent_offsets_readonly(self, tmpdir, trajectory):
shutil.copy(self.filename, str(tmpdir))

filename = str(tmpdir.join(os.path.basename(self.filename)))
print('filename', filename)
print("filename", filename)
ref_offset = trajectory._xdr.offsets
# Mock filelock acquire to raise an error
with patch.object(FileLock, "acquire", side_effect=PermissionError): # Simulate failure
with patch.object(
FileLock, "acquire", side_effect=PermissionError
): # Simulate failure
with pytest.warns(UserWarning, match="Cannot write lock"):
reader = self._reader(filename)
saved_offsets = reader._xdr.offsets
Expand All @@ -1008,12 +1010,10 @@ def test_persistent_offsets_readonly(self, tmpdir, trajectory):

@pytest.mark.skipif(
sys.platform.startswith("win"),
reason="The lock file only exists when it's locked in windows"
reason="The lock file only exists when it's locked in windows",
)
def test_offset_lock_created(self, traj):
assert os.path.exists(
XDR.offsets_filename(traj, ending="lock")
)
assert os.path.exists(XDR.offsets_filename(traj, ending="lock"))


class TestXTCReader_offsets(_GromacsReader_offsets):
Expand Down

0 comments on commit 276d3fc

Please sign in to comment.