pwdata 0.5.6.dev0__tar.gz → 0.5.8__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.
Files changed (83) hide show
  1. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/PKG-INFO +8 -1
  2. pwdata-0.5.8/README.md +10 -0
  3. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/check_envs.py +1 -1
  4. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/convert_files.py +7 -1
  5. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/extendedxyz.py +44 -19
  6. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/image.py +5 -1
  7. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/meta.py +54 -15
  8. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/movement.py +1 -1
  9. pwdata-0.5.8/pwdata/test/lmdb2aselmdb.py +131 -0
  10. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata.egg-info/PKG-INFO +8 -1
  11. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata.egg-info/SOURCES.txt +1 -1
  12. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/setup.py +1 -1
  13. pwdata-0.5.6.dev0/README.md +0 -3
  14. pwdata-0.5.6.dev0/pwdata/tmp.py +0 -59
  15. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/LICENSE +0 -0
  16. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/__init__.py +0 -0
  17. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/atomconfig.py +0 -0
  18. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/build/__init__.py +0 -0
  19. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/build/cell.py +0 -0
  20. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/build/geometry.py +0 -0
  21. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/build/supercells.py +0 -0
  22. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/build/write_struc.py +0 -0
  23. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/calculators/__init__.py +0 -0
  24. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/calculators/const.py +0 -0
  25. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/calculators/unitconvert_lmps.py +0 -0
  26. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/calculators/units.py +0 -0
  27. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/config.py +0 -0
  28. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/cp2kdata.py +0 -0
  29. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/datasets_saver.py +0 -0
  30. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/deepmd.py +0 -0
  31. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/dump.py +0 -0
  32. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/fairchem/__init__.py +0 -0
  33. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/fairchem/common/__init__.py +0 -0
  34. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/fairchem/common/registry.py +0 -0
  35. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/fairchem/common/typing.py +0 -0
  36. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/fairchem/common/utils.py +0 -0
  37. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/fairchem/datasets/__init__.py +0 -0
  38. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/fairchem/datasets/_utils.py +0 -0
  39. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/fairchem/datasets/ase_datasets.py +0 -0
  40. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/fairchem/datasets/base_dataset.py +0 -0
  41. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/fairchem/datasets/embeddings/__init__.py +0 -0
  42. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/fairchem/datasets/embeddings/atomic_radii.py +0 -0
  43. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/fairchem/datasets/embeddings/continuous_embeddings.py +0 -0
  44. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/fairchem/datasets/embeddings/khot_embeddings.py +0 -0
  45. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/fairchem/datasets/embeddings/qmof_khot_embeddings.py +0 -0
  46. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/fairchem/datasets/lmdb_database.py +0 -0
  47. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/fairchem/datasets/target_metadata_guesser.py +0 -0
  48. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/fairchem/modules/__init__.py +0 -0
  49. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/fairchem/modules/transforms.py +0 -0
  50. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/fairchem/preprocessing/__init__.py +0 -0
  51. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/lammpsdata.py +0 -0
  52. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/lmps.py +0 -0
  53. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/main.py +0 -0
  54. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/meta_omol.py +0 -0
  55. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/molecule.py +0 -0
  56. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/movement_saver.py +0 -0
  57. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/outcar.py +0 -0
  58. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/pertub/__init__.py +0 -0
  59. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/pertub/perturbation.py +0 -0
  60. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/pertub/scale.py +0 -0
  61. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/poscar.py +0 -0
  62. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/pwmlff.py +0 -0
  63. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/test/__init__.py +0 -0
  64. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/test/bamboo2lmdb.py +0 -0
  65. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/test/extact_outcar_with_ml.py +0 -0
  66. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/test/matpbe2lmdb.py +0 -0
  67. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/test/matrcan2lmdb.py +0 -0
  68. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/test/mdtrajs2config.py +0 -0
  69. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/test/mptraj2lmdb.py +0 -0
  70. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/test/oc25.py +0 -0
  71. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/test/omol25.py +0 -0
  72. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/test/outcar2mvms.py +0 -0
  73. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/test/readasedb.py +0 -0
  74. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/test/surf_test.py +0 -0
  75. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/test.py +0 -0
  76. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/utils/__init__.py +0 -0
  77. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/utils/constant.py +0 -0
  78. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata/utils/format_change.py +0 -0
  79. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata.egg-info/dependency_links.txt +0 -0
  80. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata.egg-info/entry_points.txt +0 -0
  81. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata.egg-info/requires.txt +0 -0
  82. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/pwdata.egg-info/top_level.txt +0 -0
  83. {pwdata-0.5.6.dev0 → pwdata-0.5.8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pwdata
3
- Version: 0.5.6.dev0
3
+ Version: 0.5.8
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
@@ -15,3 +15,10 @@ License-File: LICENSE
15
15
  # see doc
16
16
 
17
17
  http://doc.lonxun.com/PWMLFF/Appendix-2/
18
+
19
+ pip3 install setuptools wheel twine
20
+
21
+ rm dist/ -r
22
+ python3 setup.py sdist bdist_wheel
23
+ twine upload dist/* --verbose
24
+
pwdata-0.5.8/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # see doc
2
+
3
+ http://doc.lonxun.com/PWMLFF/Appendix-2/
4
+
5
+ pip3 install setuptools wheel twine
6
+
7
+ rm dist/ -r
8
+ python3 setup.py sdist bdist_wheel
9
+ twine upload dist/* --verbose
10
+
@@ -15,7 +15,7 @@ def cmd_infos():
15
15
  info += "\tpwdata super_cell -i input_file -f input_file_format -n output_format_name -o output_format\n"
16
16
  info += "\tYou can also use 'pwdata super_cell -h' to obtain a more detailed parameter list\n\n"
17
17
 
18
- info += "surf or surface: Under Development (2025.10.31)\n"
18
+ info += "surf or surface: Under Development (2025.12.24)\n"
19
19
  info += "\n"
20
20
 
21
21
  info += "perturb:\n"
@@ -353,11 +353,17 @@ def search_by_format(workDir, format):
353
353
  return data_path[format]
354
354
 
355
355
 
356
+ def calculate_optimal_group_size(N: int, cpu_num: int) -> dict:
357
+ if N // cpu_num >= 100:
358
+ return 100
359
+ else:
360
+ return N // cpu_num
361
+
356
362
  def load_files(input_dict:dict, input_format:str=None, atom_types:list[str]=None, query:str=None, cpu_nums=None, index=":"):
357
363
  image_data = None
358
364
  if input_format is not None:
359
365
  if input_format == FORMAT.meta:
360
- chunk_size = 100
366
+ chunk_size = calculate_optimal_group_size(len(input_dict[FORMAT.meta]), cpu_nums)
361
367
  lmdb_nums = len(input_dict[FORMAT.meta])
362
368
  metadatas = [input_dict[FORMAT.meta][i:i + chunk_size] for i in range(0, lmdb_nums, chunk_size)]
363
369
  for idx, metapaths in enumerate(tqdm(metadatas, total=lmdb_nums // chunk_size)):
@@ -54,7 +54,11 @@ def get_xyz_content(image_data:Image):
54
54
  image_data._set_cartesian()
55
55
  xyz_content +="%d\n" % image_data.atom_nums
56
56
  # data_name.write("Iteration: %s\n" % image_data.iteration)
57
- output_head = 'Lattice="%.5f %.5f %.5f %.5f %.5f %.5f %.5f %.5f %.5f" Properties=species:S:1:pos:R:3:force:R:3 pbc="T T T" energy={} '.format(image_data.Ep)
57
+ has_bec = image_data.bec is not None and len(image_data.bec) > 0
58
+ properties_head = "Properties=species:S:1:pos:R:3:"
59
+ properties_head += "bec:R:9:" if has_bec else ""
60
+ properties_head += "force:R:3"
61
+ output_head = 'Lattice="%.5f %.5f %.5f %.5f %.5f %.5f %.5f %.5f %.5f" {} pbc="T T T" energy={} '.format(properties_head, image_data.Ep)
58
62
  output_extended = (image_data.lattice[0][0], image_data.lattice[0][1], image_data.lattice[0][2],
59
63
  image_data.lattice[1][0], image_data.lattice[1][1], image_data.lattice[1][2],
60
64
  image_data.lattice[2][0], image_data.lattice[2][1], image_data.lattice[2][2])
@@ -68,9 +72,14 @@ def get_xyz_content(image_data:Image):
68
72
  xyz_content += output_head % output_extended
69
73
 
70
74
  for j in range(image_data.atom_nums):
71
- properties_format = "%s %14.8f %14.8f %14.8f %14.8f %14.8f %14.8f\n"
72
- properties = (elements[image_data.atom_types_image[j]], image_data.position[j][0], image_data.position[j][1], image_data.position[j][2],
73
- image_data.force[j][0], image_data.force[j][1], image_data.force[j][2])
75
+ if has_bec:
76
+ properties_format = "%s" + " %14.8f" * 15 + "\n"
77
+ properties = (elements[image_data.atom_types_image[j]], image_data.position[j][0], image_data.position[j][1], image_data.position[j][2],
78
+ *image_data.bec[j].reshape(-1), image_data.force[j][0], image_data.force[j][1], image_data.force[j][2])
79
+ else:
80
+ properties_format = "%s %14.8f %14.8f %14.8f %14.8f %14.8f %14.8f\n"
81
+ properties = (elements[image_data.atom_types_image[j]], image_data.position[j][0], image_data.position[j][1], image_data.position[j][2],
82
+ image_data.force[j][0], image_data.force[j][1], image_data.force[j][2])
74
83
  xyz_content += properties_format % properties
75
84
  return xyz_content
76
85
 
@@ -133,10 +142,11 @@ def read_one_structures_from_lines(lines:list[str]):
133
142
  result_dict = {key.lower(): value.strip('"') for key, value in matches}
134
143
  image.Ep = float(result_dict["energy"])
135
144
  properties = result_dict["properties"].split(":")
136
- atom_types_image, postion, force = read_properties_data(image.atom_nums, properties, lines[1:])
145
+ atom_types_image, postion, force, bec = read_properties_data(image.atom_nums, properties, lines[1:])
137
146
  image.force = force
138
147
  image.position = postion
139
148
  image.atom_types_image = atom_types_image
149
+ image.bec = bec
140
150
  lattice = [float(i) for i in result_dict["lattice"].split()]
141
151
  assert len(lattice) == 9, "lattice in extxyz file should has 9 elements"
142
152
  image.lattice = np.array(lattice).reshape(-1, 3)
@@ -150,10 +160,10 @@ def read_one_structures_from_lines(lines:list[str]):
150
160
  virial = [float(i) for i in result_dict["virial"].split()]
151
161
  assert len(virial) == 9, "virial in extxyz file should has 9 elements"
152
162
  image.virial = np.array(virial).reshape(3, 3)
153
- if "stress" in result_dict.keys():
154
- stress = [float(i) for i in result_dict["stress"].split(" ")]
163
+ elif "stress" in result_dict.keys():
164
+ stress = [float(i) for i in result_dict["stress"].split()]
155
165
  assert len(stress) == 9, "stress in extxyz file should has 9 elements"
156
- volume = np.abs(np.linalg.det(image.lattice))
166
+ volume = np.abs(np.linalg.det(image.lattice))
157
167
  image.virial = -volume * np.reshape(stress, (3, 3))
158
168
 
159
169
  atomic_energy, _, _, _ = np.linalg.lstsq([image.atom_type_num], np.array([image.Ep]), rcond=1e-3)
@@ -165,29 +175,44 @@ def read_one_structures_from_lines(lines:list[str]):
165
175
  def read_properties_data(
166
176
  num_atom:int, properties: list[str], lines: list[str]
167
177
  ):
168
- species_offset, pos_offset, force_offset = 0, 0, 0
169
178
  assert len(properties) % 3 == 0
179
+ property_map = {}
170
180
  offset = 0
171
181
  for i in range(len(properties) // 3):
172
- if properties[i * 3] == "species":
173
- species_offset = offset
174
- elif properties[i * 3] == "pos":
175
- pos_offset = offset
176
- elif properties[i * 3] == "force" or properties[i * 3] == "forces":
177
- force_offset = offset
178
- offset += int(properties[i * 3 + 2])
179
-
182
+ name = properties[i * 3].lower()
183
+ size = int(properties[i * 3 + 2])
184
+ property_map[name] = (offset, size)
185
+ offset += size
186
+
187
+ assert "species" in property_map, "species property is required in extxyz file"
188
+ assert "pos" in property_map, "pos property is required in extxyz file"
189
+ force_key = "forces" if "forces" in property_map else "force"
190
+ assert force_key in property_map, "force or forces property is required in extxyz file"
191
+ if "bec" in property_map:
192
+ assert property_map["bec"][1] == 9, "bec in extxyz file should has 9 elements per atom"
193
+
194
+ species_offset, _ = property_map["species"]
195
+ pos_offset, pos_size = property_map["pos"]
196
+ force_offset, force_size = property_map[force_key]
197
+ assert pos_size == 3, "pos in extxyz file should has 3 elements per atom"
198
+ assert force_size == 3, "force in extxyz file should has 3 elements per atom"
199
+
200
+ bec_offset = property_map["bec"][0] if "bec" in property_map else None
180
201
  assert num_atom == len(lines)
181
202
  type_list = []
182
203
  force = []
183
204
  position= []
205
+ bec = [] if bec_offset is not None else None
184
206
  for line in lines:
185
207
  data = line.split()
186
208
  type_list.append(ELEMENTTABLE[data[species_offset]])
187
209
  force.append([float(data[force_offset]), float(data[force_offset + 1]), float(data[force_offset + 2])])
188
210
  position.append([float(data[pos_offset]), float(data[pos_offset + 1]), float(data[pos_offset + 2])])
211
+ if bec_offset is not None:
212
+ bec.append([float(data[bec_offset + i]) for i in range(9)])
189
213
  type_list = np.array(type_list) #.reshape(-1, 1)
190
214
  position = np.array(position)
191
215
  force = np.array(force)
192
- return type_list, position, force
193
-
216
+ bec = np.array(bec).reshape(num_atom, 9) if bec is not None else None
217
+ return type_list, position, force, bec
218
+
@@ -13,7 +13,7 @@ class Image(object):
13
13
  atom_type = None, atom_type_num = None, atom_nums = None, atom_types_image = None,
14
14
  iteration = None, Etot = None, Ep = None, Ek = None, scf = None, lattice = None,
15
15
  virial = None, position = None, force = None, atomic_energy = None,
16
- content = None, image_nums = None, pbc = None, cartesian = None):
16
+ bec = None, content = None, image_nums = None, pbc = None, cartesian = None):
17
17
  """
18
18
  Represents an image in a AIMD trajectory.
19
19
 
@@ -29,6 +29,7 @@ class Image(object):
29
29
  scf (float): The index of the self-consistent field.
30
30
  lattice (list): The lattice vectors.
31
31
  virial (list): The virial tensor.
32
+ bec (list): The Born effective charge tensor per atom, shape (atom_nums, 9).
32
33
  position (list): The atomic positions.
33
34
  force (list): The atomic forces.
34
35
  atomic_energy (list): The atomic energies.
@@ -49,6 +50,7 @@ class Image(object):
49
50
  self.image_nums = to_integer(image_nums)
50
51
  self.lattice = to_numpy_array(lattice)
51
52
  self.virial = to_numpy_array(virial)
53
+ self.bec = to_numpy_array(bec)
52
54
  self.position = to_numpy_array(position) # this position can be fractional coordinates or cartesian coordinates
53
55
  self.force = to_numpy_array(force)
54
56
  self.atomic_energy = to_numpy_array(atomic_energy)
@@ -65,6 +67,8 @@ class Image(object):
65
67
  self.force = self.force[sort_indices]
66
68
  if self.atomic_energy is not None:
67
69
  self.atomic_energy = self.atomic_energy[sort_indices]
70
+ if self.bec is not None:
71
+ self.bec = self.bec[sort_indices]
68
72
  cout_type, indices = np.unique(self.atom_types_image, return_index=True)
69
73
  sorted_indices = np.argsort(indices)
70
74
  cout_type = cout_type[sorted_indices]
@@ -1,4 +1,5 @@
1
1
  import numpy as np
2
+ import re
2
3
  import os, glob
3
4
  from tqdm import tqdm
4
5
  from pwdata.image import Image
@@ -84,6 +85,10 @@ class META(object):
84
85
  """处理每个 atom_list 并转换为对象列表"""
85
86
  return [to_image(Atoms) for Atoms in atom_list]
86
87
 
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
+
87
92
  def load_and_query_db(db_address, atom_types, query, filter_with_elements):
88
93
  # 加载数据库
89
94
  try:
@@ -103,6 +108,16 @@ def load_and_query_db(db_address, atom_types, query, filter_with_elements):
103
108
  atom_list.extend(list(dbs.select(query, filter=filter_with_elements)))
104
109
  else: # query is not None and atom_types is None
105
110
  atom_list.extend(list(dbs.select(query)))
111
+
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
106
121
  return atom_list
107
122
 
108
123
  def query_fun(row, elements):
@@ -122,21 +137,45 @@ def to_image(Atoms):
122
137
  image.lattice = to_numpy_array(Atoms.cell).reshape(3, 3)
123
138
  image.position = to_numpy_array(Atoms.positions)
124
139
  image.cartesian = True
125
- image.force = to_numpy_array(Atoms.forces)
126
- image.Ep = to_float(Atoms.energy)
127
- # 计算 Atomic-Energy
128
- # atomic_energy, _, _, _ = np.linalg.lstsq([image.atom_type_num], np.array([image.Ep]), rcond=1e-3)
129
- # atomic_energy = np.repeat(atomic_energy, image.atom_type_num)
130
- # image.atomic_energy = atomic_energy.tolist()
131
140
 
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)
141
+ # Get forces and energy
142
+ # AtomsRow (from LMDB select): uses direct attribute access
143
+ # Atoms (with SinglePointCalculator): uses .get_*() method calls
144
+ try:
145
+ image.force = to_numpy_array(Atoms.forces)
146
+ except AttributeError:
147
+ image.force = to_numpy_array(Atoms.get_forces())
148
+ try:
149
+ image.Ep = to_float(Atoms.energy)
150
+ except AttributeError:
151
+ image.Ep = to_float(Atoms.get_potential_energy())
152
+
153
+ # Compute virial from stress tensor
154
+ # Convention: virial = -stress * volume
155
+ # AtomsRow path: .stress is 6-element Voigt [s_xx, s_yy, s_zz, s_yz, s_xz, s_xy]
156
+ # Atoms path: .get_stress(voigt=False) returns full 3x3 tensor
157
+ try:
158
+ stress_raw = Atoms.stress
159
+ except AttributeError:
160
+ stress_raw = None
161
+ try:
162
+ stress_raw = Atoms.get_stress(voigt=False)
163
+ except Exception:
164
+ pass
165
+
166
+ if stress_raw is not None:
167
+ stress = np.array(stress_raw)
168
+ volume = Atoms.volume
169
+ if stress.shape == (6,):
170
+ virial = -stress * volume
171
+ image.virial = np.array([
172
+ [virial[0], virial[5], virial[4]],
173
+ [virial[5], virial[1], virial[3]],
174
+ [virial[4], virial[3], virial[2]]
175
+ ])
176
+ else:
177
+ # Already 3x3 tensor
178
+ image.virial = -stress * volume
179
+
141
180
  image.format = 'metadata'
142
181
  return image
@@ -27,7 +27,7 @@ class MOVEMENT(object):
27
27
  elif "Lattice" in ii:
28
28
  lattice_stress = self.parse_lattice_stress(mvm_contents[idx+1:idx+4])
29
29
  image.lattice = to_numpy_array(lattice_stress["lattice"])
30
- image.virial = to_numpy_array(lattice_stress["virial"])
30
+ image.virial = -to_numpy_array(lattice_stress["virial"]) if len(lattice_stress["virial"]) > 0 else to_numpy_array(lattice_stress["virial"]) # The movement virial value is the opposite of vasp
31
31
  elif " Position" in ii:
32
32
  position = self.parse_position(mvm_contents[idx+1:idx+image.atom_nums+1])
33
33
  image.position = to_numpy_array(position["position"])
@@ -0,0 +1,131 @@
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, "*.lmdb"))
118
+ for pt in pt_list:
119
+ save_path = os.path.join(save_dir, os.path.basename(pt).replace('.lmdb', '.aselmdb'))
120
+ source = LMDBDatabase(filename=pt, readonly=True)
121
+ db = LMDBDatabase(filename=save_path, readonly=False)
122
+ atom_row_list = read2atoms(pt, db, prefix)
123
+
124
+
125
+ if __name__=="__main__":
126
+ pt_dir="/data/public/wuxingxing/catalyticLAM/metal/train"
127
+ save_dir="/data/public/wuxingxing/catalyticLAM/metal/train/tmp"
128
+ if not os.path.exists(save_dir):
129
+ os.makedirs(save_dir)
130
+ prefix = "2d"
131
+ cvtbamboo(pt_dir, save_dir, prefix)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pwdata
3
- Version: 0.5.6.dev0
3
+ Version: 0.5.8
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
@@ -15,3 +15,10 @@ License-File: LICENSE
15
15
  # see doc
16
16
 
17
17
  http://doc.lonxun.com/PWMLFF/Appendix-2/
18
+
19
+ pip3 install setuptools wheel twine
20
+
21
+ rm dist/ -r
22
+ python3 setup.py sdist bdist_wheel
23
+ twine upload dist/* --verbose
24
+
@@ -24,7 +24,6 @@ pwdata/outcar.py
24
24
  pwdata/poscar.py
25
25
  pwdata/pwmlff.py
26
26
  pwdata/test.py
27
- pwdata/tmp.py
28
27
  pwdata.egg-info/PKG-INFO
29
28
  pwdata.egg-info/SOURCES.txt
30
29
  pwdata.egg-info/dependency_links.txt
@@ -65,6 +64,7 @@ pwdata/pertub/scale.py
65
64
  pwdata/test/__init__.py
66
65
  pwdata/test/bamboo2lmdb.py
67
66
  pwdata/test/extact_outcar_with_ml.py
67
+ pwdata/test/lmdb2aselmdb.py
68
68
  pwdata/test/matpbe2lmdb.py
69
69
  pwdata/test/matrcan2lmdb.py
70
70
  pwdata/test/mdtrajs2config.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.6dev0",
14
+ version="0.5.8",
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.",
@@ -1,3 +0,0 @@
1
- # see doc
2
-
3
- http://doc.lonxun.com/PWMLFF/Appendix-2/
@@ -1,59 +0,0 @@
1
- from ase.io import read, write
2
- import os
3
- import glob
4
-
5
- """
6
- xyz_file = "/data/home/wuxingxing/codespace/EDM/outputs/edm_qm9/bk_eval/stabel_pwmat/0/molecule_stable_000.xyz"
7
- atoms = read(xyz_file)
8
- atoms.center(vacuum=8)
9
- # 获取原子符号列表,并排序
10
- symbols = atoms.get_chemical_symbols()
11
- sorted_indices = sorted(range(len(symbols)), key=lambda i: symbols[i])
12
-
13
- # 按排序后的索引重新排列原子
14
- atoms_sorted = atoms[sorted_indices]
15
-
16
- save_file = "/data/home/wuxingxing/codespace/EDM/outputs/edm_qm9/bk_eval/stabel_pwmat/0/sort.0.POSCAR"
17
- write(filename=save_file, images=atoms_sorted, format="vasp")
18
- """
19
-
20
- pseudo = ["/data/home/wuxingxing/codespace/EDM/outputs/edm_qm9/bk_eval/stabel_pwmat/F.SG15.PBE.UPF",
21
- "/data/home/wuxingxing/codespace/EDM/outputs/edm_qm9/bk_eval/stabel_pwmat/N.SG15.PBE.UPF",
22
- "/data/home/wuxingxing/codespace/EDM/outputs/edm_qm9/bk_eval/stabel_pwmat/C.SG15.PBE.UPF",
23
- "/data/home/wuxingxing/codespace/EDM/outputs/edm_qm9/bk_eval/stabel_pwmat/H.SG15.PBE.UPF",
24
- "/data/home/wuxingxing/codespace/EDM/outputs/edm_qm9/bk_eval/stabel_pwmat/O.SG15.PBE.UPF",
25
- "/data/home/wuxingxing/codespace/EDM/outputs/edm_qm9/bk_eval/stabel_pwmat/etot.input",
26
- "/data/home/wuxingxing/codespace/EDM/outputs/edm_qm9/bk_eval/stabel_pwmat/run.sh"]
27
-
28
- def set_path():
29
- xyz_path = "/data/home/wuxingxing/codespace/EDM/outputs/edm_qm9/bk_eval/molecules"
30
- save_path= "/data/home/wuxingxing/codespace/EDM/outputs/edm_qm9/bk_eval/stabel_pwmat"
31
- xyz_files = glob.glob(os.path.join(xyz_path, "molecule_stable_*.xyz"))
32
- for xyz_file in xyz_files:
33
- if "molecule_stable_000.xyz" in os.path.basename(xyz_file):
34
- pass
35
- atoms = read(xyz_file)
36
- atoms.center(vacuum=8)
37
- # 获取原子符号列表,并排序
38
- symbols = atoms.get_chemical_symbols()
39
- sorted_indices = sorted(range(len(symbols)), key=lambda i: symbols[i])
40
-
41
- # 按排序后的索引重新排列原子
42
- atoms_sorted = atoms[sorted_indices]
43
- idx = int(xyz_file.split("/")[-1].split("_")[-1].split(".")[0])
44
- save_dir = os.path.join(save_path, "{}".format(idx))
45
- if not os.path.exists(save_dir):
46
- os.makedirs(save_dir)
47
- save_file = os.path.join(save_dir, "POSCAR")
48
- write(filename=save_file, images=atoms_sorted, format="vasp")
49
-
50
- for _tmp in pseudo:
51
- os.system(f"cp {_tmp} {save_dir}")
52
-
53
- cwd = os.getcwd()
54
- os.chdir(save_dir)
55
- os.system("pwdata cvt_config -i POSCAR -f vasp/poscar -o pwmat/config")
56
- os.chdir(cwd)
57
-
58
- if __name__ == "__main__":
59
- set_path() # pwmat
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