qn-util 0.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
qn_util/__init__.py ADDED
@@ -0,0 +1,11 @@
1
+ # from rmc_dft.rmc_pot.qn.config_error import ConfigError
2
+ # from rmc_dft.rmc_pot.qn.qn_network_analysis import QnNetworkAnalysis
3
+ # from rmc_dft.rmc_pot.qn.qn_network_builder import QnNetworkBuilder
4
+ # from rmc_dft.rmc_pot.qn.rmc_constraint_writer import RmcConstraintWriter
5
+ # from rmc_dft.rmc_pot.qn.vasp_structure import VaspStructure
6
+
7
+ from qn.config_error import ConfigError
8
+ from qn.qn_network_analysis import QnNetworkAnalysis
9
+ from qn.qn_network_builder import QnNetworkBuilder
10
+ from qn.rmc_constraint_writer import RmcConstraintWriter
11
+ from qn.vasp_structure import VaspStructure
@@ -0,0 +1,11 @@
1
+ """
2
+ K.NAKADA, kengo.nakada@gmail.com
3
+ """
4
+
5
+ class ConfigError(Exception):
6
+ """
7
+ 設定ファイルまたは入力構造が不正な場合の例外。
8
+
9
+ JSON 設定の必須キー不足、POSCAR の形式不整合、未知の constraint source など、
10
+ ユーザー入力に起因するエラーをこの例外にまとめる。
11
+ """
qn_util/install.py ADDED
@@ -0,0 +1,49 @@
1
+ """qn_util に付属するサンプルスクリプトを作業ディレクトリへ配置する。"""
2
+
3
+ import argparse
4
+ import shutil
5
+ from importlib.resources import files
6
+ from pathlib import Path
7
+
8
+
9
+ def install(force: bool = False, destination: Path | None = None) -> list[Path]:
10
+ """同梱 scripts の全ファイルを指定先(既定はカレント)へコピーする。"""
11
+ target = Path.cwd() if destination is None else Path(destination)
12
+ source = files("qn_util").joinpath("scripts")
13
+ if not source.is_dir():
14
+ raise FileNotFoundError("パッケージ内に scripts がありません。配布設定を確認してください。")
15
+ items = list(source.iterdir())
16
+ conflicts = [target / item.name for item in items if (target / item.name).exists()]
17
+ if conflicts and not force:
18
+ names = ", ".join(str(x) for x in conflicts)
19
+ raise FileExistsError(f"同名ファイルが存在します: {names}(上書きには --force を指定)")
20
+ copied = []
21
+ for item in items:
22
+ dst = target / item.name
23
+ if item.is_dir():
24
+ shutil.copytree(str(item), dst, dirs_exist_ok=force)
25
+ else:
26
+ with item.open("rb") as src, dst.open("wb") as out:
27
+ shutil.copyfileobj(src, out)
28
+ copied.append(dst)
29
+ return copied
30
+
31
+
32
+ def main() -> None:
33
+ """qn_util コマンドのエントリーポイント。"""
34
+ parser = argparse.ArgumentParser(prog="qn_util")
35
+ sub = parser.add_subparsers(dest="command", required=True)
36
+ cmd = sub.add_parser("install", help="付属スクリプトをカレントディレクトリへコピー")
37
+ cmd.add_argument("--force", action="store_true", help="同名ファイルを上書き")
38
+ args = parser.parse_args()
39
+ if args.command == "install":
40
+ try:
41
+ copied = install(force=args.force)
42
+ except (FileExistsError, FileNotFoundError) as exc:
43
+ parser.exit(1, f"エラー: {exc}\n")
44
+ for path in copied:
45
+ print(f"コピー: {path}")
46
+
47
+
48
+ if __name__ == "__main__":
49
+ main()