-
Notifications
You must be signed in to change notification settings - Fork 826
Make DensityAnalysis use the Results class #3263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ff50be9
c414ad1
cfb99d6
e700621
4f09268
594e38b
70ceb07
59b1e3d
37fdc8e
138ca97
0989ee6
ccaa89c
7736cfa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,8 +74,8 @@ | |
| ow = u.select_atoms("name OW") | ||
| D = DensityAnalysis(ow, delta=1.0) | ||
| D.run() | ||
| D.density.convert_density('TIP4P') | ||
| D.density.export("water.dx", type="double") | ||
| D.results.density.convert_density('TIP4P') | ||
| D.results.density.export("water.dx", type="double") | ||
|
|
||
| The positions of all water oxygens (the :class:`AtomGroup` `ow`) are | ||
| histogrammed on a grid with spacing *delta* = 1 Å. Initially the density is | ||
|
|
@@ -87,9 +87,9 @@ | |
| can be read in VMD_, Chimera_, or PyMOL_. | ||
|
|
||
| The :class:`Density` object is accessible as the | ||
| :attr:`DensityAnalysis.density` attribute. In particular, the data for the | ||
| density is stored as a NumPy array in :attr:`Density.grid`, which can be | ||
| processed in any manner. | ||
| :attr:`DensityAnalysis.results.density` attribute. In particular, the data | ||
| for the density is stored as a NumPy array in :attr:`Density.grid`, which can | ||
| be processed in any manner. | ||
|
|
||
|
|
||
| Creating densities | ||
|
|
@@ -102,10 +102,12 @@ | |
| :members: | ||
| :inherited-members: run | ||
|
|
||
| .. attribute:: density | ||
| .. attribute:: results.density | ||
|
|
||
| After the analysis (see the :meth:`~DensityAnalysis.run` method), the resulting density is | ||
| stored in the :attr:`density` attribute as a :class:`Density` instance. | ||
| After the analysis (see the :meth:`~DensityAnalysis.run` method), the | ||
| resulting density is stored in the :attr:`results.density` attribute as | ||
| a :class:`Density` instance. Note: this replaces the now deprecated | ||
| :attr:`density` attribute. | ||
|
|
||
| .. automethod:: _set_user_grid | ||
|
|
||
|
|
@@ -166,7 +168,8 @@ | |
|
|
||
| import MDAnalysis | ||
| from MDAnalysis.core import groups | ||
| from MDAnalysis.lib.util import fixedwidth_bins, iterable, asiterable | ||
| from MDAnalysis.lib.util import (fixedwidth_bins, iterable, asiterable, | ||
| deprecate,) | ||
| from MDAnalysis.lib import NeighborSearch as NS | ||
| from MDAnalysis import NoDataError, MissingDataWarning | ||
| from .. import units | ||
|
|
@@ -208,12 +211,19 @@ class DensityAnalysis(AnalysisBase): | |
| zdim : float (optional) | ||
| User defined z dimension box edge in ångström. | ||
|
|
||
| Returns | ||
| ------- | ||
| :class:`Density` | ||
| Attributes | ||
| ---------- | ||
| results.density : :class:`Density` | ||
| A :class:`Density` instance containing a physical density of units | ||
| :math:`Angstrom^{-3}`. | ||
|
|
||
| density : :class:`Density` | ||
| Alias to the :attr:`results.density`. | ||
|
|
||
| .. deprecated:: 2.0.0 | ||
| Will be removed in MDAnalysis 3.0.0. Please use | ||
| :attr:`results.density` instead. | ||
|
|
||
| Raises | ||
| ------ | ||
| ValueError | ||
|
|
@@ -282,11 +292,11 @@ class DensityAnalysis(AnalysisBase): | |
| ow = u.select_atoms("name OW") | ||
| D = density.DensityAnalysis(ow, delta=1.0) | ||
| D.run() | ||
| D.density.convert_density('TIP4P') | ||
| D.results.density.convert_density('TIP4P') | ||
|
|
||
| The positions of all water oxygens are histogrammed on a grid with spacing | ||
| *delta* = 1 Å and stored as a :class:`Density` object in the attribute | ||
| :attr:`DensityAnalysis.density`. | ||
| :attr:`DensityAnalysis.results.density`. | ||
|
|
||
| .. rubric:: Working with a density | ||
|
|
||
|
|
@@ -304,7 +314,7 @@ class DensityAnalysis(AnalysisBase): | |
| density in units of Å\ :sup:`-3`. If you are interested in recovering the | ||
| underlying **probability density**, simply divide by the sum:: | ||
|
|
||
| probability_density = D.density.grid / D.density.grid.sum() | ||
| probability_density = D.results.density.grid / D.results.density.grid.sum() | ||
|
|
||
| Similarly, if you would like to recover a grid containing a **histogram of | ||
| atom counts**, simply multiply by the volume `dV` of each bin (or voxel); | ||
|
|
@@ -314,10 +324,10 @@ class DensityAnalysis(AnalysisBase): | |
| import numpy as np | ||
|
|
||
| # ensure that the density is A^{-3} | ||
| D.density.convert_density("A^{-3}") | ||
| D.results.density.convert_density("A^{-3}") | ||
|
|
||
| dV = np.prod(D.density.delta) | ||
| atom_count_histogram = D.density.grid * dV | ||
| dV = np.prod(D.results.density.delta) | ||
| atom_count_histogram = D.results.density.grid * dV | ||
|
|
||
|
|
||
| .. rubric:: Writing the density to a file | ||
|
|
@@ -330,7 +340,7 @@ class DensityAnalysis(AnalysisBase): | |
| <https://www.mdanalysis.org/GridDataFormats/gridData/basic.html#writing-out-data>`_ | ||
| ``water.dx`` that can be read with VMD, PyMOL, or Chimera:: | ||
|
|
||
| D.density.export("water.dx", type="double") | ||
| D.results.density.export("water.dx", type="double") | ||
|
|
||
|
|
||
| .. rubric:: Example: Water density in the whole simulation | ||
|
|
@@ -384,6 +394,8 @@ class DensityAnalysis(AnalysisBase): | |
| .. versionadded:: 1.0.0 | ||
| .. versionchanged:: 2.0.0 | ||
| :func:`_set_user_grid` is now a method of :class:`DensityAnalysis`. | ||
| :class:`Density` results are now stored in a | ||
| :class:`MDAnalysis.analysis.base.Results` instance. | ||
| """ | ||
|
|
||
| def __init__(self, atomgroup, delta=1.0, | ||
|
|
@@ -457,7 +469,6 @@ def _prepare(self): | |
| self._edges = edges | ||
| self._arange = arange | ||
| self._bins = bins | ||
| self.density = None | ||
|
|
||
| def _single_frame(self): | ||
| h, _ = np.histogramdd(self._atomgroup.positions, | ||
|
|
@@ -476,7 +487,15 @@ def _conclude(self): | |
| units={'length': "Angstrom"}, | ||
| parameters={'isDensity': False}) | ||
| density.make_density() | ||
| self.density = density | ||
| self.results.density = density | ||
|
|
||
| @property | ||
| def density(self): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sad the the docs become messy when we use mda's @deprecate decorator...
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it enforces docstring which is just not very human friendly :(
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but this still looks good and as a good template for the other classes. |
||
| wmsg = ("The `density` attribute was deprecated in MDAnalysis 2.0.0 " | ||
| "and will be removed in MDAnalysis 3.0.0. Please use " | ||
| "`results.density` instead") | ||
| warnings.warn(wmsg, DeprecationWarning) | ||
| return self.results.density | ||
|
|
||
| @staticmethod | ||
| def _set_user_grid(gridcenter, xdim, ydim, zdim, smin, smax): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.