Skip to content
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

More comprehensive primitive generation #314

Merged
merged 47 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
7601834
initial commit
shoubhikraj Dec 11, 2023
b3e4b3a
second commit
shoubhikraj Dec 13, 2023
31659ee
second commit
shoubhikraj Dec 13, 2023
0a88af7
simplify code
shoubhikraj Dec 14, 2023
a261052
linear angle
shoubhikraj Dec 14, 2023
5453082
linear angle
shoubhikraj Dec 14, 2023
d46415c
test update, more fixes needed
shoubhikraj Dec 17, 2023
994e14a
unifinished update
shoubhikraj Dec 18, 2023
cf7de52
linear angle update
shoubhikraj Dec 18, 2023
30f1fc8
unfinished update
shoubhikraj Dec 18, 2023
d025602
unfinished update
shoubhikraj Dec 18, 2023
865ba19
unifinished update
shoubhikraj Dec 19, 2023
f72d68e
unfinished update
shoubhikraj Dec 20, 2023
e5859b5
better linear angles
shoubhikraj Dec 20, 2023
0fc99bb
better linear angles
shoubhikraj Dec 20, 2023
d561f9b
minor change
shoubhikraj Dec 20, 2023
d2a768b
fix linear bend code
shoubhikraj Dec 21, 2023
5f97251
fix some tests
shoubhikraj Dec 21, 2023
b176e3a
add tests
shoubhikraj Dec 21, 2023
0757cda
fix failing test
shoubhikraj Dec 21, 2023
de52e9e
add tests
shoubhikraj Dec 22, 2023
40abfd7
minor dihedral fix
shoubhikraj Dec 22, 2023
f600b3c
dihedral code fix
shoubhikraj Dec 22, 2023
113f621
add test for linear bend with ref
shoubhikraj Dec 22, 2023
902aa74
add test for linear bend with ref
shoubhikraj Dec 22, 2023
de46ccc
add tests
shoubhikraj Dec 23, 2023
bbe1f14
make bond angle consistent
shoubhikraj Dec 23, 2023
c1a90fe
add tests and fix value bug
shoubhikraj Dec 25, 2023
f2e5f65
add tests
shoubhikraj Dec 25, 2023
3e826c9
fix test
shoubhikraj Dec 25, 2023
483fbe6
change backup hessian update scheme for crfo
shoubhikraj Dec 27, 2023
46ce93a
revert change to hessian update scheme
shoubhikraj Dec 27, 2023
acddba4
correction to angle code
shoubhikraj Dec 28, 2023
05305b0
assert only for graph
shoubhikraj Dec 28, 2023
a18f9d2
fix tests
shoubhikraj Dec 28, 2023
800089b
pr suggestions 1
shoubhikraj Dec 29, 2023
e51ca4d
pr suggestions 2 partial
shoubhikraj Dec 30, 2023
7fa4454
test fix
shoubhikraj Dec 30, 2023
6887a87
put methods into anypic class
shoubhikraj Dec 30, 2023
cff5079
pr update 3
shoubhikraj Dec 30, 2023
32ddb13
pr update 4
shoubhikraj Dec 30, 2023
d6fabb4
pr update 5
shoubhikraj Dec 31, 2023
239c08a
pr update 6
shoubhikraj Dec 31, 2023
16282cb
pr update 7
shoubhikraj Dec 31, 2023
3943421
pr update 8
shoubhikraj Jan 1, 2024
2547c03
pr update
shoubhikraj Jan 1, 2024
f8187e8
pr update, changelog update
shoubhikraj Jan 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions autode/atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,9 +1041,10 @@ def angle(self, i: int, j: int, k: int) -> Angle:
f"least one zero vector"
)

value = np.arccos(np.dot(vec1, vec2) / norms)
# Cos(theta) must lie within [-1, 1]
cos_value = np.clip(np.dot(vec1, vec2) / norms, a_min=-1, a_max=1)

return Angle(value)
return Angle(np.arccos(cos_value))

