dcg-sci-tool 0.1.0__tar.gz
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.
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dcg-sci-tool
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Scientific computing tools for data analysis.
|
|
5
|
+
Project-URL: Homepage, https://github.com/yourusername/dcg-sci-tool
|
|
6
|
+
Project-URL: Bug Tracker, https://github.com/yourusername/dcg-sci-tool/issues
|
|
7
|
+
Author-email: colindong <dcg899@163.com>
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Requires-Python: >=3.7
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# Summation Tool
|
|
15
|
+
|
|
16
|
+
A lightweight Python library to compute the sum of integers from 1 to n efficiently using Gauss's formula.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dcg-sci-tool" # ⚠️ 关键:你必须改一个全球唯一的名字!例如加你的用户名后缀:summation-tool-alice
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="colindong", email="dcg899@163.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "Scientific computing tools for data analysis."
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.7"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
dependencies = [] # 本项目没有依赖
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
"Homepage" = "https://github.com/yourusername/dcg-sci-tool"
|
|
23
|
+
"Bug Tracker" = "https://github.com/yourusername/dcg-sci-tool/issues"
|
|
24
|
+
|
|
25
|
+
[tool.hatch.build.targets.wheel]
|
|
26
|
+
packages = ["src/dcg-sci-tool"]
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""
|
|
2
|
+
dcg-sci-tool is a Python package that provides utility functions for scientific computing. It includes functions for summing numbers to a target value and extracting atom types from molecular data. This package is designed to be easy to use and integrate into various scientific workflows.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from .sum_to_n import sum_to_n
|
|
6
|
+
from .extract_atom_types import extract_atom_types
|
|
7
|
+
|
|
8
|
+
__version__ = "0.1.0"
|
|
9
|
+
__all__ = ["sum_to_n", "extract_atom_types"]
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""
|
|
2
|
+
提取正确的原子类型列表,保持原始顺序
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from typing import List, Set, Tuple, Dict
|
|
6
|
+
def extract_atom_types(trajectory_file: str) -> List[str]:
|
|
7
|
+
"""
|
|
8
|
+
简单直观的实现,保持原始顺序
|
|
9
|
+
|
|
10
|
+
参数:
|
|
11
|
+
trajectory_file: xyz轨迹文件的路径
|
|
12
|
+
|
|
13
|
+
返回:
|
|
14
|
+
包含第一个构型中所有原子类型的列表(不重复,保持原始顺序)
|
|
15
|
+
"""
|
|
16
|
+
with open(trajectory_file, 'r', encoding='utf-8') as f:
|
|
17
|
+
n_atoms = int(f.readline().strip())
|
|
18
|
+
f.readline() # 跳过注释行
|
|
19
|
+
|
|
20
|
+
types = []
|
|
21
|
+
for _ in range(n_atoms):
|
|
22
|
+
atom_type = f.readline().split()[1] # gases_analysis_5.py中原子类型在第二列(索引1)
|
|
23
|
+
if not atom_type.isdigit(): # 过滤数字
|
|
24
|
+
types.append(atom_type)
|
|
25
|
+
|
|
26
|
+
# 去重但保持顺序
|
|
27
|
+
result = []
|
|
28
|
+
seen = set()
|
|
29
|
+
for atom in types:
|
|
30
|
+
if atom not in seen:
|
|
31
|
+
seen.add(atom)
|
|
32
|
+
result.append(atom)
|
|
33
|
+
|
|
34
|
+
return result
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Core summation module.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def sum_to_n(n: int) -> int:
|
|
8
|
+
"""
|
|
9
|
+
Calculate the sum of all integers from 1 to n inclusive.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
n (int): The upper limit (must be a positive integer).
|
|
13
|
+
|
|
14
|
+
Returns:
|
|
15
|
+
int: The sum 1 + 2 + ... + n.
|
|
16
|
+
|
|
17
|
+
Raises:
|
|
18
|
+
ValueError: If n is not a positive integer.
|
|
19
|
+
|
|
20
|
+
Examples:
|
|
21
|
+
>>> sum_to_n(5)
|
|
22
|
+
15
|
|
23
|
+
>>> sum_to_n(100)
|
|
24
|
+
5050
|
|
25
|
+
"""
|
|
26
|
+
if not isinstance(n, int) or n <= 0:
|
|
27
|
+
raise ValueError("n must be a positive integer.")
|
|
28
|
+
return n * (n + 1) // 2 # 使用高斯求和公式,效率O(1)
|