# calcstate

Calculate states based on given data sets and criteria.

`calcstate {state <ID>,<dataset>,<min>,<max>} [out <state v time file>] [name <setname>] [curveout <curve file>] [stateout <states file>] [transout <transitions file>]`

`state <ID>,<dataset>,<min>,<max>` Define a state according to given data set and criteria. Multiple states can be given.
`<ID>` ID to give each state index (e.g. 1, 2, etc). State indices start at 0. -1 means “undefined state”.
`<dataset>` Data set to use.
`<min>,<max>` Frames with data set value above <min> and below <max> will be assigned <ID>.
`[out <state v time file>]` File to write state index vs frame to.
`[name <setname>]` Data set name.
`[curveout <curve file>]` File to write state lifetime and transition curves to.
`[stateout <states file>]` File to write state lifetime data to.
`[transout <transitions file>]` File to write state transition data to.

DataSets Created:
`<setname>` State index vs frame.
`<setname>[sCurve]:X` State curves; lifetime curve for transitions from given state to any other state.
`<setname>[tCurve]:X` Transition curves; lifetime curve for transitions from given state to other specific state.

Data for the specified data set(s) that matches the given criteria will be assigned a state index. State indices start from 0 and match the order in which state keywords were given. For example, the following input:

```parm DPDP.parm7
trajin DPDP.nc
distance d1 :19@O :12@N
angle a1 :19@O :12@H :12@N
calcstate state D,d1,3.0,4.0 state A,a1,100,120 out state.dat curveout curve.agr \
stateout States.dat transout States.dat name d1_a1
run```

Defines two states. State index 0 is defined as a state named “D” based on the distance from ’:19@O’ to ’:12@N’ being between 3 and 4 Angstroms. State index 1 is defined as a state named “A” based on the angle between ’:19@O’, ’:12@H’, and ’:12@N’ being between 100 and 120 degrees. The output in state.dat might look like:

```#Frame d1_a1
1 -1
2 0
3 0
4 0
5 -1
6 1
7 -1
8 -1
9 0
10 -1```

where the values in column d1_a1 refer to state index: -1 is undefined, 0 is state “D”, and 1 is state “A”.

Lifetime curves are calculated for transitions from each state to any other state (aspect [sCurve]) and each state to each other state (aspect [tCurve]). In this case there will be 3 sCurves and 4 tCurves:

```d1_a1[sCurve]:0 "Undefined" (double), size is 10
d1_a1[sCurve]:1 "D" (double), size is 3
d1_a1[sCurve]:2 "A" (double), size is 1
d1_a1[tCurve]:0 "Undefined->D" (double), size is 10
d1_a1[tCurve]:1 "D->Undefined" (double), size is 3
d1_a1[tCurve]:2 "Undefined->A" (double), size is 1
d1_a1[tCurve]:3 "A->Undefined" (double), size is 1```

Lifetime analysis from each state to any other state is directed to the file specified by stateout and has format:

`#Index    N    Average    Max    State`

Where #Index is the state index, N is the number of lifetimes in that state, Average is the average lifetime while in that state (in frames), Max is the maximum lifetime while in that state (in frames) and State is the name of the state.

Finally, lifetime analysis of transitions from each state to each other state is directory to the file specified by transout and has format:

`#N    Average    Max    Transition`

Where #N is the number of transitions, Average is the average lifetime (in frames) in the first state before transitioning to the second state, Max is the max lifetime (in frames) before transitioning to the second state, and Transition is the name of the transition.