.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/preprocessing.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_preprocessing.py: Preprocessing of Molecular Dynamics Data =============================================== MDANCE provides a set of tools to preprocess molecular dynamics trajectories before clustering. This includes reading the trajectories, normalizing them, and aligning them. This snippet demonstrates how to read a trajectory and save it as a numpy array. .. GENERATED FROM PYTHON SOURCE LINES 11-14 Imports - `numpy `_ for manipulating and saving arrays. - ``gen_traj_numpy`` for using the `MDAnalysis `_ library to read the trajectories and save them as numpy arrays. .. GENERATED FROM PYTHON SOURCE LINES 14-20 .. code-block:: Python import numpy as np from mdance import data from mdance.inputs.preprocess import gen_traj_numpy .. GENERATED FROM PYTHON SOURCE LINES 21-28 Inputs - ``input_top`` is the path to the topology file. Check `here `_ for all accepted formats. - ``input_traj`` is the path to the trajectory file. Check `here `_ for all accepted formats. - **The trajectory file should be aligned and centered beforehand if needed!** - ``output_name`` is the name of the output file. The output file will be saved as ``{output_name}.npy`` for faster loading in the future. - ``atomSelection`` is the atom selection used for clustering that must be compatible with the `MDAnalysis Atom Selections Language `_. - ``gen_traj_numpy`` will convert the trajectory to a numpy array with the shape ``(n_frames, n_atoms * 3)`` for comparison purposes. .. GENERATED FROM PYTHON SOURCE LINES 28-36 .. code-block:: Python input_top = data.top input_traj = data.traj output_base_name = 'backbone' atomSelection = 'resid 3 to 12 and name N CA C O H' traj_numpy = gen_traj_numpy(input_top, input_traj, atomSelection) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/mdance/envs/latest/lib/python3.10/site-packages/MDAnalysis/topology/PDBParser.py:350: UserWarning: Element information is missing, elements attribute will not be populated. If needed these can be guessed using universe.guess_TopologyAttrs(context='default', to_guess=['elements']). warnings.warn("Element information is missing, elements attribute " /home/docs/checkouts/readthedocs.org/user_builds/mdance/envs/latest/lib/python3.10/site-packages/MDAnalysis/coordinates/DCD.py:165: DeprecationWarning: DCDReader currently makes independent timesteps by copying self.ts while other readers update self.ts inplace. This behavior will be changed in 3.0 to be the same as other readers. Read more at https://github.com/MDAnalysis/mdanalysis/issues/3889 to learn if this change in behavior might affect you. warnings.warn("DCDReader currently makes independent timesteps" Number of atoms in trajectory: 217 Number of frames in trajectory: 6001 Number of atoms in selection: 50 .. GENERATED FROM PYTHON SOURCE LINES 37-39 Outputs - The output is a numpy array of shape ``(n_frames, n_atoms * 3)``. .. GENERATED FROM PYTHON SOURCE LINES 39-41 .. code-block:: Python output_name = output_base_name + '.npy' np.save(output_name, traj_numpy) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.178 seconds) .. _sphx_glr_download_examples_preprocessing.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: preprocessing.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: preprocessing.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_