sawnergy 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of sawnergy might be problematic. Click here for more details.
- sawnergy-1.0.0/LICENSE +201 -0
- sawnergy-1.0.0/NOTICE +4 -0
- sawnergy-1.0.0/PKG-INFO +290 -0
- sawnergy-1.0.0/README.md +259 -0
- sawnergy-1.0.0/sawnergy/__init__.py +13 -0
- sawnergy-1.0.0/sawnergy/embedding/SGNS_pml.py +135 -0
- sawnergy-1.0.0/sawnergy/embedding/SGNS_torch.py +177 -0
- sawnergy-1.0.0/sawnergy/embedding/__init__.py +34 -0
- sawnergy-1.0.0/sawnergy/embedding/embedder.py +578 -0
- sawnergy-1.0.0/sawnergy/logging_util.py +54 -0
- sawnergy-1.0.0/sawnergy/rin/__init__.py +9 -0
- sawnergy-1.0.0/sawnergy/rin/rin_builder.py +936 -0
- sawnergy-1.0.0/sawnergy/rin/rin_util.py +391 -0
- sawnergy-1.0.0/sawnergy/sawnergy_util.py +1182 -0
- sawnergy-1.0.0/sawnergy/visual/__init__.py +42 -0
- sawnergy-1.0.0/sawnergy/visual/visualizer.py +690 -0
- sawnergy-1.0.0/sawnergy/visual/visualizer_util.py +387 -0
- sawnergy-1.0.0/sawnergy/walks/__init__.py +16 -0
- sawnergy-1.0.0/sawnergy/walks/walker.py +795 -0
- sawnergy-1.0.0/sawnergy/walks/walker_util.py +384 -0
- sawnergy-1.0.0/sawnergy.egg-info/PKG-INFO +290 -0
- sawnergy-1.0.0/sawnergy.egg-info/SOURCES.txt +29 -0
- sawnergy-1.0.0/sawnergy.egg-info/dependency_links.txt +1 -0
- sawnergy-1.0.0/sawnergy.egg-info/requires.txt +6 -0
- sawnergy-1.0.0/sawnergy.egg-info/top_level.txt +1 -0
- sawnergy-1.0.0/setup.cfg +4 -0
- sawnergy-1.0.0/tests/test_embedding.py +203 -0
- sawnergy-1.0.0/tests/test_rin.py +47 -0
- sawnergy-1.0.0/tests/test_storage.py +42 -0
- sawnergy-1.0.0/tests/test_visual.py +46 -0
- sawnergy-1.0.0/tests/test_walks.py +47 -0
sawnergy-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 Yehor Mishchyriak
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
sawnergy-1.0.0/NOTICE
ADDED
sawnergy-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sawnergy
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Toolkit for transforming molecular dynamics (MD) trajectories into rich graph representations
|
|
5
|
+
Home-page: https://github.com/Yehor-Mishchyriak/SAWNERGY
|
|
6
|
+
Author: Yehor Mishchyriak
|
|
7
|
+
License: Apache-2.0
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.11
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
License-File: NOTICE
|
|
15
|
+
Requires-Dist: numpy>=2.0
|
|
16
|
+
Requires-Dist: zarr>=3.0
|
|
17
|
+
Requires-Dist: threadpoolctl>=3.0
|
|
18
|
+
Requires-Dist: matplotlib>=3.7
|
|
19
|
+
Requires-Dist: psutil>=5.9
|
|
20
|
+
Requires-Dist: ym-pure-ml>=1.2.0
|
|
21
|
+
Dynamic: author
|
|
22
|
+
Dynamic: classifier
|
|
23
|
+
Dynamic: description
|
|
24
|
+
Dynamic: description-content-type
|
|
25
|
+
Dynamic: home-page
|
|
26
|
+
Dynamic: license
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
Dynamic: requires-dist
|
|
29
|
+
Dynamic: requires-python
|
|
30
|
+
Dynamic: summary
|
|
31
|
+
|
|
32
|
+
# SAWNERGY
|
|
33
|
+
|
|
34
|
+
A toolkit for transforming molecular dynamics (MD) trajectories into rich graph representations, sampling
|
|
35
|
+
random and self-avoiding walks, learning node embeddings, and visualising residue interaction networks (RINs). SAWNERGY
|
|
36
|
+
keeps the full workflow — from `cpptraj` output to skip-gram embeddings (node2vec approach) — inside Python, backed by efficient Zarr-based archives and optional GPU acceleration.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Why SAWNERGY?
|
|
41
|
+
|
|
42
|
+
- **Bridge simulations and graph ML**: Convert raw MD trajectories into residue interaction networks ready for graph
|
|
43
|
+
algorithms and downstream machine learning tasks.
|
|
44
|
+
- **Deterministic, shareable artefacts**: Every stage produces compressed Zarr archives that contain both data and metadata so runs can be reproduced, shared, or inspected later.
|
|
45
|
+
- **High-performance data handling**: Heavy arrays live in shared memory during walk sampling to allow parallel processing without serealization overhead; archives are written in chunked, compressed form for fast read/write.
|
|
46
|
+
- **Flexible embedding backends**: Train skip-gram with negative sampling (SGNS) models using either PureML or PyTorch.
|
|
47
|
+
- **Visualization out of the box**: Plot and animate residue networks without leaving Python, using the data produced by RINBuilder
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Pipeline at a Glance
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
MD Trajectory + Topology
|
|
55
|
+
│
|
|
56
|
+
▼
|
|
57
|
+
RINBuilder
|
|
58
|
+
│ → RIN archive (.zip/.zarr) → Visualizer (display/animate RINs)
|
|
59
|
+
▼
|
|
60
|
+
Walker
|
|
61
|
+
│ → Walks archive (RW/SAW per frame)
|
|
62
|
+
▼
|
|
63
|
+
Embedder
|
|
64
|
+
│ → Embedding archive (frame × vocab × dim)
|
|
65
|
+
▼
|
|
66
|
+
Downstream ML
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Each stage consumes the archive produced by the previous one. Metadata embedded in the archives ensures frame order,
|
|
70
|
+
node indexing, and RNG seeds stay consistent across the toolchain.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Core Components
|
|
75
|
+
|
|
76
|
+
### `sawnergy.rin.RINBuilder`
|
|
77
|
+
|
|
78
|
+
* Wraps the AmberTools `cpptraj` executable to:
|
|
79
|
+
- compute per-frame electrostatic (EMAP) and van der Waals (VMAP) energy matrices at the atomic level,
|
|
80
|
+
- project atom–atom interactions to residue–residue interactions using compositional masks,
|
|
81
|
+
- prune, symmetrise, remove self-interactions, and L1-normalise the matrices,
|
|
82
|
+
- compute per-residue centres of mass (COM) over the same frames.
|
|
83
|
+
* Outputs a compressed Zarr archive with transition matrices, optional prenormalised energies, COM snapshots, and rich
|
|
84
|
+
metadata (frame range, pruning quantile, molecule ID, etc.).
|
|
85
|
+
* Supports parallel `cpptraj` execution, batch processing, and keeps temporary stores tidy via
|
|
86
|
+
`ArrayStorage.compress_and_cleanup`.
|
|
87
|
+
|
|
88
|
+
### `sawnergy.visual.Visualizer`
|
|
89
|
+
|
|
90
|
+
* Opens RIN archives, resolves dataset names from attributes, and renders nodes plus attractive/repulsive edge bundles
|
|
91
|
+
in 3D using Matplotlib.
|
|
92
|
+
* Allows both static frame visualization and trajectory animation.
|
|
93
|
+
* Handles backend selection (`Agg` fallback in headless environments) and offers convenient colour palettes via
|
|
94
|
+
`visualizer_util`.
|
|
95
|
+
|
|
96
|
+
### `sawnergy.walks.Walker`
|
|
97
|
+
|
|
98
|
+
* Attaches to the RIN archive and loads attractive/repulsive transition matrices into shared memory using
|
|
99
|
+
`walker_util.SharedNDArray` so multiple processes can sample without copying.
|
|
100
|
+
* Samples random walks (RW) and self-avoiding walks (SAW), optionally time-aware, that is, walks move through transition matrices with transition probabilities proportional to cosine similarity between the current and next frame. Randomness is controlled by the seed passed to the class constructor.
|
|
101
|
+
* Persists walks as `(time, walk_id, length+1)` tensors (1-based node indices) alongside metadata such as
|
|
102
|
+
`walk_length`, `walks_per_node`, and RNG scheme.
|
|
103
|
+
|
|
104
|
+
### `sawnergy.embedding.Embedder`
|
|
105
|
+
|
|
106
|
+
* Consumes walk archives, generates skip-gram pairs, and normalises them to 0-based indices.
|
|
107
|
+
* Provides a unified interface to SGNS implementations:
|
|
108
|
+
- **PureML backend** (`SGNS_PureML`): works with the `pureml` ecosystem, optimistic for CPU training.
|
|
109
|
+
- **PyTorch backend** (`SGNS_Torch`): uses `torch.nn.Embedding` plays nicely with GPUs.
|
|
110
|
+
* Both `SGNS_PureML` and `SGNS_Torch` accept training hyperparameters such as batch_size, LR, optimizer and LR_scheduler, etc.
|
|
111
|
+
* Exposes `embed_frame` (single frame) and `embed_all` (all frames, deterministic seeding per frame) which return the
|
|
112
|
+
learned input embedding matrices and write them to disk when requested.
|
|
113
|
+
|
|
114
|
+
### Supporting Utilities
|
|
115
|
+
|
|
116
|
+
* `sawnergy.sawnergy_util`
|
|
117
|
+
- `ArrayStorage`: thin wrapper over Zarr v3 with helpers for chunk management, attribute coercion to JSON, and transparent compression to `.zip` archives.
|
|
118
|
+
- Parallel helpers (`elementwise_processor`, `compose_steps`, etc.), temporary file management, logging, and runtime
|
|
119
|
+
inspection utilities.
|
|
120
|
+
* `sawnergy.logging_util.configure_logging`: configure rotating file/console logging consistently across scripts.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Archive Layouts
|
|
125
|
+
|
|
126
|
+
| Archive | Key datasets (name → shape, dtype) | Important attributes (root `attrs`) |
|
|
127
|
+
|---|---|---|
|
|
128
|
+
| **RIN** | `ATTRACTIVE_transitions` → **(T, N, N)**, float32 • `REPULSIVE_transitions` → **(T, N, N)**, float32 (optional) • `ATTRACTIVE_energies` → **(T, N, N)**, float32 (optional) • `REPULSIVE_energies` → **(T, N, N)**, float32 (optional) • `COM` → **(T, N, 3)**, float32 | `time_created` (ISO) • `com_name` = `"COM"` • `molecule_of_interest` (int) • `frame_range` = `(start, end)` inclusive • `frame_batch_size` (int) • `prune_low_energies_frac` (float in [0,1]) • `attractive_transitions_name` / `repulsive_transitions_name` (dataset names or `None`) • `attractive_energies_name` / `repulsive_energies_name` (dataset names or `None`) |
|
|
129
|
+
| **Walks** | `ATTRACTIVE_RWs` → **(T, N·num_RWs, L+1)**, int32 (optional) • `REPULSIVE_RWs` → **(T, N·num_RWs, L+1)**, int32 (optional) • `ATTRACTIVE_SAWs` → **(T, N·num_SAWs, L+1)**, int32 (optional) • `REPULSIVE_SAWs` → **(T, N·num_SAWs, L+1)**, int32 (optional) <br/>_Note:_ node IDs are **1-based**.| `time_created` (ISO) • `seed` (int) • `rng_scheme` = `"SeedSequence.spawn_per_batch_v1"` • `num_workers` (int) • `in_parallel` (bool) • `batch_size_nodes` (int) • `num_RWs` / `num_SAWs` (ints) • `node_count` (N) • `time_stamp_count` (T) • `walk_length` (L) • `walks_per_node` (int) • `attractive_RWs_name` / `repulsive_RWs_name` / `attractive_SAWs_name` / `repulsive_SAWs_name` (dataset names or `None`) • `walks_layout` = `"time_leading_3d"` |
|
|
130
|
+
| **Embeddings** | `FRAME_EMBEDDINGS` → **(frames_written, vocab_size, D)**, typically float32 | `time_created` (ISO) • `seed` (int) • `rng_scheme` = `"SeedSequence.spawn_per_frame_v1"` • `source_walks_path` (str) • `model_base` = `"torch"` or `"pureml"` • `rin_type` = `"attr"` or `"repuls"` • `using_mode` = `"RW"|"SAW"|"merged"` • `window_size` (int) • `alpha` (float; noise exponent) • `dimensionality` = D • `num_negative_samples` (int) • `num_epochs` (int) • `batch_size` (int) • `shuffle_data` (bool) • `frames_written` (int) • `vocab_size` (int) • `frame_count` (int) • `embedding_dtype` (str) • `frame_embeddings_name` = `"FRAME_EMBEDDINGS"` • `arrays_per_chunk` (int) • `compression_level` (int) |
|
|
131
|
+
|
|
132
|
+
**Notes**
|
|
133
|
+
|
|
134
|
+
- In **RIN**, `T` equals the number of frame **batches** written (i.e., `frame_range` swept in steps of `frame_batch_size`). `ATTRACTIVE/REPULSIVE_energies` are **pre-normalised** absolute energies (written only when `keep_prenormalized_energies=True`), whereas `ATTRACTIVE/REPULSIVE_transitions` are the **row-wise L1-normalised** versions used for sampling.
|
|
135
|
+
- All archives are Zarr v3 groups. ArrayStorage also maintains per-block metadata in root attrs: `array_chunk_size_in_block`, `array_shape_in_block`, and `array_dtype_in_block` (dicts keyed by dataset name). You’ll see these in every archive.
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Installation
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
pip install sawnergy
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
> **Note:** RIN building requires `cpptraj` (AmberTools). Ensure it is discoverable via `$PATH` or the `CPPTRAJ`
|
|
146
|
+
> environment variable.
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Quick Start
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
from pathlib import Path
|
|
154
|
+
from sawnergy.logging_util import configure_logging
|
|
155
|
+
from sawnergy.rin import RINBuilder
|
|
156
|
+
from sawnergy.walks import Walker
|
|
157
|
+
from sawnergy.embedding import Embedder
|
|
158
|
+
|
|
159
|
+
import logging
|
|
160
|
+
configure_logging("./logs", file_level=logging.WARNING, console_level=logging.INFO)
|
|
161
|
+
|
|
162
|
+
# 1. Build a Residue Interaction Network archive
|
|
163
|
+
rin_path = Path("./RIN_demo.zip")
|
|
164
|
+
rin_builder = RINBuilder()
|
|
165
|
+
rin_builder.build_rin(
|
|
166
|
+
topology_file="system.prmtop",
|
|
167
|
+
trajectory_file="trajectory.nc",
|
|
168
|
+
molecule_of_interest=1,
|
|
169
|
+
frame_range=(1, 100),
|
|
170
|
+
frame_batch_size=10,
|
|
171
|
+
prune_low_energies_frac=0.3,
|
|
172
|
+
output_path=rin_path,
|
|
173
|
+
include_attractive=True,
|
|
174
|
+
include_repulsive=False,
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
# 2. Sample walks from the RIN
|
|
178
|
+
walker = Walker(rin_path, seed=123)
|
|
179
|
+
walks_path = Path("./WALKS_demo.zip")
|
|
180
|
+
walker.sample_walks(
|
|
181
|
+
walk_length=16,
|
|
182
|
+
walks_per_node=32,
|
|
183
|
+
saw_frac=0.25,
|
|
184
|
+
include_attractive=True,
|
|
185
|
+
include_repulsive=False,
|
|
186
|
+
time_aware=False,
|
|
187
|
+
output_path=walks_path,
|
|
188
|
+
in_parallel=False,
|
|
189
|
+
)
|
|
190
|
+
walker.close()
|
|
191
|
+
|
|
192
|
+
# 3. Train embeddings per frame (PyTorch backend)
|
|
193
|
+
import torch
|
|
194
|
+
|
|
195
|
+
embedder = Embedder(walks_path, base="torch", seed=999)
|
|
196
|
+
embeddings_path = embedder.embed_all(
|
|
197
|
+
RIN_type="attr",
|
|
198
|
+
using="merged",
|
|
199
|
+
window_size=4,
|
|
200
|
+
num_negative_samples=5,
|
|
201
|
+
num_epochs=5,
|
|
202
|
+
batch_size=1024,
|
|
203
|
+
dimensionality=128,
|
|
204
|
+
shuffle_data=True,
|
|
205
|
+
output_path="./EMBEDDINGS_demo.zip",
|
|
206
|
+
sgns_kwargs={
|
|
207
|
+
"optim": torch.optim.Adam,
|
|
208
|
+
"optim_kwargs": {"lr": 1e-3},
|
|
209
|
+
"lr_sched": torch.optim.lr_scheduler.LambdaLR,
|
|
210
|
+
"lr_sched_kwargs": {"lr_lambda": lambda _: 1.0},
|
|
211
|
+
"device": "cuda" if torch.cuda.is_available() else "cpu",
|
|
212
|
+
},
|
|
213
|
+
)
|
|
214
|
+
print("Embeddings written to", embeddings_path)
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
> For the PureML backend, supply the relevant optimiser and scheduler via `sgns_kwargs`
|
|
218
|
+
> (for example `optim=pureml.optimizers.Adam`, `lr_sched=pureml.optimizers.CosineAnnealingLR`).
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## Visualisation
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
from sawnergy.visual import Visualizer
|
|
226
|
+
|
|
227
|
+
v = sawnergy.visual.Visualizer("./RIN_demo.zip")
|
|
228
|
+
v.build_frame(1,
|
|
229
|
+
node_colors="rainbow",
|
|
230
|
+
displayed_nodes="ALL",
|
|
231
|
+
displayed_pairwise_attraction_for_nodes="DISPLAYED_NODES",
|
|
232
|
+
displayed_pairwise_repulsion_for_nodes="DISPLAYED_NODES",
|
|
233
|
+
show_node_labels=True,
|
|
234
|
+
show=True
|
|
235
|
+
)
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
`Visualizer` lazily loads datasets and works even in headless environments (falls back to the `Agg` backend).
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Advanced Notes
|
|
243
|
+
|
|
244
|
+
- **Time-aware walks**: Set `time_aware=True`, provide `stickiness` and `on_no_options` when calling `Walker.sample_walks`.
|
|
245
|
+
- **Shared memory lifecycle**: Call `Walker.close()` (or use a context manager) to release shared-memory segments.
|
|
246
|
+
- **PureML vs PyTorch**: Choose the backend via `Embedder(..., base="pureml"|"torch")` and provide backend-specific
|
|
247
|
+
constructor kwargs through `sgns_kwargs` (optimizer, scheduler, device).
|
|
248
|
+
- **ArrayStorage utilities**: Use `ArrayStorage` directly to peek into archives, append arrays, or manage metadata.
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## Testing & Quality Assurance
|
|
253
|
+
|
|
254
|
+
The automated test suite (`pytest`) synthesises deterministic cpptraj outputs and exercises the entire workflow:
|
|
255
|
+
|
|
256
|
+
- RIN parsing, residue aggregation, and metadata verification.
|
|
257
|
+
- Random/self-avoiding walk sampling and probability consistency with the RIN.
|
|
258
|
+
- Embedding orchestration, frame ordering, SGNS pair generation property tests.
|
|
259
|
+
- PureML and PyTorch SGNS smoke tests verifying finite weights and decreasing loss.
|
|
260
|
+
- Visualiser smoke tests that cover data loading and artist updates.
|
|
261
|
+
|
|
262
|
+
Run the suite (inside the project virtualenv):
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
python -m pytest
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## Project Structure
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
├── sawnergy/
|
|
274
|
+
│ ├── rin/ # RINBuilder and cpptraj integration helpers
|
|
275
|
+
│ ├── walks/ # Walker class and shared-memory utilities
|
|
276
|
+
│ ├── embedding/ # Embedder + SGNS backends (PureML / PyTorch)
|
|
277
|
+
│ ├── visual/ # Visualizer and palette utilities
|
|
278
|
+
│ ├── logging_util.py
|
|
279
|
+
│ └── sawnergy_util.py
|
|
280
|
+
├── tests/ # Synthetic end-to-end tests (pytest)
|
|
281
|
+
│
|
|
282
|
+
└── README.md
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
## Acknowledgements
|
|
288
|
+
|
|
289
|
+
SAWNERGY builds on the AmberTools `cpptraj` ecosystem, NumPy, Matplotlib, Zarr, and PyTorch (for GPU acceleration if necessary; PureML is available by default).
|
|
290
|
+
Big thanks to the upstream communities whose work makes this toolkit possible.
|