2

Quick contextualisation, I am trying to follow the orientation of a molecule (represented as a rigid object) in respect to the z axis. The molecule is basically shaped as an hexagon, so what i thought was to define 2 vectors: $\vec u$ running from one vertex to the opposite one of the hexagon and a $\vec v $, orthogonal to $\vec u$ . What i do then is simply measuring their angle with the z axis, which i call respectively $\theta$ and $\psi$ and counting the number of occurence of every couple ( $\theta$ , $\psi$ ). With that i fill a 180x180 matrix with the number of occurence of every couple, then divide by the total number of observations. When i plot this matrix i get a typically shaped diamond plot with the probability on the edges showing higher values due to the correlation of the two vectors and the geometrical density of the states (and with this i mean the that the angle of a vector with a fixed axes has a non uniform density distribution).

The specific thing that i'm looking for is to correct for this "geometrical" effect so that when the molecule is freely rotating in respect to the z axis then the 3D plot of the angle probability looks "flat" inside the diamond, or if you want "even".

To better explain, if i was to measure just the probability of occurence of one angle, say $\theta$, i would divide every probability value of $\theta$ by the $sin(\theta)$ to "correct" for the geometrical effect, and than the plot would be evened out (although ofc at 0 you have sin(0)=0 which creates a problem which is still solvable by binning). But if i have two angles i guess a conditional probability is necessary to normalize my distribution since $\theta$ and $\psi$ are not independent, and i can't get my head around what it should be.

Can anyone help by any chance? I attach an image of the angle map that i get and that i would want to flat out:

Edit: After correction i get the map flattened as wanted. The peaks i think are due to the machine calculation of the radicand which is not perfect.

on x and y, the angles $\theta,\psi$, on z you have the probability

 flattened map after correction

1 Answers1

2

Here's a new answer, based on the clarifications in the comments below.

You clarified that what you're interested in isn't really normalization, but rather a reference density that would be expected for a free molecule so that you can divide this out in order to visualize effects that cause deviations from this free-molecule density.

Let's regard the molecule as fixed and the reference axis for $\theta$ and $\psi$ as freely rotating; that is, let's view the angles $\theta$ and $\psi$ as the angles that two fixed orthogonal vectors form with a uniformly random direction. Let the fixed $x$ and $y$ axes point along the two orthogonal vectors. A uniformly random unit direction vector has independent uniform distributions of $z$ over $[-1,1]$ and of $\phi$ (the angle about the $z$ axis) over $[0,2\pi]$. (Here the $z$ axis is not the random reference axis, but the fixed coordinate axis orthogonal to the $x$ and $y$ axes.) The transformation from $z,\phi$ to $x,y$ is

$$ x=\sqrt{1-z^2}\cos\phi\;,\\ y=\sqrt{1-z^2}\sin\phi\;. $$

Thus

\begin{eqnarray*} \frac{\partial(x,y)}{\partial(z,\phi)} &=&\left|\matrix{\frac{\partial x}{\partial z}&\frac{\partial x}{\partial\phi}\\\frac{\partial y}{\partial z}&\frac{\partial y}{\partial\phi}}\right| \\ &=&\left|\matrix{\frac z{\sqrt{1-z^2}}\cos\phi&-\sqrt{1-z^2}\sin\phi\\\frac z{\sqrt{1-z^2}}\sin\phi&\sqrt{1-z^2}\cos\phi}\right| \\ &=& z \\ &=& \sqrt{1-x^2-y^2}\;. \end{eqnarray*}

The further transform according to $x=\cos\theta$ and $y=\cos\psi$ has Jacobian

$$ \frac{\partial(x,y)}{\partial(\theta,\psi)}=\sin\theta\sin\psi\;, $$

so in all we have

$$ \frac{\partial(z,\phi)}{\partial(\theta,\psi)}=\frac{\sin\theta\sin\psi}{\sqrt{1-\cos^2\theta-\cos^2\psi}}\;. $$

This is the factor you need to divide by, since the density for $z$ and $\phi$ is flat (as these variables are independently uniformly distributed), and the densities are releated by

$$ f_{z,\phi}(z,\phi)\mathrm dz\mathrm d\phi=f_{\theta,\psi}(\theta,\psi)\mathrm d\theta\mathrm d\psi $$

and thus