def dihedral(self, w: int, x: int, y: int, z: int) -> Angle:
r"""
Expand Down
9 changes: 9 additions & 0 deletions autode/mol_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ def node_matcher(self):

return matcher

@property
def is_connected(self) -> bool:
"""Is this graph fully connected (i.e. not separate parts)"""
return nx.is_connected(self)

def connected_components(self):
"""Generate the separate connected components"""
return nx.connected_components(self)


def make_graph(
species: "Species",
Expand Down
2 changes: 1 addition & 1 deletion autode/opt/coordinates/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from autode.opt.coordinates.base import OptCoordinates, CartesianComponent
from autode.opt.coordinates.base import OptCoordinates
from autode.opt.coordinates.cartesian import CartesianCoordinates
from autode.opt.coordinates.dic import DIC, DICWithConstraints
31 changes: 24 additions & 7 deletions autode/opt/coordinates/_autodiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,9 @@ class DifferentiableVector3D:
hyper-dual numbers
"""

def __init__(self, items: Sequence["VectorHyperDual"]):
def __init__(
self, items: Sequence[Union["VectorHyperDual", numeric_type]]
):
"""
Initialise the 3D vector from a list of 3 hyperdual numbers

Expand All @@ -590,7 +592,9 @@ def __init__(self, items: Sequence["VectorHyperDual"]):
items = list(items)
if len(items) != 3:
raise ValueError("A 3D vector must have only 3 components")
assert all(isinstance(item, VectorHyperDual) for item in items)
assert all(
isinstance(item, (VectorHyperDual, *numeric)) for item in items
)
self._data = items

@staticmethod
Expand All @@ -600,7 +604,9 @@ def _check_same_type(other) -> None:
raise ValueError("Operation must be done with another 3D vector!")
return None

def dot(self, other: "DifferentiableVector3D") -> "VectorHyperDual":
def dot(
self, other: "DifferentiableVector3D"
) -> Union["VectorHyperDual", numeric_type]:
"""
Dot product of two 3D vectors

Expand All @@ -611,13 +617,12 @@ def dot(self, other: "DifferentiableVector3D") -> "VectorHyperDual":
(VectorHyperDual): A scalar number (with derivatives)
"""
self._check_same_type(other)
dot = 0
dot: Union[VectorHyperDual, numeric_type] = 0
for k in range(3):
dot = dot + self._data[k] * other._data[k]
assert isinstance(dot, VectorHyperDual)
return dot

def norm(self) -> "VectorHyperDual":
def norm(self) -> Union["VectorHyperDual", numeric_type]:
"""
Euclidean (l2) norm of this 3D vector

Expand All @@ -627,7 +632,6 @@ def norm(self) -> "VectorHyperDual":
norm = DifferentiableMath.sqrt(
self._data[0] ** 2 + self._data[1] ** 2 + self._data[2] ** 2
)
assert isinstance(norm, VectorHyperDual)
return norm

def __add__(
Expand Down Expand Up @@ -690,6 +694,18 @@ def __rmul__(self, other):
"""Multiplication of scalar and vector is commutative"""
return self.__mul__(other)

def __truediv__(self, other: Union[VectorHyperDual, numeric_type]):
"""
Division of a 3D vector with a scalar

Args:
other (VectorHyperDual|float|int):

Returns:
(DifferentiableVector3D):
"""
return self.__mul__(1 / other)

def cross(
self, other: "DifferentiableVector3D"
) -> "DifferentiableVector3D":
Expand All @@ -702,6 +718,7 @@ def cross(
Returns:
(DifferentiableVector3D):
"""
self._check_same_type(other)
return DifferentiableVector3D(
[
self._data[1] * other._data[2]
Expand Down
10 changes: 0 additions & 10 deletions autode/opt/coordinates/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# mypy: disable-error-code="has-type"
import numpy as np
from copy import deepcopy
from enum import IntEnum, unique
from typing import Optional, Union, Sequence, List, TYPE_CHECKING
from abc import ABC, abstractmethod

Expand All @@ -15,15 +14,6 @@
from autode.hessians import Hessian


@unique
class CartesianComponent(IntEnum):
"""Cartesian component in 3D space"""

x = 0
y = 1
z = 2


class OptCoordinates(ValueArray, ABC):
"""Coordinates used to perform optimisations"""

Expand Down
Loading