diporder does not compute the right quantities
The diporder code does not calculate the quantities it advertises to compute. Two of them are wrong:
-
E[cos(theta)] does not compute the actual expectation value of cosine theta. The diporder code right now calculates the average value of cos(theta) for every bin in every frame. In the end all those values are averaged over the number of frames. The problem arises in the interface: In some frames there are no molecules in the bins thus it adds 0 as an average orientation but still counts the frame in the end. Basically right now cos(theta) gives the actual cos(theta) multiplied with the probability that there is at least one molecule in a given bin. In the attached pdf this point is made clear. In the associated merge request i propose a code change which adds up all the cos(theta) values over the whole trajectory and counts the number of molecules per bin as well. The expectation value is computed in the end by a single division of the sum of cosine values by number of molecules per bin.
-
E[cos^2(theta)] has the same problem but there is a second error: Not the individual cosine values are squared but the sum of cosines is squared each frame. Since square of sum =/= sum of squares this is wrong.
Find attached a comparison of the output of diporder against the output of my proposed code. I used a simple air-water interface as an example.