Viscosity

Viscosity — transport_analysis.analysis.viscosity

This module offers a class for the lightweight computation of shear viscosity via the Einstein-Helfand method. It outputs the “viscosity function,” the product of viscosity and time as a function of time, from which the slope is taken to calculate the shear viscosity. This is described in eq. 5 of E M Kirova and G E Norman 2015 J. Phys.: Conf. Ser. 653 012106.

class transport_analysis.viscosity.ViscosityHelfand(atomgroup: AtomGroup, temp_avg: float = 300.0, dim_type: str = 'xyz', linear_fit_window: tuple[int, int] = None, **kwargs)[source]

Class to calculate viscosity using the Einstein-Helfand approach. Note that the slope of the viscosity function, the product of viscosity and time as a function of time, must be taken to obtain the viscosity.

Particle velocities are required to calculate the viscosity function. Thus you are limited to MDA trajectories that contain velocity information, e.g. GROMACS .trr files, H5MD files, etc. See the MDAnalysis documentation: https://docs.mdanalysis.org/stable/documentation_pages/coordinates/init.html#writers.

Parameters
  • atomgroup (AtomGroup) – An MDAnalysis AtomGroup. Note that UpdatingAtomGroup instances are not accepted.

  • temp_avg (float (optional, default 300)) – Average temperature over the course of the simulation, in Kelvin.

  • dim_type ({‘xyz’, ‘xy’, ‘yz’, ‘xz’, ‘x’, ‘y’, ‘z’}) – Desired dimensions to be included in the viscosity calculation. Defaults to ‘xyz’.

  • linear_fit_window (tuple of int (optional)) – A tuple of two integers specifying the start and end lag-time for the linear fit of the viscosity function. If not provided, the linear fit is not performed and viscosity is not calculated.

Variables
  • atomgroup (AtomGroup) – The atoms to which this analysis is applied

  • dim_fac (int) – Dimensionality \(d\) of the viscosity computation.

  • results.timeseries (numpy.ndarray) – The averaged viscosity function over all the particles with respect to lag-time. Obtained after calling ViscosityHelfand.run()

  • results.visc_by_particle (numpy.ndarray) – The viscosity function of each individual particle with respect to lag-time.

  • results.viscosity (float) – The viscosity coefficient of the solvent. The argument linear_fit_window must be provided to calculate this to avoid misinterpretation of the viscosity function.

  • start (Optional[int]) – The first frame of the trajectory used to compute the analysis.

  • stop (Optional[int]) – The frame to stop at for the analysis.

  • step (Optional[int]) – Number of frames to skip between each analyzed frame.

  • n_frames (int) – Number of frames analysed in the trajectory.

  • n_particles (int) – Number of particles viscosity was calculated over.

plot_viscosity_function()[source]

Plot the viscosity function as a function of lag-time.

If a linear fit window is provided, the window is highlighted.