Skip to content

Commit

Permalink
Added basic coordinate array distance geometry methods
Browse files Browse the repository at this point in the history
  • Loading branch information
timbernat committed Apr 24, 2024
1 parent 2b1ad88 commit 40ee085
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion polymerist/maths/lattices.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,30 @@
import numpy as np
from itertools import product as cartesian_product

from ..genutils.typetools.numpytypes import Shape, N
from ..genutils.typetools.numpytypes import Shape, N, M, DType


# COORDINATE ARRAY OPERATIONS
def mean_coord(coords : np.ndarray[Shape[M, N], DType]) -> np.ndarray[Shape[N], DType]:
'''The average (center-of-mass) coordinate of a vector of coordinates'''
return coords.mean(axis=0)
center_of_mass = COM = mean_coord

def dists_to_point(coords : np.ndarray[Shape[M, N], DType], point : np.ndarray[Shape[N], DType], norm_order : Optional[int]=None) -> np.ndarray[Shape[M], DType]:
'''The distance between each point in a coordinate array and a single arbitrary point'''
return np.linalg.norm(coords - point, ord=norm_order, axis=1)

def dists_to_centroid(coords : np.ndarray[Shape[M, N], DType], norm_order : Optional[int]=None) -> np.ndarray[Shape[M], DType]:
'''The distance of each coordinate in an array of coordinates to the coordinates' centroid'''
return dists_to_point(coords, point=mean_coord(coords), norm_order=norm_order)

def bounding_box_extrema(coords : np.ndarray[Shape[M, N], DType]) -> np.ndarray[Shape[2, N], DType]:
'''The minimal and maximal coordinates of the tight bounding box around an array of coordinate'''
return coords.min(axis=0), coords.max(axis=0)

def bounding_box_dims(coords : np.ndarray[Shape[M, N], DType]) -> np.ndarray[Shape[N], DType]:
'''The tight bounding box side lengths around an array of coordinates'''
return coords.ptp(axis=0)


# INTEGER LATTICES (UNIT BASIS SUPERCELLS)
Expand Down

0 comments on commit 40ee085

Please sign in to comment.