Skip to content

Commit

Permalink
Merge branch 'develop' into rdkit-converter-inferring
Browse files Browse the repository at this point in the history
  • Loading branch information
orbeckst authored Jun 11, 2024
2 parents ea26569 + 347a0c0 commit 6070d89
Show file tree
Hide file tree
Showing 19 changed files with 2,223 additions and 60 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/gh-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: coverage.xml
fail_ci_if_error: True
fail_ci_if_error: False
verbose: True


Expand Down Expand Up @@ -259,22 +259,22 @@ jobs:
- name: check_package_build
run: |
DISTRIBUTION=$(ls -t1 dist/MDAnalysis-*.tar.gz | head -n1)
DISTRIBUTION=$(ls -t1 dist/mdanalysis-*.tar.gz | head -n1)
test -n "${DISTRIBUTION}" || { echo "no distribution dist/MDAnalysis-*.tar.gz found"; exit 1; }
twine check $DISTRIBUTION
- name: check_testsuite_build
run: |
DISTRIBUTION=$(ls -t1 dist/MDAnalysisTests-*.tar.gz | head -n1)
DISTRIBUTION=$(ls -t1 dist/mdanalysistests-*.tar.gz | head -n1)
test -n "${DISTRIBUTION}" || { echo "no distribution dist/MDAnalysisTests-*.tar.gz found"; exit 1; }
twine check $DISTRIBUTION
- name: install sdist
working-directory: ./dist
run: |
ls -a .
python -m pip install MDAnalysis-*.tar.gz
python -m pip install MDAnalysisTests-*.tar.gz
python -m pip install mdanalysis-*.tar.gz
python -m pip install mdanalysistests-*.tar.gz
- name: run tests
working-directory: ./dist
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ jobs:
micromamba: true
full-deps: true
numpy: numpy=1.23.2
rdkit: rdkit=2023.09.3

- name: install
run: |
Expand Down
13 changes: 6 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,18 @@ Citation
When using MDAnalysis in published work, please cite the following
two papers:

* R. J. Gowers, M. Linke, J. Barnoud, T. J. E. Reddy,
M. N. Melo, S. L. Seyler, D. L. Dotson, J. Domanski,
S. Buchoux, I. M. Kenney, and O. Beckstein. MDAnalysis:
* R\. J. Gowers, M. Linke, J. Barnoud, T. J. E. Reddy,
M\. N. Melo, S. L. Seyler, D. L. Dotson, J. Domanski,
S\. Buchoux, I. M. Kenney, and O. Beckstein. MDAnalysis:
A Python package for the rapid analysis of molecular
dynamics simulations. In S. Benthall and S. Rostrup,
editors, Proceedings of the 15th Python in Science
Conference, pages 102-109, Austin, TX, 2016. SciPy.
doi:`10.25080/Majora-629e541a-00e`_

doi: `10.25080/Majora-629e541a-00e`_
* N. Michaud-Agrawal, E. J. Denning, T. B. Woolf,
and O. Beckstein. MDAnalysis: A Toolkit for the Analysis of Molecular
Dynamics Simulations. *J. Comput. Chem.* **32** (2011), 2319--2327.
doi:`10.1002/jcc.21787`_
doi: `10.1002/jcc.21787`_

For citations of included algorithms and sub-modules please see the references_.

Expand Down Expand Up @@ -194,4 +193,4 @@ For citations of included algorithms and sub-modules please see the references_.

.. |discussions| image:: https://img.shields.io/github/discussions/MDAnalysis/MDAnalysis
:alt: GitHub Discussions
:target: https://github.com/MDAnalysis/mdanalysis/discussions
:target: https://github.com/MDAnalysis/mdanalysis/discussions
10 changes: 8 additions & 2 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ The rules for this file:
-------------------------------------------------------------------------------
??/??/?? IAlibay, HeetVekariya, marinegor, lilyminium, RMeli,
ljwoods2, aditya292002, pstaerk, PicoCentauri, BFedder,
tyler.je.reddy, SampurnaM, leonwehrhan, kainszs, orionarcher, cbouy

tyler.je.reddy, SampurnaM, leonwehrhan, kainszs, orionarcher,
yuxuanzhuang, cbouy

* 2.8.0

