Skip to content

Commit e604e4a

Browse files
authored
clean API pages batch 1to4 (#4999)
* clean API pages batch 1to4 * Address PR review comments
1 parent 950df33 commit e604e4a

File tree

3 files changed

+54
-239
lines changed

3 files changed

+54
-239
lines changed

package/doc/sphinx/source/documentation_pages/analysis_modules.rst

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,40 @@
22
33
.. module:: MDAnalysis.analysis
44

5+
.. _analysis-label:
6+
57
****************
68
Analysis modules
79
****************
810

9-
The :mod:`MDAnalysis.analysis` module contains code to carry out specific
10-
analysis functionality for MD trajectories. It is based on the core
11-
functionality (i.e. trajectory I/O, selections etc). The analysis modules can
12-
be used as examples for how to use MDAnalysis but also as working code for
13-
research projects; typically all contributed code has been used by the authors
14-
in their own work.
15-
16-
Getting started with analysis
17-
=============================
11+
The :mod:`MDAnalysis.analysis` module provides a wide collection of analysis tools for
12+
molecular dynamics trajectories. These modules build upon MDAnalysis core functionality
13+
(trajectory I/O, selections, etc.) and are designed both for reuse in research workflows
14+
and as examples of using the MDAnalysis API. Each module typically defines an analysis
15+
class that follows a standard interface.
1816

19-
.. SeeAlso::
17+
See the `User Guide Analysis section`_ for interactive examples and additional context.
2018

21-
The `User Guide: Analysis`_ contains extensive documentation of the analysis
22-
capabilities with user-friendly examples.
19+
.. _User Guide Analysis section: https://userguide.mdanalysis.org/stable/examples/analysis/README.html
2320

24-
.. _`User Guide: Analysis`:
25-
https://userguide.mdanalysis.org/stable/examples/analysis/README.html
2621

27-
Using the analysis classes
28-
--------------------------
22+
Getting started with analysis
23+
=============================
2924

30-
Most analysis tools in MDAnalysis are written as a single class. An analysis
31-
usually follows the same pattern:
25+
Most analysis tools are implemented as single classes and follow this usage pattern:
3226

33-
#. Import the desired module, since analysis modules are not imported
34-
by default.
35-
#. Initialize the analysis class instance from the previously imported module.
36-
#. Run the analysis with the :meth:`~MDAnalysis.analysis.base.AnalysisBase.run`
37-
method, optionally for specific trajectory slices.
38-
#. Access the analysis from the
39-
:attr:`~MDAnalysis.analysis.base.AnalysisBase.results` attribute
27+
#. Import the module (e.g., :mod:`MDAnalysis.analysis.rms`).
28+
#. Initialize the analysis class with the required arguments.
29+
#. Run the analysis with :meth:`~MDAnalysis.analysis.base.AnalysisBase.run`.
30+
#. Access results via the :attr:`~MDAnalysis.analysis.base.AnalysisBase.results` attribute.
4031

4132
.. code-block:: python
4233
4334
from MDAnalysis.analysis import ExampleAnalysisModule # (e.g. RMSD)
44-
4535
analysis_obj = ExampleAnalysisModule.AnalysisClass(universe, ...)
4636
analysis_obj.run(start=start_frame, stop=stop_frame, step=step)
4737
print(analysis_obj.results)
4838
49-
5039
Please see the individual module documentation for any specific caveats
5140
and also read and cite the reference papers associated with these algorithms.
5241

@@ -95,10 +84,8 @@ for maximum available on your machine):
9584
rmsd = RMSD(u, ref, select='backbone')
9685
rmsd.run(backend='multiprocessing', n_workers=multiprocessing.cpu_count())
9786
98-
For now, you have to be explicit and specify both ``backend`` and ``n_workers``,
99-
since the feature is new and there are no good defaults for it. For example,
100-
if you specify a too big `n_workers`, and your trajectory frames are big,
101-
you might get and out-of-memory error when executing your run.
87+
Be explicit and specify both ``backend`` and ``n_workers``. Choosing too many
88+
workers or using large trajectory frames may lead to an out-of-memory error.
10289

