Skip to content

Commit

Permalink
Merge pull request #19 from Degiacomi-Lab/clustering
Browse files Browse the repository at this point in the history
Clustering
  • Loading branch information
degiacom authored Jun 3, 2024
2 parents 0b210b1 + e2c5505 commit 79abb57
Show file tree
Hide file tree
Showing 10 changed files with 132,408 additions and 2 deletions.
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
2 changes: 2 additions & 0 deletions docs/source/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ Data Loading
.. autoclass:: molearn.data.PDBData
:members:

.. autoclass:: molearn.data.DataAssembler
:members:
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()
5 changes: 3 additions & 2 deletions 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 All @@ -11,5 +11,6 @@
"""
loaders holds classes for loading data
"""
from .pdb_data import PDBData

from .pdb_data import PDBData
from .prepare import DataAssembler
Loading

0 comments on commit 79abb57

Please sign in to comment.