Skip to content

New class design and CLI

Philip Loche requested to merge (removed):rework_AnalysisBase into develop

As discussed several time we should start a major redesign of MAICos. This MR introduces changes to the class design, the CLI as well as further cosmetic changes for modern Python code. The current changes require PR82 of the mdacli library. All changes currently only work for the density modules!

I would like ask @All to take a look at the code and give some feedback.

Changes

  • Remove spaghetti code in __main__.py and introduce mdacli library as cli server.
  • Remove SingleGroupAnalysisBase and MultiGroupAnalysisBase classes in favour of a unified AnalysisBase class
  • Change planar_base decorator to PlanarBase class. This is not only simpler to understand but also should resolve our doc problems.
  • Rename modules to be consistent with PEP8 (density_planar -> DensityPlanar)
  • Use Numpy's docstyle for doc formatting
  • Use Python's powerful logger library instead of print
  • Use PY3.6 string formatting
  • Remove _calculate_results methods. This method is covered by the _conclude ,method.
  • Make results saving a public function (save)
  • Decorator for PlanarDocstring

UI Changes

Using mdacli as library for the CLI slightly changes the user interfaces at the command line. Especially the short flags are replaced by the explicit parameter names. For example the UI for the planar density changes from

maicos density_planar -f traj.trr -s topol.tpr -groups 'all' -o 'foo.dat'

to

maicos density_planar -f traj.trr -s topol.tpr -atomgroups 'all' -output 'foo.dat'

I think that this is acceptable. One the other side we now have a nicely structured help page for MAICoS itself

$ maicos -h
usage: maicos [-h] [--version] [--debug] [--logfile LOGFILE] {densitycylinder,densityplanar} ...

    Analyse molecular dynamics simulations of interfacial and confined systems.

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --debug               Run with debug options.
  --logfile LOGFILE     Logfile (optional)

MAICoS Analysis Modules:
  {densitycylinder,densityplanar}
    densitycylinder     Compute partial densities across a cylinder.
    densityplanar       Compute partial densities/temperature profiles in the Cartesian systems.

and for each specific module

$ maicos densityplanar -h
usage: maicos densityplanar [-h] [-b START] [-e STOP] [-dt STEP] [-v] [-s TOPOLOGY] [-top TOPOLOGY_FORMAT] [-atom_style ATOM_STYLE]
                            [-f COORDINATES [COORDINATES ...]] [-traj TRAJECTORY_FORMAT] [-dimensions DIMENSIONS [DIMENSIONS ...]]
                            [-atomgroups ATOMGROUPS [ATOMGROUPS ...]] [-binwidth BINWIDTH] [-center] [-comgroup COMGROUP]
                            [-concfreq CONCFREQ] [-dens DENS] [-dim DIM] [-mass MASS] [-mu] [-muout MUOUT] [-output OUTPUT]
                            [-temperature TEMPERATURE] [-zpos ZPOS]

Compute partial densities/temperature profiles in the Cartesian systems.

optional arguments:
  -h, --help            show this help message and exit

Analysis Run Parameters:
  Genereal parameters specific for running the analysis

  -b START              frame or start time for evaluation. (default: 0)
  -e STOP               frame or end time for evaluation. (default: -1)
  -dt STEP              step or time step for evaluation. (default: 1)
  -v                    Be loud and noisy

Mandatory Parameters:
  Mandatory parameters of this Analysis

  -atomgroups ATOMGROUPS [ATOMGROUPS ...]
                        a list of :class:`~MDAnalysis.core.groups.AtomGroup` for which the densities are calculated Use a MDAnalysis
                        selection string.

