The purpose of this project is to introduce you to fundamental C-language (or C++) programming techniques in the context of a scientific problem, viz. the calculation of the internal coordinates (bond lengths, bond angles, dihedral angles), moments of inertia, and rotational constants of a polyatomic molecule. A concise set of instructions for this project may be found here.
We thank Dr. Yukio Yamaguchi of the University of Georgia for the original version of this project.
The input to the program is the set of Cartesian coordinates of the atoms (in bohr) and their associated atomic numbers. A sample molecule (acetaldehyde) to use as input to the program is:
7
6 0.000000000000 0.000000000000 0.000000000000
6 0.000000000000 0.000000000000 2.845112131228
8 1.899115961744 0.000000000000 4.139062527233
1 -1.894048308506 0.000000000000 3.747688672216
1 1.942500819960 0.000000000000 -0.701145981971
1 -1.007295466862 -1.669971842687 -0.705916966833
1 -1.007295466862 1.669971842687 -0.705916966833
The first line above is the number of atoms (an integer), while the remaining lines contain the z-values and x-, y-, and z-coordinates of each atom (one integer followed by three double-precision floating-point numbers). This input file ("acetaldehyde.dat") along with a few other test cases can be found in this repository in the input directory.
After downloading the file to your computer (to a file called “geom.dat”, for example), you must open the file, read the data from each line into appropriate variables, and finally close the file.
- Hint #1: Opening and closing the file stream
- Hint #2: Reading the number of atoms
- Hint #3: Storing the z-values and the coordinates
- Solution
Calculate the interatomic distances using the expression:

where x, y, and z are Cartesian coordinates and i and j denote atomic indices.
- Hint 1: Memory allocation
- Hint 2: Loop structure
- Hint 3: Printing the results
- Hint 4: Extending the Molecule class
- Solution
Calculate all possible bond angles. For example, the angle, φijk, between atoms i-j-k, where j is the central atom is given by:

where the eij are unit vectors between the atoms, e.g.,

- Hint 1: Memory allocation for the unit vectors
- Hint 2: Avoiding a divide-by-zero
- Hint 3: Memory allocation for the bond angles
- Hint 4: Smart printing
- Hint 5: Trigonometric functions
- Solution
Calculate all possible out-of-plane angles. For example, the angle θijkl for atom i out of the plane containing atoms j-k-l (with k as the central atom, connected to i) is given by:

- Hint 1: Memory allocation?
- Hint 2: Cross products
- Hint 3: Numerical precision
- Hint 4: Smarter printing
- Solution
Calculate all possible torsional angles. For example, the torsional angle τijkl for the atom connectivity i-j-k-l is given by:

Can you also determine the sign of the torsional angle?
Find the center of mass of the molecule:

where mi is the mass of atom i and the summation runs over all atoms in the molecule.
Translate the input coordinates of the molecule to the center-of-mass.
Calculate elements of the moment of inertia tensor.
Diagonal:

Off-diagonal (add a negative sign):

Diagonalize the inertia tensor to obtain the principal moments of inertia:

Report the moments of inertia in amu bohr2, amu Å2, and g cm2.
Based on the relative values of the principal moments, determine the molecular rotor type: linear, oblate, prolate, asymmetric.
Compute the rotational constants in cm-1 and MHz:

- Acetaldehyde: input coordinates | output
- Benzene: input coordinates | output
- Allene: input coordinates | output
E.B. Wilson, J.C. Decius, and P.C. Cross, Molecular Vibrations, McGraw-Hill, 1955.