10390
You can also implement your own backends -- see :mod:`MDAnalysis.analysis.backends`.
10491

Lines changed: 31 additions & 202 deletions
Original file line numberDiff line numberDiff line change
@@ -1,219 +1,48 @@
11
.. _overview-label:
22

33
==========================
4-
Overview over MDAnalysis
4+
Overview of MDAnalysis
55
==========================
66

7-
**MDAnalysis** is a Python package that provides classes to access
8-
data in molecular dynamics trajectories. It is object oriented so it
9-
treats atoms, groups of atoms, trajectories, etc as different
10-
objects. Each object has a number of operations defined on itself
11-
(also known as "methods") and also contains values describing the
12-
object ("attributes"). For example, a
13-
:class:`~MDAnalysis.core.groups.AtomGroup` object has a
14-
:meth:`~MDAnalysis.core.groups.AtomGroup.center_of_mass` method that
15-
returns the center of mass of the group of atoms. It also contains an
16-
attribute called :attr:`~MDAnalysis.core.groups.AtomGroup.residues`
17-
that lists all the residues that belong to the group. Using methods
18-
such as :meth:`~MDAnalysis.core.groups.AtomGroup.select_atoms`
19-
(which uses `CHARMM-style`_ atom :ref:`selection-commands-label`) one
20-
can create new objects (in this case, another
21-
:class:`~MDAnalysis.core.groups.AtomGroup`).
7+
MDAnalysis is a Python package for the analysis of molecular dynamics simulations.
8+
It provides an object-oriented interface to molecular structures and trajectories,
9+
with direct access to atomic coordinates as :class:`numpy.ndarray` objects for seamless
10+
integration with `NumPy`_ and `SciPy`_.
2211

23-
A typical usage pattern is to iterate through a trajectory and analyze
24-
coordinates for every frame. In the following example the end-to-end distance
25-
of a protein and the radius of gyration of the backbone atoms are calculated::
12+
This page gives a high-level overview of the most important public classes and modules.
13+
For usage examples and tutorials, refer to the `User Guide`_.
2614

27-
import MDAnalysis as mda
28-
from MDAnalysis.tests.datafiles import PSF,DCD # test trajectory
29-
import numpy.linalg
30-
u = mda.Universe(PSF,DCD) # always start with a Universe
31-
nterm = u.select_atoms('segid 4AKE and name N')[0] # can access structure via segid (s4AKE) and atom name
32-
cterm = u.select_atoms('segid 4AKE and name C')[-1] # ... takes the last atom named 'C'
33-
bb = u.select_atoms('protein and backbone') # a selection (a AtomGroup)
34-
for ts in u.trajectory: # iterate through all frames
35-
r = cterm.position - nterm.position # end-to-end vector from atom positions
36-
d = numpy.linalg.norm(r) # end-to-end distance
37-
rgyr = bb.radius_of_gyration() # method of a AtomGroup; updates with each frame
38-
print(f"frame = {ts.frame}: d = {d} Angstroem, Rgyr = {rgyr} Angstroem")
15+
.. _User Guide: https://userguide.mdanalysis.org/stable/index.html
16+
.. _NumPy: https://numpy.org/
17+
.. _SciPy: https://scipy.org/
3918

19+
Key Classes
20+
===========
4021

