pwdata 0.4.0__tar.gz → 0.4.1__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.
Potentially problematic release.
This version of pwdata might be problematic. Click here for more details.
- {pwdata-0.4.0 → pwdata-0.4.1}/PKG-INFO +1 -1
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/convert_files.py +40 -23
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/extendedxyz.py +1 -1
- pwdata-0.4.1/pwdata/meta.py +173 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata.egg-info/PKG-INFO +1 -1
- {pwdata-0.4.0 → pwdata-0.4.1}/setup.py +1 -1
- pwdata-0.4.0/pwdata/meta.py +0 -121
- {pwdata-0.4.0 → pwdata-0.4.1}/LICENSE +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/README.md +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/__init__.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/atomconfig.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/build/__init__.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/build/cell.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/build/geometry.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/build/supercells.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/build/write_struc.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/calculators/__init__.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/calculators/const.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/calculators/unitconvert_lmps.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/calculators/units.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/check_envs.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/config.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/cp2kdata.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/datasets_saver.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/deepmd.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/dump.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/fairchem/__init__.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/fairchem/common/__init__.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/fairchem/common/registry.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/fairchem/common/typing.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/fairchem/common/utils.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/fairchem/datasets/__init__.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/fairchem/datasets/_utils.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/fairchem/datasets/ase_datasets.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/fairchem/datasets/base_dataset.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/fairchem/datasets/embeddings/__init__.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/fairchem/datasets/embeddings/atomic_radii.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/fairchem/datasets/embeddings/continuous_embeddings.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/fairchem/datasets/embeddings/khot_embeddings.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/fairchem/datasets/embeddings/qmof_khot_embeddings.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/fairchem/datasets/lmdb_database.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/fairchem/datasets/target_metadata_guesser.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/fairchem/modules/__init__.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/fairchem/modules/transforms.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/fairchem/preprocessing/__init__.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/image.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/lammpsdata.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/lmps.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/main.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/movement.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/movement_saver.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/outcar.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/pertub/__init__.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/pertub/perturbation.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/pertub/scale.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/poscar.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/pwmlff.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/test/__init__.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/test.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/utils/__init__.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata/utils/constant.py +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata.egg-info/SOURCES.txt +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata.egg-info/dependency_links.txt +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata.egg-info/entry_points.txt +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata.egg-info/requires.txt +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/pwdata.egg-info/top_level.txt +0 -0
- {pwdata-0.4.0 → pwdata-0.4.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pwdata
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: pwdata is a data pre-processing tool for PWMLFF, which can be used to extract features and labels. It also provides convenient interfaces for data conversion between different software.
|
|
5
5
|
Home-page: https://github.com/LonxunQuantum/pwdata
|
|
6
6
|
Author: LonxunQuantum
|
|
@@ -13,7 +13,7 @@ from ase.db.row import AtomsRow
|
|
|
13
13
|
from pwdata.fairchem.datasets.ase_datasets import AseDBDataset
|
|
14
14
|
from concurrent.futures import ProcessPoolExecutor, as_completed
|
|
15
15
|
import multiprocessing
|
|
16
|
-
|
|
16
|
+
from tqdm import tqdm
|
|
17
17
|
def do_convert_config(input_file:str,
|
|
18
18
|
input_format:str = None,
|
|
19
19
|
atom_types:list[str] = None,
|
|
@@ -253,9 +253,10 @@ def search_by_format(workDir, format):
|
|
|
253
253
|
if format == FORMAT.meta:
|
|
254
254
|
for root, dirs, files in os.walk(workDir):
|
|
255
255
|
for file in files:
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
256
|
+
_, ext = os.path.splitext(file)
|
|
257
|
+
if '.aselmdb' == ext:
|
|
258
|
+
data_path[FORMAT.meta].append(os.path.join(root, file))
|
|
259
|
+
# break
|
|
259
260
|
|
|
260
261
|
return data_path[format]
|
|
261
262
|
|
|
@@ -264,9 +265,19 @@ def load_files(input_dict:dict, input_format:str=None, atom_types:list[str]=None
|
|
|
264
265
|
image_data = None
|
|
265
266
|
if input_format is not None:
|
|
266
267
|
if input_format == FORMAT.meta:
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
268
|
+
chunk_size = 100
|
|
269
|
+
lmdb_nums = len(input_dict[FORMAT.meta])
|
|
270
|
+
metadatas = [input_dict[FORMAT.meta][i:i + chunk_size] for i in range(0, lmdb_nums, chunk_size)]
|
|
271
|
+
for idx, metapaths in enumerate(tqdm(metadatas, total=lmdb_nums // chunk_size)):
|
|
272
|
+
if image_data is None:
|
|
273
|
+
image_data = Config(input_format, metapaths, atom_names=atom_types, query=query, cpu_nums=cpu_nums)
|
|
274
|
+
if not isinstance(image_data.images, list): # for the first pwmlff/npy dir only has one picture
|
|
275
|
+
image_data.images = [image_data.images]
|
|
276
|
+
else:
|
|
277
|
+
tmp_image_data = Config(input_format, metapaths, atom_names=atom_types, query=query, cpu_nums=cpu_nums)
|
|
278
|
+
image_data.images.extend(tmp_image_data.images)
|
|
279
|
+
print("There are a total of {} aselmdb, and the current progress has been loaded {} %".format(lmdb_nums, np.round(idx*chunk_size/lmdb_nums, 2)))
|
|
280
|
+
|
|
270
281
|
else:
|
|
271
282
|
if len(input_dict[FORMAT.traj]) > 0:# the input is traj files
|
|
272
283
|
for data_path in input_dict[FORMAT.traj]:
|
|
@@ -274,7 +285,7 @@ def load_files(input_dict:dict, input_format:str=None, atom_types:list[str]=None
|
|
|
274
285
|
if not isinstance(image_data.images, list): # for the first pwmlff/npy dir only has one picture
|
|
275
286
|
image_data.images = [image_data.images]
|
|
276
287
|
else:
|
|
277
|
-
for data_path in input_dict[input_format]:
|
|
288
|
+
for data_path in tqdm(input_dict[input_format], total=len(input_dict[input_format])):
|
|
278
289
|
image_data = Config(input_format, data_path, atom_names=atom_types, query=query, cpu_nums=cpu_nums)
|
|
279
290
|
if not isinstance(image_data.images, list): # for the first pwmlff/npy dir only has one picture
|
|
280
291
|
image_data.images = [image_data.images]
|
|
@@ -285,14 +296,28 @@ def load_files(input_dict:dict, input_format:str=None, atom_types:list[str]=None
|
|
|
285
296
|
if len(data_list) == 0:
|
|
286
297
|
continue
|
|
287
298
|
if format == FORMAT.meta:
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
299
|
+
chunk_size = 500
|
|
300
|
+
lmdb_nums = len(input_dict[FORMAT.meta])
|
|
301
|
+
metadatas = [input_dict[FORMAT.meta][i:i + chunk_size] for i in range(0, lmdb_nums, chunk_size)]
|
|
302
|
+
for idx, metapaths in enumerate(tqdm(metadatas, total=lmdb_nums // chunk_size)):
|
|
303
|
+
if image_data is None:
|
|
304
|
+
image_data = Config(input_format, metapaths, atom_names=atom_types, query=query, cpu_nums=cpu_nums)
|
|
305
|
+
if not isinstance(image_data.images, list): # for the first pwmlff/npy dir only has one picture
|
|
306
|
+
image_data.images = [image_data.images]
|
|
307
|
+
else:
|
|
308
|
+
tmp_image_data = Config(input_format, metapaths, atom_names=atom_types, query=query, cpu_nums=cpu_nums)
|
|
309
|
+
image_data.images.extend(tmp_image_data.images)
|
|
310
|
+
# print("There are a total of {} aselmdb, and the current progress has been loaded {} %".format(lmdb_nums, np.round(idx*chunk_size/lmdb_nums, 2)))
|
|
311
|
+
|
|
291
312
|
else:
|
|
292
|
-
for data_path in data_list:
|
|
293
|
-
image_data
|
|
294
|
-
|
|
295
|
-
image_data.images
|
|
313
|
+
for data_path in tqdm(data_list, total=len(data_list)):
|
|
314
|
+
if image_data is None:
|
|
315
|
+
image_data = Config(None, data_path, atom_names=atom_types, query=query, cpu_nums=cpu_nums)
|
|
316
|
+
if not isinstance(image_data.images, list): # for the first pwmlff/npy dir only has one picture
|
|
317
|
+
image_data.images = [image_data.images]
|
|
318
|
+
else:
|
|
319
|
+
tmp_image_data = Config(None, data_path, atom_names=atom_types, query=query, cpu_nums=cpu_nums)
|
|
320
|
+
image_data.images.extend(tmp_image_data.images)
|
|
296
321
|
return image_data
|
|
297
322
|
|
|
298
323
|
'''
|
|
@@ -337,11 +362,3 @@ def split_image_by_atomtype_nums(image_data, format=None):
|
|
|
337
362
|
new_key = "".join(new_key)
|
|
338
363
|
new_split[new_key] = key_dict[key]
|
|
339
364
|
return new_split
|
|
340
|
-
|
|
341
|
-
def make_query(elements:list[str]):
|
|
342
|
-
# 这个闭包函数将捕获 elements 参数
|
|
343
|
-
def query(row):
|
|
344
|
-
if sorted(set(row.symbols)) == sorted(elements):
|
|
345
|
-
return True
|
|
346
|
-
return False
|
|
347
|
-
return query
|
|
@@ -21,7 +21,7 @@ class EXTXYZ(object):
|
|
|
21
21
|
self.image_list=image_list
|
|
22
22
|
|
|
23
23
|
def save_to_extxyz(image_data_all: list, output_path: str, train_data_path = "train.xyz", valid_data_path = "valid.xyz",
|
|
24
|
-
train_ratio = None, random = True, seed = 2024, retain_raw = False, write_patthen="
|
|
24
|
+
train_ratio = None, random = True, seed = 2024, retain_raw = False, write_patthen="a"
|
|
25
25
|
):
|
|
26
26
|
if not os.path.exists(output_path):
|
|
27
27
|
os.makedirs(output_path)
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import os, glob
|
|
3
|
+
from tqdm import tqdm
|
|
4
|
+
from pwdata.image import Image
|
|
5
|
+
from concurrent.futures import ProcessPoolExecutor, as_completed
|
|
6
|
+
import multiprocessing
|
|
7
|
+
from collections import Counter
|
|
8
|
+
from functools import partial
|
|
9
|
+
from pwdata.fairchem.datasets.ase_datasets import AseDBDataset
|
|
10
|
+
|
|
11
|
+
class META(object):
|
|
12
|
+
def __init__(self, files: list[str], atom_names: list[str] = None, query: str = None, cpu_nums: int=None):
|
|
13
|
+
self.image_list:list[Image] = []
|
|
14
|
+
self.load_files_cpus(files, atom_names, query, cpu_nums)
|
|
15
|
+
# assert len(self.image_list) > 0, "No data loaded!"
|
|
16
|
+
|
|
17
|
+
def get(self):
|
|
18
|
+
return self.image_list
|
|
19
|
+
|
|
20
|
+
def load_files(self, input:list[str], atom_types: list[str] = None, query: str = None, cpu_nums: int=None):
|
|
21
|
+
def query_fun(row, elements:list[str]=None):
|
|
22
|
+
if elements is None:
|
|
23
|
+
return True
|
|
24
|
+
return sorted(set(row.symbols)) == elements
|
|
25
|
+
|
|
26
|
+
search_dict = {'src': input}
|
|
27
|
+
dataset = AseDBDataset(config=search_dict)
|
|
28
|
+
if atom_types is not None:
|
|
29
|
+
filter_with_elements = partial(query_fun, elements=sorted(atom_types))
|
|
30
|
+
for ids, dbs in enumerate(dataset.dbs):
|
|
31
|
+
if query is None and atom_types is None:
|
|
32
|
+
atom_list = list(dbs.select())
|
|
33
|
+
elif query is None and atom_types is not None:
|
|
34
|
+
atom_list = list(dbs.select("".join(atom_types), filter=filter_with_elements))
|
|
35
|
+
elif query is not None and atom_types is not None:
|
|
36
|
+
atom_list = list(dbs.select(query, filter=filter_with_elements))
|
|
37
|
+
else:# query is not None and atom_types is None:
|
|
38
|
+
atom_list = list(dbs.select(query))
|
|
39
|
+
for Atoms in atom_list:
|
|
40
|
+
image = to_image(Atoms)
|
|
41
|
+
self.image_list.append(image)
|
|
42
|
+
|
|
43
|
+
# def load_files_cpus(self, input: list[str], atom_types: list[str] = None, query: str = None, cpu_nums: int = None):
|
|
44
|
+
# from pwdata.fairchem.datasets.ase_datasets import AseDBDataset
|
|
45
|
+
|
|
46
|
+
# def query_fun(row, elements):
|
|
47
|
+
# return sorted(set(row.symbols)) == elements
|
|
48
|
+
|
|
49
|
+
# # 设置数据源和查询过滤器
|
|
50
|
+
# search_dict = {'src': input}
|
|
51
|
+
# dataset = AseDBDataset(config=search_dict)
|
|
52
|
+
# if atom_types is not None:
|
|
53
|
+
# filter_with_elements = partial(query_fun, elements=sorted(atom_types))
|
|
54
|
+
# if cpu_nums is None:
|
|
55
|
+
# cpu_nums = multiprocessing.cpu_count()
|
|
56
|
+
# else:
|
|
57
|
+
# cpu_nums = min(cpu_nums, multiprocessing.cpu_count())
|
|
58
|
+
# # 使用多进程并行处理数据库查询
|
|
59
|
+
# with ProcessPoolExecutor(max_workers=cpu_nums) as executor:
|
|
60
|
+
# futures = []
|
|
61
|
+
# for dbs in dataset.dbs:
|
|
62
|
+
# if query is None and atom_types is None:
|
|
63
|
+
# atom_list = list(dbs.select())
|
|
64
|
+
# elif query is None and atom_types is not None:
|
|
65
|
+
# atom_list = list(dbs.select("".join(atom_types), filter=filter_with_elements))
|
|
66
|
+
# elif query is not None and atom_types is not None:
|
|
67
|
+
# atom_list = list(dbs.select(query, filter=filter_with_elements))
|
|
68
|
+
# else: # query is not None and atom_types is None
|
|
69
|
+
# atom_list = list(dbs.select(query))
|
|
70
|
+
|
|
71
|
+
# # 提交查询和转换任务
|
|
72
|
+
# futures.append(executor.submit(self.process_atoms, atom_list))
|
|
73
|
+
|
|
74
|
+
# # 收集所有结果
|
|
75
|
+
# for future in as_completed(futures):
|
|
76
|
+
# self.image_list.extend(future.result())
|
|
77
|
+
|
|
78
|
+
# @staticmethod
|
|
79
|
+
# def process_atoms(atom_list):
|
|
80
|
+
# """处理每个 atom_list 并转换为图像对象列表"""
|
|
81
|
+
# return [to_image(Atoms) for Atoms in atom_list]
|
|
82
|
+
|
|
83
|
+
# no use
|
|
84
|
+
# def make_query(elements:list[str]):
|
|
85
|
+
# # 这个闭包函数将捕获 elements 参数
|
|
86
|
+
# def query(row):
|
|
87
|
+
# if sorted(set(row.symbols)) == sorted(elements):
|
|
88
|
+
# return True
|
|
89
|
+
# return False
|
|
90
|
+
# return query
|
|
91
|
+
def load_files_cpus(self, input: list[str], atom_types: list[str] = None, query: str = None, cpu_nums: int = None):
|
|
92
|
+
# 设置查询过滤器
|
|
93
|
+
search_dict = {'src': input}
|
|
94
|
+
filter_with_elements = partial(query_fun, elements=sorted(atom_types)) if atom_types else None
|
|
95
|
+
if cpu_nums is None:
|
|
96
|
+
cpu_nums = multiprocessing.cpu_count()
|
|
97
|
+
else:
|
|
98
|
+
cpu_nums = min(cpu_nums, multiprocessing.cpu_count())
|
|
99
|
+
|
|
100
|
+
# 使用多进程并行加载和查询数据库
|
|
101
|
+
with ProcessPoolExecutor(max_workers=cpu_nums) as executor:
|
|
102
|
+
futures = []
|
|
103
|
+
for db_address in input:
|
|
104
|
+
futures.append(executor.submit(load_and_query_db, db_address, atom_types, query, filter_with_elements))
|
|
105
|
+
|
|
106
|
+
# 收集查询结果
|
|
107
|
+
atom_lists = []
|
|
108
|
+
for future in as_completed(futures):
|
|
109
|
+
atom_lists.append(future.result())
|
|
110
|
+
|
|
111
|
+
# 处理所有结果
|
|
112
|
+
for atom_list in atom_lists:
|
|
113
|
+
if len(atom_list) > 0:
|
|
114
|
+
self.image_list.extend([to_image(Atoms) for Atoms in atom_list])
|
|
115
|
+
|
|
116
|
+
# @staticmethod
|
|
117
|
+
# def process_atoms(self, atom_list):
|
|
118
|
+
# """处理每个 atom_list 并转换为对象列表"""
|
|
119
|
+
# return [to_image(Atoms) for Atoms in atom_list]
|
|
120
|
+
|
|
121
|
+
def load_and_query_db(db_address, atom_types, query, filter_with_elements):
|
|
122
|
+
# 加载数据库
|
|
123
|
+
try:
|
|
124
|
+
dataset = AseDBDataset(config={'src': db_address})
|
|
125
|
+
except Exception as e:
|
|
126
|
+
if "No valid ase data found" in e.args[0]:
|
|
127
|
+
return []
|
|
128
|
+
else:
|
|
129
|
+
return e
|
|
130
|
+
atom_list = []
|
|
131
|
+
for dbs in dataset.dbs:
|
|
132
|
+
if query is None and atom_types is None:
|
|
133
|
+
atom_list.extend(list(dbs.select()))
|
|
134
|
+
elif query is None and atom_types is not None:
|
|
135
|
+
atom_list.extend(list(dbs.select("".join(atom_types), filter=filter_with_elements)))
|
|
136
|
+
elif query is not None and atom_types is not None:
|
|
137
|
+
atom_list.extend(list(dbs.select(query, filter=filter_with_elements)))
|
|
138
|
+
else: # query is not None and atom_types is None
|
|
139
|
+
atom_list.extend(list(dbs.select(query)))
|
|
140
|
+
return atom_list
|
|
141
|
+
|
|
142
|
+
def query_fun(row, elements):
|
|
143
|
+
return sorted(set(row.symbols)) == elements
|
|
144
|
+
|
|
145
|
+
def to_image(Atoms):
|
|
146
|
+
image = Image()
|
|
147
|
+
image.formula = Atoms.formula
|
|
148
|
+
image.pbc = Atoms.pbc
|
|
149
|
+
image.atom_nums = Atoms.natoms
|
|
150
|
+
type_nums_dict = Counter(Atoms.numbers)
|
|
151
|
+
image.atom_type = np.array(list(type_nums_dict.keys()))
|
|
152
|
+
image.atom_type_num = np.array(list(type_nums_dict.values()))
|
|
153
|
+
image.atom_types_image = np.array(Atoms.numbers)
|
|
154
|
+
image.lattice = np.array(Atoms.cell)
|
|
155
|
+
image.position = Atoms.positions
|
|
156
|
+
image.cartesian = True
|
|
157
|
+
image.force = Atoms.forces
|
|
158
|
+
image.Ep = Atoms.energy
|
|
159
|
+
|
|
160
|
+
# 计算 Atomic-Energy
|
|
161
|
+
atomic_energy, _, _, _ = np.linalg.lstsq([image.atom_type_num], np.array([image.Ep]), rcond=1e-3)
|
|
162
|
+
atomic_energy = np.repeat(atomic_energy, image.atom_type_num)
|
|
163
|
+
image.atomic_energy = atomic_energy.tolist()
|
|
164
|
+
|
|
165
|
+
vol = Atoms.volume
|
|
166
|
+
virial = (-np.array(Atoms.stress) * vol)
|
|
167
|
+
image.virial = np.array([
|
|
168
|
+
[virial[0], virial[5], virial[4]],
|
|
169
|
+
[virial[5], virial[1], virial[3]],
|
|
170
|
+
[virial[4], virial[3], virial[2]]
|
|
171
|
+
])
|
|
172
|
+
image.format = 'metadata'
|
|
173
|
+
return image
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pwdata
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: pwdata is a data pre-processing tool for PWMLFF, which can be used to extract features and labels. It also provides convenient interfaces for data conversion between different software.
|
|
5
5
|
Home-page: https://github.com/LonxunQuantum/pwdata
|
|
6
6
|
Author: LonxunQuantum
|
|
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
|
|
|
5
5
|
|
|
6
6
|
setuptools.setup(
|
|
7
7
|
name="pwdata",
|
|
8
|
-
version="0.4.
|
|
8
|
+
version="0.4.1",
|
|
9
9
|
author="LonxunQuantum",
|
|
10
10
|
author_email="lonxun@pwmat.com",
|
|
11
11
|
description="pwdata is a data pre-processing tool for PWMLFF, which can be used to extract features and labels. It also provides convenient interfaces for data conversion between different software.",
|
pwdata-0.4.0/pwdata/meta.py
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import numpy as np
|
|
2
|
-
import os, glob
|
|
3
|
-
from tqdm import tqdm
|
|
4
|
-
from pwdata.image import Image
|
|
5
|
-
from concurrent.futures import ProcessPoolExecutor, as_completed
|
|
6
|
-
import multiprocessing
|
|
7
|
-
from collections import Counter
|
|
8
|
-
from functools import partial
|
|
9
|
-
|
|
10
|
-
class META(object):
|
|
11
|
-
def __init__(self, files: list[str], atom_names: list[str] = None, query: str = None, cpu_nums: int=None):
|
|
12
|
-
self.image_list:list[Image] = []
|
|
13
|
-
self.load_files_cpus(files, atom_names, query, cpu_nums)
|
|
14
|
-
# assert len(self.image_list) > 0, "No data loaded!"
|
|
15
|
-
|
|
16
|
-
def get(self):
|
|
17
|
-
return self.image_list
|
|
18
|
-
|
|
19
|
-
def load_files(self, input:list[str], atom_types: list[str] = None, query: str = None, cpu_nums: int=None):
|
|
20
|
-
from pwdata.fairchem.datasets.ase_datasets import AseDBDataset
|
|
21
|
-
|
|
22
|
-
def query_fun(row, elements:list[str]=None):
|
|
23
|
-
if elements is None:
|
|
24
|
-
return True
|
|
25
|
-
return sorted(set(row.symbols)) == elements
|
|
26
|
-
|
|
27
|
-
search_dict = {'src': input}
|
|
28
|
-
dataset = AseDBDataset(config=search_dict)
|
|
29
|
-
if atom_types is not None:
|
|
30
|
-
filter_with_elements = partial(query_fun, elements=sorted(atom_types))
|
|
31
|
-
for ids, dbs in enumerate(dataset.dbs):
|
|
32
|
-
if query is None and atom_types is None:
|
|
33
|
-
atom_list = list(dbs.select())
|
|
34
|
-
elif query is None and atom_types is not None:
|
|
35
|
-
atom_list = list(dbs.select("".join(atom_types), filter=filter_with_elements))
|
|
36
|
-
elif query is not None and atom_types is not None:
|
|
37
|
-
atom_list = list(dbs.select(query, filter=filter_with_elements))
|
|
38
|
-
else:# query is not None and atom_types is None:
|
|
39
|
-
atom_list = list(dbs.select(query))
|
|
40
|
-
for Atoms in atom_list:
|
|
41
|
-
image = to_image(Atoms)
|
|
42
|
-
self.image_list.append(image)
|
|
43
|
-
|
|
44
|
-
def load_files_cpus(self, input: list[str], atom_types: list[str] = None, query: str = None, cpu_nums: int = None):
|
|
45
|
-
from pwdata.fairchem.datasets.ase_datasets import AseDBDataset
|
|
46
|
-
|
|
47
|
-
def query_fun(row, elements):
|
|
48
|
-
return sorted(set(row.symbols)) == elements
|
|
49
|
-
|
|
50
|
-
# 设置数据源和查询过滤器
|
|
51
|
-
search_dict = {'src': input}
|
|
52
|
-
dataset = AseDBDataset(config=search_dict)
|
|
53
|
-
if atom_types is not None:
|
|
54
|
-
filter_with_elements = partial(query_fun, elements=sorted(atom_types))
|
|
55
|
-
if cpu_nums is None:
|
|
56
|
-
cpu_nums = multiprocessing.cpu_count()
|
|
57
|
-
else:
|
|
58
|
-
cpu_nums = min(cpu_nums, multiprocessing.cpu_count())
|
|
59
|
-
# 使用多进程并行处理数据库查询
|
|
60
|
-
with ProcessPoolExecutor(max_workers=cpu_nums) as executor:
|
|
61
|
-
futures = []
|
|
62
|
-
for dbs in dataset.dbs:
|
|
63
|
-
if query is None and atom_types is None:
|
|
64
|
-
atom_list = list(dbs.select())
|
|
65
|
-
elif query is None and atom_types is not None:
|
|
66
|
-
atom_list = list(dbs.select("".join(atom_types), filter=filter_with_elements))
|
|
67
|
-
elif query is not None and atom_types is not None:
|
|
68
|
-
atom_list = list(dbs.select(query, filter=filter_with_elements))
|
|
69
|
-
else: # query is not None and atom_types is None
|
|
70
|
-
atom_list = list(dbs.select(query))
|
|
71
|
-
|
|
72
|
-
# 提交查询和转换任务
|
|
73
|
-
futures.append(executor.submit(self.process_atoms, atom_list))
|
|
74
|
-
|
|
75
|
-
# 收集所有结果
|
|
76
|
-
for future in as_completed(futures):
|
|
77
|
-
self.image_list.extend(future.result())
|
|
78
|
-
|
|
79
|
-
@staticmethod
|
|
80
|
-
def process_atoms(atom_list):
|
|
81
|
-
"""处理每个 atom_list 并转换为图像对象列表"""
|
|
82
|
-
return [to_image(Atoms) for Atoms in atom_list]
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
# def make_query(elements:list[str]):
|
|
86
|
-
# # 这个闭包函数将捕获 elements 参数
|
|
87
|
-
# def query(row):
|
|
88
|
-
# if sorted(set(row.symbols)) == sorted(elements):
|
|
89
|
-
# return True
|
|
90
|
-
# return False
|
|
91
|
-
# return query
|
|
92
|
-
|
|
93
|
-
def to_image(Atoms):
|
|
94
|
-
image = Image()
|
|
95
|
-
image.formula = Atoms.formula
|
|
96
|
-
image.pbc = Atoms.pbc
|
|
97
|
-
image.atom_nums = Atoms.natoms
|
|
98
|
-
type_nums_dict = Counter(Atoms.numbers)
|
|
99
|
-
image.atom_type = np.array(list(type_nums_dict.keys()))
|
|
100
|
-
image.atom_type_num = np.array(list(type_nums_dict.values()))
|
|
101
|
-
image.atom_types_image = np.array(Atoms.numbers)
|
|
102
|
-
image.lattice = np.array(Atoms.cell)
|
|
103
|
-
image.position = Atoms.positions
|
|
104
|
-
image.cartesian = True
|
|
105
|
-
image.force = Atoms.forces
|
|
106
|
-
image.Ep = Atoms.energy
|
|
107
|
-
|
|
108
|
-
# 计算 Atomic-Energy
|
|
109
|
-
atomic_energy, _, _, _ = np.linalg.lstsq([image.atom_type_num], np.array([image.Ep]), rcond=1e-3)
|
|
110
|
-
atomic_energy = np.repeat(atomic_energy, image.atom_type_num)
|
|
111
|
-
image.atomic_energy = atomic_energy.tolist()
|
|
112
|
-
|
|
113
|
-
vol = Atoms.volume
|
|
114
|
-
virial = (-np.array(Atoms.stress) * vol)
|
|
115
|
-
image.virial = np.array([
|
|
116
|
-
[virial[0], virial[5], virial[4]],
|
|
117
|
-
[virial[5], virial[1], virial[3]],
|
|
118
|
-
[virial[4], virial[3], virial[2]]
|
|
119
|
-
])
|
|
120
|
-
image.format = 'metadata'
|
|
121
|
-
return image
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|