# 4.8.2. Linear Density — MDAnalysis.analysis.lineardensity¶

A tool to compute mass and charge density profiles along the three cartesian axes [xyz] of the simulation cell. Works only for orthorombic, fixed volume cells (thus for simulations in canonical NVT ensemble).

class MDAnalysis.analysis.lineardensity.LinearDensity(select, grouping='atoms', binsize=0.25, **kwargs)[source]

Linear density profile

Parameters: select (AtomGroup) – any atomgroup grouping (str {'atoms', 'residues', 'segments', 'fragments'}) – Density profiles will be computed on the center of geometry of a selected group of atoms binsize (float) – Bin width in Angstrom used to build linear density histograms. Defines the resolution of the resulting density profile (smaller –> higher resolution) verbose (bool, optional) – Show detailed progress of the calculation if set to True
results.x.dim

index of the [xyz] axes

Type: int
results.x.pos

mass density in [xyz] direction

Type: numpy.ndarray
results.x.pos_std

standard deviation of the mass density in [xyz] direction

Type: numpy.ndarray
results.x.char

charge density in [xyz] direction

Type: numpy.ndarray
results.x.char_std

standard deviation of the charge density in [xyz] direction

Type: numpy.ndarray
results.x.slice_volume

volume of bin in [xyz] direction

Type: float

Example

First create a LinearDensity object by supplying a selection, then use the run() method. Finally access the results stored in results, i.e. the mass density in the x direction.

ldens = LinearDensity(selection)
ldens.run()
print(ldens.results.x.pos)


New in version 0.14.0.

Changed in version 1.0.0: Support for the start, stop, and step keywords has been removed. These should instead be passed to LinearDensity.run(). The save() method was also removed, you can use np.savetxt() or np.save() on the LinearDensity.results dictionary contents instead.

Changed in version 1.0.0: Changed selection keyword to select

Changed in version 2.0.0: Results are now instances of Results allowing access via key and attribute.