trans_per_state
- mdtools.dtrj.trans_per_state(dtrj, **kwargs)[source]
Count the number of transitions leading into or out of a state.
- Parameters:
dtrj (
array_like
) – Array containing the discrete trajectory.kwargs (
dict
, optional) – Additional keyword arguments to parse tomdtools.dtrj.locate_trans()
. See there for possible choices. This function sets the following default values:pin = "end"
trans_type = None
min_state = None
max_state = None
- Returns:
hist_start (
numpy.ndarray
ortuple
) – 1d array or tuple of 1d arrays (if trans_type is'both'
or an iterable of ints). The histogram counts how many state transitions started from a given state, i.e. how many transitions led out of a given state. Is not returned if pin is"end"
.hist_end (
numpy.ndarray
ortuple
) – 1d array or tuple of 1d arrays (if trans_type is'both'
or an iterable of ints). The histogram counts how many state transitions ended in a given state, i.e. how many transitions led into a given state. Is not returned if pin is"start"
.
See also
mdtools.dtrj.trans_per_state_vs_time()
Count the number of transitions leading into or out of a state for each frame in a discrete trajectory
mdtools.dtrj.locate_trans()
Locate the frames of state transitions inside a discrete trajectory
Notes
The histograms contain the counts for all states ranging from the minimum to the maximum state in dtrj in whole numbers. This means, the states corresponding to the counts in hist_start and hist_end are given by
numpy.arange(np.min(dtrj), np.max(dtrj)+1)
.Examples
>>> dtrj = np.array([[1, 2, 2, 3, 3, 3], ... [2, 2, 3, 3, 3, 1], ... [3, 3, 3, 1, 2, 2], ... [1, 3, 3, 3, 2, 2]]) >>> hist_start, hist_end = mdt.dtrj.trans_per_state( ... dtrj, pin="both" ... ) >>> # Number of transitions starting from the 1st, 2nd or 3rd state >>> hist_start array([3, 2, 3]) >>> # Number of transitions ending in the 1st, 2nd or 3rd state >>> hist_end array([2, 3, 3]) >>> hist_start_type, hist_end_type = mdt.dtrj.trans_per_state( ... dtrj, pin="both", trans_type="both" ... ) >>> # Number of transitions starting from the 1st, 2nd or 3rd state and ending in an >>> # * higher state (hist_start_type[0]) >>> # * lower state (hist_start_type[1]) >>> hist_start_type (array([3, 2, 0]), array([0, 0, 3])) >>> np.array_equal(np.sum(hist_start_type, axis=0), hist_start) True >>> # Number of transitions ending in the 1st, 2nd or 3rd state and starting from an >>> # * lower state (hist_end_type[0]) >>> # * higher state (hist_end_type[1]) >>> hist_end_type (array([0, 2, 3]), array([2, 1, 0])) >>> np.array_equal(np.sum(hist_end_type, axis=0), hist_end) True >>> # Number of transitions starting from the 1st, 2nd or 3rd state where the difference >>> # between the final and initial state is plus or minus one >>> hist_plus_one, hist_minus_one = mdt.dtrj.trans_per_state( ... dtrj, pin="start", trans_type=(1, -1) ... ) >>> hist_plus_one array([2, 2, 0]) >>> hist_minus_one array([0, 0, 1]) >>> hist_start_wrap, hist_end_wrap = mdt.dtrj.trans_per_state( ... dtrj, pin="both", wrap=True ... ) >>> hist_start_wrap array([4, 4, 4]) >>> hist_end_wrap array([4, 4, 4]) >>> hist_start_type_wrap, hist_end_type_wrap = mdt.dtrj.trans_per_state( ... dtrj, pin="both", trans_type="both", wrap=True ... ) >>> hist_start_type_wrap (array([4, 3, 0]), array([0, 1, 4])) >>> np.array_equal( ... np.sum(hist_start_type_wrap, axis=0), hist_start_wrap ... ) True >>> hist_end_type_wrap (array([0, 3, 4]), array([4, 1, 0])) >>> np.array_equal( ... np.sum(hist_end_type_wrap, axis=0), hist_end_wrap ... ) True >>> hist_start_tfft, hist_end_tfft = mdt.dtrj.trans_per_state( ... dtrj, pin="both", tfft=True ... ) >>> hist_start_tfft array([3, 2, 3]) >>> hist_end_tfft array([4, 4, 4]) >>> hist_start_tlft, hist_end_tlft = mdt.dtrj.trans_per_state( ... dtrj, pin="both", tlft=True ... ) >>> hist_start_tlft array([4, 4, 4]) >>> hist_end_tlft array([2, 3, 3]) >>> hist_start_tfft_tlft, hist_end_tfft_tlft = mdt.dtrj.trans_per_state( ... dtrj, pin="both", tfft=True, tlft=True ... ) >>> hist_start_tfft_tlft array([4, 4, 4]) >>> hist_end_tfft_tlft array([4, 4, 4])
Interpret first dimension as frames and second dimension as compounds:
>>> hist_start, hist_end = mdt.dtrj.trans_per_state( ... dtrj, axis=0, pin="both" ... ) >>> hist_start array([3, 3, 4]) >>> hist_end array([3, 3, 4]) >>> hist_start_type, hist_end_type = mdt.dtrj.trans_per_state( ... dtrj, axis=0, pin="both", trans_type="both" ... ) >>> hist_start_type (array([3, 3, 0]), array([0, 0, 4])) >>> np.array_equal(np.sum(hist_start_type, axis=0), hist_start) True >>> hist_end_type (array([0, 2, 4]), array([3, 1, 0])) >>> np.array_equal(np.sum(hist_end_type, axis=0), hist_end) True >>> hist_plus_one, hist_minus_one = mdt.dtrj.trans_per_state( ... dtrj, axis=0, pin="start", trans_type=(1, -1) ... ) >>> hist_plus_one array([2, 3, 0]) >>> hist_minus_one array([0, 0, 1]) >>> hist_start_wrap, hist_end_wrap = mdt.dtrj.trans_per_state( ... dtrj, axis=0, pin="both", wrap=True ... ) >>> hist_start_wrap array([3, 5, 6]) >>> hist_end_wrap array([3, 5, 6]) >>> hist_start_type_wrap, hist_end_type_wrap = mdt.dtrj.trans_per_state( ... dtrj, axis=0, pin="both", trans_type="both", wrap=True ... ) >>> hist_start_type_wrap (array([3, 5, 0]), array([0, 0, 6])) >>> np.array_equal( ... np.sum(hist_start_type_wrap, axis=0), hist_start_wrap ... ) True >>> hist_end_type_wrap (array([0, 2, 6]), array([3, 3, 0])) >>> np.array_equal( ... np.sum(hist_end_type_wrap, axis=0), hist_end_wrap ... ) True >>> hist_start_tfft, hist_end_tfft = mdt.dtrj.trans_per_state( ... dtrj, axis=0, pin="both", tfft=True ... ) >>> hist_start_tfft array([3, 3, 4]) >>> hist_end_tfft array([4, 5, 7]) >>> hist_start_tlft, hist_end_tlft = mdt.dtrj.trans_per_state( ... dtrj, axis=0, pin="both", tlft=True ... ) >>> hist_start_tlft array([4, 5, 7]) >>> hist_end_tlft array([3, 3, 4]) >>> hist_start_tfft_tlft, hist_end_tfft_tlft = mdt.dtrj.trans_per_state( ... dtrj, axis=0, pin="both", tfft=True, tlft=True ... ) >>> hist_start_tfft_tlft array([4, 5, 7]) >>> hist_end_tfft_tlft array([4, 5, 7])