def random_dimer(molecule0, molecule1, thresholds, shoot_max):
<EOL>center = np.zeros(<NUM_LIT:3>, float)<EOL>angle = np.random.uniform(<NUM_LIT:0>, <NUM_LIT:2>*np.pi)<EOL>axis = random_unit()<EOL>rotation = Complete.about_axis(center, angle, axis)<EOL>cor1 = np.dot(molecule1.coordinates, rotation.r)<EOL>atom0 = np.random.randint(len(molecule0.numbers))<EOL>atom1 = np.random.randint(len(molecule1.numbers))<EOL>delta = molecule0.coordinates[atom0] - cor1[atom1]<EOL>cor1 += delta<EOL>direction = random_unit()<EOL>cor1 += <NUM_LIT:1>*direction<EOL>threshold_mat = np.zeros((len(molecule0.numbers), len(molecule1.numbers)), float)<EOL>distance_mat = np.zeros((len(molecule0.numbers), len(molecule1.numbers)), float)<EOL>for i1, n1 in enumerate(molecule0.numbers):<EOL><INDENT>for i2, n2 in enumerate(molecule1.numbers):<EOL><INDENT>threshold = thresholds.get(frozenset([n1, n2]))<EOL>threshold_mat[i1, i2] = threshold**<NUM_LIT:2><EOL><DEDENT><DEDENT>while True:<EOL><INDENT>cor1 += <NUM_LIT:0.1>*direction<EOL>distance_mat[:] = <NUM_LIT:0><EOL>for i in <NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:2>:<EOL><INDENT>distance_mat += np.subtract.outer(molecule0.coordinates[:, i], cor1[:, i])**<NUM_LIT:2><EOL><DEDENT>if (distance_mat > threshold_mat).all():<EOL><INDENT>break<EOL><DEDENT><DEDENT>while True:<EOL><INDENT>cor1 += direction*np.random.uniform(<NUM_LIT:0>, shoot_max)<EOL>distance_mat[:] = <NUM_LIT:0><EOL>for i in <NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:2>:<EOL><INDENT>distance_mat += np.subtract.outer(molecule0.coordinates[:, i], cor1[:, i])**<NUM_LIT:2><EOL><DEDENT>if (distance_mat > threshold_mat).all():<EOL><INDENT>break<EOL><DEDENT><DEDENT>dimer = Molecule(<EOL>np.concatenate([molecule0.numbers, molecule1.numbers]),<EOL>np.concatenate([molecule0.coordinates, cor1])<EOL>)<EOL>dimer.direction = direction<EOL>dimer.atom0 = atom0<EOL>dimer.atom1 = atom1<EOL>return dimer<EOL>
Create a random dimer.

       molecule0 and molecule1 are placed in one reference frame at random
       relative positions. Interatomic distances are above the thresholds.
       Initially a dimer is created where one interatomic distance approximates
       the threshold value. Then the molecules are given an additional
       separation in the range [0, shoot_max].

       thresholds has the following format:
       {frozenset([atom_number1, atom_number2]): distance}