How do I rotate a group of vectors so that one points in the direction of a given vector and the others maintain their angles from it and each other. I am a computational chemistry undergraduate researcher and am working on a program that builds random molecules. To do this the program places atoms on a grid and assigns bond geometries to them. The first atom is easy, it gets placed at the origin and assigned a geometry, lets say tetrahedral. a set of 4 unit vectors are assigned to it 
$[(0,0,1),(0,0.9426, -0.3338), (0.8176,-0.4723,-0.3338), (-0.8176,-0.4723,-0.3338)]$
The next atom randomly picks one of those vectors and is placed on the grid a bond length away from the first atom along that vector.
The problem is this: that second atom, and every one after, needs to have unique unit vectors based off the original but with one of the vectors pointing in the opposite direction as the vector it placed itself using and the remaining vectors rotated so that they maintain there geometry.
What I would like to happen is to input a vector (x,y,z), and take my first vector (0,0,1) and turn it into (x,y,z) in a way that I can apply the same transformation to the remaining vectors.
 A: Let $\boldsymbol{v}_1,\, \boldsymbol{v}_2,\, \dots,\, \boldsymbol{v}_n$ be the set of vectors, that we would like to rotate, and let $\boldsymbol{d}$ be the given vector, in whose direction we want $\boldsymbol{v}_1$ to point. Assuming right-hand convention.


*

*Take cross product
$$
\boldsymbol{u} := \boldsymbol{d} \times \boldsymbol{v}_1
$$
This gives vector $\boldsymbol{u}$ that is orthogonal to the plane spanned by $\boldsymbol{d}$ and $\boldsymbol{v}_1$.

*Normalize $\boldsymbol{u}$ to get the unit vector
$$
\hat{\boldsymbol{u}} := \frac{1}{\left\lVert \boldsymbol{u} \right\rVert} \boldsymbol{u},
$$
where
$$
{\left\lVert \boldsymbol{u} \right\rVert} := \sqrt{u_x^2 + u_y^2 + u_z^2}
$$
is an Euclidean norm.

*Determine angle $\theta$ between $\boldsymbol{d}$ and $\boldsymbol{v}_1$ using relation
$$
\cos\theta = \frac{\boldsymbol{d} \cdot \boldsymbol{v}_1}{{\left\lVert \boldsymbol{d} \right\rVert} {\left\lVert \boldsymbol{v}_1 \right\rVert}}
$$
where
$$
\boldsymbol{d} \cdot \boldsymbol{v}_1 := d_x {v_1}_x + d_y {v_1}_y + d_z {v_1}_z
$$
is an inner product between $\boldsymbol{d}$ and $\boldsymbol{v}_1$.

*Then rotation matrix $R$ that rotates by angle $\theta$ about $\hat{\boldsymbol{u}}$ is given by
$$
R :={\begin{bmatrix}\cos \theta +\hat{u}_{x}^{2}\left(1-\cos \theta \right)&\hat{u}_{x}\hat{u}_{y}\left(1-\cos \theta \right)-\hat{u}_{z}\sin \theta &\hat{u}_{x}\hat{u}_{z}\left(1-\cos \theta \right)+\hat{u}_{y}\sin \theta \\\hat{u}_{y}\hat{u}_{x}\left(1-\cos \theta \right)+\hat{u}_{z}\sin \theta &\cos \theta +\hat{u}_{y}^{2}\left(1-\cos \theta \right)&\hat{u}_{y}\hat{u}_{z}\left(1-\cos \theta \right)-\hat{u}_{x}\sin \theta \\\hat{u}_{z}\hat{u}_{x}\left(1-\cos \theta \right)-\hat{u}_{y}\sin \theta &\hat{u}_{z}\hat{u}_{y}\left(1-\cos \theta \right)+\hat{u}_{x}\sin \theta &\cos \theta +\hat{u}_{z}^{2}\left(1-\cos \theta \right)\end{bmatrix}}
$$


see https://en.wikipedia.org/wiki/Rotation_matrix for derivation of $R$.


*Finally our desired vectors are given as
$$
R \boldsymbol{v}_1,\, R \boldsymbol{v}_2,\, \dots,\, R \boldsymbol{v}_n.
$$

