-
Notifications
You must be signed in to change notification settings - Fork 613
feat(pt): Add DPA4/SeZM descriptor & model 🎉🎉🎉 #5448
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
Open
OutisLi
wants to merge
10
commits into
deepmodeling:master
Choose a base branch
from
OutisLi:dpa4
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
096f4b9
feat(pt): add DPA4 model components
OutisLi 964ac8e
feat(pt): support DPA4 training and export
OutisLi 57abd8d
docs: add DPA4 guide and examples
OutisLi 9d9f58c
test(pt): add DPA4 coverage
OutisLi 2d2208d
fix(pt): multiple DPA4 bugs fix
OutisLi 4021ec7
add torch to ci
OutisLi 7b84ec8
add atom_modify map yes
OutisLi 049fb95
update doc
OutisLi 478cba6
fix charge_spin & limit torch to 2.11 for compile
OutisLi 2edfd4f
fix ut
OutisLi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # SPDX-License-Identifier: LGPL-3.0-or-later | ||
| """Minimum pairwise distance check for frame validity filtering.""" | ||
|
|
||
| from __future__ import ( | ||
| annotations, | ||
| ) | ||
|
|
||
| import numpy as np | ||
|
|
||
| _MIN_PAIR_DIST_BLOCK_PAIRS = 262_144 | ||
|
|
||
|
|
||
| def compute_min_pair_dist_single( | ||
| coord: np.ndarray, | ||
| box: np.ndarray | None, | ||
| atype: np.ndarray, | ||
| stop_below: float | None = None, | ||
| ) -> float: | ||
| """Compute the minimum pairwise atomic distance for a single frame. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| coord : np.ndarray | ||
| Atomic coordinates, flattened with shape (natoms * 3,) | ||
| or reshaped as (natoms, 3). | ||
| box : np.ndarray or None | ||
| Box vectors with shape (9,) for PBC, or None for non-PBC. | ||
| atype : np.ndarray | ||
| Atom types with shape (natoms,). Virtual atoms (type < 0) | ||
| are excluded from the distance check. | ||
| stop_below : float or None | ||
| Optional early-stop threshold. If a block has any pair closer | ||
| than this value, the block minimum is returned immediately. | ||
|
|
||
| Returns | ||
| ------- | ||
| float | ||
| Minimum pairwise distance. Returns inf if fewer than 2 | ||
| real atoms exist. | ||
| """ | ||
| coord = coord.reshape(-1, 3) | ||
|
|
||
| # === Step 1. Filter out virtual atoms === | ||
| real_mask = atype.ravel() >= 0 | ||
| real_coord = coord[real_mask] | ||
| n_real = real_coord.shape[0] | ||
| if n_real < 2: | ||
| return float("inf") | ||
|
|
||
| # === Step 2. Prepare minimum image convention for PBC === | ||
| if box is not None: | ||
| cell = box.reshape(3, 3) | ||
| inv_cell = np.linalg.inv(cell) | ||
| else: | ||
| cell = None | ||
| inv_cell = None | ||
|
njzjz marked this conversation as resolved.
Dismissed
|
||
|
|
||
| # === Step 3. Compute distances in bounded row blocks === | ||
| block_size = max(1, min(n_real, _MIN_PAIR_DIST_BLOCK_PAIRS // n_real)) | ||
| min_dist_sq = float("inf") | ||
| stop_dist_sq = ( | ||
| float(stop_below) * float(stop_below) | ||
| if stop_below is not None and stop_below > 0.0 | ||
| else None | ||
| ) | ||
| for start in range(0, n_real, block_size): | ||
| stop = min(start + block_size, n_real) | ||
| diff = real_coord[np.newaxis, :, :] - real_coord[start:stop, np.newaxis, :] | ||
|
|
||
| if cell is not None and inv_cell is not None: | ||
| frac_diff = diff @ inv_cell | ||
| frac_diff -= np.round(frac_diff) | ||
| diff = frac_diff @ cell | ||
|
|
||
| dist_sq = np.sum(diff * diff, axis=-1) | ||
| rows = np.arange(stop - start, dtype=np.int64) | ||
| dist_sq[rows, start + rows] = np.inf | ||
| min_dist_sq = min(min_dist_sq, float(dist_sq.min())) | ||
| if min_dist_sq == 0.0 or ( | ||
| stop_dist_sq is not None and min_dist_sq < stop_dist_sq | ||
| ): | ||
| break | ||
|
|
||
| return float(np.sqrt(min_dist_sq)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.