Skip to content
This repository was archived by the owner on Jan 26, 2022. It is now read-only.

Commit 60947e9

Browse files
committed
Merge pull request #276 from rmcgibbo/trim
Fix #252 on master
2 parents bf5fd4a + 074d923 commit 60947e9

File tree

1 file changed

+34
-35
lines changed

1 file changed

+34
-35
lines changed

scripts/CalculateImpliedTimescales.py

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,39 @@
1717
# along with this program; if not, write to the Free Software
1818
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1919

20+
import logging
2021
import numpy as np
21-
2222
from msmbuilder import arglib
2323
from msmbuilder import msm_analysis
24-
25-
import logging
2624
logger = logging.getLogger('msmbuilder.scripts.CalculateImpliedTimescales')
2725

26+
parser = arglib.ArgumentParser(description="""
27+
\nCalculates the implied timescales of a set of assigned data, up to
28+
the argument 'lagtime'. Returns: ImpliedTimescales.dat, a flat file that
29+
contains all the lag times.\n""")
30+
parser.add_argument('assignments', type=str)
31+
parser.add_argument('lagtime', help="""The lagtime range to calculate.
32+
Pass two ints as X,Y with NO WHITESPACE, where X is the lowest
33+
timescale you want and Y is the biggest. EG: '-l 5,50'.""")
34+
parser.add_argument('output', help="""The name of the implied
35+
timescales data file (use .dat extension)""", default='ImpliedTimescales.dat')
36+
parser.add_argument('procs', help='''Number of concurrent processes
37+
(cores) to use''', default=1, type=int)
38+
parser.add_argument('eigvals', help="""Number of slowest implied timescales to
39+
retrieve at each lag time. Note: an n-state model will have n-1
40+
implied timescales.""", default=10, type=int)
41+
parser.add_argument('interval', help="""Interval between times (intervals)
42+
to calculate lagtimes for""", default=1, type=int)
43+
parser.add_argument('symmetrize', help="""Method by which to estimate a
44+
symmetric counts matrix. Symmetrization ensures reversibility, but may skew
45+
dynamics. We recommend maximum likelihood estimation (MLE) when tractable,
46+
else try Transpose. It is strongly recommended you read the documentation
47+
surrounding this choice.""", default='MLE',
48+
choices=['MLE', 'Transpose', 'None'])
49+
parser.add_argument('notrim', help="""Do not apply an ergodic trim.
50+
By default, we keep only the largest observed ergodic subset of the data.
51+
supplied, keeps everything.""", action='store_true')
52+
2853

2954
def run(MinLagtime, MaxLagtime, Interval, NumEigen, AssignmentsFn, trimming,
3055
symmetrize, nProc):
@@ -34,40 +59,13 @@ def run(MinLagtime, MaxLagtime, Interval, NumEigen, AssignmentsFn, trimming,
3459
logger.info("Building MSMs at the following lag times: %s", lagTimes)
3560

3661
# Get the implied timescales (eigenvalues)
37-
impTimes = msm_analysis.get_implied_timescales(AssignmentsFn, lagTimes,
38-
n_implied_times=NumEigen, sliding_window=True, trimming=trimming,
39-
symmetrize=symmetrize, n_procs=nProc)
40-
62+
impTimes = msm_analysis.get_implied_timescales(
63+
AssignmentsFn, lagTimes, n_implied_times=NumEigen, sliding_window=True,
64+
trimming=trimming, symmetrize=symmetrize, n_procs=nProc)
4165
return impTimes
4266

4367

4468
if __name__ == "__main__":
45-
parser = arglib.ArgumentParser(description="""
46-
\nCalculates the implied timescales of a set of assigned data, up to
47-
the argument 'lagtime'. Returns: ImpliedTimescales.dat, a flat file that
48-
contains all the lag times.\n""")
49-
parser.add_argument('assignments', type=str)
50-
parser.add_argument('lagtime', help="""The lagtime range to calculate.
51-
Pass two ints as X,Y with NO WHITESPACE, where X is the lowest
52-
timescale you want and Y is the biggest. EG: '-l 5,50'.""")
53-
parser.add_argument('output', help="""The name of the implied
54-
timescales data file (use .dat extension)""", default='ImpliedTimescales.dat')
55-
parser.add_argument('procs', help='''Number of concurrent processes
56-
(cores) to use''', default=1, type=int)
57-
parser.add_argument('eigvals', help="""Number of slowest implied timescales to
58-
retrieve at each lag time. Note: an n-state model will have n-1
59-
implied timescales.""", default=10, type=int)
60-
parser.add_argument('interval', help="""Interval between times (intervals)
61-
to calculate lagtimes for""", default=1, type=int)
62-
parser.add_argument('symmetrize', help="""Method by which to estimate a
63-
symmetric counts matrix. Symmetrization ensures reversibility, but may skew
64-
dynamics. We recommend maximum likelihood estimation (MLE) when tractable,
65-
else try Transpose. It is strongly recommended you read the documentation
66-
surrounding this choice.""", default='MLE',
67-
choices=['MLE', 'Transpose', 'None'])
68-
parser.add_argument('trim', help="""Whether or not to apply an ergodic trim.
69-
If true, keeps only the largest observed ergodic subset of the data, if
70-
false, keeps everything. Default: True.""", default=True, type=bool)
7169
args = parser.parse_args()
7270
arglib.die_if_path_exists(args.output)
7371

@@ -79,7 +77,8 @@ def run(MinLagtime, MaxLagtime, Interval, NumEigen, AssignmentsFn, trimming,
7977
if args.symmetrize in ["None", "none", None]:
8078
args.symmetrize = None
8179

82-
impTimes = run(MinLagtime, MaxLagtime, args.interval, args.eigvals, args.assignments,
83-
args.trim, args.symmetrize, args.procs)
80+
impTimes = run(
81+
MinLagtime, MaxLagtime, args.interval, args.eigvals, args.assignments,
82+
(not args.notrim), args.symmetrize, args.procs)
8483
np.savetxt(args.output, impTimes)
8584
logger.info("Saved output to %s", args.output)

0 commit comments

Comments
 (0)