|
44 | 44 | ob.obErrorLog.SetOutputLevel(0) |
45 | 45 | logger = get_logger() |
46 | 46 |
|
| 47 | +DIST_PRECISION = 0.01 # Angstrom |
| 48 | +ANGL_PRECISION = 0.1 # rad (for both bond angle and dihedral) |
| 49 | + |
47 | 50 |
|
48 | 51 | def str_to_xyz(xyz_str: str, |
49 | 52 | project_directory: Optional[str] = None, |
@@ -2074,7 +2077,7 @@ def calculate_errors(result_coords): |
2074 | 2077 |
|
2075 | 2078 | def meets_precision(result_coords): |
2076 | 2079 | r_error, a_error, d_error = calculate_errors(result_coords) |
2077 | | - return r_error < 0.01 and a_error < 0.1 and d_error < 0.1 |
| 2080 | + return r_error < DIST_PRECISION and a_error < ANGL_PRECISION and d_error < ANGL_PRECISION |
2078 | 2081 |
|
2079 | 2082 | guess_functions = [ |
2080 | 2083 | generate_initial_guess_r_a, |
@@ -2262,7 +2265,9 @@ def angle_eq(x, y, z): |
2262 | 2265 | cross_product_length = np.linalg.norm(np.cross(BA, BX)) |
2263 | 2266 | dot_product = np.dot(BA, BX) |
2264 | 2267 | calc_angle = math.atan2(cross_product_length, dot_product) |
2265 | | - return (calc_angle - target_angle) ** 2 |
| 2268 | + angle_diff = calc_angle - target_angle |
| 2269 | + wrapped_diff = np.arctan2(np.sin(angle_diff), np.cos(angle_diff)) # wrapped to the range (-pi, pi] |
| 2270 | + return wrapped_diff |
2266 | 2271 |
|
2267 | 2272 | return angle_eq |
2268 | 2273 |
|
@@ -2310,7 +2315,7 @@ def dihedral_eq(x, y, z): |
2310 | 2315 | BC_norm = np.linalg.norm(BC) |
2311 | 2316 | cos_calc = np.dot(N1, N2) / (N1_norm * N2_norm) |
2312 | 2317 | sin_calc = np.dot(BC, np.cross(N1, N2)) / (BC_norm * N1_norm * N2_norm) |
2313 | | - return (cos_calc - cos_d) ** 2 + (sin_calc - sin_d) ** 2 |
| 2318 | + return np.sqrt((cos_calc - cos_d) ** 2 + (sin_calc - sin_d) ** 2) |
2314 | 2319 |
|
2315 | 2320 | return dihedral_eq |
2316 | 2321 |
|
|
0 commit comments