Molecular geomatry Problem !

Hi,

I am an undergraduate in the field of Biology. I am dealing with proteins and wish to calculate the dihedral angles. The problem is as follows-

Given the coordinates of 4 atoms how can we calculate the dihedral or torsion angle between the planes defined by atom 123 and 234 ?

Now there are two components, first, magnitude of the dihedral angle and second, sign +/- as dihedral angle varies from -180 degree to +180 degree.

How can we calculate both magnitude and the sign of the dihedral angle ? I have to implement the solution in a computer program.

The second program is vice-versa of the first one. Given all the internal coordinates i.e. all bond lengths, bond angles and the dihedral angle how can we find the x,y,z coordinates of the fourth atom? If not given we can assume the coordinates of first atom to be 0,0,0.

Please tell the solution. Thanks in anticipation.

-Param