Original Markov chain

L=4;
n=2;
S=Permutations[Join[ConstantArray[0,L-n],Range[n]]];
nonz=Table[RotateLeft[Range[n],i],{i,0,n-1}];
T={};
For[i=1,i≤Length[S],i++,
If[MemberQ[nonz,Select[S[[i]],#>0&]],
AppendTo[T,S[[i]]];
];
];
T
M = ConstantArray[0,{Length[T],Length[T]}];
For[i=1,i≤Length[T],i++,
For[j=1,j≤L-1,j++,
If[T[[i,j]]>0&&T[[i,j+1]]==0,
(lis=Join[T[[i,;;j-1]],{T[[i,j+1]],T[[i,j]]},T[[i,j+2;;]]];
M[[Position[T,lis][[1,1]],i]]+=p[T[[i,j]]];)
];
If[T[[i,j]]==0&&T[[i,j+1]]>0,
(lis=Join[T[[i,;;j-1]],{T[[i,j+1]],T[[i,j]]},T[[i,j+2;;]]];
M[[Position[T,lis][[1,1]],i]]+=q[T[[i,j+1]]];)
];
];
If[T[[i,1]]>0&&T[[i,L]]==0,
(lis=Join[{0},T[[i,2;;L-1]],{T[[i,1]]}];
M[[Position[T,lis][[1,1]],i]]+=q[T[[i,1]]];)
];
If[T[[i,L]]>0&&T[[i,1]]==0,
(lis=Join[{T[[i,L]]},T[[i,2;;L-1]],{0}];
M[[Position[T,lis][[1,1]],i]]+=p[T[[i,L]]];)
];
];
For[i=1,i≤Length[T],i++,
M[[i,i]]=-Sum[If[j==i,0,M[[j,i]]],{j,Length[T]}];
]
M//MatrixForm

ss=NullSpace[M][[1]];
ss=Table[Factor[((ss[[i]])/(Total[ss]))],{i,Length[ss]}]

Enriched Markov chain on words

L=4;
n=2;
S=Permutations[Flatten[Join[Table[ConstantArray[-i,L-n],{i,n}],Range[n]]],{L}];
For[i=1,i≤n,i++,
S=Select[S,Count[#,i]==1&];
];
nonz=Table[RotateLeft[Range[n],i],{i,0,n-1}];
T={};
For[i=1,i≤Length[S],i++,
If[MemberQ[nonz,Select[S[[i]],#>0&]],
AppendTo[T,S[[i]]];
];
];
T
M = ConstantArray[0,{Length[T],Length[T]}];
For[i=1,i≤Length[T],i++,
For[j=1,j≤L-1,j++,
If[T[[i,j]]>0&&T[[i,j+1]]<0&&T[[i,j]]≠-T[[i,j+1]],
(lis=Join[T[[i,;;j-1]],{T[[i,j+1]],T[[i,j]]},T[[i,j+2;;]]];
M[[Position[T,lis][[1,1]],i]]+=p[T[[i,j]]];)
];

If[T[[i,j]]>0&&T[[i,j]]==-T[[i,j+1]],
(pos=Position[T[[i]],If[T[[i,j]]>1,T[[i,j]]-1,n]][[1,1]];
If[pos<j,
lis=Join[T[[i,;;pos]],{If[T[[i,j+1]]<-1,T[[i,j+1]]+1,-n]},T[[i,pos+1;;j]],T[[i,j+2;;]]],
If[pos<L,
lis=Join[{T[[i,L]]},T[[i,;;j]],T[[i,j+2;;pos]],{If[T[[i,j+1]]<-1,T[[i,j+1]]+1,-n]},T[[i,pos+1;;L-1]]],
lis=Join[{If[T[[i,j+1]]<-1,T[[i,j+1]]+1,-n]},T[[i,;;j]],T[[i,j+2;;]]]
];
];
M[[Position[T,lis][[1,1]],i]]+=p[T[[i,j]]];)
];

If[T[[i,j]]<0&&T[[i,j+1]]>0&&T[[i,j]]≠-T[[i,j+1]],
(lis=Join[T[[i,;;j-1]],{T[[i,j+1]],T[[i,j]]},T[[i,j+2;;]]];
M[[Position[T,lis][[1,1]],i]]+=q[T[[i,j+1]]];)
];

If[T[[i,j]]<0&&T[[i,j]]==-T[[i,j+1]],
(pos=Position[T[[i]],If[T[[i,j+1]]<n,T[[i,j+1]]+1,1]][[1,1]];
If[pos>j+1,
lis=Join[T[[i,;;j-1]],T[[i,j+1;;pos-1]],{If[T[[i,j]]>-n,T[[i,j]]-1,-1]},T[[i,pos;;]]],
If[pos>1,
lis=Join[T[[i,2;;pos-1]],{If[T[[i,j]]>-n,T[[i,j]]-1,-1]},T[[i,pos;;j-1]],T[[i,j+1;;]],{T[[i,1]]}],
lis=Join[T[[i,;;j-1]],T[[i,j+1;;]],{If[T[[i,j]]>-n,T[[i,j]]-1,-1]}]
];
];
M[[Position[T,lis][[1,1]],i]]+=q[T[[i,j+1]]];)
];
];

If[T[[i,1]]>0&&T[[i,L]]<0&&T[[i,1]]≠-T[[i,L]],
(lis=Join[{T[[i,L]]},T[[i,2;;L-1]],{T[[i,1]]}];
M[[Position[T,lis][[1,1]],i]]+=q[T[[i,1]]];)
];

If[T[[i,1]]>0&&T[[i,L]]==-T[[i,1]],
(pos=Position[T[[i]],If[T[[i,1]]<n,T[[i,1]]+1,1]][[1,1]];
lis=Join[T[[i,2;;pos-1]],{If[T[[i,L]]>-n,T[[i,L]]-1,-1]},T[[i,pos;;L-1]],{T[[i,1]]}];
M[[Position[T,lis][[1,1]],i]]+=q[T[[i,1]]];)
];


If[T[[i,L]]>0&&T[[i,1]]<0&&T[[i,1]]≠-T[[i,L]],
(lis=Join[{T[[i,L]]},T[[i,2;;L-1]],{T[[i,1]]}];
M[[Position[T,lis][[1,1]],i]]+=p[T[[i,L]]];)
];
If[T[[i,L]]>0&&T[[i,1]]==-T[[i,L]],
(pos=Position[T[[i]],If[T[[i,L]]>1,T[[i,L]]-1,n]][[1,1]];
lis=Join[{T[[i,L]]},T[[i,2;;pos]],{If[T[[i,1]]<-1,T[[i,1]]+1,-n]},T[[i,pos+1;;L-1]]];
M[[Position[T,lis][[1,1]],i]]+=p[T[[i,L]]];)
];
];
For[i=1,i≤Length[T],i++,
M[[i,i]]=-Sum[If[j==i,0,M[[j,i]]],{j,Length[T]}];
]
M//MatrixForm

ss=NullSpace[M/.Join[Table[p[i]->(p^i),{i,3}],Table[q[i]->i,{i,3}]]][[1]];
ss=Table[Factor[((ss[[i]])/(Total[ss]))],{i,Length[ss]}]

vec=((p[2])^2){1,q0/p1, q0/p1, q0^2/p1^2, q1/p1, (q0*q1)/(p1^2), p0/p1, p0*q0/p1^2, q1^2/p1^2, (p0*q1)/(p1^2), p0*q1/p1^2, p0^2/p1^2}/.{q0->q[1],q1->q[2],p0->p[1],p1->p[2]}

configs={{1,-1,-1,2},{1,-2,-1,2},{1,-1,-2,2},{1,-2,-2,2},{1,-1,2,-1},{1,-2,2,-1},{1,-1,2,-2},{1,-2,2,-2},{1,2,-1,-1},{1,2,-2,-1},{1,2,-1,-2},{1,2,-2,-2}}

V=ConstantArray[0,Length[M]];
For[i=1,i≤Length[T],i++,
For[k=1,k≤Length[configs],k++,
For[j=0,j<L,j++,
If[RotateLeft[T[[i]],j]==configs[[k]],
V[[i]]+=vec[[k]];
];
];
];
];
V

Simplify[M.V]

Two dimensional process

Programs

Clear[W,W2,w,configs,wtconfig,torusconfigs,wttorusconfig,Z,dens2]
W[n_,k_,i_]:=If[i≤k,Product[q[j],{j,k-i+1,k}],Product[q[j],{j,1,k}]Product[q[n+j],{j,k-i+1,0}]]((Product[p[j],{j,1,n}])/(If[i≤k-1,Product[p[j],{j,k-i,k}],Product[p[j],{j,1,k}]Product[p[j+n],{j,k-i,0}]]))
configs[L_,n_]:=Flatten[Map[Permutations[#]&,Map[PadRight[#,n]&,IntegerPartitions[L-n,n]]],1]
g[n_,k_]:=Sum[W[n,k,i],{i,0,n-1}]
wtconfig[w_]:=Product[((g[Length[w],k])^(w[[k]])),{k,Length[w]}]

torusconfigs[L_,n_]:=Module[{S},
S=Permutations[Join[{1},ConstantArray[2,L-n],ConstantArray[0,L-1]],{L}];
S=Select[S,Count[#,1]==1&];
S=Tuples[S,n];
S=Select[S,Count[Flatten[#],2]==L-n&];
S=Select[S,Sort[Position[#,0][[All,2]]]==Sort[Flatten[ConstantArray[Range[L],n-1]]]&];
S=Select[S,#[[1,1]]==1&];
S=Select[S,Sort[Position[#,1][[All,2]]]==Position[#,1][[All,2]]&];
Return[S];
]
wttorusconfig[T_]:=Module[{pos1,pos2,wt,i,k},
pos1=Position[T,1][[All,2]];
pos2=Position[T,2];
wt=1;
For[i=1,i≤Length[pos2],i++,
k=Length[Select[pos1,#<pos2[[i,2]]&]];
If[pos2[[i,1]]≤k,
wt*=Product[q[j],{j,pos2[[i,1]]+1,k}]Product[p[j],{j,k+1,Length[T]}]Product[p[j],{j,1,pos2[[i,1]]-1}],
wt*=Product[p[j],{j,k+1,pos2[[i,1]]-1}]Product[q[j],{j,pos2[[i,1]]+1,Length[T]}]Product[q[j],{j,1,k}]
];
];
Return[wt]
]
w[n_,k_,i_]:=If[i≤k,Product[q[j],{j,i+1,k}]Product[p[j],{j,k+1,n}]Product[p[j],{j,1,i-1}],Product[p[j],{j,k+1,i-1}]Product[q[j],{j,i+1,n}]Product[q[j],{j,1,k}]]
W2[n_,k_]:=Sum[w[n,k,i],{i,1,n}]
Z[L_,n_]:=Sum[wtconfig[w],{w,configs[L,n]}]
dens2[L_,n_,k_]:=Sum[w[n,i,k]((W2[n,i])^(j-1))Z[L-j,n],{i,n},{j,1,L-n}]

Examples

Table[Collect[Z[n,2],p[1]],{n,2,4}]//MatrixForm

Map[{MatrixForm[#],wttorusconfig[#]}&,torusconfigs[5,3]]

Map[MatrixForm,Select[torusconfigs[5,3],(wttorusconfig[#]/.q[1]->0)=!=0&]]

Partition function

Table[Factor[Z[L,n]/.Table[p[i]->p,{i,n}]/.Table[q[i]->q,{i,n}]],{n,1,5},{L,n,n+5}]//MatrixForm

Table[Factor[Z[L,n]/.Table[q[i]->p[i],{i,n}]],{n,1,5},{L,n,n+3}]//MatrixForm

Table[Factor[Z[L,n]/.Table[q[i]->0,{i,n}]],{n,1,5},{L,n,n+5}]//MatrixForm

Current of 1s

Factor[Sum[If[Position[T,1][[2,2]]==2,0,p[1]wttorusconfig[T]],{T,torusconfigs[5,3]}]-Sum[If[Position[T,1][[3,2]]==5,0,q[1]wttorusconfig[T]],{T,torusconfigs[5,3]}]]

Expand[Z[4,3]]

Current of 2s vertically

Factor[Sum[If[MemberQ[Position[T,2],{2,i}]&&MemberQ[Position[T,1],{2,i-1}],p[2]wttorusconfig[T],0],{T,torusconfigs[5,3]},{i,2,5}]]
Factor[Sum[If[MemberQ[Position[T,2],{1,5}],q[1]wttorusconfig[T],0],{T,torusconfigs[5,3]}]]

Factor[%%-%]

Expand[Z[4,3]]

Factor[%%/%]