Skip to content

Fix Trajectory Unwrapping#151

Merged
andthum merged 43 commits intomainfrom
fix/trajectory-unwrapping
Mar 6, 2023
Merged

Fix Trajectory Unwrapping#151
andthum merged 43 commits intomainfrom
fix/trajectory-unwrapping

Conversation

@andthum
Copy link
Owner

@andthum andthum commented Mar 6, 2023

Fix Trajectory Unwrapping

Type of change

  • Change of core package.
  • Change of scripts.
  • Bug fix.
  • New feature.
  • Code refactoring.
  • Dependency update.
  • Documentation update.
  • Maintenance.
  • Other: Description.
  • Non-breaking (backward-compatible) change.
  • Breaking (non-backward-compatible) change.

Proposed changes

Breaking Changes:

  • Script unwrap_trj.py: Completely rewrite the script to use the new function mdtools.box.unwrap_frame.
    Add the following command-line arguments:
    • -b: First frame to read.
    • --every: Read every n-th frame.
    • --method: The unwrapping method to use.
      Rename the following command-line arguments:
    • --otrj to --trj-out: Output trajectory.
    • --otop to --top-out: Output topology.
    • --compound to --cmp: The compounds to make whole.
      Remove the following command-line arguments:
    • --make-whole.
    • --keep-whole.
  • Remove the function mdtools.box.unwrap because it is replaced by the new function mdtools.box.unwrap_frame.
  • Remove the function mdtools.box.unwrap_trj because it uses the displacement unwrapping method that only works for constant simulation boxes and was only implemented for orthorhombic boxes. Use the script unwrap_trj or the function mdtools.box.unwrap_frame instead.
  • Function mdtools.box.vdist: If box has shape (k, 6) a two-dimensional position array is not any longer interpreted to have the shape (k, 3). Instead it is now interpreted to have shape (n, 3). Here k is the number of frames and n is the number of particles.
  • Function mdtools.box.wrap_pos: Remove the mda_backend argument, because mdtools.box.wrap_pos no longer uses MDAnalysis.lib.distances.apply_PBC internally.
  • Function mdtools.box.wrap_pos: If box has shape (k, 6) a two-dimensional position array is not any longer interpreted to have the shape (k, 3). Instead it is now interpreted to have shape (n, 3). Here k is the number of frames and n is the number of particles.
  • Function mdtools.structure.wcenter_pos: Remove the mda_backend argument.
  • Function mdtools.structure.wcenter_pos: If box has shape (k, 6) a two-dimensional position array is not any longer interpreted to have the shape (k, 3). Instead it is now interpreted to have shape (n, 3). Here k is the number of frames and n is the number of particles.
  • Function mdtools.structure.wcenter_pos: If centers are calculated for multiple frames, always return an array of shape (k, 1, 3) instead of (k, 3).

New Features:

  • Create a new script rmsd_trj_trj.py that calculates the Root Mean Square Deviation (RMSD) between two trajectories for each frame.
  • Add a new function mdtools.box.unwrap_frame that unwraps a single trajectory frame. The new functions implements five different unwrapping algorithms: "scaling", "heuristic", "displacement", "hybrid", "in-house". See
    • Sören von Bülow, Jakob Tómas Bullerjahn, and Gerhard Hummer,
      Systematic errors in diffusion coefficients from long-time moleculardynamics simulations at constant pressure,
      The Journal of Chemical Physics, 2020, 153, 021101,
    • Martin Kulke and Josh V. Vermaas,
      Reversible Unwrapping Algorithm for Constant-Pressure Molecular Dynamics Simulations,
      Journal of Chemical Theory and Computation, 2022, 18, 10, 6161-6171.
  • Function mdtools.box.vdist: Add support for triclinic simulation boxes.
  • Function mdtools.box.wrap_pos: Add support for triclinic simulation boxes.
  • Function mdtools.structure.rmsd: Add support for triclinic simulation boxes.
  • Function mdtools.structure.wcenter_pos: Add support for triclinic simulation boxes.
  • Add a new function mdtools.box.cart2box that transforms Cartesian coordinates to box coordinates.
  • Add a new function mdtools.box.box2cart that transforms box coordinates to Cartesian coordinates.
  • Add a new function mdtools.box.triclinic_vectors that converts the length-angle representation of a simulation box to the matrix representation.
  • Add a new function mdtools.box.triclinic_box that converts the matrix representation of a simulation box to the length-angle representation.
  • Add a new function mdtools.check.box_mat that checks if the input array satisfies the conditions for a (triclinic) simulation box matrix.

