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

Molecule Measurements #27

Merged
merged 3 commits into from
Feb 5, 2019
Merged

Molecule Measurements #27

merged 3 commits into from
Feb 5, 2019

Conversation

dgasmith
Copy link
Collaborator

@dgasmith dgasmith commented Feb 4, 2019

Adds several routines for computing distances, angles, and dihedrals within QCElemental. In addition adds a Molecule.measure command to check internal values.

@dgasmith dgasmith added the Enhancement Project enhancement discussion label Feb 4, 2019
@codecov
Copy link

codecov bot commented Feb 4, 2019

Codecov Report

Merging #27 into master will decrease coverage by 0.05%.
The diff coverage is 95.45%.

"""

tmp = np.atleast_2d(points)
return np.sqrt(np.einsum("ij,ij->i", tmp, tmp))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not duplicating

def distance_matrix(a, b):
"""Euclidean distance matrix between rows of arrays `a` and `b`. Equivalent to
`scipy.spatial.distance.cdist(a, b, 'euclidean')`. Returns a.shape[0] x b.shape[0] array.
"""
assert a.shape[1] == b.shape[1], """Inner dimensions do not match"""
distm = np.zeros([a.shape[0], b.shape[0]])
for i in range(a.shape[0]):
distm[i] = np.linalg.norm(a[i] - b, axis=1)
return distm
, is it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is just a fast norm equivalent to np.linalg.norm(arr, axis=1). Somewhat meaningless, but something I often do.


def measure_coordinates(coordinates, measurements, degrees=False):
"""
Measures a geometry array based on indices provided, automatically detects distance, angle,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"0-based indices"

points3 : np.ndarray
The third list of points, can be 1D or 2D
degrees : bool, options
Returns the angle in degress rather than radians if True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"degrees" (ditto in dihedral)

Copy link
Collaborator

@Lnaden Lnaden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than @loriab's remarks, I think this is pretty slick.

@@ -228,6 +228,13 @@ def json(self, *args, **kwargs):

### Non-Pydantic API functions

def measure(self, measurements, degrees=True):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are degrees really the default people expect for quantum chemistry applications? Just a side thought is all

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, happy to take other comments here however,

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user-facing is usually degrees, I think. coders would rather convert than deal with confused gen chem students running labs and touting vespr. :-)

@dgasmith dgasmith merged commit 014aa24 into MolSSI:master Feb 5, 2019
@dgasmith dgasmith deleted the measure branch October 18, 2019 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Project enhancement discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants