Skip to content

Commit

Permalink
Add primitives if missing
Browse files Browse the repository at this point in the history
  • Loading branch information
t-young31 committed Nov 15, 2022
1 parent 268d640 commit 7d74791
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
6 changes: 6 additions & 0 deletions autode/opt/coordinates/cartesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,9 @@ def to(self, value: str) -> OptCoordinates:
raise ValueError(
f"Cannot convert Cartesian coordinates to {value}"
)

@property
def expected_number_of_dof(self) -> int:
"""Expected number of degrees of freedom for the system"""
n_atoms = len(self.flatten()) // 3
return 3 * n_atoms - 6
2 changes: 1 addition & 1 deletion autode/opt/coordinates/dic.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _calc_U(primitives: PIC, x: "CartesianCoordinates") -> np.ndarray:
# of 3N - 6 non-redundant internals for a system of N atoms
idxs = np.where(np.abs(lambd) > 1e-10)[0]

if len(idxs) < (len(x.flatten()) - 6):
if len(idxs) < x.expected_number_of_dof:
raise RuntimeError(
"Failed to create a complete set of delocalised internal "
f"coordinates. {len(idxs)} < 3 N_atoms - 6. Likely due to "
Expand Down
14 changes: 13 additions & 1 deletion autode/opt/optimisers/crfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,20 @@ def _build_internal_coordinates(self):
)

cartesian_coords = CartesianCoordinates(self._species.coordinates)
primitives = self._primitives

if len(primitives) < cartesian_coords.expected_number_of_dof:
logger.info(
"Had an incomplete set of primitives. Adding "
"additional distances"
)
for i, j in itertools.combinations(
range(self._species.n_atoms), 2
):
primitives.append(Distance(i, j))

self._coords = DICWithConstraints.from_cartesian(
x=cartesian_coords, primitives=self._primitives
x=cartesian_coords, primitives=primitives
)
self._coords.zero_lagrangian_multipliers()
return None
Expand Down

0 comments on commit 7d74791

Please sign in to comment.