pwdata 0.5.2__tar.gz → 0.5.4.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.

Files changed (79) hide show
  1. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/PKG-INFO +1 -1
  2. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/deepmd.py +6 -5
  3. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/lammpsdata.py +3 -1
  4. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/meta.py +27 -25
  5. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/outcar.py +1 -1
  6. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/pwmlff.py +9 -8
  7. pwdata-0.5.4.dev0/pwdata/test/bamboo2lmdb.py +130 -0
  8. pwdata-0.5.4.dev0/pwdata/test/extact_outcar_with_ml.py +206 -0
  9. pwdata-0.5.4.dev0/pwdata/test/omol25.py +13 -0
  10. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata.egg-info/PKG-INFO +1 -1
  11. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata.egg-info/SOURCES.txt +2 -0
  12. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/setup.py +1 -1
  13. pwdata-0.5.2/pwdata/test/omol25.py +0 -42
  14. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/LICENSE +0 -0
  15. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/README.md +0 -0
  16. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/__init__.py +0 -0
  17. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/atomconfig.py +0 -0
  18. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/build/__init__.py +0 -0
  19. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/build/cell.py +0 -0
  20. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/build/geometry.py +0 -0
  21. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/build/supercells.py +0 -0
  22. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/build/write_struc.py +0 -0
  23. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/calculators/__init__.py +0 -0
  24. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/calculators/const.py +0 -0
  25. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/calculators/unitconvert_lmps.py +0 -0
  26. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/calculators/units.py +0 -0
  27. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/check_envs.py +0 -0
  28. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/config.py +0 -0
  29. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/convert_files.py +0 -0
  30. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/cp2kdata.py +0 -0
  31. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/datasets_saver.py +0 -0
  32. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/dump.py +0 -0
  33. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/extendedxyz.py +0 -0
  34. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/fairchem/__init__.py +0 -0
  35. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/fairchem/common/__init__.py +0 -0
  36. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/fairchem/common/registry.py +0 -0
  37. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/fairchem/common/typing.py +0 -0
  38. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/fairchem/common/utils.py +0 -0
  39. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/fairchem/datasets/__init__.py +0 -0
  40. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/fairchem/datasets/_utils.py +0 -0
  41. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/fairchem/datasets/ase_datasets.py +0 -0
  42. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/fairchem/datasets/base_dataset.py +0 -0
  43. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/fairchem/datasets/embeddings/__init__.py +0 -0
  44. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/fairchem/datasets/embeddings/atomic_radii.py +0 -0
  45. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/fairchem/datasets/embeddings/continuous_embeddings.py +0 -0
  46. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/fairchem/datasets/embeddings/khot_embeddings.py +0 -0
  47. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/fairchem/datasets/embeddings/qmof_khot_embeddings.py +0 -0
  48. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/fairchem/datasets/lmdb_database.py +0 -0
  49. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/fairchem/datasets/target_metadata_guesser.py +0 -0
  50. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/fairchem/modules/__init__.py +0 -0
  51. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/fairchem/modules/transforms.py +0 -0
  52. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/fairchem/preprocessing/__init__.py +0 -0
  53. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/image.py +0 -0
  54. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/lmps.py +0 -0
  55. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/main.py +0 -0
  56. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/meta_omol.py +0 -0
  57. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/molecule.py +0 -0
  58. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/movement.py +0 -0
  59. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/movement_saver.py +0 -0
  60. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/pertub/__init__.py +0 -0
  61. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/pertub/perturbation.py +0 -0
  62. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/pertub/scale.py +0 -0
  63. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/poscar.py +0 -0
  64. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/test/__init__.py +0 -0
  65. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/test/matpbe2lmdb.py +0 -0
  66. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/test/matrcan2lmdb.py +0 -0
  67. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/test/mdtrajs2config.py +0 -0
  68. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/test/mptraj2lmdb.py +0 -0
  69. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/test/outcar2mvms.py +0 -0
  70. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/test.py +0 -0
  71. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/tmp.py +0 -0
  72. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/utils/__init__.py +0 -0
  73. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/utils/constant.py +0 -0
  74. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata/utils/format_change.py +0 -0
  75. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata.egg-info/dependency_links.txt +0 -0
  76. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata.egg-info/entry_points.txt +0 -0
  77. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata.egg-info/requires.txt +0 -0
  78. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/pwdata.egg-info/top_level.txt +0 -0
  79. {pwdata-0.5.2 → pwdata-0.5.4.dev0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pwdata
3
- Version: 0.5.2
3
+ Version: 0.5.4.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
@@ -52,15 +52,16 @@ class DPNPY(object):
52
52
  def load_npy(self, npy_files, atom_nums):
53
53
  virial = None
54
54
  for npy_file in tqdm(npy_files, desc="Loading data"):
55
- if "box" in npy_file:
55
+ npy_file_name = os.path.basename(npy_file)
56
+ if "box" in npy_file_name:
56
57
  box = np.load(npy_file).reshape(-1, 3, 3).astype(np.float64)
57
- elif "coord" in npy_file:
58
+ elif "coord" in npy_file_name:
58
59
  coord = np.load(npy_file).reshape(-1, atom_nums, 3)
59
- elif "energy" in npy_file:
60
+ elif "energy" in npy_file_name:
60
61
  energy = np.load(npy_file)
61
- elif "force" in npy_file:
62
+ elif "force" in npy_file_name:
62
63
  force = np.load(npy_file).reshape(-1, atom_nums, 3)
63
- elif "virial" in npy_file:
64
+ elif "virial" in npy_file_name:
64
65
  virial = np.load(npy_file).reshape(-1, 3, 3)
65
66
 
66
67
  image_nums = len(box)
@@ -4,7 +4,7 @@ from tqdm import tqdm
4
4
  from collections import Counter
5
5
  from pwdata.image import Image
6
6
  from pwdata.calculators.unitconvert_lmps import convert
7
- from pwdata.calculators.const import ELEMENTMASSTABLE
7
+ from pwdata.calculators.const import ELEMENTMASSTABLE, ELEMENTTABLE
8
8
  from pwdata.utils.format_change import to_numpy_array, to_integer, to_float
9
9
  class LMP(object):
10
10
  def __init__(self, lmp_file, atom_names: list[str] = None, units: str = 'metal', style: str = 'atomic', sort_by_id: bool = True) -> None:
@@ -323,6 +323,8 @@ class LMP(object):
323
323
  ids[ind] = id
324
324
  # by type
325
325
  types[ind] = type
326
+ if self.atom_names is not None:
327
+ atom_types_image[ind] = ELEMENTTABLE[self.atom_names[type - 1]]
326
328
  if len(atom_names) == 0:
327
329
  atom_types_image[ind] = type
328
330
  else:
@@ -52,24 +52,25 @@ class META(object):
52
52
  cpu_nums = min(cpu_nums, multiprocessing.cpu_count())
53
53
  if isinstance(input, str):
54
54
  input = [input]
55
+ atom_lists = []
55
56
  # single cpu debug
56
- # atom_lists = []
57
- # for i, _ in enumerate(input):
58
- # print(i)
59
- # _atom_lists = load_and_query_db(_, atom_types, query, filter_with_elements)
60
- # for _ in _atom_lists:
61
- # print(_.formula)
62
- # atom_lists.extend(_atom_lists)
63
- # 使用多进程并行加载和查询数据库
64
- with ProcessPoolExecutor(max_workers=cpu_nums) as executor:
65
- futures = []
66
- for db_address in input:
67
- futures.append(executor.submit(load_and_query_db, db_address, atom_types, query, filter_with_elements))
68
-
69
- # 收集查询结果
70
- atom_lists = []
71
- for future in as_completed(futures):
72
- atom_lists.append(future.result())
57
+ if cpu_nums == 1:
58
+ for i, _ in enumerate(input):
59
+ _atom_lists = load_and_query_db(_, atom_types, query, filter_with_elements)
60
+ # for _ in _atom_lists:
61
+ # print(_.formula)
62
+ atom_lists.append(_atom_lists)
63
+ else:
64
+ # 使用多进程并行加载和查询数据库
65
+ with ProcessPoolExecutor(max_workers=cpu_nums) as executor:
66
+ futures = []
67
+ for db_address in input:
68
+ futures.append(executor.submit(load_and_query_db, db_address, atom_types, query, filter_with_elements))
69
+
70
+ # 收集查询结果
71
+ atom_lists = []
72
+ for future in as_completed(futures):
73
+ atom_lists.append(future.result())
73
74
 
74
75
  # 处理所有结果
75
76
  for atom_list in atom_lists:
@@ -123,18 +124,19 @@ def to_image(Atoms):
123
124
  image.cartesian = True
124
125
  image.force = to_numpy_array(Atoms.forces)
125
126
  image.Ep = to_float(Atoms.energy)
126
-
127
127
  # 计算 Atomic-Energy
128
128
  # atomic_energy, _, _, _ = np.linalg.lstsq([image.atom_type_num], np.array([image.Ep]), rcond=1e-3)
129
129
  # atomic_energy = np.repeat(atomic_energy, image.atom_type_num)
130
130
  # image.atomic_energy = atomic_energy.tolist()
131
131
 
132
- vol = Atoms.volume
133
- virial = (-np.array(Atoms.stress) * vol)
134
- image.virial = np.array([
135
- [virial[0], virial[5], virial[4]],
136
- [virial[5], virial[1], virial[3]],
137
- [virial[4], virial[3], virial[2]]
138
- ])
132
+ if hasattr(Atoms, 'virial') is False and hasattr(Atoms, 'stress'):
133
+ vol = Atoms.volume
134
+ virial = (-np.array(Atoms.stress) * vol)
135
+ image.virial = np.array([
136
+ [virial[0], virial[5], virial[4]],
137
+ [virial[5], virial[1], virial[3]],
138
+ [virial[4], virial[3], virial[2]]
139
+ ])
140
+ # print(image.virial)
139
141
  image.format = 'metadata'
140
142
  return image
@@ -77,7 +77,7 @@ class OUTCAR(object):
77
77
  max_scf_idx = idx
78
78
  prev_idx = idx
79
79
  if "Elapsed time (sec):" in ii:
80
- if max_insw < nelm:
80
+ if max_insw <= nelm:
81
81
  converged_images.append(outcar_contents[max_scf_idx:idx])
82
82
 
83
83
  for converged_image in tqdm(converged_images, total=len(converged_images), desc="Loading converged data"):
@@ -38,21 +38,22 @@ class PWNPY(object):
38
38
  virial = None
39
39
  coord = None
40
40
  for npy_file in npy_files:
41
- if "atom_type" in npy_file:
41
+ npy_file_name = os.path.basename(npy_file)
42
+ if "atom_type.npy" in npy_file_name:
42
43
  atom_type = to_numpy_array(np.load(npy_file).squeeze())
43
- elif "ei" in npy_file:
44
+ elif "ei.npy" in npy_file_name:
44
45
  atomic_energy = np.load(npy_file) if atomic_energy is None else np.concatenate((atomic_energy, np.load(npy_file)))
45
- elif "energies" in npy_file:
46
+ elif "energies.npy" in npy_file_name:
46
47
  Ep = np.load(npy_file) if Ep is None else np.concatenate((Ep, np.load(npy_file)))
47
- elif "forces" in npy_file:
48
+ elif "forces.npy" in npy_file_name:
48
49
  force = np.load(npy_file) if force is None else np.concatenate((force, np.load(npy_file)))
49
- elif "image_type" in npy_file:
50
+ elif "image_type.npy" in npy_file_name:
50
51
  atom_types_image = np.load(npy_file).squeeze()
51
- elif "lattice" in npy_file:
52
+ elif "lattice.npy" in npy_file_name:
52
53
  lattice = np.load(npy_file) if lattice is None else np.concatenate((lattice, np.load(npy_file)))
53
- elif "virials" in npy_file:
54
+ elif "virials.npy" in npy_file_name:
54
55
  virial = np.load(npy_file) if virial is None else np.concatenate((virial, np.load(npy_file)))
55
- elif "position" in npy_file:
56
+ elif "position.npy" in npy_file_name:
56
57
  coord = np.load(npy_file) if coord is None else np.concatenate((coord, np.load(npy_file)))
57
58
 
58
59
  image_nums = len(Ep)
@@ -0,0 +1,130 @@
1
+ import os
2
+ import glob
3
+ from ase import Atoms
4
+ from ase.db.row import AtomsRow
5
+ from pwdata.utils.constant import get_atomic_number_from_name
6
+ from tqdm import tqdm
7
+ import numpy as np
8
+ import torch
9
+ from pwdata.fairchem.datasets.ase_datasets import LMDBDatabase
10
+
11
+ atomic_number_to_symbol = {
12
+ 1: 'H', 2: 'He', 3: 'Li', 4: 'Be', 5: 'B', 6: 'C', 7: 'N', 8: 'O', 9: 'F', 10: 'Ne',
13
+ 11: 'Na', 12: 'Mg', 13: 'Al', 14: 'Si', 15: 'P', 16: 'S', 17: 'Cl', 18: 'Ar', 19: 'K', 20: 'Ca',
14
+ 21: 'Sc', 22: 'Ti', 23: 'V', 24: 'Cr', 25: 'Mn', 26: 'Fe', 27: 'Co', 28: 'Ni', 29: 'Cu', 30: 'Zn',
15
+ 31: 'Ga', 32: 'Ge', 33: 'As', 34: 'Se', 35: 'Br', 36: 'Kr', 37: 'Rb', 38: 'Sr', 39: 'Y', 40: 'Zr',
16
+ 41: 'Nb', 42: 'Mo', 43: 'Tc', 44: 'Ru', 45: 'Rh', 46: 'Pd', 47: 'Ag', 48: 'Cd', 49: 'In', 50: 'Sn',
17
+ 51: 'Sb', 52: 'Te', 53: 'I', 54: 'Xe', 55: 'Cs', 56: 'Ba', 57: 'La', 58: 'Ce', 59: 'Pr', 60: 'Nd',
18
+ 61: 'Pm', 62: 'Sm', 63: 'Eu', 64: 'Gd', 65: 'Tb', 66: 'Dy', 67: 'Ho', 68: 'Er', 69: 'Tm', 70: 'Yb',
19
+ 71: 'Lu', 72: 'Hf', 73: 'Ta', 74: 'W', 75: 'Re', 76: 'Os', 77: 'Ir', 78: 'Pt', 79: 'Au', 80: 'Hg',
20
+ 81: 'Tl', 82: 'Pb', 83: 'Bi', 84: 'Po', 85: 'At', 86: 'Rn', 87: 'Fr', 88: 'Ra', 89: 'Ac', 90: 'Th',
21
+ 91: 'Pa', 92: 'U', 93: 'Np', 94: 'Pu', 95: 'Am', 96: 'Cm', 97: 'Bk', 98: 'Cf', 99: 'Es', 100: 'Fm',
22
+ 101: 'Md', 102: 'No', 103: 'Lr', 104: 'Rf', 105: 'Db', 106: 'Sg', 107: 'Bh', 108: 'Hs', 109: 'Mt',
23
+ 110: 'Ds', 111: 'Rg', 112: 'Cn', 113: 'Nh', 114: 'Fl', 115: 'Mc', 116: 'Lv', 117: 'Ts', 118: 'Og'
24
+ }
25
+
26
+ def cvt_matdict_2_atomrow(config:dict):
27
+ cell = read_from_dict('matrix', config['structure']['lattice'], require=True)
28
+ atom_type_list = get_atomic_number_from_name([_['label'] for _ in config['structure']['sites']])
29
+ position = [_['xyz'] for _ in config['structure']['sites']]
30
+ magmom = [_['properties']['magmom'] for _ in config['structure']['sites']]
31
+ # magmom = read_from_dict('magmom', config, require=True)
32
+ atom = Atoms(positions=position,
33
+ numbers=atom_type_list,
34
+ magmoms=magmom,
35
+ cell=cell)
36
+
37
+ atom_rows = AtomsRow(atom)
38
+ atom_rows.pbc = np.ones(3, bool)
39
+ # read stress -> xx, yy, zz, yz, xz, xy
40
+ virial = read_from_dict('stress', config, require=True) # this is vrial and the order is xx, yy, zz, yz, xz, xy
41
+ stress = -np.array(virial) / config['volume']
42
+ atom_rows.stress = [stress[0],stress[1],stress[2],stress[3],stress[4],stress[5]]
43
+ force = read_from_dict('forces', config, require=True) #mat is s
44
+ energy = read_from_dict('energy', config, require=True)
45
+ atom_rows.__setattr__('force', force)
46
+ atom_rows.__setattr__('forces', force)
47
+ atom_rows.__setattr__('energy', energy)
48
+ data = {}
49
+ return atom_rows, data
50
+
51
+ def read_from_dict(key:str, config:dict, default=None, require=False):
52
+ if key in config:
53
+ return config[key]
54
+ else:
55
+ if require:
56
+ raise ValueError("key {} not found in config".format(key))
57
+ else:
58
+ return default
59
+
60
+ def atom_type_to_symbol(atom_type):
61
+ return atomic_number_to_symbol.get(int(atom_type), 'X') # Default to 'X' for unknown types
62
+
63
+ def atom_types_to_symbol(atom_types):
64
+ return [atom_type_to_symbol(atom) for atom in atom_types]
65
+
66
+ # xyz_file = "/data/home/wuxingxing/codespace/EDM/outputs/edm_qm9/eval/stabel_pwmat/0/molecule_stable_000.xyz"
67
+ # atoms = read(xyz_file)
68
+ # atoms.center(vacuum=8)
69
+ # # 获取原子符号列表,并排序
70
+ # symbols = atoms.get_chemical_symbols()
71
+ # sorted_indices = sorted(range(len(symbols)), key=lambda i: symbols[i])
72
+
73
+ # # 按排序后的索引重新排列原子
74
+ # atoms_sorted = atoms[sorted_indices]
75
+
76
+ # save_file = "/data/home/wuxingxing/codespace/EDM/outputs/edm_qm9/bk_eval/stabel_pwmat/0/sort.0.POSCAR"
77
+ # write(filename=save_file, images=atoms_sorted, format="vasp")
78
+
79
+ def read2atoms(pt_file, db, prefix):
80
+ atom_row_list = []
81
+ val = torch.load(pt_file, map_location="cpu")
82
+ # Get the necessary tensors
83
+ cumsum_atom = val['cumsum_atom'].numpy() # Convert to numpy for easier handling
84
+ positions = val['pos'].numpy() # Shape: [410945, 3]
85
+ atom_types = val['atom_types'].numpy() # Shape: [410945]
86
+ forces = val['forces'].numpy()
87
+ charges = val['charge'].numpy()
88
+ for id, i in tqdm(enumerate(range(len(cumsum_atom) - 1)), total=len(cumsum_atom) - 1, desc="bamboo ptfile to aselmdb"):
89
+ start_idx = cumsum_atom[i]
90
+ end_idx = cumsum_atom[i + 1]
91
+ energy = val['energy'][id].item()
92
+ # Get positions and atom types for the current structure
93
+ struct_pos = positions[start_idx:end_idx]
94
+ struct_types = atom_types[start_idx:end_idx]
95
+ force = forces[start_idx:end_idx]
96
+ charge = charges[start_idx:end_idx]
97
+ symbol = atom_types_to_symbol(struct_types)
98
+ atom = Atoms(symbols=symbol,
99
+ positions=struct_pos,
100
+ charges=charge,
101
+ pbc=False)
102
+ atom.center(vacuum=5)
103
+ atom_rows = AtomsRow(atom)
104
+ atom_rows.__setattr__('force', force)
105
+ atom_rows.__setattr__('forces', force)
106
+ atom_rows.__setattr__('energy', energy)
107
+ data = {}
108
+ data['total_charge'] = val['total_charge'][id].item()
109
+ data['dipole'] = list(val['dipole'][id].numpy())
110
+ data['quadrupole'] = list(val['quadrupole'][id].numpy())
111
+ data["idx"] = f"{id}-{prefix}"
112
+ db._write(atom_rows, key_value_pairs={}, data=data)
113
+ atom_row_list.append(atom_rows)
114
+ db.close()
115
+
116
+ def cvtbamboo(pt_dir, save_dir, prefix):
117
+ pt_list = glob.glob(os.path.join(pt_dir, "*.pt"))
118
+ for pt in pt_list:
119
+ save_path = os.path.join(save_dir, os.path.basename(pt).replace('.pt', '.aselmdb'))
120
+ db = LMDBDatabase(filename=save_path, readonly=False)
121
+ atom_row_list = read2atoms(pt, db, prefix)
122
+
123
+
124
+ if __name__=="__main__":
125
+ pt_dir="/share/public/PWMLFF_test_data/bamboo/mini"
126
+ save_dir="/share/public/PWMLFF_test_data/bamboo/mini_aselmdb"
127
+ if not os.path.exists(save_dir):
128
+ os.makedirs(save_dir)
129
+ prefix = "bamboo-mini"
130
+ cvtbamboo(pt_dir, save_dir, prefix)
@@ -0,0 +1,206 @@
1
+ import os
2
+ import sys
3
+ import argparse
4
+ import numpy as np
5
+ import re
6
+ from tqdm import tqdm
7
+ from collections import Counter
8
+ from pwdata import Config
9
+ from pwdata.image import Image, elements_to_order
10
+ from pwdata.utils.format_change import to_numpy_array, to_integer, to_float
11
+
12
+ class OUTCAR(object):
13
+ def __init__(self, outcar_file) -> None:
14
+ self.image_list:list[Image] = []
15
+ self.number_pattern = re.compile(r"[-+]?\d+(?:\.\d+)?(?:[eE][-+]?\d+)?")
16
+ self.load_outcar_file(outcar_file)
17
+
18
+ def get(self):
19
+ return self.image_list
20
+
21
+ def load_outcar_file(self, outcar_file):
22
+ # seperate content to image contents
23
+ with open(outcar_file, 'r') as rf:
24
+ outcar_contents = rf.readlines()
25
+
26
+ atom_names = []
27
+ atom_type_num = None
28
+ nelm = None
29
+ for idx, ii in enumerate(outcar_contents):
30
+ if "POTCAR" in ii:
31
+ # get atom names from POTCAR info, tested only for PAW_PBE ...
32
+ _ii = ii.split()[2]
33
+ if '_' in _ii:
34
+ # atom_names.append(_ii.split('_')[0])
35
+ atom_name = _ii.split('_')[0]
36
+ if atom_name not in atom_names:
37
+ atom_names.append(atom_name)
38
+ else:
39
+ atom_name = _ii
40
+ if atom_name not in atom_names:
41
+ atom_names.append(atom_name)
42
+ elif 'ions per type' in ii:
43
+ atom_type_num_ = [int(s) for s in ii.split()[4:]]
44
+ if atom_type_num is None:
45
+ atom_type_num = atom_type_num_
46
+ else:
47
+ assert (atom_type_num == atom_type_num_), "inconsistent number of atoms in OUTCAR"
48
+ elif 'NELM =' in ii:
49
+ nelm = int(ii.split()[2][:-1])
50
+ break
51
+ assert (nelm is not None), "cannot find maximum steps for each SC iteration"
52
+ assert (atom_type_num is not None), "cannot find ion type info in OUTCAR"
53
+ atom_names = atom_names[:len(atom_type_num)]
54
+ atom_types_image = []
55
+ for idx, ii in enumerate(atom_type_num) :
56
+ for _ in range(ii) :
57
+ atom_types_image.append(idx+1)
58
+ atom_nums = sum(atom_type_num)
59
+ atom_types_image = elements_to_order(atom_names, atom_types_image, atom_nums)
60
+
61
+ max_scf_idx = 0
62
+ prev_idx = 0
63
+ converged_images = []
64
+ max_insw = -1
65
+ for idx, ii in tqdm(enumerate(outcar_contents), total=len(outcar_contents), desc="Processing data"):
66
+ if "Ionic step" in ii:
67
+ if prev_idx == 0:
68
+ prev_idx = idx
69
+ else:
70
+ if max_insw < nelm:
71
+ converged_images.append(outcar_contents[max_scf_idx:idx])
72
+ max_insw = 0
73
+ if "Iteration" in ii:
74
+ scf_index = int(ii.split()[3][:-1])
75
+ if scf_index == 1 and prev_idx != 0:
76
+ if max_insw < nelm:
77
+ converged_images.append(outcar_contents[max_scf_idx:idx])
78
+ max_insw = 0
79
+ if scf_index > max_insw:
80
+ max_insw = scf_index
81
+ max_scf_idx = idx
82
+ prev_idx = idx
83
+ if "Elapsed time (sec):" in ii:
84
+ if max_insw < nelm:
85
+ converged_images.append(outcar_contents[max_scf_idx:idx])
86
+
87
+ for converged_image in tqdm(converged_images, total=len(converged_images), desc="Loading converged data"):
88
+ is_ionic = False
89
+ for idx, line in enumerate(converged_image):
90
+ if "Iteration" in line or "Ionic step" in line:
91
+
92
+ image = Image()
93
+ if "Iteration" in line:
94
+ image.scf = int(line.split()[3][:-1])
95
+ elif "Ionic step" in line:
96
+ is_ionic = True
97
+ image.scf = int(line.split()[3])
98
+ elif "in kB" in line:
99
+ virial_info = self.parse_virial_info(converged_image[idx - 1])
100
+ image.virial = to_numpy_array(virial_info["virial"]).reshape(3, 3)
101
+ elif "VOLUME and BASIS" in line:
102
+ lattice_info = self.parse_lattice(converged_image[idx+5:idx+8])
103
+ image.lattice = to_numpy_array(lattice_info["lattice"])
104
+ elif is_ionic and "volume of cell" in line:
105
+ lattice_info = self.parse_lattice(converged_image[idx+2:idx+5])
106
+ image.lattice = to_numpy_array(lattice_info["lattice"])
107
+ elif "TOTAL-FORCE" in line:
108
+ force_info = self.parse_force(converged_image[idx+2:idx+2+atom_nums])
109
+ image.force = to_numpy_array(force_info["force"])
110
+ image.position = to_numpy_array(force_info["position"])
111
+ image.cartesian = True
112
+ elif "free energy TOTEN" in line or "free energy ML TOTEN" in line:
113
+ energy_info = self.parse_energy_info(line)
114
+ image.Ep = to_float(energy_info["Etot"])
115
+ if image.Ep is None or abs(image.Ep) < 1e-8:
116
+ continue
117
+ image.atom_nums = atom_nums
118
+ image.atom_types_image = to_numpy_array(atom_types_image)
119
+ image.atom_type = to_numpy_array(list(Counter(atom_types_image).keys()))
120
+ image.atom_type_num = to_numpy_array(atom_type_num)
121
+ # If Atomic-Energy is not in the file, calculate it from the Ep
122
+ if image is not None and image.atomic_energy is None and image.atom_type_num is not None:
123
+ atomic_energy, _, _, _ = np.linalg.lstsq([image.atom_type_num], np.array([image.Ep]), rcond=1e-3)
124
+ atomic_energy = np.repeat(atomic_energy, image.atom_type_num)
125
+ image.atomic_energy = to_numpy_array(atomic_energy.tolist())
126
+ self.image_list.append(image)
127
+
128
+ # atom_type_num = list(counter.values())
129
+ image.image_nums = len(self.image_list)
130
+ print("Load data %s successfully! \t\t\t\t Image nums: %d" % (outcar_file, image.image_nums))
131
+
132
+ def parse_virial_info(self, virial_content):
133
+ numbers = self.number_pattern.findall(virial_content)
134
+ tmp_virial = [float(_) for _ in numbers]
135
+ virial = np.zeros(9)
136
+ virial[0] = tmp_virial[0] # xx
137
+ virial[4] = tmp_virial[1] # yy
138
+ virial[8] = tmp_virial[2] # zz
139
+ virial[1] = tmp_virial[3] # xy
140
+ virial[3] = tmp_virial[3] # yx
141
+ virial[5] = tmp_virial[4] # yz
142
+ virial[7] = tmp_virial[4] # zy
143
+ virial[2] = tmp_virial[5] # xz
144
+ virial[6] = tmp_virial[5] # zx
145
+ return {"virial": virial}
146
+
147
+ def parse_lattice(self, lattice_content):
148
+ lattice1 = [float(_) for _ in self.number_pattern.findall(lattice_content[0])]
149
+ lattice2 = [float(_) for _ in self.number_pattern.findall(lattice_content[1])]
150
+ lattice3 = [float(_) for _ in self.number_pattern.findall(lattice_content[2])]
151
+ lattice = [lattice1[:3], lattice2[:3], lattice3[:3]]
152
+ return {"lattice": lattice}
153
+
154
+ def parse_force(self, force_content):
155
+ force = []
156
+ position = []
157
+ for i in range(0, len(force_content)):
158
+ numbers = self.number_pattern.findall(force_content[i])
159
+ position.append([float(_) for _ in numbers[:3]])
160
+ force.append([float(_) for _ in numbers[3:6]])
161
+ return {"position": position, "force": force}
162
+
163
+ def parse_energy_info(self, energy_content):
164
+ numbers = self.number_pattern.findall(energy_content)
165
+ Etot = float(numbers[0])
166
+ return {"Etot": Etot}
167
+
168
+ def extract_outcar_with_ml(data_path, savepath, savename, output_format, gap):
169
+ image_data = Config()
170
+ for outcar_file in data_path:
171
+ tmp_image_data = OUTCAR(outcar_file).image_list
172
+ image_data.images.extend(tmp_image_data[::gap])
173
+ image_data.to(data_path=savepath, data_name=savename, format=output_format)
174
+ return image_data
175
+
176
+ if __name__ == "__main__":
177
+
178
+ parser = argparse.ArgumentParser(description='Extract OUTCAR traj containing ml data.\n')
179
+
180
+ parser.add_argument('-i', '--input', type=str, required=True, nargs='+', help="The path of outcar files")
181
+ parser.add_argument('-s', '--savename', type=str, required=False, help="Output file name, if it is in the format of 'extxyz', the output file is 'savename.xyz', if it is 'pwmlff/npy', the output is in the directory 'savename'", default="outcar2xyz.xyz")
182
+ parser.add_argument('-o', '--output_format', type=str, required=False, default='extxyz', help="the output file format, only support the format ['pwmlff/npy','extxyz'], if not provided, the 'extxyz' format be used. ")
183
+ parser.add_argument('-g', '--gap', help='Set the number of steps to take a frame trajectory, default is 1', type=int, default=1)
184
+
185
+ args = parser.parse_args(sys.argv[1:])
186
+
187
+ file_lists = args.input
188
+ savename = args.savename
189
+ output_format = args.output_format
190
+ gap = args.gap
191
+
192
+ # os.chdir("/data/home/wuxingxing/datas/debugs/czy")
193
+ # file_lists = ["/data/home/wuxingxing/datas/debugs/czy/tmp.OUTCAR", "/data/home/wuxingxing/datas/debugs/czy/Si_OUTCAR"]
194
+ # savename = "outcar2xyz.xyz"
195
+ # output_format = "extxyz"
196
+ # gap = 1
197
+
198
+ if format == "extxyz" and '.xyz' not in savename:
199
+ savename = savename + ".xyz"
200
+ if isinstance(file_lists, str):
201
+ file_lists = [file_lists]
202
+ if output_format not in ['pwmlff/npy', 'extxyz']:
203
+ raise ValueError("The output format must be in ['pwmlff/npy', 'extxyz']")
204
+ savepath = os.getcwd()
205
+ extract_outcar_with_ml(file_lists, savepath, savename, output_format, gap)
206
+ print("Done!")
@@ -0,0 +1,13 @@
1
+ from pwdata import META_OMol, Molecule, read_oMol_data
2
+
3
+ if __name__ == "__main__":
4
+ file_list = [
5
+ "/data/home/wuxingxing/codespace/pwdata_dev/examples/omol_data"
6
+ ]
7
+
8
+ atom_names = ["C", "H"]
9
+ query = None
10
+ cpu_nums = 3
11
+
12
+ omol_data = read_oMol_data(file_list, atom_names, query, cpu_nums)
13
+ print(len(omol_data.image_list))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pwdata
3
- Version: 0.5.2
3
+ Version: 0.5.4.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
@@ -63,6 +63,8 @@ pwdata/pertub/__init__.py
63
63
  pwdata/pertub/perturbation.py
64
64
  pwdata/pertub/scale.py
65
65
  pwdata/test/__init__.py
66
+ pwdata/test/bamboo2lmdb.py
67
+ pwdata/test/extact_outcar_with_ml.py
66
68
  pwdata/test/matpbe2lmdb.py
67
69
  pwdata/test/matrcan2lmdb.py
68
70
  pwdata/test/mdtrajs2config.py
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name="pwdata",
8
- version="0.5.2",
8
+ version="0.5.4.dev",
9
9
  author="LonxunQuantum",
10
10
  author_email="lonxun@pwmat.com",
11
11
  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.",
@@ -1,42 +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
- from pwdata.fairchem.datasets.ase_datasets import AseDBDataset
10
- from pwdata.utils.format_change import to_numpy_array, to_integer, to_float
11
- from pwdata.meta_omol import META_OMol
12
- from pwdata.convert_files import search_by_format
13
- from pwdata.utils.constant import FORMAT, get_atomic_name_from_number, check_atom_type_name
14
-
15
- def read_oMol_data(file_list:list[str], atom_names:list[str]=None, query:str=None, cpu_nums:int=1):
16
- image_list = META_OMol(lmdb_list, atom_names, query, cpu_nums)
17
- return image_list
18
-
19
- if __name__ == "__main__":
20
- file_list = [
21
- "/data/home/wuxingxing/codespace/pwdata_dev/examples/omol_data"
22
- ]
23
- lmdb_list = []
24
- for file in file_list:
25
- _tmp = search_by_format(file, "meta")
26
- if len(_tmp) > 0:
27
- lmdb_list.extend(_tmp)
28
- atom_names = None #["C", "H"]
29
- query = None
30
- cpu_nums = 1
31
-
32
- if atom_names is not None:
33
- try:
34
- atom_names = get_atomic_name_from_number(atom_names)
35
- except Exception as e:
36
- if check_atom_type_name(atom_names):
37
- pass
38
- else:
39
- raise Exception("The input '-t' or '--atom_types': '{}' is not valid, please check the input".format(" ".join(atom_names)))
40
-
41
- image_list = read_oMol_data(lmdb_list, atom_names, query, cpu_nums)
42
- print(len(image_list))
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