forked from deepmodeling/deepmd-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Grid density #1
Open
zjgemi
wants to merge
18
commits into
devel
Choose a base branch
from
grid-density
base: devel
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
Grid density #1
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
759830b
Support loading grid density in DeepmdData
zjgemi 62e262c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 82c8801
fix bugs
zjgemi fabf9e1
Merge branch 'grid-density' of github.com:zjgemi/deepmd-kit into grid…
zjgemi aff1eef
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 47537ae
seperate grid and density
zjgemi e76e324
Merge branch 'grid-density' of github.com:zjgemi/deepmd-kit into grid…
zjgemi 4240dcf
fix typo
zjgemi 9275d82
add convert funcs and test density in dpdata
jieli-matrix ff75a0a
fix filename
jieli-matrix 4454085
fix density
jieli-matrix 4d8e8df
tests passed
jieli-matrix bcaff4c
add test data with 1 frame
jieli-matrix be26f78
fix density nan
jieli-matrix 36baba9
Merge pull request #2 from jieli-matrix/grid-density
zjgemi 1b0b359
add UT for FFT density
jieli-matrix 6dc1ed3
remove unnessary data files
jieli-matrix aceb4ea
Merge pull request #3 from jieli-matrix/grid-density
zjgemi 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 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 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,135 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
import numpy as np | ||
from typing import Tuple | ||
class DensityCalculator: | ||
def __init__(self, binary_file: str, lattice_constant: float): | ||
self.lattice_constant = lattice_constant # in Bohr | ||
self.read_binary_file(binary_file) | ||
|
||
def read_binary_file(self, filename: str): | ||
# Read the binary file for g_vectors & rhog | ||
with open(filename, 'rb') as f: | ||
# Read header | ||
size = np.fromfile(f, dtype=np.int32, count=1)[0] | ||
assert size == 3, f"Unexpected header value: {size}" | ||
|
||
self.gammaonly, self.ngm_g, self.nspin = np.fromfile(f, dtype=np.int32, count=3) | ||
_ = np.fromfile(f, dtype=np.int32, count=1)[0] # Skip the last '3' | ||
|
||
# Read reciprocal lattice vectors | ||
size = np.fromfile(f, dtype=np.int32, count=1)[0] | ||
assert size == 9, f"Unexpected header value: {size}" | ||
self.bmat = np.fromfile(f, dtype=np.float64, count=9).reshape(3, 3) | ||
_ = np.fromfile(f, dtype=np.int32, count=1)[0] # Skip the last '9' | ||
|
||
# Read Miller indices | ||
size = np.fromfile(f, dtype=np.int32, count=1)[0] | ||
assert size == self.ngm_g * 3, f"Unexpected Miller indices size: {size}" | ||
self.miller_indices = np.fromfile(f, dtype=np.int32, count=self.ngm_g*3).reshape(self.ngm_g, 3) | ||
_ = np.fromfile(f, dtype=np.int32, count=1)[0] # Skip the size at the end | ||
|
||
# Read rhog | ||
size = np.fromfile(f, dtype=np.int32, count=1)[0] | ||
assert size == self.ngm_g, f"Unexpected rhog size: {size}" | ||
self.rhog = np.fromfile(f, dtype=np.complex128, count=self.ngm_g) | ||
_ = np.fromfile(f, dtype=np.int32, count=1)[0] # Skip the size at the end | ||
|
||
# If nspin == 2, read second spin component | ||
if self.nspin == 2: | ||
size = np.fromfile(f, dtype=np.int32, count=1)[0] | ||
assert size == self.ngm_g, f"Unexpected rhog_spin2 size: {size}" | ||
self.rhog_spin2 = np.fromfile(f, dtype=np.complex128, count=self.ngm_g) | ||
_ = np.fromfile(f, dtype=np.int32, count=1)[0] # Skip the size at the end | ||
|
||
# Calculate real space lattice vectors (dimensionless) | ||
self.lat_vec = np.linalg.inv(self.bmat).T | ||
|
||
# Calculate cell volume | ||
self.cell_volume = np.abs(np.linalg.det(self.lattice_constant * self.lat_vec)) | ||
|
||
# Calculate G vectors (in units of 2π/lattice_constant) | ||
self.bmat = 2 * np.pi * self.bmat / self.lattice_constant | ||
# self.g_vectors = 2 * np.pi * np.dot(self.miller_indices, self.bmat.T) | ||
self.g_vectors = np.dot(self.miller_indices, self.bmat.T) | ||
def calculate_density_batch(self, points: np.ndarray) -> np.ndarray: | ||
""" | ||
Calculate the exact density using Fourier transform. | ||
|
||
Args: | ||
points (np.ndarray): Array of points in real space, shape (n, 3), in units of lattice_constant | ||
|
||
Returns: | ||
np.ndarray: Exact density values | ||
""" | ||
phases = np.exp(1j * np.dot(points, self.g_vectors.T)) | ||
densities = np.real(np.dot(phases, self.rhog)) | ||
return densities | ||
|
||
def get_lattice_vectors(self) -> np.ndarray: | ||
""" | ||
Get the real space lattice vectors. | ||
|
||
Returns: | ||
np.ndarray: Real space lattice vectors, shape (3, 3), in Bohr units | ||
""" | ||
return self.lattice_constant * self.lat_vec | ||
|
||
|
||
# def generate_grid( | ||
# lattice_vectors: np.ndarray, | ||
# grid_size: Tuple[int, int, int], | ||
# origin: np.ndarray = np.zeros(3), | ||
# ) -> np.ndarray: | ||
# """ | ||
# 生成给定晶格和网格大小的实空间网格点。 | ||
|
||
# 参数: | ||
# lattice_vectors (np.ndarray): 形状为 (3, 3) 的晶格向量 | ||
# grid_size (Tuple[int, int, int]): 三个方向上的网格点数 | ||
# origin (np.ndarray): 网格原点坐标,默认为 (0, 0, 0) | ||
|
||
# 返回: | ||
# np.ndarray: 形状为 (N, 3) 的网格点坐标数组 | ||
# """ | ||
# nx, ny, nz = grid_size | ||
# x = np.linspace(0, 1, nx, endpoint=False) | ||
# y = np.linspace(0, 1, ny, endpoint=False) | ||
# z = np.linspace(0, 1, nz, endpoint=False) | ||
|
||
# grid = np.meshgrid(x, y, z, indexing="ij") | ||
# points = np.stack(grid, axis=-1).reshape(-1, 3) | ||
|
||
# # 将分数坐标转换为实空间坐标 | ||
# real_points = np.dot(points, lattice_vectors) + origin | ||
|
||
# return real_points | ||
|
||
|
||
# def calculate_density( | ||
# filename: str, | ||
# lattice_vectors: np.ndarray, | ||
# grid_size: Tuple[int, int, int], | ||
# origin: np.ndarray = np.zeros(3), | ||
# batch_size: int = 1000, | ||
# ) -> Iterator[Tuple[np.ndarray, np.ndarray]]: | ||
# """ | ||
# 计算给定网格的电子密度,以迭代器形式返回结果。 | ||
|
||
# 参数: | ||
# filename (str): 包含 n(G) 数据的二进制文件路径 | ||
# grid_size (Tuple[int, int, int]): 三个方向上的网格点数 | ||
# origin (np.ndarray): 网格原点坐标,默认为 (0, 0, 0) | ||
# lattice_vectors (np.ndarray): 形状为 (3, 3) 的晶格向量 | ||
# batch_size (int): 每批处理的点数 | ||
|
||
# 返回: | ||
# Iterator[Tuple[np.ndarray, np.ndarray]]: yielding (坐标, 密度值) 对 | ||
# """ | ||
# calculator = DensityCalculator(filename) | ||
|
||
# points = generate_grid(lattice_vectors, grid_size, origin) | ||
|
||
# for i in range(0, len(points), batch_size): | ||
# batch_points = points[i : i + batch_size] | ||
# batch_densities = calculator.calculate_density_batch(batch_points) | ||
# yield batch_points, batch_densities |
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+5.41 MB
source/tests/dentest/dataset/Al13Cu3/set.000/densities/ABACUS-CHARGE-DENSITY.000000.restart
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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,16 @@ | ||
0 | ||
0 | ||
0 | ||
0 | ||
0 | ||
0 | ||
0 | ||
0 | ||
0 | ||
0 | ||
0 | ||
0 | ||
0 | ||
1 | ||
1 | ||
1 |
This file contains 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,2 @@ | ||
Al | ||
Cu |
This file contains 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 @@ | ||
done |
1 change: 1 addition & 0 deletions
1
source/tests/dentest/dataset/Mg1Al20Cu11/.lbg-18431-14407614_base.sh
This file contains 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 @@ | ||
ulimit -s unlimited;ulimit -m unlimited;cd /home/input_lbg-18431-14407614;touch /home/input_lbg-18431-14407614/STDOUTERR;/bin/bash /home/input_lbg-18431-14407614/lbg-18431-14407614.sh >/home/input_lbg-18431-14407614/STDOUTERR 2>&1 |
1 change: 1 addition & 0 deletions
1
source/tests/dentest/dataset/Mg1Al20Cu11/.lbg-compute-completed
This file contains 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 @@ | ||
done |
This file contains 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,13 @@ | ||
INPUT_PARAMETERS | ||
calculation scf | ||
ecutwfc 100.000000 | ||
scf_thr 1.000000e-07 | ||
scf_nmax 100 | ||
basis_type pw | ||
dft_functional pbe | ||
gamma_only 0 | ||
kspacing 0.1 | ||
symmetry 0 | ||
mixing_beta 0.1 | ||
out_chg 1 7 | ||
ks_solver dav_subspace |
This file contains 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,4 @@ | ||
K_POINTS | ||
0 | ||
Gamma | ||
5 4 3 0 0 0 |
Binary file added
BIN
+220 KB
source/tests/dentest/dataset/Mg1Al20Cu11/OUT.ABACUS/.SPIN1_CHG.cube.swp
Binary file not shown.
Binary file added
BIN
+23 MB
source/tests/dentest/dataset/Mg1Al20Cu11/OUT.ABACUS/ABACUS-CHARGE-DENSITY.restart
Binary file not shown.
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.
Check notice
Code scanning / CodeQL
Unused import Note