pwdata 0.5.10__tar.gz → 0.5.11.dev0__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.5.10 → pwdata-0.5.11.dev0}/PKG-INFO +1 -1
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/convert_files.py +69 -2
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/main.py +4 -2
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/meta.py +0 -14
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/test/mptraj2lmdb.py +5 -5
- pwdata-0.5.11.dev0/pwdata/test/test_meta_output.py +183 -0
- pwdata-0.5.11.dev0/pwdata/test/test_meta_stress.py +35 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/utils/constant.py +4 -1
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata.egg-info/PKG-INFO +1 -1
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata.egg-info/SOURCES.txt +2 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/setup.py +1 -1
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/LICENSE +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/README.md +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/__init__.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/atomconfig.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/build/__init__.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/build/cell.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/build/geometry.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/build/supercells.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/build/write_struc.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/calculators/__init__.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/calculators/const.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/calculators/unitconvert_lmps.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/calculators/units.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/castepdata.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/check_envs.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/config.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/cp2kdata.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/datasets_saver.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/deepmd.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/dump.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/extendedxyz.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/__init__.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/common/__init__.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/common/registry.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/common/typing.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/common/utils.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/datasets/__init__.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/datasets/_utils.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/datasets/ase_datasets.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/datasets/base_dataset.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/datasets/embeddings/__init__.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/datasets/embeddings/atomic_radii.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/datasets/embeddings/continuous_embeddings.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/datasets/embeddings/khot_embeddings.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/datasets/embeddings/qmof_khot_embeddings.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/datasets/lmdb_database.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/datasets/target_metadata_guesser.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/modules/__init__.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/modules/transforms.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/preprocessing/__init__.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/image.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/lammpsdata.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/lmps.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/meta_omol.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/molecule.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/movement.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/movement_saver.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/outcar.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/pertub/__init__.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/pertub/perturbation.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/pertub/scale.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/poscar.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/pwmlff.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/test/__init__.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/test/bamboo2lmdb.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/test/extact_outcar_with_ml.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/test/lmdb2aselmdb.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/test/matpbe2lmdb.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/test/matrcan2lmdb.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/test/mdtrajs2config.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/test/oc25.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/test/omol25.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/test/outcar2mvms.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/test/readasedb.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/test/surf_test.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/test.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/utils/__init__.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/utils/format_change.py +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata.egg-info/dependency_links.txt +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata.egg-info/entry_points.txt +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata.egg-info/requires.txt +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata.egg-info/top_level.txt +0 -0
- {pwdata-0.5.10 → pwdata-0.5.11.dev0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pwdata
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.11.dev0
|
|
4
4
|
Summary: pwdata is a data pre-processing tool for MatPL, 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
|
|
@@ -3,6 +3,7 @@ import sys
|
|
|
3
3
|
import glob
|
|
4
4
|
import numpy as np
|
|
5
5
|
import random
|
|
6
|
+
import tempfile
|
|
6
7
|
from pwdata.config import Config
|
|
7
8
|
from pwdata.build.supercells import make_supercell
|
|
8
9
|
from pwdata.pertub.perturbation import perturb_structure
|
|
@@ -11,9 +12,10 @@ from pwdata.utils.constant import FORMAT, ELEMENTTABLE, get_atomic_name_from_num
|
|
|
11
12
|
from pwdata.castepdata import looks_like_castep_traj
|
|
12
13
|
from pwdata.image import Image
|
|
13
14
|
from collections import Counter
|
|
15
|
+
from ase import Atoms
|
|
14
16
|
from ase.build import general_surface
|
|
15
17
|
from ase.db.row import AtomsRow
|
|
16
|
-
from pwdata.fairchem.datasets.ase_datasets import AseDBDataset
|
|
18
|
+
from pwdata.fairchem.datasets.ase_datasets import AseDBDataset, LMDBDatabase
|
|
17
19
|
from concurrent.futures import ProcessPoolExecutor, as_completed
|
|
18
20
|
import multiprocessing
|
|
19
21
|
from tqdm import tqdm
|
|
@@ -243,8 +245,73 @@ param {*} data_shuffle
|
|
|
243
245
|
return {*}
|
|
244
246
|
author: wuxingxing
|
|
245
247
|
'''
|
|
248
|
+
def image_to_atomrow(image):
|
|
249
|
+
if image.Ep is None:
|
|
250
|
+
raise ValueError("META output requires energy for every image")
|
|
251
|
+
if image.force is None:
|
|
252
|
+
raise ValueError("META output requires forces for every image")
|
|
253
|
+
positions = image.position
|
|
254
|
+
if not image.cartesian:
|
|
255
|
+
positions = np.dot(positions, image.lattice)
|
|
256
|
+
atoms = Atoms(
|
|
257
|
+
positions=positions,
|
|
258
|
+
numbers=image.atom_types_image,
|
|
259
|
+
cell=image.lattice,
|
|
260
|
+
pbc=image.pbc,
|
|
261
|
+
)
|
|
262
|
+
atom_row = AtomsRow(atoms)
|
|
263
|
+
atom_row.energy = image.Ep
|
|
264
|
+
atom_row.force = image.force
|
|
265
|
+
atom_row.forces = image.force
|
|
266
|
+
if image.virial is not None:
|
|
267
|
+
volume = image.get_volume()
|
|
268
|
+
if volume == 0:
|
|
269
|
+
raise ValueError("Cannot write virial to META format for a zero-volume cell")
|
|
270
|
+
virial = np.asarray(image.virial).reshape(3, 3)
|
|
271
|
+
if not np.allclose(virial, virial.T, rtol=1e-7, atol=1e-8):
|
|
272
|
+
raise ValueError("META output requires a symmetric virial tensor")
|
|
273
|
+
virial = (virial + virial.T) / 2
|
|
274
|
+
stress = -virial / volume
|
|
275
|
+
atom_row.stress = np.array([
|
|
276
|
+
stress[0, 0], stress[1, 1], stress[2, 2],
|
|
277
|
+
stress[1, 2], stress[0, 2], stress[0, 1],
|
|
278
|
+
])
|
|
279
|
+
return atom_row
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def save_to_meta(savepath, images, data_shuffle=False):
|
|
283
|
+
os.makedirs(savepath, exist_ok=True)
|
|
284
|
+
output_file = os.path.join(savepath, FORMAT.meta_name)
|
|
285
|
+
if os.path.exists(output_file):
|
|
286
|
+
raise FileExistsError("META output already exists: {}".format(output_file))
|
|
287
|
+
output_images = list(images)
|
|
288
|
+
if data_shuffle:
|
|
289
|
+
random.Random(2024).shuffle(output_images)
|
|
290
|
+
descriptor, temporary_file = tempfile.mkstemp(
|
|
291
|
+
prefix=".dataset-", suffix=".aselmdb", dir=savepath
|
|
292
|
+
)
|
|
293
|
+
os.close(descriptor)
|
|
294
|
+
os.remove(temporary_file)
|
|
295
|
+
try:
|
|
296
|
+
with LMDBDatabase(filename=temporary_file, readonly=False) as database:
|
|
297
|
+
for index, image in enumerate(tqdm(output_images, desc="writing META")):
|
|
298
|
+
database._write(
|
|
299
|
+
image_to_atomrow(image),
|
|
300
|
+
key_value_pairs={},
|
|
301
|
+
data={"idx": index},
|
|
302
|
+
)
|
|
303
|
+
os.replace(temporary_file, output_file)
|
|
304
|
+
finally:
|
|
305
|
+
for path in (temporary_file, temporary_file + "-lock"):
|
|
306
|
+
if os.path.exists(path):
|
|
307
|
+
os.remove(path)
|
|
308
|
+
return output_file
|
|
309
|
+
|
|
310
|
+
|
|
246
311
|
def save_images(savepath, image_data, output_format, data_shuffle=False, merge=True):
|
|
247
|
-
if merge is True and output_format == FORMAT.
|
|
312
|
+
if merge is True and output_format == FORMAT.meta:
|
|
313
|
+
save_to_meta(savepath, image_data.images, data_shuffle)
|
|
314
|
+
elif merge is True and output_format == FORMAT.extxyz:
|
|
248
315
|
save_dir = savepath
|
|
249
316
|
image_data.to(
|
|
250
317
|
data_path=save_dir,
|
|
@@ -343,7 +343,7 @@ def run_convert_configs(cmd_list:list[str]):
|
|
|
343
343
|
parser.add_argument('-i', '--input', type=str, required=True, nargs='+', help="The directory or file path of the datas.\nYou can also use JSON file to list all file paths in 'datapath': [], such as 'pwdata/test/meta_data.json'")
|
|
344
344
|
parser.add_argument('-f', '--input_format', type=str, required=False, default=None, help="The input file format, if not specified, the format will be automatically inferred based on the input files. the supported format as {}".format(FORMAT.support_images_format))
|
|
345
345
|
parser.add_argument('-s', '--savepath', type=str, required=False, help="The output dir path, if not provided, the current dir will be used", default="./")
|
|
346
|
-
parser.add_argument('-o', '--output_format', type=str, required=False, default='pwmlff/npy', help="the output file format, only support the format ['pwmlff/npy','extxyz'], if not provided, the 'pwmlff/npy' format be used. ")
|
|
346
|
+
parser.add_argument('-o', '--output_format', type=str, required=False, default='pwmlff/npy', help="the output file format, only support the format ['pwmlff/npy','extxyz','meta'], if not provided, the 'pwmlff/npy' format be used. ")
|
|
347
347
|
# parser.add_argument('-c', '--cartesian', action='store_true', help="if '-c' is set, the cartesian coordinates will be used, otherwise the fractional coordinates will be used.")
|
|
348
348
|
parser.add_argument('-r', '--split_rand', action='store_true', help="Whether to randomly divide the dataset into training and test sets, '-r' is randomly")
|
|
349
349
|
parser.add_argument('-m', '--merge', type=int, required=False, default=1, help="if '-m 1' the output config files will save into one xyzfile. Otherwise, the out configs will be saved separately according to the structural element types. The default value is 1")
|
|
@@ -378,9 +378,11 @@ def run_convert_configs(cmd_list:list[str]):
|
|
|
378
378
|
else:
|
|
379
379
|
args.gap = f"::{args.gap}"
|
|
380
380
|
# FORMAT.check_format(args.input_format, FORMAT.support_images_format)
|
|
381
|
-
FORMAT.check_format(args.output_format, [FORMAT.pwmlff_npy, FORMAT.extxyz])
|
|
381
|
+
FORMAT.check_format(args.output_format, [FORMAT.pwmlff_npy, FORMAT.extxyz, FORMAT.meta])
|
|
382
382
|
|
|
383
383
|
merge = True if args.merge == 1 else False
|
|
384
|
+
if args.output_format == FORMAT.meta and not merge:
|
|
385
|
+
raise ValueError("META output requires -m 1")
|
|
384
386
|
do_convert_images(input_list, args.input_format, args.savepath, args.output_format, args.split_rand, args.gap, atom_types, args.query, args.cpu_nums, merge)
|
|
385
387
|
|
|
386
388
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import numpy as np
|
|
2
|
-
import re
|
|
3
2
|
import os, glob
|
|
4
3
|
from tqdm import tqdm
|
|
5
4
|
from pwdata.image import Image
|
|
@@ -85,10 +84,6 @@ class META(object):
|
|
|
85
84
|
"""处理每个 atom_list 并转换为对象列表"""
|
|
86
85
|
return [to_image(Atoms) for Atoms in atom_list]
|
|
87
86
|
|
|
88
|
-
# MPtrj LMDB stores stress in kbar rather than eV/ų
|
|
89
|
-
# 1 kbar = 6.241509e-4 eV/ų
|
|
90
|
-
KBAR_TO_EV_PER_A3 = 6.241509e-4
|
|
91
|
-
|
|
92
87
|
def load_and_query_db(db_address, atom_types, query, filter_with_elements):
|
|
93
88
|
# 加载数据库
|
|
94
89
|
try:
|
|
@@ -109,15 +104,6 @@ def load_and_query_db(db_address, atom_types, query, filter_with_elements):
|
|
|
109
104
|
else: # query is not None and atom_types is None
|
|
110
105
|
atom_list.extend(list(dbs.select(query)))
|
|
111
106
|
|
|
112
|
-
# MPtrj 系列数据集 stress 单位为 kbar,需转为 eV/ų
|
|
113
|
-
if re.search(r'mptrj', db_address, re.IGNORECASE):
|
|
114
|
-
for atoms in atom_list:
|
|
115
|
-
try:
|
|
116
|
-
stress_val = atoms.stress
|
|
117
|
-
if stress_val is not None:
|
|
118
|
-
atoms.stress = np.array(stress_val, dtype=float) * KBAR_TO_EV_PER_A3
|
|
119
|
-
except (AttributeError, TypeError):
|
|
120
|
-
pass
|
|
121
107
|
return atom_list
|
|
122
108
|
|
|
123
109
|
def query_fun(row, elements):
|
|
@@ -12,9 +12,9 @@ from tqdm import tqdm
|
|
|
12
12
|
import numpy as np
|
|
13
13
|
|
|
14
14
|
def MPjson2lmdb():
|
|
15
|
-
mp_file = "/data/home/wuxingxing/codespace/pwdata_dev/examples/mp_data/mptest.json"
|
|
16
|
-
|
|
17
|
-
save_file = "/data/
|
|
15
|
+
# mp_file = "/data/home/wuxingxing/codespace/pwdata_dev/examples/mp_data/mptest.json"
|
|
16
|
+
mp_file = "/data/public/wuxingxing/MPtrj/MPtrj_2022.9_full.json"# 12G too big
|
|
17
|
+
save_file = "/data/public/wuxingxing/MPtrj/mptrj-Ep-uncorrected.aselmdb"
|
|
18
18
|
matjson = json.load(open(mp_file))
|
|
19
19
|
db = LMDBDatabase(filename=save_file, readonly=False)
|
|
20
20
|
for key_1, val_1 in tqdm(matjson.items(), total=len(matjson.keys())):
|
|
@@ -39,12 +39,12 @@ def cvt_mpdict_2_atomrow(config:dict):
|
|
|
39
39
|
stress = read_from_dict('stress', config, require=True)
|
|
40
40
|
atom_rows.stress = [stress[0][0],stress[1][1],stress[2][2],stress[1][2],stress[0][2],stress[0][1]]
|
|
41
41
|
force = read_from_dict('force', config, require=True)
|
|
42
|
-
energy = read_from_dict('
|
|
42
|
+
energy = read_from_dict('uncorrected_total_energy', config, require=True)
|
|
43
43
|
atom_rows.__setattr__('force', force)
|
|
44
44
|
atom_rows.__setattr__('energy', energy)
|
|
45
45
|
data = {}
|
|
46
46
|
data['uncorrected_total_energy'] = read_from_dict('uncorrected_total_energy', config, default=None)
|
|
47
|
-
data['corrected_total_energy'] = read_from_dict('
|
|
47
|
+
data['corrected_total_energy'] = read_from_dict('corrected_total_energy', config, default=None)
|
|
48
48
|
data['energy_per_atom'] = read_from_dict('energy_per_atom', config, default=None)
|
|
49
49
|
data['ef_per_atom'] = read_from_dict('ef_per_atom', config, default=None)
|
|
50
50
|
data['e_per_atom_relaxed'] = read_from_dict('e_per_atom_relaxed', config, default=None)
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pytest
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from pwdata.config import Config
|
|
6
|
+
from pwdata.convert_files import image_to_atomrow, save_to_meta
|
|
7
|
+
from pwdata.image import Image
|
|
8
|
+
from pwdata.main import run_convert_configs
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
EXTXYZ_FRAME = """2
|
|
12
|
+
Lattice=\"3.0 0.0 0.0 0.0 4.0 0.0 0.0 0.0 5.0\" Properties=species:S:1:pos:R:3:forces:R:3 energy=-1.25 virial=\"1.0 0.2 0.3 0.2 2.0 0.4 0.3 0.4 3.0\" pbc=\"T F T\"
|
|
13
|
+
H 0.1 0.2 0.3 1.0 2.0 3.0
|
|
14
|
+
O 1.1 1.2 1.3 -1.0 -2.0 -3.0
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def make_image(lattice=None, energy=-1.0, force=None, virial=None):
|
|
19
|
+
return Image(
|
|
20
|
+
atom_nums=1,
|
|
21
|
+
atom_types_image=[1],
|
|
22
|
+
lattice=np.eye(3) if lattice is None else lattice,
|
|
23
|
+
position=[[0.0, 0.0, 0.0]],
|
|
24
|
+
force=[[0.0, 0.0, 0.0]] if force is None else force,
|
|
25
|
+
Ep=energy,
|
|
26
|
+
virial=np.eye(3) if virial is None else virial,
|
|
27
|
+
pbc=[True, True, True],
|
|
28
|
+
cartesian=True,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_cvt_configs_writes_meta_database_readable_by_pwdata(tmp_path):
|
|
33
|
+
source = tmp_path / "input.xyz"
|
|
34
|
+
output_dir = tmp_path / "output"
|
|
35
|
+
source.write_text(EXTXYZ_FRAME, encoding="utf-8")
|
|
36
|
+
source_image = Config(data_path=str(source), format="extxyz").images[0]
|
|
37
|
+
|
|
38
|
+
run_convert_configs(
|
|
39
|
+
[
|
|
40
|
+
"-i",
|
|
41
|
+
str(source),
|
|
42
|
+
"-f",
|
|
43
|
+
"extxyz",
|
|
44
|
+
"-s",
|
|
45
|
+
str(output_dir),
|
|
46
|
+
"-o",
|
|
47
|
+
"meta",
|
|
48
|
+
]
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
output_file = output_dir / "dataset.aselmdb"
|
|
52
|
+
assert output_file.is_file()
|
|
53
|
+
|
|
54
|
+
converted = Config(data_path=str(output_file), format="meta")
|
|
55
|
+
assert len(converted.images) == 1
|
|
56
|
+
image = converted.images[0]
|
|
57
|
+
|
|
58
|
+
np.testing.assert_array_equal(image.atom_types_image, [1, 8])
|
|
59
|
+
np.testing.assert_allclose(image.lattice, np.diag([3.0, 4.0, 5.0]))
|
|
60
|
+
np.testing.assert_allclose(
|
|
61
|
+
image.position, [[0.1, 0.2, 0.3], [1.1, 1.2, 1.3]]
|
|
62
|
+
)
|
|
63
|
+
np.testing.assert_array_equal(image.pbc, source_image.pbc)
|
|
64
|
+
assert image.Ep == -1.25
|
|
65
|
+
np.testing.assert_allclose(
|
|
66
|
+
image.force, [[1.0, 2.0, 3.0], [-1.0, -2.0, -3.0]]
|
|
67
|
+
)
|
|
68
|
+
np.testing.assert_allclose(
|
|
69
|
+
image.virial, [[1.0, 0.2, 0.3], [0.2, 2.0, 0.4], [0.3, 0.4, 3.0]]
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_cvt_configs_rejects_unmerged_meta_output(tmp_path):
|
|
74
|
+
source = tmp_path / "input.xyz"
|
|
75
|
+
source.write_text(EXTXYZ_FRAME, encoding="utf-8")
|
|
76
|
+
|
|
77
|
+
with pytest.raises(ValueError, match="META output requires -m 1"):
|
|
78
|
+
run_convert_configs(
|
|
79
|
+
[
|
|
80
|
+
"-i",
|
|
81
|
+
str(source),
|
|
82
|
+
"-f",
|
|
83
|
+
"extxyz",
|
|
84
|
+
"-s",
|
|
85
|
+
str(tmp_path / "output"),
|
|
86
|
+
"-o",
|
|
87
|
+
"meta",
|
|
88
|
+
"-m",
|
|
89
|
+
"0",
|
|
90
|
+
]
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def test_cvt_configs_converts_pwmlff_npy_to_meta(tmp_path):
|
|
95
|
+
source = Path(__file__).parents[2] / "examples" / "pwmlff_data" / "LiSiC" / "C2"
|
|
96
|
+
output_dir = tmp_path / "output"
|
|
97
|
+
expected = Config(data_path=str(source), format="pwmlff/npy")
|
|
98
|
+
|
|
99
|
+
run_convert_configs(
|
|
100
|
+
[
|
|
101
|
+
"-i",
|
|
102
|
+
str(source),
|
|
103
|
+
"-f",
|
|
104
|
+
"pwmlff/npy",
|
|
105
|
+
"-s",
|
|
106
|
+
str(output_dir),
|
|
107
|
+
"-o",
|
|
108
|
+
"meta",
|
|
109
|
+
]
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
converted = Config(
|
|
113
|
+
data_path=str(output_dir / "dataset.aselmdb"), format="meta"
|
|
114
|
+
)
|
|
115
|
+
assert len(converted.images) == len(expected.images) == 15
|
|
116
|
+
np.testing.assert_array_equal(
|
|
117
|
+
converted.images[0].atom_types_image, expected.images[0].atom_types_image
|
|
118
|
+
)
|
|
119
|
+
expected_position = expected.images[0].position
|
|
120
|
+
if not expected.images[0].cartesian:
|
|
121
|
+
expected_position = np.dot(expected_position, expected.images[0].lattice)
|
|
122
|
+
np.testing.assert_allclose(converted.images[0].position, expected_position)
|
|
123
|
+
np.testing.assert_allclose(converted.images[0].force, expected.images[0].force)
|
|
124
|
+
np.testing.assert_allclose(converted.images[0].virial, expected.images[0].virial)
|
|
125
|
+
assert converted.images[0].Ep == expected.images[0].Ep
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def test_cvt_configs_refuses_to_append_to_existing_meta_database(tmp_path):
|
|
129
|
+
source = tmp_path / "input.xyz"
|
|
130
|
+
output_dir = tmp_path / "output"
|
|
131
|
+
source.write_text(EXTXYZ_FRAME, encoding="utf-8")
|
|
132
|
+
args = [
|
|
133
|
+
"-i",
|
|
134
|
+
str(source),
|
|
135
|
+
"-f",
|
|
136
|
+
"extxyz",
|
|
137
|
+
"-s",
|
|
138
|
+
str(output_dir),
|
|
139
|
+
"-o",
|
|
140
|
+
"meta",
|
|
141
|
+
]
|
|
142
|
+
run_convert_configs(args)
|
|
143
|
+
|
|
144
|
+
with pytest.raises(FileExistsError, match="already exists"):
|
|
145
|
+
run_convert_configs(args)
|
|
146
|
+
|
|
147
|
+
converted = Config(
|
|
148
|
+
data_path=str(output_dir / "dataset.aselmdb"), format="meta"
|
|
149
|
+
)
|
|
150
|
+
assert len(converted.images) == 1
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
@pytest.mark.parametrize(
|
|
154
|
+
("energy", "force", "missing_label"),
|
|
155
|
+
[(None, [[0.0, 0.0, 0.0]], "energy"), (-1.0, None, "forces")],
|
|
156
|
+
)
|
|
157
|
+
def test_meta_output_rejects_missing_training_labels(energy, force, missing_label):
|
|
158
|
+
image = make_image(energy=energy, force=force)
|
|
159
|
+
if missing_label == "forces":
|
|
160
|
+
image.force = None
|
|
161
|
+
|
|
162
|
+
with pytest.raises(ValueError, match="requires {}".format(missing_label)):
|
|
163
|
+
image_to_atomrow(image)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def test_meta_output_rejects_asymmetric_virial():
|
|
167
|
+
image = make_image(
|
|
168
|
+
virial=[[1.0, 0.2, 0.0], [0.4, 2.0, 0.0], [0.0, 0.0, 3.0]]
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
with pytest.raises(ValueError, match="symmetric virial"):
|
|
172
|
+
image_to_atomrow(image)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def test_meta_output_removes_partial_database_after_failure(tmp_path):
|
|
176
|
+
valid_image = make_image()
|
|
177
|
+
invalid_image = make_image(lattice=np.zeros((3, 3)))
|
|
178
|
+
|
|
179
|
+
with pytest.raises(ValueError, match="zero-volume cell"):
|
|
180
|
+
save_to_meta(tmp_path, [valid_image, invalid_image])
|
|
181
|
+
|
|
182
|
+
assert not (tmp_path / "dataset.aselmdb").exists()
|
|
183
|
+
assert list(tmp_path.iterdir()) == []
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import shutil
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import pytest
|
|
5
|
+
from ase import Atoms
|
|
6
|
+
from ase.calculators.singlepoint import SinglePointCalculator
|
|
7
|
+
|
|
8
|
+
from pwdata.config import Config
|
|
9
|
+
from pwdata.fairchem.datasets.ase_datasets import LMDBDatabase
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@pytest.mark.parametrize("cpu_nums", [1, 2])
|
|
13
|
+
@pytest.mark.parametrize("relative_path", ["mptrj.aselmdb", "MPTRJ/dataset.aselmdb"])
|
|
14
|
+
def test_meta_stress_is_independent_of_database_path(tmp_path, cpu_nums, relative_path):
|
|
15
|
+
stress = np.array([[0.1, 0.02, 0.03], [0.02, -0.2, 0.04], [0.03, 0.04, 0.3]])
|
|
16
|
+
atoms = Atoms("H", positions=[[0.0, 0.0, 0.0]], cell=[2.0, 3.0, 4.0], pbc=True)
|
|
17
|
+
atoms.calc = SinglePointCalculator(
|
|
18
|
+
atoms, energy=-1.25, forces=np.zeros((1, 3)), stress=stress
|
|
19
|
+
)
|
|
20
|
+
source = tmp_path / "standard.aselmdb"
|
|
21
|
+
db = LMDBDatabase(filename=str(source), readonly=False)
|
|
22
|
+
try:
|
|
23
|
+
db.write(atoms)
|
|
24
|
+
finally:
|
|
25
|
+
db.close()
|
|
26
|
+
copied = tmp_path / relative_path
|
|
27
|
+
copied.parent.mkdir(parents=True, exist_ok=True)
|
|
28
|
+
shutil.copyfile(source, copied)
|
|
29
|
+
|
|
30
|
+
expected = -stress * atoms.get_volume()
|
|
31
|
+
for path in (source, copied):
|
|
32
|
+
image = Config(data_path=str(path), format="meta", cpu_nums=cpu_nums).images[0]
|
|
33
|
+
np.testing.assert_allclose(image.virial, expected)
|
|
34
|
+
assert image.Ep == -1.25
|
|
35
|
+
np.testing.assert_array_equal(image.force, np.zeros((1, 3)))
|
|
@@ -38,6 +38,7 @@ class FORMAT:
|
|
|
38
38
|
extxyz="extxyz"
|
|
39
39
|
extxyz_name="extxyz.xyz"
|
|
40
40
|
meta = "meta"
|
|
41
|
+
meta_name = "dataset.aselmdb"
|
|
41
42
|
traj = "traj"
|
|
42
43
|
|
|
43
44
|
support_config_format = [pwmat_config, vasp_poscar, lammps_lmp, cp2k_scf, castep_scf]
|
|
@@ -62,6 +63,8 @@ class FORMAT:
|
|
|
62
63
|
return FORMAT.pwmlff_npy_name
|
|
63
64
|
elif input_format == FORMAT.extxyz:
|
|
64
65
|
return FORMAT.extxyz_name
|
|
66
|
+
elif input_format == FORMAT.meta:
|
|
67
|
+
return FORMAT.meta_name
|
|
65
68
|
else:
|
|
66
69
|
raise ValueError("Unknown format: {}".format(input_format))
|
|
67
70
|
|
|
@@ -146,4 +149,4 @@ def get_atomic_name_from_str(atom_strs):
|
|
|
146
149
|
return get_atomic_number_from_name(atom_strs)
|
|
147
150
|
|
|
148
151
|
def check_atom_type_name(atom_types:list[str]):
|
|
149
|
-
return all([_ in ELEMENTTABLE.keys() for _ in atom_types])
|
|
152
|
+
return all([_ in ELEMENTTABLE.keys() for _ in atom_types])
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pwdata
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.11.dev0
|
|
4
4
|
Summary: pwdata is a data pre-processing tool for MatPL, 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
|
|
@@ -75,6 +75,8 @@ pwdata/test/omol25.py
|
|
|
75
75
|
pwdata/test/outcar2mvms.py
|
|
76
76
|
pwdata/test/readasedb.py
|
|
77
77
|
pwdata/test/surf_test.py
|
|
78
|
+
pwdata/test/test_meta_output.py
|
|
79
|
+
pwdata/test/test_meta_stress.py
|
|
78
80
|
pwdata/utils/__init__.py
|
|
79
81
|
pwdata/utils/constant.py
|
|
80
82
|
pwdata/utils/format_change.py
|
|
@@ -11,7 +11,7 @@ with open("README.md", "r") as fh:
|
|
|
11
11
|
|
|
12
12
|
setuptools.setup(
|
|
13
13
|
name="pwdata",
|
|
14
|
-
version="0.5.
|
|
14
|
+
version="0.5.11.dev0",
|
|
15
15
|
author="LonxunQuantum",
|
|
16
16
|
author_email="lonxun@pwmat.com",
|
|
17
17
|
description="pwdata is a data pre-processing tool for MatPL, which can be used to extract features and labels. It also provides convenient interfaces for data conversion between different software.",
|
|
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
|
{pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/datasets/embeddings/continuous_embeddings.py
RENAMED
|
File without changes
|
|
File without changes
|
{pwdata-0.5.10 → pwdata-0.5.11.dev0}/pwdata/fairchem/datasets/embeddings/qmof_khot_embeddings.py
RENAMED
|
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
|