41-
.. _NumPy: https://numpy.org/
42-
.. _CHARMM: http://www.charmm.org/
43-
.. _LAMMPS: http://lammps.sandia.gov/
44-
.. _NAMD: http://www.ks.uiuc.edu/Research/namd/
45-
.. _Gromacs: http://www.gromacs.org/
22+
The core of MDAnalysis revolves around the :class:`~MDAnalysis.core.universe.Universe` class,
23+
which serves as the central data structure that loads and connects topology and coordinate data.
24+
From a :class:`~MDAnalysis.core.universe.Universe`, users typically interact with :class:`~MDAnalysis.core.groups.AtomGroup`
25+
objects — flexible collections of atoms that support structural selections and analysis operations. These selections
26+
are created using `CHARMM-style`_ selection syntax via the :meth:`~MDAnalysis.core.groups.AtomGroup.select_atoms` method,
27+
allowing users to query atoms based on names, residue numbers, segments, and more.
4628

47-
.. _CHARMM-style:
48-
http://www.charmm.org/documentation/c37b1/select.html
29+
Individual atoms are represented by the :class:`~MDAnalysis.core.groups.Atom` class, while residues and segments (or chains) are modeled using the
30+
:class:`~MDAnalysis.core.groups.Residue` and :class:`~MDAnalysis.core.groups.Segment` classes, respectively. Together, these
31+
classes form an intuitive, object-oriented hierarchy that makes it easy to navigate and analyze molecular systems.
4932

50-
.. TODO: more about philosophy etc... copy and paste from paper
33+
.. _CHARMM-style: http://www.charmm.org/documentation/c37b1/select.html
5134

