Kinetic energy tutorial#
Here we analyse a box of water molecules. To follow this tutorial, the data test files kineticenergy
of MAICoS are needed. You can obtain them by cloning MAICoS repository:
git clone git@gitlab.com:maicos-devel/maicos.git
Simulation details - The system contains around 500 water molecules simulated for 200 ps in the NVE ensemble. Periodic boundary conditions were employed in all directions, long range electrostatics were modelled using the PME method, and the LINCS algorithm was used to constraint the H-Bonds.
Option 1: from the Python interpreter#
First, let us ignore unnecessary warnings:
[1]:
import warnings
warnings.filterwarnings("ignore")
Then, import MAICoS, NumPy, MDAnalysis, and PyPlot:
[2]:
import maicos
import numpy as np
import MDAnalysis as mda
import matplotlib.pyplot as plt
from matplotlib.ticker import AutoMinorLocator
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In [2], line 1
----> 1 import maicos
2 import numpy as np
3 import MDAnalysis as mda
File ~/checkouts/readthedocs.org/user_builds/maicos/envs/v0.5/lib/python3.10/site-packages/maicos/__init__.py:36
29 from .modules.density import DensityPlanar, DensityCylinder
30 from .modules.epsilon import (
31 EpsilonBulk,
32 EpsilonPlanar,
33 EpsilonCylinder,
34 DielectricSpectrum
35 )
---> 36 from .modules.structure import Saxs, Debye, Diporder
37 from .modules.timeseries import DipoleAngle, KineticEnergy
38 from .modules.transport import Velocity
File ~/checkouts/readthedocs.org/user_builds/maicos/envs/v0.5/lib/python3.10/site-packages/maicos/modules/structure.py:24
18 from .. import tables
19 from ..decorators import (
20 make_whole,
21 set_planar_class_doc,
22 set_verbose_doc,
23 )
---> 24 from ..lib import sfactor
25 from ..utils import check_compound, savetxt
27 logger = logging.getLogger(__name__)
ImportError: dynamic module does not define module export function (PyInit_sfactor)
and set a few parameters for plotting purpose:
[3]:
fontsize = 25
font = {'family': 'sans', 'color': 'black',
'weight': 'normal', 'size': fontsize}
my_color_1 = np.array([0.090, 0.247, 0.560])
my_color_2 = np.array([0.235, 0.682, 0.639])
my_color_3 = np.array([1.000, 0.509, 0.333])
my_color_4 = np.array([0.588, 0.588, 0.588])
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In [3], line 4
1 fontsize = 25
2 font = {'family': 'sans', 'color': 'black',
3 'weight': 'normal', 'size': fontsize}
----> 4 my_color_1 = np.array([0.090, 0.247, 0.560])
5 my_color_2 = np.array([0.235, 0.682, 0.639])
6 my_color_3 = np.array([1.000, 0.509, 0.333])
NameError: name 'np' is not defined
Define the path to the kineticenergy
data folder of MAICoS:
[4]:
datapath = "../../../../tests/data/kineticenergy/"
Create a MDAnalysis universe:
[5]:
u = mda.Universe(datapath+"nve.tpr",
datapath+"nve.trr")
atoms = u.atoms
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In [5], line 1
----> 1 u = mda.Universe(datapath+"nve.tpr",
2 datapath+"nve.trr")
3 atoms = u.atoms
NameError: name 'mda' is not defined
Let us print a few information about the trajectory file:
[6]:
print(f"The number of water molecules is {np.int32(u.atoms.n_atoms/3)}")
timestep = np.round(u.trajectory.dt,2)
print(f"The time interval between the frames is {timestep} ps")
total_time = np.round(u.trajectory.totaltime,2)
print(f"The total simulation time is {total_time} ps")
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In [6], line 1
----> 1 print(f"The number of water molecules is {np.int32(u.atoms.n_atoms/3)}")
2 timestep = np.round(u.trajectory.dt,2)
3 print(f"The time interval between the frames is {timestep} ps")
NameError: name 'np' is not defined
Run the MAICOS dipole angle function:
[7]:
kenergy = maicos.KineticEnergy(atoms)
kenergy.run()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In [7], line 1
----> 1 kenergy = maicos.KineticEnergy(atoms)
2 kenergy.run()
NameError: name 'maicos' is not defined
Then extract the kinetic energy:
[8]:
ke_trans = kenergy.results["trans"]
ke_rot = kenergy.results["rot"]
print(f"The average translational kinetic energy "
f"is {np.round(np.mean(ke_trans),2)} kJ/mol")
print(f"The average rotational kinetic energy "
f"is {np.round(np.mean(ke_rot),2)} kJ/mol")
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In [8], line 1
----> 1 ke_trans = kenergy.results["trans"]
2 ke_rot = kenergy.results["rot"]
3 print(f"The average translational kinetic energy "
4 f"is {np.round(np.mean(ke_trans),2)} kJ/mol")
NameError: name 'kenergy' is not defined
Option 2 : from the command line interface#
Go to the kineticenergy
data folder of MAICoS, then use the maicos
command directly from the terminal:
maicos KineticEnergy -s md.tpr -f md.trr -o ke.dat
The output file ke.dat
is similar to ke.results
and contains the data in columns