Skip to content

Commit

Permalink
vector updates + linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalbam1 committed Jul 11, 2024
1 parent c1d222a commit 6eccdcc
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 43 deletions.
97 changes: 54 additions & 43 deletions automol/util/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ def unit_direction(xyz1: Sequence | np.ndarray, xyz2: Sequence | np.ndarray) ->
return uxyz12


def are_parallel( xyz1: Sequence | np.ndarray, xyz2: Sequence | np.ndarray,
orig_xyz: Sequence | np.ndarray = (0.0, 0.0, 0.0),anti: bool = False,
tol: float = 1e-3,
def are_parallel(
xyz1: Sequence | np.ndarray,
xyz2: Sequence | np.ndarray,
orig_xyz: Sequence | np.ndarray = (0.0, 0.0, 0.0),
anti: bool = False,
tol: float = 1e-3,
) -> bool:
"""Assess if two vectors are parallel to each other.
Expand Down Expand Up @@ -77,7 +80,7 @@ def orthogonalize(xyz1, xyz2, normalize=False):
return oxyz2


def flip_if_left_handed(xvec:Vector, yvec:Vector, zvec:Vector) -> Vector:
def flip_if_left_handed(xvec: Vector, yvec: Vector, zvec: Vector) -> Vector:
"""Given three vectors, flips the third one, if necessary, to make a right-handed
coordinate system.
Expand All @@ -96,7 +99,7 @@ def flip_if_left_handed(xvec:Vector, yvec:Vector, zvec:Vector) -> Vector:
return tuple(map(float, zvec))


def best_unit_perpendicular(xyzs:list[Vector]):
def best_unit_perpendicular(xyzs: list[Vector]):
"""Find a vector that is perpendicular to a series of points as much as possible.
For 1 point, this is an arbitrary vector.
Expand Down Expand Up @@ -161,8 +164,12 @@ def unit_perpendicular(
return uxyz3


def unit_bisector(xyz1: Sequence | np.ndarray , xyz2: Sequence | np.ndarray,
orig_xyz: Sequence | np.ndarray, outer: bool = False) -> np.ndarray:
def unit_bisector(
xyz1: Sequence | np.ndarray,
xyz2: Sequence | np.ndarray,
orig_xyz: Sequence | np.ndarray,
outer: bool = False,
) -> np.ndarray:
"""Calculate a unit bisector.
:param xyz1: 3D vector
Expand All @@ -184,12 +191,13 @@ def unit_bisector(xyz1: Sequence | np.ndarray , xyz2: Sequence | np.ndarray,


def from_internals(
dist: float=0.0,
xyz1: Sequence|np.ndarray =(0.0, 0.0, 0.0),
ang: float=0.0,
xyz2: Sequence | np.ndarray=(0.0, 0.0, 1.0),
dih: float=0.0,
xyz3: Sequence | np.ndarray=(0.0, 1.0, 0.0)) -> tuple [float] :
dist: float = 0.0,
xyz1: Sequence | np.ndarray = (0.0, 0.0, 0.0),
ang: float = 0.0,
xyz2: Sequence | np.ndarray = (0.0, 0.0, 1.0),
dih: float = 0.0,
xyz3: Sequence | np.ndarray = (0.0, 1.0, 0.0),
) -> tuple[float]:
"""Determine the position of a point (xyz4) in Cartesian coordinates whose
position is related to three other points (xyz1, xyz2, xyz3) via a set
of internal coordinates.
Expand All @@ -208,7 +216,9 @@ def from_internals(
return xyz4


def _local_position(dist:float =0.0, ang: float =0.0, dih: float=0.0)-> tuple[float]:
def _local_position(
dist: float = 0.0, ang: float = 0.0, dih: float = 0.0
) -> tuple[float]:
"""Determine the xyz coordinates of a point in the local axis frame
defined by a set of internal coordinates.
Expand All @@ -225,9 +235,10 @@ def _local_position(dist:float =0.0, ang: float =0.0, dih: float=0.0)-> tuple[fl


def _local_axes(
xyz1: Sequence | np.ndarray=(0.0, 0.0, 0.0),
xyz2: Sequence | np.ndarray=(0.0, 0.0, 1.0),
xyz3: Sequence | np.ndarray=(0.0, 1.0, 0.0)) -> tuple[float]:
xyz1: Sequence | np.ndarray = (0.0, 0.0, 0.0),
xyz2: Sequence | np.ndarray = (0.0, 0.0, 1.0),
xyz3: Sequence | np.ndarray = (0.0, 1.0, 0.0),
) -> tuple[float]:
"""Determine the local axes for defining bond, angle, dihedral from
the Cartesian coordinates of three support atoms.
Expand All @@ -246,7 +257,7 @@ def _local_axes(
return (x_ax, y_ax, z_ax)


def distance(xyz1: Sequence | np.ndarray, xyz2: Sequence | np.ndarray)->float:
def distance(xyz1: Sequence | np.ndarray, xyz2: Sequence | np.ndarray) -> float:
"""Measure the distance between points.
:param xyz1: 3D vector to point 1
Expand All @@ -258,15 +269,17 @@ def distance(xyz1: Sequence | np.ndarray, xyz2: Sequence | np.ndarray)->float:
return dist


def angle(xyz1: Sequence | np.ndarray,
xyz2: Sequence | np.ndarray,
orig_xyz: Sequence | np.ndarray=(0.0, 0.0, 0.0))-> float:
def angle(
xyz1: Sequence | np.ndarray,
xyz2: Sequence | np.ndarray,
orig_xyz: Sequence | np.ndarray = (0.0, 0.0, 0.0),
) -> float:
"""Measure the angle inscribed by three atoms.
:param xyz1: 3D vector to point 1
:param xyz2: 3D vector to point 2
:param xyz3: 3D vector to point 3
:Note: there is no xyz3
:Note: there is no xyz3
:param orig_xyz: Origin of coordinate system `xyz1` and `xyz2` are in
:return: Angle between three atoms
"""
Expand All @@ -283,9 +296,11 @@ def angle(xyz1: Sequence | np.ndarray,
return ang


def central_angle(xyz1: Sequence | np.ndarray,
xyz2: Sequence | np.ndarray,
xyz3: Sequence | np.ndarray)-> float:
def central_angle(
xyz1: Sequence | np.ndarray,
xyz2: Sequence | np.ndarray,
xyz3: Sequence | np.ndarray,
) -> float:
"""Measure the angle inscribed by three atoms.
:param xyz1: 3D vector to point 1
Expand All @@ -296,17 +311,18 @@ def central_angle(xyz1: Sequence | np.ndarray,
return angle(xyz1=xyz1, xyz2=xyz3, orig_xyz=xyz2)


def projected_central_angle(xyz1, xyz2, xyz3):
def projected_central_angle(
xyz1: Sequence | np.ndarray,
xyz2: Sequence | np.ndarray,
xyz3: Sequence | np.ndarray,
) -> float:
"""Measure the angle inscribed by three atoms,
projected onto the normal plane of the central atom.
:param xyz1: 3D vector to point 1
:type xyz1: tuple, list, or numpy nd.array
:param xyz2: 3D vector to point 2
:type xyz2: tuple, list, or numpy nd.array
:param xyz3: 3D vector to point 3
:type xyz3: tuple, list, or numpy nd.array
:rtype: float
:return: Angle projected on normal plane
"""
uxyz21 = unit_perpendicular(xyz2, xyz1)
uxyz23 = unit_perpendicular(xyz2, xyz3)
Expand All @@ -321,18 +337,19 @@ def projected_central_angle(xyz1, xyz2, xyz3):
return ang


def dihedral_angle(xyz1, xyz2, xyz3, xyz4):
def dihedral_angle(
xyz1: Sequence | np.ndarray,
xyz2: Sequence | np.ndarray,
xyz3: Sequence | np.ndarray,
xyz4: Sequence | np.ndarray,
) -> float:
"""Measure the dihedral angle defined by four atoms.
:param xyz1: 3D vector to point 1
:type xyz1: tuple, list, or numpy nd.array
:param xyz2: 3D vector to point 2
:type xyz2: tuple, list, or numpy nd.array
:param xyz3: 3D vector to point 3
:type xyz3: tuple, list, or numpy nd.array
:param xyz4: 3D vector to point 4
:type xyz4: tuple, list, or numpy nd.array
:rtype: float
:return: Dihedral angle of four atoms
"""
# Get the cosine of the angle
uxyz21 = unit_direction(xyz2, xyz1)
Expand Down Expand Up @@ -369,15 +386,9 @@ def rotator(
"""Get a function for axis-angle rotations, optionally specifying the origin.
:param axis: Rotational axis (norm is ignored)
:type axis: Vector
:param ang: Rotational angle
:type ang: float
:param degree: _description_, defaults to False
:type degree: bool, optional
:param orig_xyz: _description_, defaults to None
:type orig_xyz: Optional[Vector], optional
:return: _description_
:rtype: Callable[[Vector], Vector]
"""
orig_xyz = np.array([0.0, 0.0, 0.0] if orig_xyz is None else orig_xyz)
ang = ang * phycon.DEG2RAD if degree else ang
Expand All @@ -394,7 +405,7 @@ def rotate_(xyz: Vector) -> Vector:


# I/O
def string(vec, num_per_row=None, val_format="{0:>8.3f}"):
def string(vec:Sequence | np.ndarray, num_per_row=None, val_format="{0:>8.3f}")->str:
"""Write a vector to a string.
:param vec: vector to form string with
Expand Down
4 changes: 4 additions & 0 deletions docs/source/automol/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ some words
## automol.util.tensor
```{eval-rst}
.. automodule:: automol.util.tensor
```
## automol.util.vector
```{eval-rst}
.. automodule:: automol.util.vector
```

0 comments on commit 6eccdcc

Please sign in to comment.