$$ f_{\theta,\psi}(\theta,\psi)=\frac{\partial(z,\phi)}{\partial(\theta,\psi)}f_{z,\phi}(z,\phi)\propto\frac{\partial(z,\phi)}{\partial(\theta,\psi)}\;. $$

Here $\theta$ and $\psi$ are limited to values for which the radicand in the denominator is non-negative, that is, to the diamond

$$ \left|\,\theta-\frac\pi2\right|+\left|\,\psi-\frac\pi2\right|\le\frac\pi2\;. $$

This result fits with your image. It's restricted to the diamond; it shows roughly a $\sin\theta\sin\psi$ behaviour along the boundary; and the divergence at the boundary (mitigated by your binning procedure) is recognizable.

joriki
  • 238,052
  • Sorry, i forgot to include the part that gives a sense to the "normalization" (not the best word in this case) part. After filling the matrix i'm basically plotting it into a 3D surface, now i can follow the matrix changing in function of some parameters that are not important for the sake of the question, but what i would like to see is the 3D surface becoming "flat" with the variation of these parameters. But as both $\theta$ and $\psi$ have a probability density that is not uniform, if i want to see the distribution actually becoming flat i think i have to kind "correct" for it. – user3458909 Aug 15 '18 at 07:33
  • @user3458909: So does the answer answer your question? (And if not, what's missing?) – joriki Aug 15 '18 at 07:38
  • Sorry i'm definitely not practical when it comes to probabilities, i'm just not getting what do you mean with p(z$\theta$,z$\psi$). Let's call the prob of every $\theta$,$\psi$ that i observe p($\theta$,$\psi$)$_o$, which again is the number of occurence of the couple divided by the total number of observations, and the distribution i want to plot p($\theta$,$\psi$)$_p$. Let's assume now that my molecule is freely rotating, and that in this eventuality i want to see a flat distribution of p($\theta$,$\psi$)$_p$, what would i have to divide my non flat observed p($\theta$,$\psi$)$_o$ by? – user3458909 Aug 15 '18 at 08:35
  • @user3458909: I'm not sure I understand what you mean by "in this eventuality i want to see a flat distribution". If $\theta$ and $\psi$ are defined as in your question, then you don't want to see a flat distribution (since these are angles of orthogonal vectors, which e.g. can't be $0$ at the same time). So I'm not sure how to interpret that hypothetical scenario. It seems to me a better example is if you just observed the angles $\theta$ and $\psi$ of the symmetry axes of two different, independently freely rotating molecules... – joriki Aug 15 '18 at 08:53
  • ... In that case, you'd want $p(\theta,\psi)_p$ to be flat, and you'd expect $p(\theta,\psi)_0$ to be proportional to $\sin\theta\sin\psi$, so you'd divide it by $\sin\theta\sin\psi$ to get something that's flat (but, as you correctly pointed out above, not normalized). – joriki Aug 15 '18 at 08:55
  • @user3458909: Note that you're dividing by zero at $\theta,\psi=0,\pi$, so you might need a more careful treatment of the approximation that you're implicitly making, that the distribution is roughly constant across your $1°$ bins. But depending on what you want to use this for, perhaps it's good enough to just divide the outermost bins by $\sin0.5°$. – joriki Aug 15 '18 at 08:59
  • I'm tracking the "tumbling" of the molecule on a surface (z is the normal to the surface) and basically i have a parameter A for which at low values the tumbling is difficult, and the molecules get locked in one angle (so i'll observe a picked distribution of angles), while at high values of A the molecule will tumble freely (the distribution should be more "flat". With flat i mean "kinda even for every point of the distribution"). The problem is ofc that the distribution is not "even", cause naturally the density of states is not uniform. – user3458909 Aug 15 '18 at 09:20
  • @user3458909: But I wasn't talking about anything related to the density of states. Even if you have a completely free molecule, just rotating classically with equidistribution of energy, you can't get a flat distribution for the angles of two orthogonal vectors on the same molecule. They're correlated simply by virtue of being orthogonal vectors on the same molecule, quite independent of any further physical complications due to tumbling, density of states etc. – joriki Aug 15 '18 at 09:27
  • I want to make it so for illustration purpose, so i can plot a map and instantly see if the molecule is freely tumbling (even distribution without the effect of overpopulation due to states density) or if it has some preferential orientations. Also then i can discriminate the effect of the surface on the molecule from the density of states too. (thank you so much for your time btw :P ) – user3458909 Aug 15 '18 at 09:29
  • Well what i will get will be that some states are not accessible, in the specifical you get a plot that looks like a rhombus in your 3D space (i'll post a figure) but inside the rhombus i supposed that i could get an even distribution. Although i'm not sure. As you can see in the fig (https://ibb.co/ecDtap) the edge of the rhombus are higher than the centre, but that's due to density of states, cause if I divide the either of the single angles occurencies by its sine the distributions comes flat. – user3458909 Aug 15 '18 at 09:38
  • 1
    @user3458909: Ah, I think I finally understood what you want to do :-). You really do want a flat distribution inside the rhombus for the orthogonal freely rotating molecule, not because it's actually flat but because you want to be able see the other effects stand out from a flat reference. (Part of the misunderstanding was that I thought that by "density of states" you were referring to a physical effect, but it seems you meant the geometric effect that you're trying to divide out.) (I studied physics a long time ago, by the way. :-) – joriki Aug 15 '18 at 09:53
  • @user3458909: I'll think about this and will come back to you (need to finish something else first). – joriki Aug 15 '18 at 09:53
  • That's it, i think now we're on the same page! Thank you very much man, take your time =D – user3458909 Aug 15 '18 at 10:00
  • Also, i'm not familiar with this website, should i update the question with everything we discussed? – user3458909 Aug 16 '18 at 05:06
  • @user3458909: Not necessarily with everything we've discussed, but with whatever is necessary/helpful to understand the question. Also I just noticed that you added the image with the rhombus at the top of my answer -- it doesn't belong there; it should be part of your clarifications to the question. – joriki Aug 16 '18 at 05:18
  • @user3458909: OK, I've updated the answer -- I hope this is now the result you were looking for -- feel free to ask if anything remains unclear. – joriki Aug 16 '18 at 22:44
  • I just have a few clarification to ask, but i think that's actually exactly what i was looking for! So if i understood well what you're making so that $\vec u and \vec v$ lay on the x and y axes, then look at a random vector, let's call it$\vec r$, calculate its angle with z ($\phi$) and it's projection on the z axes (z), then from that you obtain the projection on x and y (which would be on $\vec u,\vec v$) and transform it to $\theta,\phi$. So, sorry to be so dull but could you explain why:... – user3458909 Aug 17 '18 at 03:49
  • ... a) Why is that $\vec r$ it has a uniform distribution of z and $\phi$ ? Wouldn't it have the same problem that $\theta$ and $\psi$ presented with the z axis? b) Could you just provide the geometrical "relations" that you used to derive this or their name so i can google them? I mean like why is that $ x=\sqrt{1-z^2} \cos \phi$ . I know it can be a pain, but my geometry background is really bad and i really want to understand this properly :/

    Also, i love you and if you gimme your email and your bank account i'll buy you a beer =P

    – user3458909 Aug 17 '18 at 03:55
  • 1
    @user3458909: a) No; it's a nice feature of a sphere in three dimensions that it has equal surface area in slices of equal height; see e.g. here and here. More generally, in $n$ dimensions a slice of a hypersphere of height $\mathrm dz$ has surface proportional to $\sin^{n-2}\theta\frac{\mathrm dz}{\sin\theta}=\sin^{n-3}\theta\mathrm dz$, and it just so happens that the dependence on $\theta$ vanishes for $n=3$. – joriki Aug 17 '18 at 04:22
  • 1
    @user3458909: b) I think the best thing to search for here is "spherical coordinates" (e.g. at Wikipedia). If $x=\sin\theta\cos\phi$, $y=\sin\theta\sin\phi$ and $z=\cos\theta$, then $\sin\theta=\sqrt{1-\cos^2\theta}=\sqrt{1-z^2}$ and thus $x=\sqrt{1-z^2}\cos\phi$. Also, unfortunately I don't drink beer :-) But thanks anyway! – joriki Aug 17 '18 at 04:22
  • @user3458909: I just noticed that you write above "its angle with $z$ ($\phi$)". That's not what $\phi$ is. I described it as "the angle about the $z$ axis". This is not the angle formed with the $z$ axis, but the angle in the $x$-$y$-plane. If you describe the vector's projection onto the $x$-$y$-plane using polar coordinates, $\phi$ would be the polar angle. – joriki Aug 17 '18 at 04:30
  • 1
    @user3458909: Further to a): This is actually exactly why you'd divide by $\sin\theta$ if you'd look only at the angle a single vector forms with the $z$ axis: $z=\cos\theta$ is uniformly distributed, and the Jacobian $\frac{\mathrm dz}{\mathrm d\theta}$ is $\sin\theta$, so if you take the density for $\theta$, it becomes flat if you divide it by $\sin\theta$, since you thereby transform it into the uniform density for $z$. – joriki Aug 17 '18 at 04:34
  • Hey, back from the dead. So i had a look on the spherical coordinates, i was confused cause i guess my $\theta$ is another way the polar angle is expressed :) I think i kinda understood now, so a few things just to check: a)When you said "$\phi$ would be the polar angle" did you mean the azimuth? As i understand you are having $\phi$ be the azimuth, and express the polar angle as z. b)More onto your last message, cause i thought of the thing graphically more than analitically. If i have a single angle $z=\cos\theta$ i thought that it was the density of z that was not uniform.... – user3458909 Aug 20 '18 at 06:48
  • @user3458909: a) Sorry, the "polar angle" thing was unnecessarily confusing. I was talking about the projection onto the $x$-$y$-plane, and in polar coordinates in the plane the terms "polar angle" and "azimuth" refer to the same thing. You're right that in the spherical coordinates $\phi$ is the azimuth, not the polar angle. b) I'm not sure what to say about that -- you thought so, but you were wrong :-). – joriki Aug 20 '18 at 06:54
  • ...While you seem to imply that it's the density of $\theta$, which now that i think has a lot of sense. In the specific what i thought is "i will find more values of z with a certain values than others, cause in 3D it is more likely for $\cos\theta$ to assume certain values, so i'll have to divide by the opposite of how it varies". So you're saying basically my $z=\cos\theta$ is not distributed uniformly cause $\theta$ is not, and then, correct me if i'm wrong, you say that dividing a function by the derivative of in respect of one of its variable you rule out the density of that variable? – user3458909 Aug 20 '18 at 07:02
  • Haha i was not finish :P. Although thinking back, the derivative of $\cos\theta$ is $-\sin\theta$ , why do i divide by $+\sin\theta$ ? – user3458909 Aug 20 '18 at 07:29
  • @user3458909: I'm not entirely sure I'm following you, but I'll try to respond. You're making bins of $1°$ each for $\theta$. This would yield equal expected numbers in each bin if $\theta$ were uniformly distributed. Since it isn't, you need to correct for that if you want the "reference distribution" to have equal numbers in each bin. A bin of size $\Delta\theta=1°$ in $\theta$ corresponds to a bin of size $\Delta z\approx\left|\frac{\mathrm dz}{\mathrm d\theta}\right|\Delta\theta$ in $z$. – joriki Aug 20 '18 at 07:41
  • @user3458909: Since the distribution is uniform in $z$, the expectation in this bin is proportional to $\left|\frac{\mathrm dz}{\mathrm d\theta}\right|$. Thus you have to divide by that to make it flat. The sign doesn't matter. – joriki Aug 20 '18 at 07:42
  • 1
    Perfect, i think that's all that i had to understand, thank you SO MUCH. I'll now code it and eventually put up an image of the flattened map! – user3458909 Aug 20 '18 at 08:00
  • @user3458909: Yes, I was thinking it would be nice to see that image :-) – joriki Aug 20 '18 at 08:19
  • Here it is, as you see there are still some random peaks, but i think they are due to imprecise calculations of trigonometric function by the computer, as even imposing the $\left|,\theta-\frac\pi2\right|+\left|,\psi-\frac\pi2\right|\le\frac\pi2;.$ condition, some of the couple still come out with a negative radicand. As an example the cos(90) doesn't return zero, but a very small number, so in that cases in which i get a negative small number i force it manually to go to zero. – user3458909 Aug 22 '18 at 05:01
  • @user3458909: Thanks! So this is the real molecule with surface binding effects? I'd suggest to make the same diagram for a freely rotating molecule to check whether it's flat. – joriki Aug 22 '18 at 07:05