-
Notifications
You must be signed in to change notification settings - Fork 825
Move angles to results.angles for dihedral classes #3266
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
c7f2f70
1a507b1
0a8e851
3bfffb7
77570fc
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 |
|---|---|---|
|
|
@@ -66,7 +66,7 @@ | |
| from MDAnalysis.analysis.dihedrals import Dihedral | ||
| R = Dihedral(ags).run() | ||
|
|
||
| The angles can then be accessed with :attr:`Dihedral.angles`. | ||
| The angles can then be accessed with :attr:`Dihedral.results.angles`. | ||
|
|
||
| Ramachandran analysis | ||
| ~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
@@ -103,7 +103,7 @@ | |
| and the "marginally allowed" regions. | ||
|
|
||
| To plot the data yourself, the angles can be accessed using | ||
| :attr:`Ramachandran.angles`. | ||
| :attr:`Ramachandran.results.angles`. | ||
|
|
||
| .. Note:: | ||
|
|
||
|
|
@@ -124,7 +124,7 @@ | |
| <figure-janin>` as an example. | ||
|
|
||
| The data for the angles can be accessed in the attribute | ||
| :attr:`Janin.angles`. | ||
| :attr:`Janin.results.angles`. | ||
|
|
||
| .. _figure-janin: | ||
|
|
||
|
|
@@ -153,7 +153,8 @@ | |
| ~~~~~~~~~~~~~~~ | ||
|
|
||
| Reference plots can be added to the axes for both the Ramachandran and Janin | ||
| classes using the kwarg ``ref=True``. The Ramachandran reference data | ||
| classes using the kwarg ``ref=True`` for the :meth:`Ramachandran.plot` | ||
| and :meth:`Janin.plot` methods. The Ramachandran reference data | ||
| (:data:`~MDAnalysis.analysis.data.filenames.Rama_ref`) and Janin reference data | ||
| (:data:`~MDAnalysis.analysis.data.filenames.Janin_ref`) were made using data | ||
| obtained from a large selection of 500 PDB files, and were analyzed using these | ||
|
|
@@ -173,32 +174,65 @@ | |
| :members: | ||
| :inherited-members: | ||
|
|
||
| .. attribute:: angles | ||
| .. attribute:: results.angles | ||
|
|
||
| Contains the time steps of the angles for each atomgroup in the list as | ||
| an ``n_frames×len(atomgroups)`` :class:`numpy.ndarray` with content | ||
| ``[[angle 1, angle 2, ...], [time step 2], ...]``. | ||
|
|
||
| .. versionadded:: 2.0.0 | ||
|
|
||
| .. attribute:: angles | ||
|
|
||
| Alias to the :attr:`results.angles` attribute. | ||
|
|
||
| .. deprecated:: 2.0.0 | ||
| Will be removed in MDAnalysis 3.0.0. Please use | ||
| :attr:`results.angles` instead. | ||
|
|
||
|
|
||
| .. autoclass:: Ramachandran | ||
| :members: | ||
| :inherited-members: | ||
|
|
||
| .. attribute:: angles | ||
| .. attribute:: results.angles | ||
|
|
||
| Contains the time steps of the :math:`\phi` and :math:`\psi` angles for | ||
| each residue as an ``n_frames×n_residues×2`` :class:`numpy.ndarray` with | ||
| content ``[[[phi, psi], [residue 2], ...], [time step 2], ...]``. | ||
|
|
||
|
Comment on lines
+198
to
203
Member
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. add versionadded:: 2.0.0
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. There's a
Member
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. I know and that's (=changes) good. I find that the versionadded completes the picture. I put it in the general instructions in #3261 . We can update whenever, though. |
||
| .. versionadded:: 2.0.0 | ||
|
|
||
| .. attribute:: angles | ||
|
|
||
| Alias to the :attr:`results.angles` attribute. | ||
|
|
||
| .. deprecated:: 2.0.0 | ||
| Will be removed in MDAnalysis 3.0.0. Please use | ||
| :attr:`results.angles` instead. | ||
|
|
||
|
|
||
| .. autoclass:: Janin | ||
| :members: | ||
| :inherited-members: | ||
|
|
||
| .. attribute:: angles | ||
| .. attribute:: results.angles | ||
|
|
||
| Contains the time steps of the :math:`\chi_1` and :math:`\chi_2` angles | ||
| for each residue as an ``n_frames×n_residues×2`` :class:`numpy.ndarray` | ||
| with content ``[[[chi1, chi2], [residue 2], ...], [time step 2], ...]``. | ||
|
|
||
| .. versionadded:: 2.0.0 | ||
|
|
||
| .. attribute:: angles | ||
|
|
||
| Alias to the :attr:`results.angles` attribute. | ||
|
|
||
| .. deprecated:: 2.0.0 | ||
| Will be removed in MDAnalysis 3.0.0. Please use | ||
| :attr:`results.angles` instead. | ||
|
|
||
|
|
||
| References | ||
| ---------- | ||
|
|
||
|
|
@@ -251,6 +285,11 @@ class Dihedral(AnalysisBase): | |
| selection of atomgroups. If there is only one atomgroup of interest, then | ||
| it must be given as a list of one atomgroup. | ||
|
|
||
|
|
||
| .. versionchanged:: 2.0.0 | ||
| :attr:`angles` results are now stored in a | ||
| :class:`MDAnalysis.analysis.base.Results` instance. | ||
|
|
||
| """ | ||
|
|
||
| def __init__(self, atomgroups, **kwargs): | ||
|
|
@@ -278,16 +317,25 @@ def __init__(self, atomgroups, **kwargs): | |
| self.ag4 = mda.AtomGroup([ag[3] for ag in atomgroups]) | ||
|
|
||
| def _prepare(self): | ||
| self.angles = [] | ||
| self.results.angles = [] | ||
|
|
||
| def _single_frame(self): | ||
| angle = calc_dihedrals(self.ag1.positions, self.ag2.positions, | ||
| self.ag3.positions, self.ag4.positions, | ||
| box=self.ag1.dimensions) | ||
| self.angles.append(angle) | ||
| self.results.angles.append(angle) | ||
|
|
||
| def _conclude(self): | ||
| self.angles = np.rad2deg(np.array(self.angles)) | ||
| self.results.angles = np.rad2deg(np.array(self.results.angles)) | ||
|
|
||
| @property | ||
| def angles(self): | ||
| wmsg = ("The `angle` attribute was deprecated in MDAnalysis 2.0.0 " | ||
| "and will be removed in MDAnalysis 3.0.0. Please use " | ||
| "`results.angles` instead") | ||
| warnings.warn(wmsg, DeprecationWarning) | ||
| return self.results.angles | ||
|
|
||
|
|
||
| class Ramachandran(AnalysisBase): | ||
| r"""Calculate :math:`\phi` and :math:`\psi` dihedral angles of selected | ||
|
|
@@ -349,6 +397,9 @@ class Ramachandran(AnalysisBase): | |
|
|
||
| .. versionchanged:: 1.0.0 | ||
| added c_name, n_name, ca_name, and check_protein keyword arguments | ||
| .. versionchanged:: 2.0.0 | ||
| :attr:`angles` results are now stored in a | ||
| :class:`MDAnalysis.analysis.base.Results` instance. | ||
|
|
||
| """ | ||
|
|
||
|
|
@@ -405,7 +456,7 @@ def __init__(self, atomgroup, c_name='C', n_name='N', ca_name='CA', | |
|
|
||
|
|
||
| def _prepare(self): | ||
| self.angles = [] | ||
| self.results.angles = [] | ||
|
|
||
| def _single_frame(self): | ||
| phi_angles = calc_dihedrals(self.ag1.positions, self.ag2.positions, | ||
|
|
@@ -415,16 +466,16 @@ def _single_frame(self): | |
| self.ag4.positions, self.ag5.positions, | ||
| box=self.ag1.dimensions) | ||
| phi_psi = [(phi, psi) for phi, psi in zip(phi_angles, psi_angles)] | ||
| self.angles.append(phi_psi) | ||
| self.results.angles.append(phi_psi) | ||
|
|
||
| def _conclude(self): | ||
| self.angles = np.rad2deg(np.array(self.angles)) | ||
| self.results.angles = np.rad2deg(np.array(self.results.angles)) | ||
|
|
||
| def plot(self, ax=None, ref=False, **kwargs): | ||
| """Plots data into standard Ramachandran plot. | ||
|
|
||
| Each time step in :attr:`Ramachandran.angles` is plotted onto the same | ||
| graph. | ||
| Each time step in :attr:`Ramachandran.results.angles` is plotted onto | ||
| the same graph. | ||
|
|
||
| Parameters | ||
| ---------- | ||
|
|
@@ -463,10 +514,19 @@ def plot(self, ax=None, ref=False, **kwargs): | |
| levels = [1, 17, 15000] | ||
| colors = ['#A1D4FF', '#35A1FF'] | ||
| ax.contourf(X, Y, np.load(Rama_ref), levels=levels, colors=colors) | ||
| a = self.angles.reshape(np.prod(self.angles.shape[:2]), 2) | ||
| a = self.results.angles.reshape( | ||
| np.prod(self.results.angles.shape[:2]), 2) | ||
| ax.scatter(a[:, 0], a[:, 1], **kwargs) | ||
| return ax | ||
|
|
||
| @property | ||
| def angles(self): | ||
| wmsg = ("The `angle` attribute was deprecated in MDAnalysis 2.0.0 " | ||
| "and will be removed in MDAnalysis 3.0.0. Please use " | ||
| "`results.angles` instead") | ||
| warnings.warn(wmsg, DeprecationWarning) | ||
| return self.results.angles | ||
|
|
||
|
|
||
| class Janin(Ramachandran): | ||
| r"""Calculate :math:`\chi_1` and :math:`\chi_2` dihedral angles of selected | ||
|
|
@@ -523,7 +583,9 @@ def __init__(self, atomgroup, | |
|
|
||
|
|
||
| .. versionchanged:: 2.0.0 | ||
| `select_remove` and `select_protein` keywords were added | ||
| `select_remove` and `select_protein` keywords were added. | ||
| :attr:`angles` results are now stored in a | ||
| :class:`MDAnalysis.analysis.base.Results` instance. | ||
| """ | ||
| super(Ramachandran, self).__init__( | ||
| atomgroup.universe.trajectory, **kwargs) | ||
|
|
@@ -557,12 +619,13 @@ def __init__(self, atomgroup, | |
| "missing or duplicate atoms in topology.") | ||
|
|
||
| def _conclude(self): | ||
| self.angles = (np.rad2deg(np.array(self.angles)) + 360) % 360 | ||
| self.results.angles = (np.rad2deg(np.array( | ||
| self.results.angles)) + 360) % 360 | ||
|
|
||
| def plot(self, ax=None, ref=False, **kwargs): | ||
| """Plots data into standard Janin plot. | ||
|
|
||
| Each time step in :attr:`Janin.angles` is plotted onto the | ||
| Each time step in :attr:`Janin.results.angles` is plotted onto the | ||
| same graph. | ||
|
|
||
| Parameters | ||
|
|
@@ -601,6 +664,7 @@ def plot(self, ax=None, ref=False, **kwargs): | |
| levels = [1, 6, 600] | ||
| colors = ['#A1D4FF', '#35A1FF'] | ||
| ax.contourf(X, Y, np.load(Janin_ref), levels=levels, colors=colors) | ||
| a = self.angles.reshape(np.prod(self.angles.shape[:2]), 2) | ||
| a = self.results.angles.reshape(np.prod( | ||
| self.results.angles.shape[:2]), 2) | ||
| ax.scatter(a[:, 0], a[:, 1], **kwargs) | ||
| return ax | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add versionadded:: 2.0.0