You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Project#01/README.md
+38-38
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# TODO:
2
2
-[ ] Add embedded equations
3
-
-[] Add hints and solutions for each step
3
+
-[x] Add hints and solutions for each step
4
4
-[x] Add input/output links for test cases
5
5
6
6
# Molecular-Geometry-Analysis
7
-
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](https://github.com/CrawfordGroup/ProgrammingProjects/blob/master/Project%2301/project1-instructions.pdf).
7
+
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](./project1-instructions.pdf).
8
8
9
9
We thank Dr. Yukio Yamaguchi of the University of Georgia for the original version of this project.
10
10
@@ -20,14 +20,14 @@ The input to the program is the set of Cartesian coordinates of the atoms (in bo
20
20
1 -1.007295466862 -1.669971842687 -0.705916966833
21
21
1 -1.007295466862 1.669971842687 -0.705916966833
22
22
23
-
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](https://github.com/CrawfordGroup/ProgrammingProjects/blob/master/Project%2301/input/acetaldehyde.dat) ("acetaldehyde.dat") along with a few other test cases can be found in this repository in the [input directory](https://github.com/CrawfordGroup/ProgrammingProjects/tree/master/Project%2301/input).
23
+
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](./input/acetaldehyde.dat) ("acetaldehyde.dat") along with a few other test cases can be found in this repository in the [input directory](./input).
24
24
25
25
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.
26
26
27
-
- Hint #1: Opening and closing the file stream
28
-
- Hint #2: Reading the number of atoms
29
-
- Hint #3: Storing the z-values and the coordinates
30
-
- Solution
27
+
-[Hint #1](./hints/hint1-1.md): Opening and closing the file stream
28
+
-[Hint #2](./hints/hint1-2.md): Reading the number of atoms
29
+
-[Hint #3](./hints/hint1-3.md): Storing the z-values and the coordinates
30
+
-[Solution](./hints/step1-solution.md)
31
31
32
32
## Step 2: Bond Lengths
33
33
Calculate the interatomic distances using the expression:
@@ -38,11 +38,11 @@ EQUATION
38
38
39
39
where x, y, and z are Cartesian coordinates and i and j denote atomic indices.
40
40
41
-
- Hint 1: Memory allocation
42
-
- Hint 2: Loop structure
43
-
- Hint 3: Printing the results
44
-
- Hint 4: Extending the Molecule class
45
-
- Solution
41
+
-[Hint 1](./hints/hint2-1.md): Memory allocation
42
+
-[Hint 2](./hints/hint2-2.md): Loop structure
43
+
-[Hint 3](./hints/hint2-3.md): Printing the results
44
+
-[Hint 4](./hints/hint2-4.md): Extending the Molecule class
45
+
-[Solution](./hints/step2-solution.md)
46
46
47
47
## Step 3: Bond Angles
48
48
Calculate all possible bond angles. For example, the angle, φ<sub>ijk</sub>, between atoms i-j-k, where j is the central atom is given by:
@@ -57,12 +57,12 @@ where the e⃗<sub>ij</sub> are unit vectors between the atoms, e.g.,
57
57
EQUATION
58
58
```
59
59
60
-
- Hint 1: Memory allocation for the unit vectors
61
-
- Hint 2: Avoiding a divide-by-zero
62
-
- Hint 3: Memory allocation for the bond angles
63
-
- Hint 4: Smart printing
64
-
- Hint 5: Trigonometric functions
65
-
- Solution
60
+
-[Hint 1](./hints/hint3-1.md): Memory allocation for the unit vectors
61
+
-[Hint 2](./hints/hint3-2.md): Avoiding a divide-by-zero
62
+
-[Hint 3](./hints/hint3-3.md): Memory allocation for the bond angles
Calculate all possible out-of-plane angles. For example, the angle θ<sub>ijkl</sub> for atom i out of the plane containing atoms j-k-l (with k as the central atom, connected to i) is given by:
@@ -71,11 +71,11 @@ Calculate all possible out-of-plane angles. For example, the angle θ<sub>i
@@ -103,9 +103,9 @@ where m<sub>i</sub> is the mass of atom i and the summation runs over all atoms
103
103
104
104
Translate the input coordinates of the molecule to the center-of-mass.
105
105
106
-
- Hint 1: Atomic masses
107
-
- Hint 2: Translating between atomic number and atomic mass
108
-
- Solution
106
+
-[Hint 1](./hints/hint6-1.md): Atomic masses
107
+
-[Hint 2](./hints/hint6-2.md): Translating between atomic number and atomic mass
108
+
-[Solution](./hints/step6-solution.md)
109
109
110
110
## Step 7: Principal Moments of Inertia
111
111
Calculate elements of the [moment of inertia tensor](http://en.wikipedia.org/wiki/Moment_of_inertia_tensor).
@@ -129,9 +129,9 @@ Report the moments of inertia in amu bohr<sup>2</sup>, amu Å<sup>2</sup>,
129
129
130
130
Based on the relative values of the principal moments, determine the [molecular rotor type](http://en.wikipedia.org/wiki/Rotational_spectroscopy): linear, oblate, prolate, asymmetric.
131
131
132
-
- Hint 1: Diagonalization of a 3×3 matrix
133
-
- Hint 2: Physical constants
134
-
- Solution
132
+
-[Hint 1](./hints/hint7-1.md): Diagonalization of a 3×3 matrix
133
+
-[Hint 2](./hints/hint7-2.md): Physical constants
134
+
-[Solution](./hints/step7-solution.md)
135
135
136
136
## Step 8: Rotational Constants
137
137
Compute the rotational constants in cm<sup>-1</sup> and MHz:
@@ -140,13 +140,13 @@ Compute the rotational constants in cm<sup>-1</sup> and MHz:
The sign of a torsional/dihedral angle among atoms **_i-j-k-l_** is positive (negative) if the vector along **_k-l_** lies to the right (left) of the plane formed by **_i-j-k_** when the plane is viewed along the **_j-k_** vector.
An excellent source for atomic masses and other physical constants is the [National Institute of Standard and Technology (NIST) website](http://physics.nist.gov/cgi-bin/Compositions/stand_alone.pl?ele=&ascii=html&isotype=some).
An elegant way to translate between the atomic number (z-value) of a given atom and its mass is to prepare a static array of the masses of the most abundant isotope of each element. I suggest preparing a header file containing a [global array](https://github.com/CrawfordGroup/ProgrammingProjects/wiki/Variable-Scope-and-Reference-Types#global-variables), e.g.:
2
+
```c++
3
+
double masses[] = {
4
+
0.0000000,
5
+
1.007825,
6
+
4.002603,
7
+
6.015123,
8
+
...};
9
+
```
10
+
Note that, for example, `masses[1] = 1.007825`, which is the correct atomic mass for a hydrogen atom.
Here are two approaches for the [diagonalization](http://en.wikipedia.org/wiki/Diagonalizable_matrix) of the moment of inertia tensor:
2
+
3
+
## Secular Determinant
4
+
Since the moment of inertia tensor is only a 3x3 matrix, a brute-force approach via the secular determinant is feasible:
5
+
6
+
```latex
7
+
\left|\begin{array}{ccc}
8
+
(I_{11}-\lambda) & I_{12} & I_{13} \\
9
+
I_{21} & (I_{22}-\lambda) & I_{23} \\
10
+
I_{31} & I_{32} & (I_{33}-\lambda) \\
11
+
\end{array}\right| = 0
12
+
```
13
+
14
+
This leads to a cubic equation in λ, which one can solve directly. Have fun with that.
15
+
16
+
## More General Algorithms
17
+
"Canned" algorithms are definitely the way to go for general matrix diagonalization. Most such algorithms are based on a two-step procedure:
18
+
- Reduction of the matrix to a tridiagonal form using the [Householder](http://en.wikipedia.org/wiki/Householder's_method) or Givens approaches.
19
+
- Diagonalization of the tridiagonal structure, either by solving its secular determinant or by other methods, e.g. [QR or QL decompositions](http://en.wikipedia.org/wiki/QR_decomposition).
20
+
21
+
A convenient canned library for a wide range of linear algebraic operations is the [Eigen package](http://eigen.tuxfamily.org). This is a template-only library that provides a very clean interface for manipulating a large number of matrix types. You can either download and install the library from the [official website](http://eigen.tuxfamily.org) or just grab the [gzipped tarfile from here](../eigen.tar.gz). Unpack the library in the same directory as your source code, and you're ready to get started.
22
+
23
+
To use the library to diagonalize your moment inertia tensor, follow these steps:
24
+
25
+
- Add the following lines to your main source file below the inclusion of other headers:
Lots of useful and precise physical constants are available at the [National Institute of Standards and Technology website](http://physics.nist.gov/cuu/Constants/index.html?/codata86.html).
0 commit comments