Bug fixes:

  • Function mdtools.box.make_whole: Remove the debug argument that was parsed to MDAnalysis.core.groups.AtomGroup.unwrap although MDAnalysis.core.groups.AtomGroup.unwrap has no debug argument.
  • Various minor bug fixes in the mdtools.check module.

Documentation changes

  • Fix broken links in the documentation.
  • Fix various typos.
  • Include the new install_mdt build option to the developer's guide.

Maintenance

  • Sphinx Makefile for doc pages: Add a new make build option install_mdt that (re-)installs MDTools. Re-installing MDTools is necessary when changing the docstring of a script. Otherwise the changes won't be recognized by Sphinx.
  • Run Sphinx linkcheck during the CI workflow.

Requested reviewers

@andthum

PR checklist

  • I followed the guidelines in the Developer's guide.
  • New/changed code is properly tested.
  • New/changed code is properly documented.
  • The CI workflow is passing.

Add a new function `mdtools.check.box_mat` that checks if the input
array satisfies the conditions for a (triclinic) simulation box matrix.
Fix and format the function `mdtools.check.array`.

The test whether `amax` is greater than `amin` didn't took into account
that `amax` and `amin` can be arrays.
Fix and format the function `mdtools.check.pos_array`.

The dimensionality must be checked before the shape of any dimension is
checked, because the dimension might not exist in the input array.
Fix and format the function `mdtools.check.box`.

The dimensionality must be checked before the shape of any dimension is
checked, because the dimension might not exist in the input array.
Fix and format the function `mdtools.check.dtrj`.

Also check for 0-dimensional arrays.
Fix the function `mdtools.numpy_helper_functions.take` that wrongly
raised an error if a negative axis was equal to the number of dimensions
of the array.
Add a new function `mdtools.box.triclinic_box` that converts the matrix
representation of a simulation box to the length-angle representation.
Add a new function `mdtools.box.triclinic_vectors` that converts the
length-angle representation of a simulation box to the matrix
representation.
Add a new function `mdtools.box.cart2box` that transforms Cartesian
coordinates to box coordinates.
Add a new function `mdtools.box.box2cart` that transforms box
coordinates to Cartesian coordinates.
New Features:

* Add support for triclinic simulation boxes to the function
  `mdtools.box.vdist` that calculates the distance vectors between two
  position arrays with the option to account for the minimum image
  convention.

* Add the `dtype` argument to `mdtools.box.vdist` that allows the user
  to specify the data type of the output array.

* Add the `out_tmp` argument to `mdtools.box.vdist` that allows the user
  to parse a pre-allocated array to store temporary results to speed up
  the calculation if the function is called multiple times.

Breaking changes:

* If `box` has shape ``(k, 6)`` a two-dimensional position array is not
  any longer interpreted to have the shape  ``(k, 3)``.  Instead it is
  now interpreted to have shape ``(n, 3)``.  Here k is the number of
  frames and n is the number of particles.
Update the docstring of the function `mdtools.structure.rmsd`.  Because
`mdtools.box.vdist` now supports triclinic simulation boxes,
`mdtools.structure.rmsd` does so, too.
New Features:

* Add support for triclinic simulation boxes to the function
  `mdtools.box.wrap_pos` that shifts all particle positions into the
  primary unit cell.

* Add the `out` argument to `mdtools.box.wrap_pos` that allows the user
  to parse a pre-allocated array into which to store the result.

* Add the `dtype` argument to `mdtools.box.wrap_pos` that allows the
  user to specify the data type of the output array.

Breaking changes:

* Remove the `mda_backend` argument, because `mdtools.box.wrap_pos` no
  longer uses `MDAnalysis.lib.distances.apply_PBC`.

* If `box` has shape ``(k, 6)`` a two-dimensional position array is not
  any longer interpreted to have the shape ``(k, 3)``.  Instead it is
  now interpreted to have shape ``(n, 3)``.  Here k is the number of
  frames and n is the number of particles.