52-
Using MDAnalysis in python
53-
==========================
54-
55-
If you've installed MDAnalysis in the standard python modules location, load
56-
from within the interpreter::
57-
58-
from MDAnalysis import *
59-
60-
or ::
61-
62-
import MDAnalysis as mda
63-
64-
The idea behind MDAnalysis is to get trajectory data into NumPy_
65-
:class:`numpy.ndarray` arrays, where it can then be easily manipulated using
66-
all the power in NumPy_ and SciPy_.
67-
68-
MDAnalysis works well both in scripts and in interactive use. The developers
69-
very much recommend using MDAnalysis from within the IPython_ Python shell. It
70-
allows one to interactively explore the objects (using TAB-completion and
71-
online help), do analysis and immediately plot results. The examples in this manual
72-
are typically run from an interactive :program:`ipython` session.
73-
74-
Invariably, a MDAnalysis session starts with loading data into the
75-
:class:`~MDAnalysis.core.universe.Universe` class (which can be accessed
76-
as :class:`MDAnalysis.Universe`)::
77-
78-
import MDAnalysis as mda
79-
universe = mda.Universe(topology, trajectory)
80-
81-
- The *topology* file lists the atoms and residues (and also their
82-
connectivity). It can be a CHARMM/XPLOR/NAMD PSF file or a coordinate file
83-
such as a Protein Databank Brookhaven PDB file, a CHARMM card coordinate file
84-
(CRD), or a GROMOS/Gromacs GRO file.
85-
86-
- The *trajectory* contains a list of coordinates in the order defined in the
87-
*topology*. It can either be a single frame (PDB, CRD, and GRO are all read)
88-
or a time series of coordinate frames such as a CHARMM/NAMD/LAMMPS DCD
89-
binary file, a Gromacs XTC/TRR trajectory, or a XYZ trajectory (possibly
90-
compressed with gzip or bzip2).
91-
92-
For the remainder of this introduction we are using a short example trajectory
93-
that is provided with MDAnalysis (as part of the `MDAnalysis test suite`_). The
94-
trajectory is loaded with ::
95-
96-
>>> from MDAnalysis import Universe
97-
>>> from MDAnalysis.tests.datafiles import PSF,DCD
98-
>>> u = Universe(PSF, DCD)
99-
100-
(The ``>>>`` signs are the Python input prompt and are not to be typed; they
101-
just make clear in the examples what is input and what is output.)
102-
103-
The :class:`~MDAnalysis.core.universe.Universe` contains a number of important attributes,
104-
the most important ones of which is
105-
:attr:`~MDAnalysis.core.universe.Universe.atoms`::
106-
107-
>>> print(u.atoms)
108-
<AtomGroup with 3341 atoms>
109-
110-
:attr:`Universe.atoms` is a
111-
:class:`~MDAnalysis.core.groups.AtomGroup` and can be thought of as
112-
list consisting of :class:`~MDAnalysis.core.groups.Atom`
113-
objects. The :class:`~MDAnalysis.core.groups.Atom` is the
114-
elementary and fundamental object in MDAnalysis.
115-
116-
The :attr:`MDAnalysis.Universe.trajectory` attribute gives access to the coordinates
117-
over time::
118-
119-
>>> print(u.trajectory)
120-
< DCDReader '/..../MDAnalysis/tests/data/adk_dims.dcd' with 98 frames of 3341 atoms (0 fixed) >
121-
122-
Finally, the :meth:`MDAnalysis.Universe.select_atoms` method generates a new
123-
:class:`~MDAnalysis.core.groups.AtomGroup` according to a selection criterion::
124-
125-
>>> calphas = u.select_atoms("name CA")
126-
>>> print(calphas)
127-
<AtomGroup with 214 atoms>
128-
129-
as described in :ref:`selection-commands-label`.
130-
131-
.. _SciPy: http://www.scipy.org/
132-
.. _IPython: https://ipython.org/
133-
.. _MDAnalysis test suite: https://github.com/MDAnalysis/mdanalysis/wiki/UnitTests
134-
135-
136-
Examples
137-
========
138-
139-
The easiest way to get started with MDAnalysis is to read this introduction and the chapters on :ref:`topology-label` and :ref:`selection-commands-label`, then explore the package interactively in IPython_ or another interactive Python interpreter.
140-
141-
Included trajectories
142-
---------------------
143-
144-
MDAnalysis comes with a number of real trajectories for testing. You
145-
can also use them to explore the functionality and ensure that
146-
everything is working properly::
147-
148-
import MDAnalysis as mda
149-
from MDAnalysis.tests.datafiles import PSF,DCD, PDB,XTC
150-
u_dims_adk = mda.Universe(PSF,DCD)
151-
u_eq_adk = mda.Universe(PDB, XTC)
152-
153-
The PSF and DCD file are a closed-form-to-open-form transition of
154-
Adenylate Kinase (from [Beckstein2009]_) and the PDB+XTC file are ten
155-
frames from a Gromacs simulation of AdK solvated in TIP4P water with
156-
the OPLS/AA force field.
157-
158-
.. [Beckstein2009] O. Beckstein, E.J. Denning, J.R. Perilla, and
159-
T.B. Woolf. Zipping and Unzipping of Adenylate
160-
Kinase: Atomistic Insights into the Ensemble of
161-
Open <--> Closed Transitions. *J Mol Biol* **394**
162-
(2009), 160--176, doi:`10.1016/j.jmb.2009.09.009`_
163-
164-
.. _`10.1016/j.jmb.2009.09.009`: http://dx.doi.org/10.1016/j.jmb.2009.09.009
165-
166-
Code snippets
167-
-------------
168-
169-
The source code distribution comes with a directory `examples`_ that
170-
contains a number of code snippets that show how to use certain
171-
aspects of MDAnalysis.
172-
173-
For instance, there is code that shows how to
174-
175-
* fit a trajectory to a reference structure using the QCP
176-
RMSD-alignment code in :mod:`MDAnalysis.core.qcprot`
177-
(`rmsfit_qcp.py`_);
178-
179-
* do a block-averaging error analysis (`blocks.py`_);
180-
181-
* calculate a potential profile across a membrane (`potential_profile.py`_);
182-
183-
* do a native contact analysis using :mod:`MDAnalysis.analysis.contacts` (`nativecontacts.py`_)
184-
185-
* get the lipid composition of the individual leaflets of a bilayer
186-
using :mod:`MDAnalysis.analysis.leaflet` (`membrane-leaflets.py`_);
187-
188-
* define the multimeric states of a number of transmembrane peptides
189-
via clustering (`multimers-analysis.py`_);
190-
191-
* convert between trajectory formats (e.g. `dcd2xtc.py`_ or `amber2dcd.py`_)
35+
Core modules
36+
============
19237

