Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Enhancements
* Added *Group.copy() methods returning an identical copy of the respective
group (PR #1922)
* Use a faster function to deduplicate indices (PR #1951)
* Calculations in *Group.center() are performed in double precision (#PR1936)
* Functions in lib.distances accept coordinate arrays of arbitrary dtype
(PR #1936)

Fixes
* rewind in the SingleFrameReader now reads the frame from the file (Issue #1929)
Expand Down
18 changes: 15 additions & 3 deletions package/MDAnalysis/core/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,11 +711,19 @@ def center(self, weights, pbc=None, compound='group'):

atoms = self.atoms

# enforce calculations in double precision:
dtype = np.float64

if compound.lower() == 'group':
if pbc:
coords = atoms.pack_into_box(inplace=False)
else:
coords = atoms.positions
# promote coords or weights to dtype if required:
if weights is None:
coords = coords.astype(dtype, copy=False)
else:
weights = weights.astype(dtype, copy=False)
return np.average(coords, weights=weights, axis=0)
elif compound.lower() == 'residues':
compound_indices = atoms.resindices
Expand All @@ -728,14 +736,18 @@ def center(self, weights, pbc=None, compound='group'):
" one of 'group', 'residues', or 'segments'."
"".format(compound))

# Sort positions and masses by compound index:
# Sort positions and weights by compound index and promote to dtype if
# required:
sort_indices = np.argsort(compound_indices)
compound_indices = compound_indices[sort_indices]
coords = atoms.positions[sort_indices]
if weights is not None:
if weights is None:
coords = coords.astype(dtype, copy=False)
else:
weights = weights.astype(dtype, copy=False)
weights = weights[sort_indices]
# Allocate output array:
centers = np.zeros((n_compounds, 3), dtype=coords.dtype)
centers = np.zeros((n_compounds, 3), dtype=dtype)
# Get sizes of compounds:
unique_compound_indices, compound_sizes = np.unique(compound_indices,
return_counts=True)
Expand Down
Loading