def setUp(self): """Setup function.""" with path("saddle.test.data", "water.xyz") as mol_path: mol = Utils.load_file(mol_path) self.mol = Internal(mol.coordinates, mol.numbers, 0, 1) with path("saddle.test.data", "h2o2.xyz") as mol_path: mol2 = Utils.load_file(mol_path) self.h2o2 = Internal(mol2.coordinates, mol2.numbers, 0, 1)
def setUp(self): with path("saddle.test.data", "ch3_hf.xyz") as rct_path: self.rct = Utils.load_file(rct_path) with path("saddle.test.data", "ch3f_h.xyz") as prd_path: self.prd = Utils.load_file(prd_path) self.reactant_ic = Internal(self.rct.coordinates, self.rct.numbers, 0, 2) self.product_ic = Internal(self.prd.coordinates, self.prd.numbers, 0, 2)
def test_auto_select_improper_ch3_hf(self): with path("saddle.test.data", "ch3_hf.xyz") as mol_path: mol = Utils.load_file(mol_path) mol = Internal(mol.coordinates, mol.numbers, 0, 1) mol.auto_select_ic() ic_ref = np.array([ 2.02762919, 2.02769736, 2.02761705, 1.77505755, 4.27707385, 4.87406146, 2.08356856, 2.08391343, 1.64995596, 2.08364916, 1.64984524, 1.64881837, 1.06512165, 0.42765264, 3.14154596, 2.71390135, 0.59485389, -1.70630517, 1.7061358, -3.14152957, 2.09455878, -2.09427619, -2.87079827, ]) assert_allclose(mol.ic_values, ic_ref)
def test_ric_add_ic(self): with path("saddle.test.data", "water.xyz") as mol_path: mol = Utils.load_file(mol_path) ri_mol = Internal(mol.coordinates, mol.numbers, 0, 1) ri_mol = ReducedInternal.update_to_reduced_internal(ri_mol) ri_mol.add_bond(1, 0) ri_mol.add_bond(1, 2) ri_mol.add_bond(0, 2) ri_mol.vspace ri_mol.add_angle(0, 1, 2) ri_mol.add_angle(1, 0, 2) ri_mol.select_key_ic(0, 2) vp_ref = np.array( [ [4.40930006e-01, -7.79280781e-01, 6.12072474e-17], [-5.61408260e-01, -6.12047068e-01, -3.33066907e-16], [-4.57920570e-01, -3.28254718e-02, -7.16200549e-01], [-5.22760813e-01, 4.87258745e-02, 5.58315734e-01], [8.62054537e-02, 1.21112047e-01, -4.18736570e-01], ] ) for i in range(vp_ref.shape[1]): assert np.allclose(ri_mol.vspace[:, i], vp_ref[:, i]) or np.allclose( ri_mol.vspace[:, i], -1 * vp_ref[:, i] ) ri_mol.set_key_ic_number(1) assert ri_mol._red_space is None assert ri_mol._non_red_space is None
def test_auto_dihed_number_ethane(self): with path("saddle.test.data", "ethane.xyz") as mol_path: mol = Utils.load_file(mol_path) mol = Utils.load_file(mol_path) ethane = Internal(mol.coordinates, mol.numbers, 0, 1) ethane.auto_select_ic() counter = 0 for ic in ethane.ic: if isinstance(ic, DihedralAngle): counter += 1 assert counter == 5
def test_delete_ic(self): with path("saddle.test.data", "ethane.xyz") as mol_path: mol = Utils.load_file(mol_path) ethane = Internal(mol.coordinates, mol.numbers, 0, 1) ethane.auto_select_ic() ethane._delete_ic_index(0) assert len(ethane.ic) == 23 ethane.auto_select_ic(keep_bond=True) assert len(ethane.ic) == 12 # print(ethane.ic) ethane.delete_ic(1, 2, 3) assert len(ethane.ic) == 9
def test_new_dihed_converge(self): with path("saddle.test.data", "h2o2.xyz") as mol_path: mol = Utils.load_file(mol_path) mol = Utils.load_file(mol_path) h2o2 = Internal(mol.coordinates, mol.numbers, 0, 1) h2o2.auto_select_ic(dihed_special=True) assert len(h2o2.ic) == 7 # print(h2o2.ic_values) target_ic = [2.4, 1.8, 1.8, 1.6, 1.6, 0.8, 0.6] h2o2.set_target_ic(target_ic) h2o2.converge_to_target_ic() # print(h2o2.ic_values) assert_allclose(h2o2.ic_values, target_ic, atol=1e-2)
def test_dihedral_add(self): """Test add normal dihedral.""" with path("saddle.test.data", "2h-azirine.xyz") as mol_path: mol = Utils.load_file(mol_path) # create a water molecule internal = Internal(mol.coordinates, mol.numbers, 0, 1) internal.add_bond(0, 1) internal.add_bond(1, 2) internal.add_bond(1, 3) # fake add dihed internal.add_dihedral(0, 2, 3, 4) assert len(internal.ic) == 3 internal.add_dihedral(0, 1, 2, 3) assert len(internal.ic) == 4 assert internal.ic_values[3] == dihed_angle(internal.coordinates[:4])
def test_dihedral_repeak(self): with path("saddle.test.data", "h2o2.xyz") as mol_path: mol = Utils.load_file(mol_path) h2o2 = Internal(mol.coordinates, mol.numbers, 0, 1) h2o2.add_bond(0, 1) h2o2.add_bond(1, 2) h2o2.add_bond(2, 3) h2o2.add_bond(3, 2) h2o2.add_bond(0, 2) h2o2.add_bond(1, 3) assert len(h2o2.ic) == 5 h2o2.add_dihedral(0, 1, 2, 3) assert len(h2o2.ic) == 6 h2o2.add_dihedral(0, 2, 1, 3) assert len(h2o2.ic) == 6
def test_fragments_in_mole(self): with path("saddle.test.data", "ch3_hf.xyz") as mol_path: mol = Utils.load_file(mol_path) mol = Internal(mol.coordinates, mol.numbers, 0, 1) assert len(mol.fragments) == mol.natom mol.add_bond(0, 1) mol.add_bond(2, 3) # print(mol.fragments) assert len(mol.fragments) == mol.natom - 2 mol.add_bond(0, 2) assert len(mol.fragments) == mol.natom - 3 mol.add_bond(0, 3) assert len(mol.fragments) == mol.natom - 3 mol.add_bond(4, 5) assert len(mol.fragments) == mol.natom - 4 mol.add_bond(0, 5, b_type=3) assert len(mol.fragments) == 2
def test_new_dihed(self): with path("saddle.test.data", "h2o2.xyz") as mol_path: mol = Utils.load_file(mol_path) h2o2 = Internal(mol.coordinates, mol.numbers, 0, 1) h2o2.add_bond(0, 1) h2o2.add_bond(1, 2) h2o2.add_bond(2, 3) assert len(h2o2.ic) == 3 h2o2.add_dihedral(0, 1, 2, 3, special=True) assert len(h2o2.ic) == 5 assert h2o2.b_matrix.shape == (5, 12) h2o2.add_dihedral(3, 1, 2, 0) assert len(h2o2.ic) == 5 h2o2.add_dihedral(3, 2, 1, 0, special=True) assert len(h2o2.ic) == 5 ref_b = h2o2.b_matrix.copy() h2o2._regenerate_ic() assert_allclose(h2o2.b_matrix, ref_b)
def test_fragments_bond_add(self): with path("saddle.test.data", "ch3_hf.xyz") as mol_path: mol = Utils.load_file(mol_path) mol = Internal(mol.coordinates, mol.numbers, 0, 1) mol._auto_select_fragment_bond() assert len(mol.ic) == 15 mol.wipe_ic_info(True) mol.add_bond(0, 1) mol._auto_select_fragment_bond() assert len(mol.ic) == 15 mol.wipe_ic_info(True) mol.add_bond(0, 1) mol.add_bond(0, 5) mol.add_bond(0, 3) mol.add_bond(4, 2) mol._auto_select_fragment_bond() assert len(mol.ic) == 6 mol.wipe_ic_info(True) mol.add_bond(0, 1) mol.add_bond(2, 3) mol.add_bond(4, 5) mol._auto_select_fragment_bond() assert len(mol.ic) == 9 # mol.wipe_ic_info(True) mol.add_bond(0, 1) mol.add_bond(0, 2) mol.add_bond(3, 4) mol.add_bond(4, 5) mol._auto_select_fragment_bond() assert_allclose(mol.ic_values[4], 2.02761704779693) assert mol.ic[4].atoms == (0, 3) assert_allclose(mol.ic_values[5], 3.501060110109399) assert mol.ic[5].atoms == (2, 3) assert len(mol.ic) == 6
def test_dihedral_rotation(self): with path("saddle.test.data", "h2o2.xyz") as mol_path: mol = Utils.load_file(mol_path) h2o2 = Internal(mol.coordinates, mol.numbers, 0, 1) h2o2.auto_select_ic() ref_ic = np.array([ 2.47617635, 1.85058569, 1.85070922, 1.81937566, 1.81930967, 1.43966113 ]) assert_allclose(h2o2.ic_values, ref_ic) target_ic = [2.4, 1.8, 1.8, 1.6, 1.6, 1.57] h2o2.set_target_ic(target_ic) h2o2.converge_to_target_ic() assert_allclose(h2o2.ic_values, target_ic, atol=1e-3) target_ic = [2.4, 1.8, 1.8, 1.6, 1.6, 3.14] h2o2.set_target_ic(target_ic) h2o2.converge_to_target_ic() assert_allclose(h2o2.ic_values, target_ic, atol=1e-4) target_ic = [2.4, 1.8, 1.8, 1.6, 1.6, -1.57] h2o2.set_target_ic(target_ic) h2o2.converge_to_target_ic() assert_allclose(h2o2.ic_values, target_ic, atol=1e-3)
def test_file_title(self): """Test default file title.""" new_mol = Internal(self.mol.coordinates, self.mol.numbers, 0, 1) assert len(new_mol._title) == 15
def test_auto_ic_select_methanol(self): with path("saddle.test.data", "methanol.xyz") as mol_path: mol = Utils.load_file(mol_path) methanol = Internal(mol.coordinates, mol.numbers, 0, 1) methanol.auto_select_ic() assert len(methanol.ic) == 15
def test_ic_ric_transform(self): with path("saddle.test.data", "water.xyz") as mol_path: mol = Utils.load_file(mol_path) ri_mol = Internal(mol.coordinates, mol.numbers, 0, 1) ri_mol.add_bond(1, 0) ri_mol.add_bond(1, 2) ri_mol.add_bond(0, 2) ri_mol.add_angle(0, 1, 2) ri_mol.add_angle(1, 0, 2) vc_ref = np.array([1.81413724, 1.81413724, 2.96247453, 1.91063401, 0.61547931]) assert np.allclose(ri_mol.ic_values, vc_ref) ri_mol = ReducedInternal.update_to_reduced_internal(ri_mol) assert isinstance(ri_mol, ReducedInternal) ri_mol.set_key_ic_number(2) ri_mol.select_key_ic(0, 2) print(ri_mol.vspace) vp_ref = np.array( [ [4.40930006e-01, -7.79280781e-01, 6.12072474e-17], [-5.61408260e-01, -6.12047068e-01, -3.33066907e-16], [-4.57920570e-01, -3.28254718e-02, -7.16200549e-01], [-5.22760813e-01, 4.87258745e-02, 5.58315734e-01], [8.62054537e-02, 1.21112047e-01, -4.18736570e-01], ] ) for i in range(vp_ref.shape[1]): assert np.allclose(ri_mol.vspace[:, i], vp_ref[:, i]) or np.allclose( ri_mol.vspace[:, i], -1 * vp_ref[:, i] ) ri_mol.set_key_ic_number(1) assert ri_mol._red_space is None assert ri_mol._non_red_space is None ri_mol.set_key_ic_number(2) for i in range(vp_ref.shape[1]): assert np.allclose(ri_mol.vspace[:, i], vp_ref[:, i]) or np.allclose( ri_mol.vspace[:, i], -1 * vp_ref[:, i] ) new_coor = np.array( [ [1.40, -0.93019123, -0.0], [-0.0, 0.11720081, -0.0], [-1.40, -0.93019123, -0.0], ] ) ri_mol.set_new_coordinates(new_coor) ref_ic = [ 1.7484364736491811, 2.8, 1.7484364736491811, 1.8569769819, 0.6423078258, ] assert np.allclose(ri_mol.ic_values, ref_ic) ri_mol.vspace assert ri_mol._red_space is not None assert ri_mol._non_red_space is not None print(ri_mol._red_space) ri_mol.add_angle(0, 2, 1) print(ri_mol._red_space) assert ri_mol._red_space is None assert ri_mol._non_red_space is None
def test_auto_ic_select_ethane(self): with path("saddle.test.data", "ethane.xyz") as mol_path: mol = Utils.load_file(mol_path) ethane = Internal(mol.coordinates, mol.numbers, 0, 1) ethane.auto_select_ic() assert len(ethane.ic) == 24