#分子动力学 #文件格式 #xtc #gromacs

bin+lib molli

xtc 文件格式快速读取器

4 个版本

0.2.3 2024 年 7 月 14 日
0.2.2-alpha2024 年 5 月 28 日
0.2.1-alpha2024 年 5 月 24 日
0.2.0-alpha2024 年 4 月 30 日
0.1.0 2021 年 4 月 21 日

#488解析实现

MIT 许可证

1.5MB
1.5K SLoC

molli—读取 xtc 文件,快速

molly logo

纯 Rust 实现的 Gromacs xtc 文件格式 读取器。

molli 尝试从磁盘读取最少的字节数。为此,该库提供了一系列选择方法,用于轨迹中的 和每个帧中的 原子。这种选择允许进行一些有趣的优化——只有必要的位置被解压缩。同样,在最初只读取有限数量的压缩字节的场合。在需要选择帧顶部位置子集的大型轨迹的应用中,这种缓冲读取特别强大。这种缓冲读取在磁盘读取速度特别低时非常有用,例如通过网络文件存储。

为了方便在现有分析工具中使用,molli 提供了一套绑定,允许从 Python 访问其函数。

molli 还可以作为命令行工具安装,用于缩短和过滤 xtc 文件。

注意: molli 状态相当稳定,已在野外使用。请务必谨慎并验证结果。对任何工具的盲目信任是不负责任的。

如有任何问题,请随时与我联系 联系

安装

命令行应用程序

cargo install molly

用法

使用 molli 命令,可以对 xtc 文件进行过滤和缩短。可以选择帧以及帧内的原子。

  • 可以使用 -f/--frame-selection 选项选择帧,使用 start:stop:step 范围,这与 Python 中的范围类似。
  • 可以使用 -a/--atom-selection 选项选择前 n 个原子。

以下是可能使用的简要展示。

# List all options.
molly --help

# Print a summary of a trajectory to standard out.
molly --info big.xtc

# Trajectories can be filtered in a number of ways. Here are a few combinations.
# Select the 100th to the 600th frame in steps of two. From those, store only the first 161 atoms.
molly big.xtc out.xtc --frame-selection 100:600:2 --atom-selection 161
molly big.xtc out.xtc -f 100:600:2 -a 161  # With shorter arguments.

# Reverse a selection. Here we use it to select the last frame.
molly big.xtc last.xtc --reverse-frame-selection --frame-selection :1
molly big.xtc last.xtc -Rf :1  # With shorter arguments.

# Reverse a trajectory.
molly big.xtc rev.xtc --reverse

# For any of these filtering commands, the frame times and steps can be written to standard out.
molly big.xtc rev_last_ten.xtc -rRf :10 --steps --times

作为库

要在Rust项目中使用molly,请将此存储库添加到您的Cargo.toml依赖项中。在crates.io上找到mollycrates.io上的molly

作为Python模块

cargo(提供Rust编译器)是构建Python绑定所需的。 (稳定的工具链就足够了。)

要安装此模块,请运行以下命令。它将自动克隆存储库并从正确的目录安装Python库。

pip3 install 'git+https://git.sr.ht/~ma3ke/molly#egg=molly&subdirectory=bindings/python'

或者,克隆存储库,进入绑定目录,然后使用pip从那里安装。

git clone https://git.sr.ht/~ma3ke/molly
cd molly/bindings/python

# Perhaps you want to use/create a virtual environment first.
python3 -m venv venv
source venv/bin/activate

pip3 install .

示例

examples目录中可以找到一些有用的示例程序。其中一些可以用来与其他xtc读取器实现进行基准测试,或者创建测试文件。

注意: 我目前将它们留在这里,但最终我会删除或基本更改这些示例中的许多。

为了访问这些示例,请克隆存储库并构建它们。

git clone https://git.sr.ht/~ma3ke/molly
cd molly
cargo build --release --examples
target/release/examples/<name> [options]

或者直接运行

cargo run --release --example <name>

测试

库包括一些内部机制和集成测试(包括与其他库产生的值进行比较)。请注意,使用--release标志运行测试是首选的,因为调试构建运行得相当慢。

cargo test --release

性能和基准测试

如果您感兴趣,可以运行提供的基准测试!

cargo bench

此外,仓库中还有一些基准测试脚本。我可能会在稍后将其整理成一张整洁的表格。目前,一些内容仍然可能发生变化。尽管我们可以看到molly的性能故事的大致轮廓,但这还不是做出硬性承诺的时候。

看起来molly比广泛使用的Gromacs实现xdrf(约快2倍),比chemfiles实现(约快4倍)。

对于缓冲实现,这个差距稍微小一些。当考虑磁盘I/O时,缓冲读取比非缓冲读取慢约20%。但在只选择每帧顶部子集的位置的非常大的轨迹中,这种优势是相当明显的。


Marieke Westendorp,2024

依赖项

~5MB
~136K SLoC