-
Notifications
You must be signed in to change notification settings - Fork 24
Added combininig xyz's based on internal coordinates #799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
These classes unify the concept of internal coordinates and their parameters for adding to the zmat.
This function ensures that the coordinates are consistent with zmat requirements.
| from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, Tuple, Union | ||
| from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Tuple, Union | ||
| from copy import deepcopy | ||
| from arc.species.ic_params import Atom1Params, Atom2Params, Atom3Params, ParamKey |
Check notice
Code scanning / CodeQL
Unused import Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
The best way to fix the unused import problem is to remove ParamKey from the import list on line 10 in arc/species/converter.py. The other imports from arc.species.ic_params should remain if they are used elsewhere. Only edit the import statement itself; do not change the rest of the code, as there is no indication that it relies on ParamKey.
-
Copy modified line R10
| @@ -7,7 +7,7 @@ | ||
| import os | ||
| from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Tuple, Union | ||
| from copy import deepcopy | ||
| from arc.species.ic_params import Atom1Params, Atom2Params, Atom3Params, ParamKey | ||
| from arc.species.ic_params import Atom1Params, Atom2Params, Atom3Params | ||
|
|
||
| from ase import Atoms | ||
| from openbabel import openbabel as ob |
| get_parameter_from_atom_indices, | ||
| zmat_to_coords, | ||
| xyz_to_zmat) | ||
| xyz_to_zmat, |
Check failure
Code scanning / CodeQL
Module-level cyclic import Error
arc.species.zmat
arc.species.converter
definition
import
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
The best way to break the module-level cyclic import is to replace the module-level import of xyz_to_zmat (and possibly related functions from arc.species.zmat) within arc/species/converter.py with a local import inside the functions where it's needed (i.e., a function-level import). This ensures that the import is only executed when the function is called and the importing module has already completed initialization, thus avoiding the cyclic import problem.
Specifically, in arc/species/converter.py, wherever xyz_to_zmat or other items from arc.species.zmat are actually used, remove them from the module-level imports (lines 34–41). Instead, inside each relevant function, add from arc.species.zmat import xyz_to_zmat (and any other function needed) just before they are used.
To implement this, update lines 34–41, removing the imports of functions affected by the cyclic dependency, and add the appropriate local imports inside the functions (e.g., inside any function that calls xyz_to_zmat). Ensure that only the needed functions are imported; do not move all imports unless all are needed in that function.
-
Copy modified line R34
| @@ -31,14 +31,7 @@ | ||
| from arc.molecule.molecule import Atom, Bond, Molecule | ||
| from arc.molecule.resonance import generate_resonance_structures_safely | ||
| from arc.species.perceive import perceive_molecule_from_xyz | ||
| from arc.species.zmat import (KEY_FROM_LEN, | ||
| _compare_zmats, | ||
| get_all_neighbors, | ||
| get_atom_indices_from_zmat_parameter, | ||
| get_parameter_from_atom_indices, | ||
| zmat_to_coords, | ||
| xyz_to_zmat, | ||
| check_zmat_vs_coords,) | ||
| # The following imports were moved to inside the functions where needed to prevent cyclic imports. | ||
|
|
||
| if TYPE_CHECKING: | ||
| from arc.species.species import ARCSpecies |
| zmat_to_coords, | ||
| xyz_to_zmat) | ||
| xyz_to_zmat, | ||
| check_zmat_vs_coords,) |
Check failure
Code scanning / CodeQL
Module-level cyclic import Error
arc.species.zmat
arc.species.converter
definition
import
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
General approach:
To break the module-level cyclic import between arc.species.converter and arc.species.zmat, we should prevent at least one of the modules from importing the other at the module level. The most common, safe fix is to move the import statement for check_zmat_vs_coords (and any others causing the cycle) inside the function(s) where they are actually needed (a local import). This ensures that the import only happens when the function is called, well after the modules involved are fully initialized, thus breaking the cycle.
Detailed fix for this file:
- In
arc/species/converter.py, removecheck_zmat_vs_coordsfrom the module-level import on line 41. - For each function in this file that needs
check_zmat_vs_coords, add a local import at the top of the function body:
from arc.species.zmat import check_zmat_vs_coords - This achieves the same functionality with no change to API or results, but eliminates the cyclic import problem.
- Only edit code and imports shown in the provided snippet.
- Do not assume which specific functions use
check_zmat_vs_coords; add local imports only in those where it is referenced. - Do not edit other imports unless they also refer to objects from
arc.species.zmatwhich are part of the cycle, i.e., only movecheck_zmat_vs_coordsas per the warning.
-
Copy modified line R41
| @@ -38,7 +38,7 @@ | ||
| get_parameter_from_atom_indices, | ||
| zmat_to_coords, | ||
| xyz_to_zmat, | ||
| check_zmat_vs_coords,) | ||
| ) | ||
|
|
||
| if TYPE_CHECKING: | ||
| from arc.species.species import ARCSpecies | ||
| @@ -223,7 +223,6 @@ | ||
| return x, y, z | ||
|
|
||
|
|
||
| def xyz_to_coords_list(xyz_dict: dict) -> Optional[List[List[float]]]: | ||
| """ | ||
| Get the coords part of an xyz dict as a (mutable) list of lists (rather than a tuple of tuples). | ||
|
|
| 'coords': ((0.0, 0.0, 0.0), | ||
| (0.758602, 0.584882, 0.0), | ||
| (-0.758602, 0.584882, 0.0))} | ||
| combined_xyz = converter.add_two_xyzs(xyz1=xyz1, |
Check notice
Code scanning / CodeQL
Unused local variable Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
To fix the problem, remove the unused variable assignment to combined_xyz on line 4832, keeping the function call itself if side effects are required (which is rare in a test context and there's no evidence of necessity here). Since the following lines do not reference combined_xyz, and the assertion is commented out, removing the left-hand side of the assignment is sufficient. Edit only the relevant lines in arc/species/converter_test.py, deleting the assignment or just the variable on the left if the function call should still run.
-
Copy modified lines R4832-R4859
| @@ -4829,34 +4829,34 @@ | ||
| 'coords': ((0.0, 0.0, 0.0), | ||
| (0.758602, 0.584882, 0.0), | ||
| (-0.758602, 0.584882, 0.0))} | ||
| combined_xyz = converter.add_two_xyzs(xyz1=xyz1, | ||
| xyz2=xyz2, | ||
| atom1_params= {"R": {"val": 5.0, | ||
| "m2i": [0], | ||
| "m1i": [0], | ||
| }, | ||
| "A": {"val": 90.0, | ||
| "m2i": [0], | ||
| "m1i": [0, 1], | ||
| }, | ||
| "D": {"val": 90.0, | ||
| "m2i": [0], | ||
| "m1i": [0, 1, 2], | ||
| } | ||
| }, | ||
| atom2_params={"A": {"val": 90.0, | ||
| "m2i": [1], | ||
| "m1i": [0, 1],}, | ||
| "D" : {"val": 90.0, | ||
| "m2i": [1], | ||
| "m1i": [0, 1, 2],} | ||
| }, | ||
| atom3_params={"D": {"val": 90.0, | ||
| "m2i": [2], | ||
| "m1i": [0, 1, 2],} | ||
| }, | ||
| return_zmat=False, | ||
| ) | ||
| converter.add_two_xyzs(xyz1=xyz1, | ||
| xyz2=xyz2, | ||
| atom1_params= {"R": {"val": 5.0, | ||
| "m2i": [0], | ||
| "m1i": [0], | ||
| }, | ||
| "A": {"val": 90.0, | ||
| "m2i": [0], | ||
| "m1i": [0, 1], | ||
| }, | ||
| "D": {"val": 90.0, | ||
| "m2i": [0], | ||
| "m1i": [0, 1, 2], | ||
| } | ||
| }, | ||
| atom2_params={"A": {"val": 90.0, | ||
| "m2i": [1], | ||
| "m1i": [0, 1],}, | ||
| "D" : {"val": 90.0, | ||
| "m2i": [1], | ||
| "m1i": [0, 1, 2],} | ||
| }, | ||
| atom3_params={"D": {"val": 90.0, | ||
| "m2i": [2], | ||
| "m1i": [0, 1, 2],} | ||
| }, | ||
| return_zmat=False, | ||
| ) | ||
|
|
||
|
|
||
| # self.assertTrue(almost_equal_coords_lists(combined_xyz, expected_combined_xyz)) |
| combined_xyz = converter.add_two_xyzs(xyz1=xyz1, | ||
| xyz2=xyz2, | ||
| atom1_params= {"R": {"val": 5.0, | ||
| "m2i": [0], | ||
| "m1i": [0], | ||
| }, | ||
| "A": {"val": 90.0, | ||
| "m2i": [0], | ||
| "m1i": [0, 1], | ||
| }, | ||
| "D": {"val": 90.0, | ||
| "m2i": [0], | ||
| "m1i": [0, 1, 2], | ||
| } | ||
| }, | ||
| atom2_params={"A": {"val": 90.0, | ||
| "m2i": [1], | ||
| "m1i": [0, 1],}, | ||
| "D" : {"val": 90.0, | ||
| "m2i": [1], | ||
| "m1i": [0, 1, 2],} | ||
| }, | ||
| atom3_params={"D": {"val": 90.0, | ||
| "m2i": [2], | ||
| "m1i": [0, 1, 2],} | ||
| }, | ||
| return_zmat=False, | ||
| ) |
Check failure
Code scanning / CodeQL
Wrong name for an argument in a call Error
function add_two_xyzs
Keyword argument 'atom2_params' is not a supported parameter name of
function add_two_xyzs
Keyword argument 'atom3_params' is not a supported parameter name of
function add_two_xyzs
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
To fix the error, we need to ensure that the keyword arguments passed to add_two_xyzs correspond to its actual function signature. The test passes atom1_params, atom2_params, and atom3_params, but the function apparently does not expect atom1_params as a parameter. The single best way to fix this, without changing functionality, is to rename the keyword arguments in the test to match the signature of add_two_xyzs (as defined in arc/species/converter.py).
Assuming that the function expects parameters named atom1_param, atom2_param, and atom3_param (singular), we should update the call accordingly. Review the function signature in converter.py (even though not shown here), and update the names in the test to match the function parameters. Only lines 4832, 4834, 4847, and 4854 are affected in the test.
No new imports or code definitions are required.
-
Copy modified line R4834 -
Copy modified line R4847 -
Copy modified line R4854
| @@ -4831,7 +4831,7 @@ | ||
| (-0.758602, 0.584882, 0.0))} | ||
| combined_xyz = converter.add_two_xyzs(xyz1=xyz1, | ||
| xyz2=xyz2, | ||
| atom1_params= {"R": {"val": 5.0, | ||
| atom1_param= {"R": {"val": 5.0, | ||
| "m2i": [0], | ||
| "m1i": [0], | ||
| }, | ||
| @@ -4844,14 +4844,14 @@ | ||
| "m1i": [0, 1, 2], | ||
| } | ||
| }, | ||
| atom2_params={"A": {"val": 90.0, | ||
| atom2_param={"A": {"val": 90.0, | ||
| "m2i": [1], | ||
| "m1i": [0, 1],}, | ||
| "D" : {"val": 90.0, | ||
| "m2i": [1], | ||
| "m1i": [0, 1, 2],} | ||
| }, | ||
| atom3_params={"D": {"val": 90.0, | ||
| atom3_param={"D": {"val": 90.0, | ||
| "m2i": [2], | ||
| "m1i": [0, 1, 2],} | ||
| }, |
This PR includes: