-
Notifications
You must be signed in to change notification settings - Fork 824
Mass COM calculation #686
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
Mass COM calculation #686
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import numpy as np | ||
| cimport cython | ||
| cimport numpy as np | ||
|
|
||
|
|
||
| @cython.boundscheck(False) | ||
| @cython.wraparound(False) | ||
| def residue_positions( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a doc string would be nice. |
||
| float[:, :] coords not None, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can tell the compiler how the array is stored (Row or Column Major). That can be done by giving it the strides directly
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would keep your current version as this is less pain for someone who uses the function. |
||
| long[:] indices not None): | ||
| cdef Py_ssize_t i, j, k | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I usually use just int here as type. |
||
|
|
||
| cdef int n_items = indices.shape[0] | ||
| cdef int n_res = np.unique(indices).shape[0] | ||
|
|
||
| cdef long[:] counter = np.zeros(n_res, dtype=np.int64) | ||
| cdef float[:, :] output = np.zeros((n_res, 3), dtype=np.float32) | ||
|
|
||
| for i in range(n_items): | ||
| j = indices[i] | ||
| for k in range(3): | ||
| output[j, k] += coords[i, k] | ||
| counter[j] += 1 | ||
|
|
||
| for i in range(n_res): | ||
| for k in range(3): | ||
| output[i, k] /= counter[i] | ||
|
|
||
| return np.asarray(output) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can turn this off globally in setup.py file. check my pytraj's one
https://github.com/Amber-MD/pytraj/blob/master/setup.py#L327-L347