Main file for NMRforMD package.

class nmrformd.NMR.NMR(u: Universe, atom_group: AtomGroup, neighbor_group: AtomGroup | None = None, type_analysis: str = 'full', number_i: int = 0, isotropic: bool = True, f0: float | None = None, actual_dt: float | None = None, hydrogen_per_atom: float = 1.0, spin: float = 0.5, pbc: bool = True)#

Bases: object

Calculate NMR relaxation time from MDAnalysis universe.



MDAnalysis universe containing all the information describing the molecular dynamics system.


Target atom groups for NMR calculation.


Neighbor atom groups. If not specified, atom_group is used.

type_analysisstr, default full

Type of analysis, which can be full, intra_molecular, or inter_molecular.

number_iint, default 0

Number of atom of the target group to consider for the calculation. If number_i = 0, all atoms are considered.

isotropicbool, default True

If isotropic is true, only the spherical harmonic of order 0 is considered, which is usually valid for bulk systems. For non-isotropic systems, use False.

f0int, default None

Frequency at which T1 and T2 are calculated. If None, f = 0 is used.

actual_dtfloat, default None

Can be used to specify a different time interface between frames than the one detected by MDAnalysis.

hydrogen_per_atomfloat, default 1.0

Specify the number of hydrogen per atom, usefull for coarse-grained simulations.

pdbbool, default True

To turn off/on the periodic boundary condition treatment.


Calculate the correlation function.


Calculate spectral density J.

Calculate the spectral density J from the Fourier transform of the correlation function.


Calculate the relaxation time at a given frequency f0 (default is 0)


Calculate spectrums R1 and R2 from J.


Convert cartesian coordinate to spherical.


Collect data by looping over atoms, time, and evaluate correlation


Define prefactors.

See this page for details : Gamma is the gyromagnetic constant of 1H in Hz/T or C/kg K has the units of m^6/s^2 alpha_m are normalizing coefficient for harmonic function


Evaluate the F functions.

F = alpha Y / r ** 3 Y : spherical harmonic r : spin-spin distance

convention : theta = polar angle, phi = azimuthal angle note: scipy uses the opposite convention

F has the units of Angstrom^(-6)


Initialise arrays.

Create an array of zeros for the data and the correlation function. If anisotropic, the spherical harmonic may be complex, so dtype=complex64 is used. Create an array for of values separated by timestep for the time.


Prepare the calculation


Loop of the MDA trajectory and extract rij.

Run over the MDA trajectory. If start, stop, or step are specified, only a sub-part of the trajectory is analyzed.


Divide Gij by the number of spin pairs.

Optional, for coarse grained model, apply a coefficient “hydrogen_per_atom” != 1


Select atoms of the group i for the calculation.


Select atoms of the group j for the calculation.

For intra molecular analysis, group j are made of atoms of the same residue as group i. For inter molecular analysis, group j are made of atoms of different residues as group i. For full analysis, group j are made of atoms that are not in group i.


Select the target atoms i

If number_i=0, select all atoms in target_i If number_i > target_i.atoms.n_atoms, raise message Else, if 0<number_i<target_i.atoms.n_atoms, select atoms randomly


Calculate distance between position_i and position_j.

By defaults, periodic boundary conditions are assumed. Pbc can be turned off using pbc = False.


Verify that entries are correct, and that groups are not empty.