0
0

炭酸イオンを含むかどうかの判定アルゴリズムを複数のPOSCARファイルに適用(ログ)

Last updated at Posted at 2023-12-19

目標

炭酸イオンを含むかどうかの判定アルゴリズム[1]を,複数のPOSCARファイルに適用するスクリプトを作成する.

[1] 炭酸イオンかどうかの判定アルゴリズムの作成(ログ) #Python3 - Qiita
https://qiita.com/k-morii-toridai/items/972a713e62c1739932ba

スクリプトの実行

pwd
/mnt/ssd_elecom_c2c_960gb/scripts/get_some_ion_contained_pos_folder_p_list

ls -CF
CO3_contained_poscar_folder_path_list.npy*  get_CO3_contained_pos_folder_p_list.py*
get_CO3_contained_pos_folder_p_list.ipynb*  package_bond_search_algorithm/
time python3 get_CO3_contained_pos_folder_p_list.py

len(C_O_existed_poscar_folder_path_list): 205733
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 205733/205733 [58:57<00:00, 58.16it/s]
len(ion_contained_poscar_folder_path_list)/len(C_O_existed_poscar_folder_path_list) :1173/205733

real 59m8.419s
user 274m0.923s
sys 9m58.857s

作成したスクリプト

import os
from pathlib import Path
from multiprocessing import Pool, cpu_count

import numpy as np
from tqdm import tqdm

from package_bond_search_algorithm.algolithm_bond_search_for_CO3 import concat_filter
from package_bond_search_algorithm.package_file_conversion.nnlist2df import nnlist2df


def wrap_nnlist2df_and_concat_filter(nnlist_p):
    """
    This func() executes two func()s.: nnlistdf() and concat_filter().

    Usage:
    ------
    wrap_nnlist2df_and_concat_filter(nnlist_p=nnlist_p)

    Parameter:
    -----------
    nnlist_p: str or PosixPath

    Return:
    -------
    bool: True or False
    """
    df_nnlist = nnlist2df(nnlist_p)
    bool_ = concat_filter(df_nnlist=df_nnlist)

    return bool_


# ターゲットとなるイオンの元素種を含むPOSCARのディレクトリパス一覧を取得
target_npy_p = '../get_some_speceis_existed_poscar_path_list/C_O_existed_poscar_folder_path_list.npy'
C_O_existed_poscar_folder_path_list = np.load(target_npy_p, allow_pickle=True)
print(f"len(C_O_existed_poscar_folder_path_list): {len(C_O_existed_poscar_folder_path_list)}")

# ターゲットとなるイオンの元素種を含むPOSCAR.nnlistのディレクトリパス一覧を取得
add_str = '/nnlist_5/POSCAR.nnlist'
C_O_existed_poscar_nnlist_path_list = [str(p) + add_str for p in C_O_existed_poscar_folder_path_list]

# 並列化
pp = Pool(cpu_count() - 1)
total = len(C_O_existed_poscar_nnlist_path_list)
try:
    bool_ion_contain = list(tqdm(pp.imap(wrap_nnlist2df_and_concat_filter, C_O_existed_poscar_nnlist_path_list), total=total))
finally:
    pp.close()
    pp.join()

# apply filter(:bool_ion_contain) to C_O_existed_poscar_nnlist_path_list
ion_contained_poscar_nnlist_path_list = np.array(C_O_existed_poscar_nnlist_path_list)[bool_ion_contain]
# get ion contained folder path list
ion_contained_poscar_folder_path_list = [Path(os.path.split(Path(os.path.split(Path(p))[0]))[0]) for p in ion_contained_poscar_nnlist_path_list]
# save ion contained folder path list as .npy
saved_npy_fname = 'CO3_contained_poscar_folder_path_list.npy'
np.save(saved_npy_fname, ion_contained_poscar_folder_path_list)
# print parcentage
print(f"len(ion_contained_poscar_folder_path_list)/len(C_O_existed_poscar_folder_path_list) :\
{len(ion_contained_poscar_folder_path_list)}/{total}")
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0