193-
* use MDAnalysis for simple model building (`make_MthK_tetramer.py`_);
38+
MDAnalysis is organized into several core modules that provide specialized functionality for
39+
handling and analyzing molecular dynamics data. The :mod:`MDAnalysis.core` module defines the
40+
essential data structures such as :class:`~MDAnalysis.core.universe.Universe`, :class:`~MDAnalysis.core.groups.AtomGroup`,
41+
and related objects. The :mod:`MDAnalysis.analysis` module contains a collection of analysis tools for tasks like RMSD calculation,
42+
diffusion analysis, contact maps, and more. The :mod:`MDAnalysis.selections` module implements the flexible selection language used
43+
to query atoms based on structural properties. Finally, :mod:`MDAnalysis.topology` manages topology parsing and representation,
44+
supporting a wide range of file formats for loading molecular structures.
19445

195-
and more.
19646

197-
.. Links to the stable git repository:
19847

199-
.. _examples:
200-
https://github.com/MDAnalysis/MDAnalysisCookbook/tree/master/examples/
20148

202-
.. _`rmsfit_qcp.py`:
203-
https://github.com/MDAnalysis/MDAnalysisCookbook/blob/master/examples/rmsfit_qcp.py
204-
.. _`blocks.py`:
205-
https://github.com/MDAnalysis/MDAnalysisCookbook/blob/master/examples/blocks.py
206-
.. _`potential_profile.py`:
207-
https://github.com/MDAnalysis/MDAnalysisCookbook/blob/master/examples/potential_profile.py
208-
.. _`nativecontacts.py`:
209-
https://github.com/MDAnalysis/MDAnalysisCookbook/blob/master/examples/nativecontacts.py
210-
.. _`membrane-leaflets.py`:
211-
https://github.com/MDAnalysis/MDAnalysisCookbook/blob/master/examples/membrane-leaflets.py
212-
.. _`multimers-analysis.py`:
213-
https://github.com/MDAnalysis/MDAnalysisCookbook/blob/master/examples/multimers-analysis.py
214-
.. _`dcd2xtc.py`:
215-
https://github.com/MDAnalysis/MDAnalysisCookbook/blob/master/examples/dcd2xtc.py
216-
.. _`amber2dcd.py`:
217-
https://github.com/MDAnalysis/MDAnalysisCookbook/blob/master/examples/amber2dcd.py
218-
.. _`make_MthK_tetramer.py`:
219-
https://github.com/MDAnalysis/MDAnalysisCookbook/blob/master/examples/make_MthK_tetramer.py

package/doc/sphinx/source/documentation_pages/topology.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
The topology system
66
=====================
77

8-
As shown briefly in :ref:`overview-label`, the :class:`~MDAnalysis.core.universe.Universe` class is the primary object and core interface to molecular dynamics data in MDAnalysis.
9-
When loading topology information from a file, as with ::
8+
See :mod:`MDAnalysis.topology` for details on topology parsing, format support, and
9+
the :class:`~MDAnalysis.core.topology.Topology` object.
1010

11-
>>> from MDAnalysis import Universe
12-
>>> from MDAnalysis.tests.datafiles import PSF
13-
>>> u = Universe(PSF)
11+
User-level documentation can be found in the `topology section of the User Guide`_.
12+
13+
.. _topology section of the User Guide: https://userguide.mdanalysis.org/stable/topology_system.html
1414

15-
the file is read, the contents parsed, and a :class:`~MDAnalysis.core.topology.Topology` object is constructed from these contents.

0 commit comments

Comments
 (0)