3232 hydrolysis
3333 )
3434from arc .reaction import ARCReaction
35- from arc .species .converter import str_to_xyz , zmat_to_xyz , xyz_to_str , zmat_from_xyz
35+ from arc .species .converter import str_to_xyz , zmat_to_xyz , xyz_to_str
3636from arc .species .species import ARCSpecies
37- from arc .species .zmat import _compare_zmats
3837from arc .species .vectors import calculate_param
39-
40- FAMILY_SETS = {'set_1' : ['ester_hydrolysis' , 'imine_hydrolysis' ,'ether_hydrolysis' ],
41- 'set_2' : ['nitrile_hydrolysis' ]} #sub-groups of hydrolysis reaction families
42-
38+ from arc .species .zmat import _compare_zmats
4339
4440class TestHeuristicsAdapter (unittest .TestCase ):
4541 """
@@ -2326,17 +2322,6 @@ def test_are_h_abs_wells_reversed(self):
23262322 self .assertFalse (r_reversed )
23272323 self .assertFalse (p_reversed )
23282324
2329-
2330-
2331- @classmethod
2332- def tearDownClass (cls ):
2333- """
2334- A function that is run ONCE after all unit tests in this class.
2335- Delete all project directories created during these unit tests.
2336- """
2337- shutil .rmtree (os .path .join (ARC_PATH , 'arc' , 'testing' , 'heuristics' ), ignore_errors = True )
2338- shutil .rmtree (os .path .join (ARC_PATH , 'arc' , 'testing' , 'heuristics_1' ), ignore_errors = True )
2339-
23402325 def test_is_water (self ):
23412326 """Test the is_water() function."""
23422327 water = self .water
@@ -2488,6 +2473,29 @@ def test_check_dao_angle(self):
24882473 result = check_dao_angle (d2_indices , initial_xyz )
24892474 self .assertFalse (result )
24902475
2476+ # Validation Helper Functions
2477+ def check_distance (self , coords , atoms , expected , places = 0 ):
2478+ """Checks if the calculated distance between atoms is close to the expected value."""
2479+ value = calculate_param (coords = coords , atoms = atoms )
2480+ self .assertAlmostEqual (value , expected , places = places )
2481+
2482+ def check_angle (self , coords , atoms , expected , places = None , delta = None ):
2483+ """Checks if the calculated angle is within the acceptable deviation."""
2484+ value = calculate_param (coords = coords , atoms = atoms )
2485+ if delta :
2486+ self .assertAlmostEqual (value , expected , delta = delta )
2487+ elif places :
2488+ self .assertAlmostEqual (value , expected , places = places )
2489+
2490+ def check_dihedral (self , coords , atoms , expected , places = None , delta = None ):
2491+ """Checks if the calculated dihedral angle is within the acceptable deviation."""
2492+ value = calculate_param (coords = coords , atoms = atoms )
2493+ normalized = abs ((value + 180 ) % 360 - 180 )
2494+ if delta :
2495+ self .assertAlmostEqual (normalized , expected , delta = delta )
2496+ elif places :
2497+ self .assertAlmostEqual (normalized , expected , places = places )
2498+
24912499 def test_ester_hydrolysis (self ):
24922500 """Test ester hydrolysis reactions."""
24932501 water = self .water
@@ -2544,27 +2552,27 @@ def test_ester_hydrolysis(self):
25442552 self .assertIn ('ester_hydrolysis' , families )
25452553 xyz_guesses_total , zmats_total = hydrolysis (tested_rxn )
25462554
2547- for i in xyz_guesses_total :
2548- family = i ['family' ]
2555+ for guess_block in xyz_guesses_total :
2556+ family = guess_block ['family' ]
25492557 print (family )
2550- a ,b ,f ,d ,O ,H1 = i ['indices' ][0 ], i ['indices' ][1 ], i ['indices' ][2 ], i ['indices' ][3 ], i ['indices' ][4 ], i ['indices' ][5 ]
2551- for j in i ['xyz_guesses' ]:
2552- xyz_str = xyz_to_str (j )
2558+ a ,b ,f ,O ,H1 ,d = guess_block ['indices' ][0 ], guess_block ['indices' ][1 ], guess_block ['indices' ][2 ], guess_block ['indices' ][3 ], guess_block ['indices' ][4 ], guess_block ['indices' ][5 ]
2559+ print (a ,b ,f ,d ,O ,H1 )
2560+ for guess in guess_block ['xyz_guesses' ]:
2561+ xyz_str = xyz_to_str (guess )
25532562 print (xyz_str )
25542563 print ()
25552564 if family == 'ester_hydrolysis' :#the parameters of ether hydrolysis are checked in the following test section
25562565 distance_ab = (calculate_param (coords = initial_xyz ['coords' ], atoms = [b , a ]))* 1.3
2557- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [b , a ]), distance_ab , places = 0 )
2558- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [a , O ]), 1.8 , places = 0 )
2559- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [O , H1 ]), 1.21 , places = 0 )
2560- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [O , H1 + 1 ]), 0.97 , places = 2 )
2561- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [b , a , O ]), 77 , places = 0 )
2562- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [a , O , H1 ]), 71 , places = 0 )
2563- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [H1 , O , H1 + 1 ]), 111 , places = 0 )
2564- self .assertAlmostEqual (abs ((calculate_param (coords = j ['coords' ], atoms = [f , d , a , O ]) + 180 ) % 360 - 180 ), 140 , places = 0 )
2565- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [b , a , O , H1 ]), 1.64 , places = 1 )
2566- self .assertAlmostEqual (abs ((calculate_param (coords = j ['coords' ], atoms = [a , H1 , O , H1 + 1 ]) + 180 ) % 360 - 180 ), 103 , places = 0 )
2567-
2566+ self .check_distance (coords = guess ['coords' ], atoms = [b , a ], expected = distance_ab , places = 0 )
2567+ self .check_distance (coords = guess ['coords' ], atoms = [a , O ], expected = 1.8 , places = 0 )
2568+ self .check_distance (coords = guess ['coords' ], atoms = [O , H1 ], expected = 1.21 , places = 0 )
2569+ self .check_distance (coords = guess ['coords' ], atoms = [O , H1 + 1 ], expected = 0.97 ,places = 0 )
2570+ self .check_angle (coords = guess ['coords' ], atoms = [b , a , O ], expected = 77 , delta = 5 )
2571+ self .check_angle (coords = guess ['coords' ], atoms = [a , O , H1 ], expected = 71 , delta = 5 )
2572+ self .check_angle (coords = guess ['coords' ], atoms = [H1 , O , H1 + 1 ], expected = 111 , delta = 5 )
2573+ self .check_dihedral (coords = guess ['coords' ], atoms = [f , d , a , O ], expected = 140 , delta = 5 )
2574+ self .check_dihedral (coords = guess ['coords' ], atoms = [b , a , O , H1 ], expected = 1.64 , delta = 3 )
2575+ self .check_dihedral (coords = guess ['coords' ], atoms = [a , H1 , O , H1 + 1 ], expected = 103 , delta = 5 )
25682576 def test_ether_hydrolysis (self ):
25692577 """Test ether hydrolysis reactions."""
25702578 water = self .water
@@ -2598,27 +2606,25 @@ def test_ether_hydrolysis(self):
25982606 families = [entry ['family' ] for entry in product_dicts ]
25992607 self .assertIn ('ether_hydrolysis' , families )
26002608 xyz_guesses_total , zmats_total = hydrolysis (tested_rxn )
2601- for i in xyz_guesses_total :
2602- print (i ['family' ])
2603- a , b , f , d , O , H1 = i ['indices' ][0 ], i ['indices' ][1 ], i ['indices' ][2 ], i ['indices' ][3 ], i ['indices' ][4 ], i ['indices' ][5 ]
2609+ for guess_block in xyz_guesses_total :
2610+ print (guess_block ['family' ])
2611+ a , b , f , O , H1 , d = guess_block ['indices' ][0 ], guess_block ['indices' ][1 ], guess_block ['indices' ][2 ], guess_block ['indices' ][3 ], guess_block ['indices' ][4 ], guess_block ['indices' ][5 ]
26042612 print (a , b , f , d , O , H1 )
2605- for j in i ['xyz_guesses' ]:
2606- xyz_str = xyz_to_str (j )
2613+ for guess in guess_block ['xyz_guesses' ]:
2614+ xyz_str = xyz_to_str (guess )
26072615 print (xyz_str )
26082616 print ()
26092617 distance_ab = (calculate_param (coords = initial_xyz ['coords' ], atoms = [b , a ])) * 1.5
2610- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [b , a ]), distance_ab , places = 0 )
2611- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [a , O ]), 2.1 , places = 0 )
2612- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [O , H1 ]), 1.21 , places = 0 )
2613- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [O , H1 + 1 ]), 0.97 , places = 0 )
2614- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [b , a , O ]), 65 , places = 0 )
2615- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [a , O , H1 ]), 72 , places = 0 )
2616- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [H1 , O , H1 + 1 ]), 106 , places = 0 )
2617- self .assertAlmostEqual (abs ((calculate_param (coords = j ['coords' ], atoms = [f , d , a , O ]) + 180 ) % 360 - 180 ),
2618- 98.25 , places = 0 )
2619- self .assertAlmostEqual ((calculate_param (coords = j ['coords' ], atoms = [b , a , O , H1 ]) + 180 ) % 360 - 180 , - 0.72 , places = 1 )
2620- self .assertAlmostEqual (
2621- abs ((calculate_param (coords = j ['coords' ], atoms = [a , H1 , O , H1 + 1 ]) + 180 ) % 360 - 180 ), 103 , places = 0 )
2618+ self .check_distance (coords = guess ['coords' ], atoms = [b , a ], expected = distance_ab , places = 0 )
2619+ self .check_distance (coords = guess ['coords' ], atoms = [a , O ], expected = 2.1 , places = 0 )
2620+ self .check_distance (coords = guess ['coords' ], atoms = [O , H1 ], expected = 1.21 , places = 0 )
2621+ self .check_distance (coords = guess ['coords' ], atoms = [O , H1 + 1 ], expected = 0.97 , places = 0 )
2622+ self .check_angle (coords = guess ['coords' ], atoms = [b , a , O ], expected = 65 , delta = 5 )
2623+ self .check_angle (coords = guess ['coords' ], atoms = [a , O , H1 ], expected = 72 , delta = 5 )
2624+ self .check_angle (coords = guess ['coords' ], atoms = [H1 , O , H1 + 1 ], expected = 106 , delta = 6 )
2625+ self .check_dihedral (coords = guess ['coords' ], atoms = [f , d , a , O ], expected = 98.25 , delta = 10 )
2626+ self .check_dihedral (coords = guess ['coords' ], atoms = [b , a , O , H1 ], expected = - 0.72 , delta = 10 )
2627+ self .check_dihedral (coords = guess ['coords' ], atoms = [a , H1 , O , H1 + 1 ], expected = 103 , delta = 10 )
26222628
26232629 def test_imine_hydrolysis (self ):
26242630 """Test imine hydrolysis reactions."""
@@ -2640,7 +2646,7 @@ def test_imine_hydrolysis(self):
26402646 phenylalaninol = self .phenylalaninol
26412647 rxn4 = ARCReaction (r_species = [phenylethanimine , water ], p_species = [phenylalaninol ])
26422648
2643- tested_rxn = rxn4
2649+ tested_rxn = rxn3
26442650 reactant = tested_rxn .r_species [0 ]
26452651 initial_xyz = reactant .get_xyz ()
26462652 product_dicts = get_reaction_family_products (
@@ -2652,28 +2658,25 @@ def test_imine_hydrolysis(self):
26522658 families = [entry ['family' ] for entry in product_dicts ]
26532659 self .assertIn ('imine_hydrolysis' , families )
26542660 xyz_guesses_total , zmats_total = hydrolysis (reaction = tested_rxn )
2655- for i in xyz_guesses_total :
2656- print (i ['family' ])
2657- a , b , f , d , O , H1 = i ['indices' ][0 ], i ['indices' ][1 ], i ['indices' ][2 ], i ['indices' ][3 ], i ['indices' ][4 ], i ['indices' ][5 ]
2661+ for block in xyz_guesses_total :
2662+ print (block ['family' ])
2663+ a , b , f , O , H1 , d = block ['indices' ][0 ], block ['indices' ][1 ], block ['indices' ][2 ], block ['indices' ][3 ], block ['indices' ][4 ], block ['indices' ][5 ]
26582664 print (a , b , f , d , O , H1 )
2659- for j in i ['xyz_guesses' ]:
2660- xyz_str = xyz_to_str (j )
2665+ for guess in block ['xyz_guesses' ]:
2666+ xyz_str = xyz_to_str (guess )
26612667 print (xyz_str )
26622668 print ()
26632669 distance_ab = (calculate_param (coords = initial_xyz ['coords' ], atoms = [b , a ])) * 1.3
2664- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [b , a ]), distance_ab , places = 0 )
2665- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [a , O ]), 1.8 , places = 0 )
2666- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [O , H1 ]), 1.21 , places = 0 )
2667- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [O , H1 + 1 ]), 0.97 , places = 0 )
2668- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [b , a , O ]), 78 , places = 0 )
2669- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [a , O , H1 ]), 70 , places = 0 )
2670- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [H1 , O , H1 + 1 ]), 111 , places = 0 )
2671- self .assertAlmostEqual (abs ((calculate_param (coords = j ['coords' ], atoms = [f , d , a , O ]) + 180 ) % 360 - 180 ),
2672- 108 , places = 0 )
2673- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [b , a , O , H1 ]),12 , places = 0 )
2674- self .assertAlmostEqual (
2675- abs ((calculate_param (coords = j ['coords' ], atoms = [a , H1 , O , H1 + 1 ]) + 180 ) % 360 - 180 ), 113 ,
2676- places = 0 )
2670+ self .check_distance (coords = guess ['coords' ], atoms = [b , a ], expected = distance_ab , places = 0 )
2671+ self .check_distance (coords = guess ['coords' ], atoms = [a , O ], expected = 1.8 , places = 0 )
2672+ self .check_distance (coords = guess ['coords' ], atoms = [O , H1 ], expected = 1.21 , places = 0 )
2673+ self .check_distance (coords = guess ['coords' ], atoms = [O , H1 + 1 ], expected = 0.97 , places = 0 )
2674+ self .check_angle (coords = guess ['coords' ], atoms = [b , a , O ], expected = 78 , delta = 5 )
2675+ self .check_angle (coords = guess ['coords' ], atoms = [a , O , H1 ], expected = 70 , delta = 5 )
2676+ self .check_angle (coords = guess ['coords' ], atoms = [H1 , O , H1 + 1 ], expected = 111 , delta = 5 )
2677+ self .check_dihedral (coords = guess ['coords' ], atoms = [f , d , a , O ], expected = 108 , delta = 5 )
2678+ self .check_dihedral (coords = guess ['coords' ], atoms = [b , a , O , H1 ], expected = 12 , delta = 5 )
2679+ self .check_dihedral (coords = guess ['coords' ], atoms = [a , H1 , O , H1 + 1 ], expected = 113 , delta = 5 )
26772680
26782681 def test_nitrile_hydrolysis (self ):
26792682 """Test nitrile hydrolysis reactions."""
@@ -2707,27 +2710,35 @@ def test_nitrile_hydrolysis(self):
27072710 families = [entry ['family' ] for entry in product_dicts ]
27082711 self .assertIn ('nitrile_hydrolysis' , families )
27092712 xyz_guesses_total , zmats_total = hydrolysis (tested_rxn )
2710- for i in xyz_guesses_total :
2711- a , b , f , O , H1 = i ['indices' ][0 ], i ['indices' ][1 ], i ['indices' ][2 ], i ['indices' ][4 ], i ['indices' ][5 ]
2712- print (i ['family' ])
2713- for j in i ['xyz_guesses' ]:
2714- xyz_str = xyz_to_str (j )
2713+ for block in xyz_guesses_total :
2714+ a , b , f , O , H1 = block ['indices' ][0 ], block ['indices' ][1 ], block ['indices' ][2 ], block ['indices' ][4 ], block ['indices' ][5 ]
2715+ print (block ['family' ])
2716+ for guess in block ['xyz_guesses' ]:
2717+ xyz_str = xyz_to_str (guess )
27152718 print (xyz_str )
27162719 print ()
27172720 distance_ab = (calculate_param (coords = initial_xyz ['coords' ], atoms = [b , a ])) * 1.1
2718- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [b , a ]), distance_ab , places = 2 )
2719- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [a , O ]), 1.8 , places = 2 )
2720- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [O , H1 ]), 1.21 , places = 2 )
2721- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [O , H1 + 1 ]), 0.97 , places = 2 )
2722- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [b , a , O ]), 97 , places = 1 )
2723- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [a , O , H1 ]), 58 , places = 1 )
2724- self .assertAlmostEqual (calculate_param (coords = j ['coords' ], atoms = [H1 , O , H1 + 1 ]), 111 , places = 1 )
2725- self .assertAlmostEqual (abs ((calculate_param (coords = j ['coords' ], atoms = [f , b , a , O ]) + 180 ) % 360 - 180 ),
2726- 174 , places = 1 )
2727- self .assertAlmostEqual ((calculate_param (coords = j ['coords' ], atoms = [b , a , O , H1 ]) + 180 ) % 360 - 180 , - 0.0154 , places = 1 )
2728- self .assertAlmostEqual (
2729- abs ((calculate_param (coords = j ['coords' ], atoms = [a , H1 , O , H1 + 1 ]) + 180 ) % 360 - 180 ), 104 ,
2730- places = 1 )
2721+ self .check_distance (coords = guess ['coords' ], atoms = [b , a ], expected = distance_ab , places = 0 )
2722+ self .check_distance (coords = guess ['coords' ], atoms = [a , O ], expected = 1.8 , places = 0 )
2723+ self .check_distance (coords = guess ['coords' ], atoms = [O , H1 ], expected = 1.21 , places = 0 )
2724+ self .check_distance (coords = guess ['coords' ], atoms = [O , H1 + 1 ], expected = 0.97 , places = 0 )
2725+ self .check_angle (coords = guess ['coords' ], atoms = [b , a , O ], expected = 97 , delta = 5 )
2726+ self .check_angle (coords = guess ['coords' ], atoms = [a , O , H1 ], expected = 58 , delta = 5 )
2727+ self .check_angle (coords = guess ['coords' ], atoms = [H1 , O , H1 + 1 ], expected = 111 , delta = 5 )
2728+ self .check_dihedral (coords = guess ['coords' ], atoms = [f , b , a , O ], expected = 174 , delta = 5 )
2729+ self .check_dihedral (coords = guess ['coords' ], atoms = [b , a , O , H1 ], expected = - 0.0154 , delta = 5 )
2730+ self .check_dihedral (coords = guess ['coords' ], atoms = [a , O , H1 , H1 + 1 ], expected = 104 , delta = 5 )
2731+
2732+ @classmethod
2733+ def tearDownClass (cls ):
2734+ """
2735+ A function that is run ONCE after all unit tests in this class.
2736+ Delete all project directories created during these unit tests.
2737+ """
2738+ shutil .rmtree (os .path .join (ARC_PATH , 'arc' , 'testing' , 'heuristics' ), ignore_errors = True )
2739+ shutil .rmtree (os .path .join (ARC_PATH , 'arc' , 'testing' , 'heuristics_1' ), ignore_errors = True )
2740+
2741+
27312742
27322743if __name__ == '__main__' :
27332744 unittest .main (testRunner = unittest .TextTestRunner (verbosity = 2 ))
0 commit comments