Skip to content

Commit

Permalink
modify the imported units
Browse files Browse the repository at this point in the history
  • Loading branch information
robinzyb committed Jul 12, 2024
1 parent 4a83a3d commit 4722358
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cp2kdata/cube/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from cp2kdata.log import get_logger
from cp2kdata.utils import file_content, interpolate_spline
from cp2kdata.utils import au2A, au2eV
from cp2kdata.units import au2A, au2eV
from cp2kdata.cell import Cp2kCell

logger = get_logger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion cp2kdata/pdos/pdos.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from matplotlib.gridspec import GridSpec
from scipy.ndimage import gaussian_filter1d

from cp2kdata.utils import au2eV
from cp2kdata.units import au2eV

atomic_color_map = {
'Ac': (0.39344, 0.62101, 0.45034),
Expand Down
26 changes: 17 additions & 9 deletions cp2kdata/utils.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
"""
this script put misc function here.
this module sotres misc functions
"""
#from cp2kdata import Cp2kOutput
import numpy as np
import os
import shutil
from typing import Any

import numpy as np
import numpy.typing as npt
from ase.geometry.analysis import Analysis
from ase.io import read, write

from .log import get_logger
from cp2kdata.log import get_logger

logger = get_logger(__name__)
# frequently used unit convertion
au2eV = 27.211386245988
au2A = 0.529177210903


def create_path(path):
path += '/'
Expand All @@ -30,13 +27,24 @@ def create_path(path):
counter += 1
os.makedirs(path)


def interpolate_spline(old_x, old_y, new_x):
from scipy import interpolate
f = interpolate.splrep(old_x, old_y, s=0, per=True)
new_y = interpolate.splev(new_x, f)
return new_x, new_y

def find_closet_idx_by_value(arr: npt.NDArray, value: Any) -> int:
"""
Find the index of the closest value in the given array to the specified value.
Parameters:
arr (numpy.ndarray): The input array.
value (Any): The value to find the closest index for.
Returns:
int: The index of the closest value in the array.
"""
return np.abs(arr - value).argmin()

Check warning on line 47 in cp2kdata/utils.py

View check run for this annotation

Codecov / codecov/patch

cp2kdata/utils.py#L47

Added line #L47 was not covered by tests

def set_pbc(pos, cell):
"""set pbc for a list of Atoms object"""
Expand Down
6 changes: 3 additions & 3 deletions tests/test_pdos/pdos_files/case_1_pdos/answer/answer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"listidx": null,
"kind": "1",
"timestep": "0",
"fermi": 0.6222699806732536,
"homo_ener": 0.6222699806732536,
"lumo_ener": 4.414503190686633
"fermi": 0.6222699260317295,
"homo_ener": 0.6222699260317295,
"lumo_ener": 4.414502803049129
}
Binary file modified tests/test_pdos/pdos_files/case_1_pdos/answer/dos.npy
Binary file not shown.

0 comments on commit 4722358

Please sign in to comment.