Optional Parameters:
  Optional parameters specific of this Analysis

  -binwidth BINWIDTH    binwidth (nanometer) (default: 0.1)
  -center               Perform the binning relative to the center of the (changing) box.
  -comgroup COMGROUP    Perform the binning relative to the center of mass of the selected group. (default: None)
  -concfreq CONCFREQ    Default time after which results are refreshed (1000 ps). (default: 1000)
  -dens DENS            Density: mass, number, charge, temperature. (Default: mass) output :str Output filename (default: None)
  -dim DIM              Dimension for binning (0=X, 1=Y, 2=Z) (default: 2)
  -mass MASS            Mass (u) for the chemical potential. By default taken from topology. (default: None)
  -mu                   Calculate the chemical potential (sets dens='number')
  -muout MUOUT          Prefix for output filename for chemical potential (default: muout.dat)
  -output OUTPUT        No description available. (default: density.dat)
  -temperature TEMPERATURE
                        temperature (K) for chemical potential (Default: 300K) (default: 300)
  -zpos ZPOS            position (nm) at which the chemical potential will be computed. By default average over box. (default: None)

Reference Universe Parameters:
  Parameters specific for loading the reference topology and trajectory used for atom selection.

  -s TOPOLOGY           The topolgy file. The FORMATs PSF, TOP, PRMTOP, PARM7, PDB, ENT, XPDB, PQR, GRO, CRD, PDBQT, DMS, TPR, MOL2, DATA,
                        LAMMPSDUMP, XYZ, TXYZ, ARC, GMS, CONFIG, HISTORY, XML, MMTF, GSD, MINIMAL, ITP, IN, FHIAIMS, PARMED, RDKIT,
                        OPENMMTOPOLOGY, OPENMMAPP are implemented in MDAnalysis.
  -top TOPOLOGY_FORMAT  Override automatic topology type detection. See topology for implemented formats.
  -atom_style ATOM_STYLE
                        Manually set the atom_style information(currently only LAMMPS parser). E.g. atom_style='id type x y z'.
  -f COORDINATES [COORDINATES ...]
                        A single or multiple coordinate files. The FORMATs CHAIN, CHEMFILES, CRD, DCD, CONFIG, HISTORY, DMS, GMS, GRO,
                        INPCRD, RESTRT, LAMMPS, DATA, LAMMPSDUMP, MOL2, PDB, ENT, XPDB, PDBQT, PQR, TRJ, MDCRD, CRDBOX, NCDF, NC, TRR,
                        H5MD, TRZ, XTC, XYZ, TXYZ, ARC, MEMORY, MMTF, GSD, COOR, NAMDBIN, IN, FHIAIMS, PARMED, RDKIT, OPENMMSIMULATION,
                        OPENMMAPP are implemented in MDAnalysis.
  -traj TRAJECTORY_FORMAT
                        Override automatic trajectory type detection. See trajectory for implemented formats.
  -dimensions DIMENSIONS [DIMENSIONS ...]
                        Manually set/overwrite the simulation box dimensions to a vector containing unit cell dimensions [a, b, c, α, β,
                        γ], lengths a, b, c are in Å, and angles α, β, γ are in degrees. Providing only three parameters will assume a
                        rectengular simulation box (α = β = γ = 90°).

During the analysis more information is printed that MDAnalysis already has

$ maicos densityplanar -f tests/data/airwater/traj.trr -s tests/data/airwater/topol.tpr -atomgroups all -v
Logging to file is disabled.
Gromacs version   : b'VERSION 2019.3'
tpx version       : 116
tpx generation    : 26
tpx precision     : 4
tpx file_tag      : b'release'
tpx natoms        : 1056
tpx ngtc          : 1
tpx fep_state     : 0
tpx lambda        : 0.0
Choosing frames to analyze
Starting preparation
Using 60 bins
Computing mass density profile along Z-axes.
100%|████████████████████████████████████████████████████████████████████████████████████████████████████| 100/100 [00:00<00:00, 998.71it/s]
Finishing up

Documentation pages

The documentation pages look smooth again!

TODO

  • Tests
  • Docs
  • Extend new design to other classes
Edited by Philip Loche

Merge request reports