Fixes
* Fix PSFParser error when encoutering string-like resids
* (Issue #2053, Issue #4189 PR #4582)
* Fix `MDAnalysis.analysis.align.AlignTraj` not accepting writer kwargs
(Issue #4564, PR #4565)
* Fix #4259 via removing argument `parallelizable` of `NoJump` transformation.
* Fix doctest errors of analysis/pca.py related to rounding issues
(Issue #3925, PR #4377)
* Convert openmm Quantity to raw value for KE and PE in OpenMMSimulationReader.
Expand Down
12 changes: 10 additions & 2 deletions package/MDAnalysis/analysis/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ class AlignTraj(AnalysisBase):
def __init__(self, mobile, reference, select='all', filename=None,
prefix='rmsfit_', weights=None,
tol_mass=0.1, match_atoms=True, strict=False, force=True, in_memory=False,
writer_kwargs=None,
**kwargs):
"""Parameters
----------
Expand Down Expand Up @@ -720,6 +721,8 @@ def __init__(self, mobile, reference, select='all', filename=None,
verbose : bool (optional)
Set logger to show more information and show detailed progress of
the calculation if set to ``True``; the default is ``False``.
writer_kwargs : dict (optional)
kwarg dict to be passed to the constructed writer
Attributes
Expand Down Expand Up @@ -780,6 +783,9 @@ def __init__(self, mobile, reference, select='all', filename=None,
:attr:`rmsd` results are now stored in a
:class:`MDAnalysis.analysis.base.Results` instance.
.. versionchanged:: 2.8.0
Added ``writer_kwargs`` kwarg dict to pass to the writer
"""
select = rms.process_selection(select)
self.ref_atoms = reference.select_atoms(*select['reference'])
Expand Down Expand Up @@ -816,10 +822,12 @@ def __init__(self, mobile, reference, select='all', filename=None,
self.ref_atoms, self.mobile_atoms, tol_mass=tol_mass,
strict=strict, match_atoms=match_atoms)

if writer_kwargs is None:
writer_kwargs = {}
# with self.filename == None (in_memory), the NullWriter is chosen
# (which just ignores input) and so only the in_memory trajectory is
# retained
self._writer = mda.Writer(self.filename, natoms)
self._writer = mda.Writer(self.filename, natoms, **writer_kwargs)

self._weights = get_weights(self.ref_atoms, weights)

Expand Down Expand Up @@ -1661,4 +1669,4 @@ def get_atoms_byres(g, match_mask=np.logical_not(mismatch_mask)):
logger.error(errmsg)
raise SelectionError(errmsg)

return ag1, ag2
return ag1, ag2
2 changes: 1 addition & 1 deletion package/MDAnalysis/analysis/helix_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def vector_of_best_fit(coordinates):
"""
centered = coordinates - coordinates.mean(axis=0)
Mt_M = np.matmul(centered.T, centered)
u, s, vh = np.linalg.linalg.svd(Mt_M)
u, s, vh = np.linalg.svd(Mt_M)
vector = vh[0]

# does vector face first local helix origin?
Expand Down
2 changes: 1 addition & 1 deletion package/MDAnalysis/analysis/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
.. math::
g_{ab}(r) = (N_{a} N_{b})^{-1} \sum_{i=1}^{N_a} \sum_{j=1}^{N_b}
g_{ab}(r) = \frac{1}{N_{a}} \frac{1}{N_{b}/V} \sum_{i=1}^{N_a} \sum_{j=1}^{N_b}
\langle \delta(|\mathbf{r}_i - \mathbf{r}_j| - r) \rangle
which is normalized so that the RDF becomes 1 for large separations in a
Expand Down
29 changes: 20 additions & 9 deletions package/MDAnalysis/coordinates/LAMMPS.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,33 @@
:class:`~MDAnalysis.topology.LAMMPSParser.DATAParser`) together with a
LAMMPS DCD with "*real*" provide the keyword *format="LAMMPS*"::
>>> u = MDAnalysis.Universe("lammps.data", "lammps_real.dcd", format="LAMMPS")
>>> import MDAnalysis
>>> from MDAnalysis.tests.datafiles import LAMMPSdata2, LAMMPSdcd2
>>> u = MDAnalysis.Universe(LAMMPSdata2, LAMMPSdcd2, format="LAMMPS")
If the trajectory uses *units nano* then use ::
If the trajectory uses *units nano* then use
>>> u = MDAnalysis.Universe("lammps.data", "lammps_nano.dcd", format="LAMMPS",
>>> import MDAnalysis
>>> from MDAnalysis.tests.datafiles import LAMMPSdata2, LAMMPSdcd2
>>> u = MDAnalysis.Universe(LAMMPSdata2, LAMMPSdcd2, format="LAMMPS",
... lengthunit="nm", timeunit="ns")
To scan through a trajectory to find a desirable frame and write to a LAMMPS
data file,
>>> for ts in u.trajectory:
... # analyze frame
... if take_this_frame == True:
... with mda.Writer('frame.data') as W:
... W.write(u.atoms)
... break
>>> import MDAnalysis
>>> from MDAnalysis.tests.datafiles import LAMMPSdata2, LAMMPSdcd2
>>> u = MDAnalysis.Universe(LAMMPSdata2, LAMMPSdcd2, format="LAMMPS",
... lengthunit="nm", timeunit="ns")
>>> take_this_frame = False
>>> for ts in u.trajectory:
... # analyze frame
... if ts.frame == 4:
... take_this_frame = True
... if take_this_frame == True:
... with MDAnalysis.Writer('frame.data') as W:
... W.write(u.atoms)
... break
Note
----
Expand Down
6 changes: 4 additions & 2 deletions package/MDAnalysis/lib/formats/cython_util.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ cimport numpy as cnp
from libc.stdlib cimport free
from cpython cimport PyObject, Py_INCREF

from MDAnalysis.lib.util import no_copy_shim

cnp.import_array()


Expand Down Expand Up @@ -71,7 +73,7 @@ cdef class ArrayWrapper:
self.data_type = data_type
self.ndim = ndim

def __array__(self):
def __array__(self, dtype=None, copy=None):
""" Here we use the __array__ method, that is called when numpy
tries to get an array from the object."""
ndarray = cnp.PyArray_SimpleNewFromData(self.ndim,
Expand Down Expand Up @@ -110,7 +112,7 @@ cdef cnp.ndarray ptr_to_ndarray(void* data_ptr, cnp.int64_t[:] dim, int data_typ
array_wrapper = ArrayWrapper()
array_wrapper.set_data(<void*> data_ptr, <int*> &dim[0], dim.size, data_type)

cdef cnp.ndarray ndarray = np.array(array_wrapper, copy=False)
cdef cnp.ndarray ndarray = np.array(array_wrapper, copy=no_copy_shim)
# Assign our object to the 'base' of the ndarray object
ndarray[:] = array_wrapper.__array__()
# Increment the reference count, as the above assignement was done in
Expand Down
13 changes: 7 additions & 6 deletions package/MDAnalysis/lib/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
from numpy.linalg import norm

from .mdamath import angle as vecangle
from MDAnalysis.lib.util import no_copy_shim

def identity_matrix():
"""Return 4x4 identity/unit matrix.
Expand Down Expand Up @@ -326,7 +327,7 @@ def rotation_matrix(angle, direction, point=None):
M[:3, :3] = R
if point is not None:
# rotation not around origin
point = np.array(point[:3], dtype=np.float64, copy=False)
point = np.array(point[:3], dtype=np.float64, copy=no_copy_shim)
M[:3, 3] = point - np.dot(R, point)
return M

Expand Down Expand Up @@ -497,7 +498,7 @@ def projection_matrix(point, normal, direction=None,
"""
M = np.identity(4)
point = np.array(point[:3], dtype=np.float64, copy=False)
point = np.array(point[:3], dtype=np.float64, copy=no_copy_shim)
normal = unit_vector(normal[:3])
if perspective is not None:
# perspective projection
Expand All @@ -515,7 +516,7 @@ def projection_matrix(point, normal, direction=None,
M[3, 3] = np.dot(perspective, normal)
elif direction is not None:
# parallel projection
direction = np.array(direction[:3], dtype=np.float64, copy=False)
direction = np.array(direction[:3], dtype=np.float64, copy=no_copy_shim)
scale = np.dot(direction, normal)
M[:3, :3] -= np.outer(direction, normal) / scale
M[:3, 3] = direction * (np.dot(point, normal) / scale)
Expand Down Expand Up @@ -970,8 +971,8 @@ def superimposition_matrix(v0, v1, scaling=False, usesvd=True):
True
"""
v0 = np.array(v0, dtype=np.float64, copy=False)[:3]
v1 = np.array(v1, dtype=np.float64, copy=False)[:3]
v0 = np.array(v0, dtype=np.float64, copy=no_copy_shim)[:3]
v1 = np.array(v1, dtype=np.float64, copy=no_copy_shim)[:3]

if v0.shape != v1.shape or v0.shape[1] < 3:
raise ValueError("vector sets are of wrong shape or type")
Expand Down Expand Up @@ -1314,7 +1315,7 @@ def quaternion_from_matrix(matrix, isprecise=False):
True
"""
M = np.array(matrix, dtype=np.float64, copy=False)[:4, :4]
M = np.array(matrix, dtype=np.float64, copy=no_copy_shim)[:4, :4]
if isprecise:
q = np.empty((4, ), dtype=np.float64)
t = np.trace(M)
Expand Down
40 changes: 40 additions & 0 deletions package/MDAnalysis/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
from functools import wraps
import textwrap
import weakref
import itertools

import mmtf
import numpy as np
Expand Down Expand Up @@ -2552,3 +2553,42 @@ def wrapper(self, *args, **kwargs):
self._kwargs[key] = arg
return func(self, *args, **kwargs)
return wrapper


def no_copy_shim():
if np.lib.NumpyVersion >= "2.0.0rc1":
copy = None
else:
copy = False
return copy


def atoi(s: str) -> int:
"""Convert the leading number part of a string to an integer.
Parameters
----------
s : str
The string to convert to an integer.
Returns
-------
number : int
The first numeric part of the string converted to an integer.
If the string does not start with a number, 0 is returned.
Examples
--------
>>> from MDAnalysis.lib.util import atoi
>>> atoi('34f4')
34
>>> atoi('foo')
0
.. versionadded:: 2.8.0
"""
try:
return int(''.join(itertools.takewhile(str.isdigit, s.strip())))
except ValueError:
return 0
9 changes: 7 additions & 2 deletions package/MDAnalysis/topology/PSFParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from math import ceil
import numpy as np

from ..lib.util import openany
from ..lib.util import openany, atoi
from . import guessers
from .base import TopologyReaderBase, squash_by, change_squash
from ..core.topologyattrs import (
Expand Down Expand Up @@ -89,6 +89,10 @@ class PSFParser(TopologyReaderBase):
- impropers
.. _PSF: http://www.charmm.org/documentation/c35b1/struct.html
.. versionchanged:: 2.8.0
PSFParser now reads string resids and converts them to integers.
"""
format = 'PSF'

Expand Down Expand Up @@ -248,7 +252,8 @@ def _parseatoms(self, lines, atoms_per, numlines):
}
atom_parser = atom_parsers[self._format]
# once partitioned, assigned each component the correct type
set_type = lambda x: (int(x[0]) - 1, x[1] or "SYSTEM", int(x[2]), x[3],
set_type = lambda x: (int(x[0]) - 1, x[1] or "SYSTEM",
atoi(x[2]), x[3],
x[4], x[5], float(x[6]), float(x[7]))

# Oli: I don't think that this is the correct OUTPUT format:
Expand Down
5 changes: 2 additions & 3 deletions package/MDAnalysis/transformations/nojump.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ def __init__(
self,
check_continuity=True,
max_threads=None,
):
# NoJump transforms are inherently unparallelizable, since
# it depends on the previous frame's unwrapped coordinates
parallelizable=False,
):
super().__init__(max_threads=max_threads, parallelizable=parallelizable)
super().__init__(max_threads=max_threads, parallelizable=False)
self.prev = None
self.old_frame = 0
self.older_frame = "A"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ under the Apache v2.0 license.)
`mdahole2 <https://www.mdanalysis.org/mdahole2/>`_ and
will be removed in MDAnalysis 3.0.0.

.. _HOLE: http://www.holeprogram.org/


See Also
--------
Expand Down
Loading

0 comments on commit 6070d89

Please sign in to comment.