Skip to content

Commit

Permalink
Select keyword everywhere (#2531)
Browse files Browse the repository at this point in the history
  • Loading branch information
RMeli authored Feb 15, 2020
1 parent be41c70 commit f430a00
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 34 deletions.
4 changes: 2 additions & 2 deletions benchmarks/benchmarks/analysis/leaflet.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def time_leafletfinder(self, cutoff, sparse, pbc):
membrane system.
"""
leaflet.LeafletFinder(universe=self.u,
selectionstring=self.headgroup_sel,
select=self.headgroup_sel,
cutoff=cutoff,
pbc=pbc,
sparse=sparse)
Expand All @@ -58,6 +58,6 @@ def time_optimize_cutoff(self, sparse, pbc):
range.
"""
leaflet.optimize_cutoff(universe=self.u,
selection=self.headgroup_sel,
select=self.headgroup_sel,
pbc=pbc,
sparse=sparse)
2 changes: 1 addition & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Changes
in :class:`AnalysisBase`. These should now be called in :meth:`AnalysisBase.run`
(Issue #1463)
* Standardize `select` keyword by removing `selection`, `atomselection`
and `ref_select` (Issue #2461)
and `ref_select` (Issue #2461, Issue #2530)
* Removes support for setting `start`/`stop`/`step` trajecotry slicing
keywords on :class:`HOLEtraj` construction. Also removes undocumented
support for passing :class:`HOLE` parameters to :meth:`HOLEtraj.run`
Expand Down
19 changes: 12 additions & 7 deletions package/MDAnalysis/analysis/leaflet.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class LeafletFinder(object):
universe : Universe or str
:class:`MDAnalysis.Universe` or a file name (e.g., in PDB or
GRO format)
selection : AtomGroup or str
select : AtomGroup or str
A AtomGroup instance or a
:meth:`Universe.select_atoms` selection string
for atoms that define the lipid head groups, e.g.
Expand Down Expand Up @@ -134,12 +134,15 @@ class LeafletFinder(object):
instance. Similarly, all atoms in the first leaflet are then ::
leaflet0.residues.atoms
.. versionchanged:: 1.0.0
Changed `selection` keyword to `select`
"""

def __init__(self, universe, selectionstring, cutoff=15.0, pbc=False, sparse=None):
def __init__(self, universe, select, cutoff=15.0, pbc=False, sparse=None):
universe = core.universe.as_Universe(universe)
self.universe = universe
self.selectionstring = selectionstring
self.selectionstring = select
if isinstance(self.selectionstring, core.groups.AtomGroup):
self.selection = self.selectionstring
else:
Expand Down Expand Up @@ -243,7 +246,7 @@ def write_selection(self, filename, **kwargs):
"""
sw = selections.get_writer(filename, kwargs.pop('format', None))
with sw(filename, mode=kwargs.pop('mode', 'w'),
preamble="leaflets based on selection={selectionstring!r} cutoff={cutoff:f}\n".format(
preamble="leaflets based on select={selectionstring!r} cutoff={cutoff:f}\n".format(
**vars(self)),
**kwargs) as writer:
for i, ag in enumerate(self.groups_iter()):
Expand All @@ -256,7 +259,7 @@ def __repr__(self):
len(self.components))


def optimize_cutoff(universe, selection, dmin=10.0, dmax=20.0, step=0.5,
def optimize_cutoff(universe, select, dmin=10.0, dmax=20.0, step=0.5,
max_imbalance=0.2, **kwargs):
r"""Find cutoff that minimizes number of disconnected groups.
Expand All @@ -277,7 +280,7 @@ def optimize_cutoff(universe, selection, dmin=10.0, dmax=20.0, step=0.5,
----------
universe : Universe
:class:`MDAnalysis.Universe` instance
selection : AtomGroup or str
select : AtomGroup or str
AtomGroup or selection string as used for :class:`LeafletFinder`
dmin : float (optional)
dmax : float (optional)
Expand All @@ -298,11 +301,13 @@ def optimize_cutoff(universe, selection, dmin=10.0, dmax=20.0, step=0.5,
appropriate number of groups can be found; it ought to be
made more robust.
.. versionchanged:: 1.0.0
Changed `selection` keyword to `select`
"""
kwargs.pop('cutoff', None) # not used, so we filter it
_sizes = []
for cutoff in np.arange(dmin, dmax, step):
LF = LeafletFinder(universe, selection, cutoff=cutoff, **kwargs)
LF = LeafletFinder(universe, select, cutoff=cutoff, **kwargs)
# heuristic:
# 1) N > 1
# 2) no imbalance between large groups:
Expand Down
13 changes: 8 additions & 5 deletions package/MDAnalysis/analysis/lineardensity.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class LinearDensity(AnalysisBase):
Parameters
----------
selection : AtomGroup
select : AtomGroup
any atomgroup
grouping : str {'atoms', 'residues', 'segments', 'fragments'}
Density profiles will be computed on the center of geometry
Expand Down Expand Up @@ -79,14 +79,17 @@ class LinearDensity(AnalysisBase):
The ``save()`` method was also removed, you can use ``np.savetxt()`` or
``np.save()`` on the :attr:`LinearDensity.results` dictionary contents
instead.
.. versionchanged:: 1.0.0
Changed `selection` keyword to `select`
"""

def __init__(self, selection, grouping='atoms', binsize=0.25, **kwargs):
super(LinearDensity, self).__init__(selection.universe.trajectory,
def __init__(self, select, grouping='atoms', binsize=0.25, **kwargs):
super(LinearDensity, self).__init__(select.universe.trajectory,
**kwargs)
# allows use of run(parallel=True)
self._ags = [selection]
self._universe = selection.universe
self._ags = [select]
self._universe = select.universe

self.binsize = binsize

Expand Down
48 changes: 29 additions & 19 deletions package/MDAnalysis/analysis/waterdynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@
from MDAnalysis.analysis.waterdynamics import WaterOrientationalRelaxation as WOR
u = MDAnalysis.Universe(pdb, trajectory)
selection = "byres name OH2 and sphzone 6.0 protein and resid 42"
WOR_analysis = WOR(universe, selection, 0, 1000, 20)
select = "byres name OH2 and sphzone 6.0 protein and resid 42"
WOR_analysis = WOR(universe, select, 0, 1000, 20)
WOR_analysis.run()
time = 0
#now we print the data ready to plot. The first two columns are WOR_OH vs t plot,
Expand Down Expand Up @@ -253,8 +253,8 @@
from MDAnalysis.analysis.waterdynamics import MeanSquareDisplacement as MSD
u = MDAnalysis.Universe(pdb, trajectory)
selection = "byres name OH2 and cyzone 11.0 4.0 -8.0 protein"
MSD_analysis = MSD(universe, selection, 0, 1000, 20)
select = "byres name OH2 and cyzone 11.0 4.0 -8.0 protein"
MSD_analysis = MSD(universe, select, 0, 1000, 20)
MSD_analysis.run()
#now we print data ready to graph. The graph
#represents MSD vs t
Expand Down Expand Up @@ -287,8 +287,8 @@
import matplotlib.pyplot as plt
universe = MDAnalysis.Universe(pdb, trajectory)
selection = "byres name OH2 and sphzone 12.3 (resid 42 or resid 26) "
sp = SP(universe, selection, verbose=True)
select = "byres name OH2 and sphzone 12.3 (resid 42 or resid 26) "
sp = SP(universe, select, verbose=True)
sp.run(start=0, stop=100, tau_max=20)
tau_timeseries = sp.tau_timeseries
sp_timeseries = sp.sp_timeseries
Expand Down Expand Up @@ -328,8 +328,8 @@
for lipid in lipids.residues:
print("Lipid ID: %d" % lipid.resid)
selection = "resname POTASSIUM and around 3.5 (resid %d and name O13 O14) " % lipid.resid
sp = SP(u, selection, verbose=True)
select = "resname POTASSIUM and around 3.5 (resid %d and name O13 O14) " % lipid.resid
sp = SP(u, select, verbose=True)
sp.run(tau_max=20)
# Raw SP points for each tau:
Expand Down Expand Up @@ -674,11 +674,13 @@ class WaterOrientationalRelaxation(object):
.. versionadded:: 0.11.0
.. versionchanged:: 1.0.0
Changed `selection` keyword to `select`
"""

def __init__(self, universe, selection, t0, tf, dtmax, nproc=1):
def __init__(self, universe, select, t0, tf, dtmax, nproc=1):
self.universe = universe
self.selection = selection
self.selection = select
self.t0 = t0
self.tf = tf
self.dtmax = dtmax
Expand Down Expand Up @@ -855,7 +857,7 @@ class AngularDistribution(object):
----------
universe : Universe
Universe object
selection : str
select : str
Selection string to evaluate its angular distribution ['byres name OH2']
bins : int (optional)
Number of bins to create the histogram by means of :func:`numpy.histogram`
Expand All @@ -865,11 +867,14 @@ class AngularDistribution(object):
.. versionadded:: 0.11.0
.. versionchanged:: 1.0.0
Changed `selection` keyword to `select`
"""

def __init__(self, universe, selection_str, bins=40, nproc=1, axis="z"):
def __init__(self, universe, select, bins=40, nproc=1, axis="z"):
self.universe = universe
self.selection_str = selection_str
self.selection_str = select
self.bins = bins
self.nproc = nproc
self.axis = axis
Expand Down Expand Up @@ -1007,7 +1012,7 @@ class MeanSquareDisplacement(object):
----------
universe : Universe
Universe object
selection : str
select : str
Selection string for water [‘byres name OH2’].
t0 : int
frame where analysis begins
Expand All @@ -1018,11 +1023,14 @@ class MeanSquareDisplacement(object):
.. versionadded:: 0.11.0
.. versionchanged:: 1.0.0
Changed `selection` keyword to `select`
"""

def __init__(self, universe, selection, t0, tf, dtmax, nproc=1):
def __init__(self, universe, select, t0, tf, dtmax, nproc=1):
self.universe = universe
self.selection = selection
self.selection = select
self.t0 = t0
self.tf = tf
self.dtmax = dtmax
Expand Down Expand Up @@ -1161,7 +1169,7 @@ class SurvivalProbability(object):
----------
universe : Universe
Universe object
selection : str
select : str
Selection string; any selection is allowed. With this selection you
define the region/zone where to analyze, e.g.: "resname SOL and around 5 (resid 10)". See `SP-examples`_.
verbose : Boolean, optional
Expand All @@ -1170,11 +1178,13 @@ class SurvivalProbability(object):
.. versionadded:: 0.11.0
.. versionchanged:: 1.0.0
Changed `selection` keyword to `select`
"""

def __init__(self, universe, selection, t0=None, tf=None, dtmax=None, verbose=False):
def __init__(self, universe, select, t0=None, tf=None, dtmax=None, verbose=False):
self.universe = universe
self.selection = selection
self.selection = select
self.verbose = verbose

# backward compatibility
Expand Down

0 comments on commit f430a00

Please sign in to comment.