…pos`

Adapt `mdtools.structure.wcenter_pos` to the changes in
`mdtools.box.wrap_pos`.

New Features:

* Add support for triclinic simulation boxes to the function
  `mdtools.structure.wcenter_pos` that calculates the weighted center of
  an position array.

* Add the `dtype` argument to `mdtools.structure.wcenter_pos` that
  allows the user to specify the data type of the output array.

Breaking changes:

* Remove the `mda_backend` argument, because `mdtools.box.wrap_pos` no
  longer uses supports it.

* If `box` has shape ``(k, 6)`` a two-dimensional position array is not
  any longer interpreted to have the shape ``(k, 3)``.  Instead it is
  now interpreted to have shape ``(n, 3)``.  Here k is the number of
  frames and n is the number of particles.

* If centers are calculated for multiple frames, always return an array
  of shape ``(k, 1, 3)`` instead of ``(k, 3)``.
Adapt `mdtools.structure.rmsd` to the changes in
`mdtools.structure.wcenter_pos`.
Update docstring, sort imports and fix linter warnings.
Fix the function `mdtools.box.make_whole`: Remove the `debug` argument
that was parsed to `MDAnalysis.core.groups.AtomGroup.unwrap` although
`MDAnalysis.core.groups.AtomGroup.unwrap` has no `debug` argument.

Fix wrongly rendered docstring.
Create a LibreOffice Calc Spread Sheet to test different unwrapping
algorithms.
Create a new function `mdtools.box.unwrap_frame` that unwraps a single
trajectory frame.

The new functions implements five different unwrapping algorithms:
"scaling", "heuristic", "displacement", "hybrid", "in-house".

See

* Sören von Bülow, Jakob Tómas Bullerjahn, and Gerhard Hummer,
  Systematic errors in diffusion coefficients from long-time molecular
  dynamics simulations at constant pressure,
  The Journal of Chemical Physics, 2020, 153, 021101,

* Martin Kulke and Josh V. Vermaas,
  Reversible Unwrapping Algorithm for Constant-Pressure Molecular
  Dynamics Simulations,
  Journal of Chemical Theory and Computation, 2022, 18, 10, 6161-6171.
@github-actions github-actions bot added breaking Breaking changes bugfix Pull requests that fix a bug labels Mar 6, 2023
@github-actions github-actions bot added enhancement New feature or request maintenance Project maintenance major-core Breaking change in the core package major-scripts Breaking change in one ore more scripts refactoring Code refactoring labels Mar 6, 2023
Completely rewrite the script `unwrap_trj.py` to use the new function
`mdtools.box.unwrap_frame`.

* Add the following command-line arguments:

    * `-b`: First frame to read.
    * `--every`: Read every n-th frame.
    * `--method`: The unwrapping method to use.

* Rename the following command-line arguments:

   * `--otrj` to `--trj-out`: Output trajectory.
   * `--otop` to `--top-out`: Output topology.
   * `--compound` to `--cmp`: The compounds to make whole.

* Remove the following command-line arguments:

   * `--make-whole`.
   * `--keep-whole`.

* Add docstring.
@andthum andthum force-pushed the fix/trajectory-unwrapping branch 3 times, most recently from fcffea7 to 0c5eed4 Compare March 6, 2023 13:57
andthum added 14 commits March 6, 2023 16:40
Create summary doc page for all scripts that manipulate MD trajectories.
Add a new make option `install_mdt` that (re-)installs MDTools.
Re-installing MDTools is necessary when changing the docstring of a
script.  Otherwise the changes won't be recognized by Sphinx.
Add a note that doc pages of scripts might not get updated if you simply
run `make html` after changing a script's docstring.  Instead, you need
to re-install MDTools first even if you have installed it in editable
mode.
Add a note that doc pages of scripts might not get updated if you simply
run `make html` after changing a script's docstring.  Instead, you need
to re-install MDTools first even if you have installed it in editable
mode.
Remove the function `mdtools.box.unwrap` because it is replaced by the
new function `mdtools.box.unwrap_frame`.
Remove the function `mdtools.box.unwrap_trj` because it uses the
displacement unwrapping method that only works for constant simulation
boxes and was only implemented for orthorhombic boxes.

Use the script `unwrap_trj` or the function `mdtools.box.unwrap_frame`
instead.
Create a new script that calculates the Root Mean Square Deviation
(RMSD) between two trajectories for each frame.
@andthum andthum force-pushed the fix/trajectory-unwrapping branch from 0c5eed4 to 2a39429 Compare March 6, 2023 15:41
@andthum andthum merged commit df72fb0 into main Mar 6, 2023
@andthum andthum deleted the fix/trajectory-unwrapping branch March 6, 2023 15:49
@andthum andthum mentioned this pull request Mar 10, 2023
15 tasks
andthum added a commit that referenced this pull request Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Breaking changes bugfix Pull requests that fix a bug enhancement New feature or request maintenance Project maintenance major-core Breaking change in the core package major-scripts Breaking change in one ore more scripts refactoring Code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant