MasterMSM 2.0.1__py3-none-any.whl
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.
- mastermsm/__init__.py +1 -0
- mastermsm/fewsm/__init__.py +0 -0
- mastermsm/fewsm/fewsm.py +260 -0
- mastermsm/fewsm/fewsm_lib.py +106 -0
- mastermsm/msm/__init__.py +0 -0
- mastermsm/msm/msm.py +1059 -0
- mastermsm/msm/msm_lib.py +1347 -0
- mastermsm/test/__init__.py +0 -0
- mastermsm/test/download_data.py +72 -0
- mastermsm/test/test_fewsm.py +103 -0
- mastermsm/test/test_msm.py +1039 -0
- mastermsm/test/test_trajectory.py +1051 -0
- mastermsm/trajectory/__init__.py +0 -0
- mastermsm/trajectory/traj.py +704 -0
- mastermsm/trajectory/traj_lib.py +459 -0
- mastermsm-2.0.1.dist-info/METADATA +205 -0
- mastermsm-2.0.1.dist-info/RECORD +20 -0
- mastermsm-2.0.1.dist-info/WHEEL +5 -0
- mastermsm-2.0.1.dist-info/licenses/LICENSE +340 -0
- mastermsm-2.0.1.dist-info/top_level.txt +1 -0
|
File without changes
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import unittest
|
|
3
|
+
import urllib.request
|
|
4
|
+
import urllib.error
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _data_dir():
|
|
8
|
+
"""Directory for the downloaded test trajectories.
|
|
9
|
+
|
|
10
|
+
In order of preference: $MASTERMSM_TEST_DATA, the ``data`` folder
|
|
11
|
+
next to this file (source checkouts and writable installs), or a
|
|
12
|
+
per-user cache (read-only installs, e.g. system or conda packages).
|
|
13
|
+
"""
|
|
14
|
+
env = os.environ.get("MASTERMSM_TEST_DATA")
|
|
15
|
+
if env:
|
|
16
|
+
return env
|
|
17
|
+
here = os.path.join(os.path.dirname(__file__), "data")
|
|
18
|
+
if os.path.isdir(here) or os.access(os.path.dirname(here), os.W_OK):
|
|
19
|
+
return here
|
|
20
|
+
cache = os.environ.get("XDG_CACHE_HOME",
|
|
21
|
+
os.path.join(os.path.expanduser("~"), ".cache"))
|
|
22
|
+
return os.path.join(cache, "mastermsm", "test-data")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
_DATA_DIR = _data_dir()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _download(url, dest, max_redirects=10):
|
|
29
|
+
"""Download url to dest, following HTTP 308 (Python 3.10 urllib omits it).
|
|
30
|
+
|
|
31
|
+
Writes to a temporary file first so that an interrupted download
|
|
32
|
+
never leaves a truncated file at dest.
|
|
33
|
+
"""
|
|
34
|
+
part = dest + ".part"
|
|
35
|
+
try:
|
|
36
|
+
for _ in range(max_redirects):
|
|
37
|
+
try:
|
|
38
|
+
urllib.request.urlretrieve(url, part)
|
|
39
|
+
os.replace(part, dest)
|
|
40
|
+
return
|
|
41
|
+
except urllib.error.HTTPError as e:
|
|
42
|
+
if e.code == 308 and e.headers.get("Location"):
|
|
43
|
+
url = e.headers["Location"]
|
|
44
|
+
else:
|
|
45
|
+
raise
|
|
46
|
+
raise urllib.error.URLError("too many redirects: %s" % url)
|
|
47
|
+
finally:
|
|
48
|
+
if os.path.exists(part):
|
|
49
|
+
os.remove(part)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _fetch(downloads):
|
|
53
|
+
"""Download missing files; skip the calling test if that fails."""
|
|
54
|
+
try:
|
|
55
|
+
os.makedirs(_DATA_DIR, exist_ok=True)
|
|
56
|
+
for k, v in downloads.items():
|
|
57
|
+
dest = os.path.join(_DATA_DIR, k)
|
|
58
|
+
if not os.path.isfile(dest):
|
|
59
|
+
_download(v, dest)
|
|
60
|
+
except (urllib.error.URLError, OSError) as e:
|
|
61
|
+
raise unittest.SkipTest(
|
|
62
|
+
"test data could not be downloaded to %s (%s)" % (_DATA_DIR, e))
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def download_osf_alaTB():
|
|
66
|
+
_fetch({"alaTB.gro": "https://osf.io/hgbqs/download",
|
|
67
|
+
"alaTB.xtc": "https://osf.io/ujmhc/download"})
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def download_osf_ala5():
|
|
71
|
+
_fetch({"ala5.gro": "https://osf.io/6uznm/download",
|
|
72
|
+
"ala5.xtc": "https://osf.io/gmxpy/download"})
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
import mdtraj as md
|
|
3
|
+
import numpy as np
|
|
4
|
+
from mastermsm.trajectory import traj_lib, traj
|
|
5
|
+
from mastermsm.msm import msm, msm_lib
|
|
6
|
+
from mastermsm.fewsm import fewsm, fewsm_lib
|
|
7
|
+
from mastermsm.test.download_data import download_osf_alaTB
|
|
8
|
+
import os, pickle
|
|
9
|
+
|
|
10
|
+
#class TestFewSM_Lib(unittest.TestCase):
|
|
11
|
+
# def setUp(self):
|
|
12
|
+
# pass
|
|
13
|
+
#
|
|
14
|
+
# def test_sign(self):
|
|
15
|
+
# v = np.array([0] * 3)
|
|
16
|
+
# test = fewsm_lib.test_sign(v)
|
|
17
|
+
# self.assertEqual(test, False)
|
|
18
|
+
# v = np.array([-1, 0, 1])
|
|
19
|
+
# test = fewsm_lib.test_sign(v)
|
|
20
|
+
# self.assertEqual(test, True)
|
|
21
|
+
#
|
|
22
|
+
# def test_metastability(self):
|
|
23
|
+
# T_test = np.random.rand(10,10)
|
|
24
|
+
# meta = fewsm_lib.metastability(T_test)
|
|
25
|
+
# self.assertIsInstance(meta, float)
|
|
26
|
+
# self.assertEqual(meta, np.sum(np.diag(T_test)))
|
|
27
|
+
#
|
|
28
|
+
# def test_metropolis(self):
|
|
29
|
+
# delta = np.random.random()
|
|
30
|
+
# accept = fewsm_lib.metropolis(delta)
|
|
31
|
+
# self.assertIsInstance(accept, bool)
|
|
32
|
+
# delta = -1.
|
|
33
|
+
# accept = fewsm_lib.metropolis(delta)
|
|
34
|
+
# self.assertTrue(accept)
|
|
35
|
+
#
|
|
36
|
+
# def test_beta(self):
|
|
37
|
+
# tests = [
|
|
38
|
+
# {
|
|
39
|
+
# "imc": 2,
|
|
40
|
+
# "mcsasteps": 10,
|
|
41
|
+
# },
|
|
42
|
+
# {
|
|
43
|
+
# "imc":1,
|
|
44
|
+
# "mcsasteps":1
|
|
45
|
+
# }
|
|
46
|
+
# ]
|
|
47
|
+
# for test in tests:
|
|
48
|
+
#
|
|
49
|
+
# beta = fewsm_lib.beta(test["imc"], test["mcsasteps"])
|
|
50
|
+
# self.assertIsInstance(beta, float)
|
|
51
|
+
# def test_split_sign(self):
|
|
52
|
+
# macro = {}
|
|
53
|
+
# for i in range(10):
|
|
54
|
+
# macro[i] = [i * 10 + j for j in range(10)]
|
|
55
|
+
# lvec = np.random.rand(100)
|
|
56
|
+
#
|
|
57
|
+
# new_macro, vals = fewsm_lib.split_sign(macro, lvec)
|
|
58
|
+
# self.assertIsInstance(new_macro, dict)
|
|
59
|
+
# self.assertGreaterEqual(len(new_macro.keys()), len(macro.keys()))
|
|
60
|
+
#
|
|
61
|
+
# def test_split_sigma(self):
|
|
62
|
+
# macro = {}
|
|
63
|
+
# for i in range(10):
|
|
64
|
+
# macro[i] = [i * 10 + j for j in range(10)]
|
|
65
|
+
# lvec = np.random.rand(100)
|
|
66
|
+
#
|
|
67
|
+
# new_macro, vals = fewsm_lib.split_sigma(macro, lvec)
|
|
68
|
+
# self.assertIsInstance(new_macro, dict)
|
|
69
|
+
# self.assertGreaterEqual(len(new_macro.keys()), len(macro.keys()))
|
|
70
|
+
#
|
|
71
|
+
#class TestFewSM(unittest.TestCase):
|
|
72
|
+
#
|
|
73
|
+
# def setUp(self):
|
|
74
|
+
# download_test_data()
|
|
75
|
+
# self.tr = traj.TimeSeries(top='test/data/alaTB.gro', \
|
|
76
|
+
# traj=['test/data/protein_only.xtc'])
|
|
77
|
+
# self.tr.discretize('rama', states=['A', 'E'])
|
|
78
|
+
# self.tr.find_keys()
|
|
79
|
+
# self.msm = msm.SuperMSM([self.tr])
|
|
80
|
+
# self.msm.do_msm(10)
|
|
81
|
+
# self.msm.msms[10].do_trans()
|
|
82
|
+
#
|
|
83
|
+
# def test_attributes(self):
|
|
84
|
+
# self.fewsm = fewsm.FEWSM(parent=self.msm.msms[10])
|
|
85
|
+
# self.assertIsNotNone(self.fewsm.macros)
|
|
86
|
+
# self.assertEqual(len(self.fewsm.macros), 2)
|
|
87
|
+
#
|
|
88
|
+
# def test_map_trajectory(self):
|
|
89
|
+
# self.fewsm = fewsm.FEWSM(parent=self.msm.msms[10])
|
|
90
|
+
# self.fewsm.map_trajectory()
|
|
91
|
+
# self.mapped = self.fewsm.mappedtraj[0]
|
|
92
|
+
# self.assertIsNotNone(self.mapped)
|
|
93
|
+
# self.assertIsInstance(self.mapped, traj.TimeSeries)
|
|
94
|
+
# self.assertTrue(hasattr(self.mapped, 'dt'))
|
|
95
|
+
# self.assertTrue(hasattr(self.mapped, 'distraj'))
|
|
96
|
+
# self.assertEqual(len(set(self.mapped.distraj)), 2)
|
|
97
|
+
# self.assertEqual(sorted(set(self.mapped.distraj)), [0, 1])
|
|
98
|
+
#
|
|
99
|
+
# def test_eigen_group(self):
|
|
100
|
+
# self.fewsm = fewsm.FEWSM(parent=self.msm.msms[10])
|
|
101
|
+
# macros = self.fewsm.eigen_group()
|
|
102
|
+
# print("MACROS! ", macros)
|
|
103
|
+
# self.assertIsInstance(macros, dict)
|