Skip to content

Commit

Permalink
added example for data preparation
Browse files Browse the repository at this point in the history
  • Loading branch information
gwirn committed Jun 3, 2024
1 parent e92d09a commit e2c5505
Show file tree
Hide file tree
Showing 8 changed files with 131,952 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ The current version of molearn only supports Linux, and has verified to support

#### Optional Packages

To prepare a raw trajectory for training:
* [mdtraj](https://mdtraj.org/1.9.4/index.html)

To run energy evaluations with OpenMM:
* [OpenMM](https://openmm.org/documentation)
* [openmmtorchplugin](https://github.com/SCMusson/openmmtorchplugin)
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ dependencies:
- plotly
- nglview
- openmmtorchplugin
- mdtraj
- pip:
- geomloss
Binary file added examples/data/preparation/MurDclosed.dcd
Binary file not shown.
Binary file added examples/data/preparation/MurDopen.dcd
Binary file not shown.
62,009 changes: 62,009 additions & 0 deletions examples/data/preparation/topo_MurDclosed1F.pdb

Large diffs are not rendered by default.

69,881 changes: 69,881 additions & 0 deletions examples/data/preparation/topo_MurDopen1F.pdb

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions examples/prepare_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import os
import sys

sys.path.insert(0, os.path.join(os.path.abspath(os.pardir), "src"))
from molearn.data import DataAssembler


def main():
storage_path = "./clustered"
if not os.path.exists(storage_path):
os.mkdir(storage_path)
tm = DataAssembler(
# trajectories
[
"./data/preparation/MurDopen.dcd",
"./data/preparation/MurDclosed.dcd",
],
# topologies
[
"./data/preparation/topo_MurDopen1F.pdb",
"./data/preparation/topo_MurDclosed1F.pdb",
],
test_size=0.0,
n_cluster=5,
outpath=storage_path,
verbose=True,
)
# reading in the trajectories and removing of all atoms apart from protein atoms
tm.read_traj()
# using agglomerative clustering to sample the trajectories
tm.distance_cluster()
# creating the new trajectory as dcd file and a new topology as pdb file
tm.create_trajectories()
# using PCA and the first n components for KMeans clustering to sample the trajectories
tm.pca_cluster()
tm.create_trajectories()
# simply striding over the trajectories with a step size computed to result in n_cluster frames
tm.stride()
tm.create_trajectories()
"""
the given example will create the following files in a new directory named 'clustered'
* MurDopen_CLUSTER_aggl_train.dcd
* MurDopen_CLUSTER_aggl_train_frames.txt
* MurDopen_CLUSTER_pca_train.dcd
* MurDopen_CLUSTER_pca_train_frames.txt
* MurDopen_NEW_TOPO.pdb
* MurDopen_STRIDE_5_train.dcd
* MurDopen_STRIDE_5_train_frames.txt
the txt files contain the indices of frames of the original trajectory
the dcd files contain the new trajectory
the pdb file is the new topology for the new trajectory
all atoms apart from protein atoms will be removed
"""


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion src/molearn/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2022 Samuel C. Musson
# Copyright (c) 2022 Samuel C. Musson, Gregor Wirnsberger
#
# Molearn is free software ;
# you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation ;
Expand Down

0 comments on commit e2c5505

Please sign in to comment.