pwdata 0.5.0__tar.gz → 0.5.2__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 (76) hide show
  1. {pwdata-0.5.0 → pwdata-0.5.2}/PKG-INFO +2 -2
  2. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/__init__.py +5 -0
  3. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/check_envs.py +2 -2
  4. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/config.py +4 -1
  5. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/dump.py +11 -3
  6. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/fairchem/datasets/ase_datasets.py +10 -6
  7. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/image.py +11 -5
  8. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/main.py +12 -6
  9. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/meta.py +12 -1
  10. pwdata-0.5.2/pwdata/meta_omol.py +169 -0
  11. pwdata-0.5.2/pwdata/molecule.py +82 -0
  12. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/movement.py +2 -4
  13. pwdata-0.5.2/pwdata/test/omol25.py +42 -0
  14. pwdata-0.5.2/pwdata/test/outcar2mvms.py +18 -0
  15. pwdata-0.5.2/pwdata/tmp.py +59 -0
  16. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/utils/constant.py +4 -1
  17. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata.egg-info/PKG-INFO +2 -2
  18. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata.egg-info/SOURCES.txt +5 -0
  19. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata.egg-info/requires.txt +2 -1
  20. {pwdata-0.5.0 → pwdata-0.5.2}/setup.py +4 -3
  21. {pwdata-0.5.0 → pwdata-0.5.2}/LICENSE +0 -0
  22. {pwdata-0.5.0 → pwdata-0.5.2}/README.md +0 -0
  23. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/atomconfig.py +0 -0
  24. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/build/__init__.py +0 -0
  25. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/build/cell.py +0 -0
  26. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/build/geometry.py +0 -0
  27. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/build/supercells.py +0 -0
  28. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/build/write_struc.py +0 -0
  29. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/calculators/__init__.py +0 -0
  30. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/calculators/const.py +0 -0
  31. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/calculators/unitconvert_lmps.py +0 -0
  32. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/calculators/units.py +0 -0
  33. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/convert_files.py +0 -0
  34. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/cp2kdata.py +0 -0
  35. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/datasets_saver.py +0 -0
  36. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/deepmd.py +0 -0
  37. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/extendedxyz.py +0 -0
  38. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/fairchem/__init__.py +0 -0
  39. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/fairchem/common/__init__.py +0 -0
  40. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/fairchem/common/registry.py +0 -0
  41. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/fairchem/common/typing.py +0 -0
  42. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/fairchem/common/utils.py +0 -0
  43. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/fairchem/datasets/__init__.py +0 -0
  44. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/fairchem/datasets/_utils.py +0 -0
  45. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/fairchem/datasets/base_dataset.py +0 -0
  46. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/fairchem/datasets/embeddings/__init__.py +0 -0
  47. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/fairchem/datasets/embeddings/atomic_radii.py +0 -0
  48. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/fairchem/datasets/embeddings/continuous_embeddings.py +0 -0
  49. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/fairchem/datasets/embeddings/khot_embeddings.py +0 -0
  50. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/fairchem/datasets/embeddings/qmof_khot_embeddings.py +0 -0
  51. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/fairchem/datasets/lmdb_database.py +0 -0
  52. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/fairchem/datasets/target_metadata_guesser.py +0 -0
  53. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/fairchem/modules/__init__.py +0 -0
  54. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/fairchem/modules/transforms.py +0 -0
  55. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/fairchem/preprocessing/__init__.py +0 -0
  56. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/lammpsdata.py +0 -0
  57. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/lmps.py +0 -0
  58. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/movement_saver.py +0 -0
  59. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/outcar.py +0 -0
  60. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/pertub/__init__.py +0 -0
  61. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/pertub/perturbation.py +0 -0
  62. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/pertub/scale.py +0 -0
  63. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/poscar.py +0 -0
  64. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/pwmlff.py +0 -0
  65. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/test/__init__.py +0 -0
  66. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/test/matpbe2lmdb.py +0 -0
  67. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/test/matrcan2lmdb.py +0 -0
  68. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/test/mdtrajs2config.py +0 -0
  69. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/test/mptraj2lmdb.py +0 -0
  70. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/test.py +0 -0
  71. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/utils/__init__.py +0 -0
  72. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata/utils/format_change.py +0 -0
  73. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata.egg-info/dependency_links.txt +0 -0
  74. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata.egg-info/entry_points.txt +0 -0
  75. {pwdata-0.5.0 → pwdata-0.5.2}/pwdata.egg-info/top_level.txt +0 -0
  76. {pwdata-0.5.0 → pwdata-0.5.2}/setup.cfg +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pwdata
3
- Version: 0.5.0
4
- Summary: pwdata is a data pre-processing tool for PWMLFF, which can be used to extract features and labels. It also provides convenient interfaces for data conversion between different software.
3
+ Version: 0.5.2
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
7
7
  Author-email: lonxun@pwmat.com
@@ -1,4 +1,6 @@
1
1
  from .config import Save_Data, Config
2
+ from pwdata.molecule import Molecule
3
+ from .meta_omol import META_OMol, read_oMol_data
2
4
  from .build.supercells import make_supercell
3
5
  from .pertub.perturbation import perturb_structure
4
6
  from .pertub.scale import scale_cell
@@ -6,6 +8,9 @@ from .pertub.scale import scale_cell
6
8
  __all__ = [
7
9
  "Save_Data",
8
10
  "Config",
11
+ "Molecule",
12
+ "META_OMol",
13
+ "read_oMol_data",
9
14
  "make_supercell",
10
15
  "perturb_structure",
11
16
  "scale_cell"
@@ -58,8 +58,8 @@ def comm_info():
58
58
  print("\n" + "=" * 50)
59
59
  print(" PWDATA Basic Information")
60
60
  print("=" * 50)
61
- print("Version: 0.5.0")
62
- print("support pwact: >= 0.2.0")
61
+ print("Version: 0.5.2")
62
+ print("support pwact: >= 0.3.0")
63
63
  print("support MatPL: >= 2025.3")
64
64
  print("Contact: support@pwmat.com")
65
65
  print("Citation: https://github.com/LonxunQuantum/MatPL")
@@ -330,7 +330,10 @@ def infer_format(data_path: str, pbc = None, atom_names = None, index = ':', **k
330
330
  pass
331
331
  try:
332
332
  image = META(data_path, atom_names, **kwargs).image_list[index]
333
- return image, FORMAT.meta
333
+ if len(image) == 0:
334
+ pass
335
+ else:
336
+ return image, FORMAT.meta
334
337
  except Exception as e:
335
338
  pass
336
339
  try:
@@ -71,6 +71,8 @@ class DUMP(object):
71
71
  image.position = to_numpy_array(info["positions"])
72
72
  if "forces" in info.keys():
73
73
  image.force = to_numpy_array(info["forces"])
74
+ if "data" in info.keys():
75
+ image.data = info["data"]
74
76
  image.pbc = to_numpy_array(pbc)
75
77
  image.cartesian = True
76
78
 
@@ -115,10 +117,11 @@ class DUMP(object):
115
117
  if "element" in colnames:
116
118
  # priority to elements written in file
117
119
  elements = data[:, colnames.index("element")]
120
+ atom_types_image = elements_to_order(atom_names, elements, atom_nums, is_atom_type_name=True)
118
121
  elif "type" in colnames:
119
122
  # fall back to `types` otherwise
120
123
  elements = data[:, colnames.index("type")].astype(int)
121
-
124
+ atom_types_image = elements_to_order(atom_names, elements, atom_nums)
122
125
  # reconstruct types from given specorder
123
126
  if specorder:
124
127
  elements = [specorder[t - 1] for t in elements]
@@ -128,7 +131,7 @@ class DUMP(object):
128
131
  # lots of cases and new code I guess
129
132
  raise ValueError("Cannot determine atom types form LAMMPS dump file")
130
133
  # elements2type = np.array(atom_names)[elements - 1]
131
- atom_types_image = elements_to_order(atom_names, elements, atom_nums)
134
+
132
135
  sc = Counter(atom_types_image) # a list sc of (atom_types, count) pairs
133
136
  atom_type = list(sc.keys())
134
137
  atom_type_num = list(sc.values())
@@ -162,6 +165,11 @@ class DUMP(object):
162
165
  else:
163
166
  raise ValueError("No atomic positions found in LAMMPS output")
164
167
 
168
+ peratom_info = {}
169
+ for param in colnames:
170
+ if param not in ["element", "id", "type", "x", "y", "z", "xs", "ys", "zs", "xu", "yu", "zu", "xsu", "ysu", "zsu"]:
171
+ peratom_info[param] = get_quantity([param], "distance")
172
+
165
173
  velocities = get_quantity(["vx", "vy", "vz"], "velocity")
166
174
  charges = get_quantity(["q"], "charge")
167
175
  forces = get_quantity(["fx", "fy", "fz"], "force")
@@ -193,6 +201,6 @@ class DUMP(object):
193
201
  all["lattice"] = lattice
194
202
  if lattice_disp is not None:
195
203
  all["lattice_disp"] = lattice_disp
196
-
204
+ all["data"] = peratom_info
197
205
  return all
198
206
 
@@ -540,12 +540,16 @@ class AseDBDataset(AseAtomsDataset):
540
540
  ) -> ase.db.core.Database:
541
541
  if connect_args is None:
542
542
  connect_args = {}
543
- db_type = connect_args.get("type", "extract_from_name")
544
- if db_type in ("lmdb", "aselmdb") or (
545
- db_type == "extract_from_name"
546
- and str(address).rsplit(".", maxsplit=1)[-1] in ("lmdb", "aselmdb")
547
- ):
548
- return LMDBDatabase(address, readonly=True, **connect_args)
543
+ # this code ase < 3.25
544
+ # db_type = connect_args.get("type", "extract_from_name")
545
+ # if db_type in ("lmdb", "aselmdb") or (
546
+ # db_type == "extract_from_name"
547
+ # and str(address).rsplit(".", maxsplit=1)[-1] in ("lmdb", "aselmdb")
548
+ # ):
549
+ # return LMDBDatabase(address, readonly=True, **connect_args)
550
+ if "aselmdb" in address: # ase >=3.25
551
+ connect_args["readonly"] = True
552
+ connect_args["use_lock_file"] = False
549
553
 
550
554
  return ase.db.connect(address, **connect_args)
551
555
 
@@ -56,6 +56,7 @@ class Image(object):
56
56
  self.cartesian = cartesian if cartesian is not None else False
57
57
  self.pbc = to_numpy_array(pbc) if pbc is not None else np.zeros(3, bool)
58
58
  self.arrays = self.prim_dict() # here, position will be convert to cartesian coordinates
59
+ self.data = {}
59
60
 
60
61
  def sort_by_atomtype(self):
61
62
  sort_indices = np.argsort(self.atom_types_image)
@@ -256,10 +257,10 @@ class Image(object):
256
257
  return len(self.arrays['position'])
257
258
 
258
259
  '''follow functions shoule be merged into the Image class later!!!'''
259
- def elements_to_order(atom_names, atom_types_image, atom_nums):
260
+ def elements_to_order(atom_names, atom_types_image, atom_nums, is_atom_type_name=False):
260
261
  """
261
262
  Replaces the atom types's order (from 1) to the order of the elements in the atom_names list.
262
-
263
+
263
264
  Args:
264
265
  atom_names (list): List of atom names.
265
266
  atom_types_image (list): List of atom types.
@@ -268,6 +269,7 @@ def elements_to_order(atom_names, atom_types_image, atom_nums):
268
269
  Example:
269
270
  >>> atom_names = ['C', 'N']
270
271
  >>> atom_types_image = [1, 1, 1, 1, 1, ... , 2, 2, 2, 2, 2, ... , 2]
272
+ >>> if is_atom_type_name is Ture, the atom_types_image = ["C", "C", "C", "C", "C", ... , "N", "N", "N", "N", "N", ... , "N"]
271
273
  >>> atom_nums = 56
272
274
  >>> elements_to_order(atom_names, atom_types_image, atom_nums)
273
275
  [6, 6, 6, 6, 6, ... , 7, 7, 7, 7, 7, ... , 7]
@@ -279,9 +281,13 @@ def elements_to_order(atom_names, atom_types_image, atom_nums):
279
281
  # for ii in range(atom_nums):
280
282
  # if name in elements and atom_types_image[ii] == idx+1:
281
283
  # atom_types_image[ii] = elements.index(name)
282
- type_mapping = {idx+1: elements.index(name) for idx, name in enumerate(atom_names)}
283
- atom_types_image = [type_mapping[atom_type] for atom_type in atom_types_image]
284
- return atom_types_image
284
+ if is_atom_type_name:
285
+ atom_types_image = [elements.index(name) for name in atom_types_image]
286
+ return atom_types_image
287
+ else:
288
+ type_mapping = {idx+1: elements.index(name) for idx, name in enumerate(atom_names)}
289
+ atom_types_image = [type_mapping[atom_type] for atom_type in atom_types_image]
290
+ return atom_types_image
285
291
 
286
292
  def frac2cart(position, lattice):
287
293
  """
@@ -23,7 +23,7 @@ sys.path.append(os.path.dirname(os.path.abspath(__file__)))
23
23
  # from pwdata.build.write_struc import write_config, write_vasp, write_lammps
24
24
  import argparse
25
25
  from pwdata.convert_files import do_scale_cell, do_super_cell, do_perturb, do_convert_config, do_convert_images, do_count_images
26
- from pwdata.utils.constant import FORMAT, get_atomic_name_from_number
26
+ from pwdata.utils.constant import FORMAT, get_atomic_name_from_number, check_atom_type_name
27
27
  from pwdata.check_envs import print_cmd, comm_info
28
28
 
29
29
  # from pwdata.open_data.meta_data import get_meta_data
@@ -204,7 +204,7 @@ def run_convert_config(cmd_list:list[str]):
204
204
  parser.add_argument('-i', '--input', type=str, required=True, help='The input file path')
205
205
  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 file. the supported format as ['pwmat/config','vasp/poscar', 'lammps/lmp', 'cp2k/scf']")
206
206
  parser.add_argument('-s', '--savename', type=str, required=False, default=None, help="The output file name, if not provided, the 'atom.config' for pwmat/config, 'POSCAR' for vasp/poscar, 'lammps.lmp' for lammps/lmp will be used")
207
- parser.add_argument('-o', '--output_format', type=str, required=False, default=None, help="the output file format, only support the format ['pwmat/config','vasp/poscar', 'lammps/lmp'], if not provided, the input format be used. \nNote: that outputting cp2k/scf format is not supported. In this case, the default will be adjusted to pwmat atom.config")
207
+ parser.add_argument('-o', '--output_format', type=str, required=True, default=None, help="the output file format, only support the format ['pwmat/config','vasp/poscar', 'lammps/lmp']")
208
208
  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. 'pwmat/config' only supports fractional coordinates, in which case this parameter becomes invalid")
209
209
  parser.add_argument('-t', '--atom_types', type=str, required=False, default=None, nargs='+', help="the atom type list of 'lammps/lmp' or 'lammps/dump' input file, the order is same as the input file")
210
210
  args = parser.parse_args(cmd_list)
@@ -238,10 +238,16 @@ def run_convert_configs(cmd_list:list[str]):
238
238
  parser.add_argument('-t', '--atom_types', type=str, required=False, nargs='+', help="For 'lammps/lmp', 'lammps/dump': the atom type list of lammps lmp/dump file, the order is same as lammps dump file.\nFor meta data: Query structures that only exist for that element type", default=None)
239
239
 
240
240
  args = parser.parse_args(cmd_list)
241
- try:
242
- atom_types = get_atomic_name_from_number(args.atom_types)
243
- except Exception as e:
244
- atom_types = args.atom_types
241
+ if args.atom_types is None:
242
+ atom_types = None
243
+ else:
244
+ try:
245
+ atom_types = get_atomic_name_from_number(args.atom_types)
246
+ except Exception as e:
247
+ if check_atom_type_name(args.atom_types):
248
+ atom_types = args.atom_types
249
+ else:
250
+ raise Exception("The input '-t' or '--atom_types': '{}' is not valid, please check the input".format(" ".join(args.atom_types)))
245
251
  input_list = []
246
252
  for _input in args.input:
247
253
  if os.path.isfile(_input) and "json" in os.path.basename(_input) and os.path.exists(_input):
@@ -13,7 +13,8 @@ class META(object):
13
13
  def __init__(self, files: list[str], atom_names: list[str] = None, query: str = None, cpu_nums: int=None):
14
14
  self.image_list:list[Image] = []
15
15
  self.load_files_cpus(files, atom_names, query, cpu_nums)
16
- assert len(self.image_list) > 0, "No data loaded!"
16
+ if len(self.image_list) < 1:
17
+ print("Warining! No data loaded!")
17
18
  # self.load_files(files, atom_names, query, cpu_nums) used to debug on one cpu
18
19
 
19
20
  def get(self):
@@ -51,6 +52,14 @@ class META(object):
51
52
  cpu_nums = min(cpu_nums, multiprocessing.cpu_count())
52
53
  if isinstance(input, str):
53
54
  input = [input]
55
+ # 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)
54
63
  # 使用多进程并行加载和查询数据库
55
64
  with ProcessPoolExecutor(max_workers=cpu_nums) as executor:
56
65
  futures = []
@@ -65,6 +74,8 @@ class META(object):
65
74
  # 处理所有结果
66
75
  for atom_list in atom_lists:
67
76
  if len(atom_list) > 0:
77
+ # for _ in atom_list:
78
+ # print(_.formula)
68
79
  self.image_list.extend([to_image(Atoms) for Atoms in atom_list])
69
80
 
70
81
  @staticmethod
@@ -0,0 +1,169 @@
1
+ import numpy as np
2
+ import os, glob
3
+ from tqdm import tqdm
4
+ from pwdata.molecule import Molecule as 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 ase.db.row import AtomsRow
12
+ from ase.atoms import Atoms
13
+ from pwdata.convert_files import search_by_format
14
+ from pwdata.utils.constant import FORMAT, get_atomic_name_from_number, check_atom_type_name
15
+
16
+ class META_OMol(object):
17
+ def __init__(self, files: list[str], atom_names: list[str] = None, query: str = None, cpu_nums: int=None):
18
+ self.image_list:list[Image] = []
19
+ self.load_files_cpus(files, atom_names, query, cpu_nums)
20
+ if len(self.image_list) < 1:
21
+ print("Warining! No data loaded!")
22
+ # self.load_files(files, atom_names, query, cpu_nums) used to debug on one cpu
23
+
24
+ def get(self):
25
+ return self.image_list
26
+
27
+ def load_files(self, input:list[str], atom_types: list[str] = None, query: str = None, cpu_nums: int=None):
28
+ def query_fun(row, elements:list[str]=None):
29
+ if elements is None:
30
+ return True
31
+ return sorted(set(row.symbols)) == elements
32
+
33
+ search_dict = {'src': input}
34
+ dataset = AseDBDataset(config=search_dict)
35
+ if atom_types is not None:
36
+ filter_with_elements = partial(query_fun, elements=sorted(atom_types))
37
+ for ids, dbs in enumerate(dataset.dbs):
38
+ if query is None and atom_types is None:
39
+ atom_list = list(dbs.select())
40
+ elif query is None and atom_types is not None:
41
+ atom_list = list(dbs.select("".join(atom_types), filter=filter_with_elements))
42
+ elif query is not None and atom_types is not None:
43
+ atom_list = list(dbs.select(query, filter=filter_with_elements))
44
+ else:# query is not None and atom_types is None:
45
+ atom_list = list(dbs.select(query))
46
+ for Atoms in atom_list:
47
+ image = to_image(Atoms)
48
+ self.image_list.append(image)
49
+
50
+ def load_files_cpus(self, input: list[str], atom_types: list[str] = None, query: str = None, cpu_nums: int = None):
51
+ # 设置查询过滤器
52
+ filter_with_elements = partial(query_fun, elements=sorted(atom_types)) if atom_types is not None else None
53
+ if cpu_nums is None:
54
+ cpu_nums = 1
55
+ else:
56
+ cpu_nums = min(cpu_nums, multiprocessing.cpu_count())
57
+ if isinstance(input, str):
58
+ input = [input]
59
+ # single cpu debug
60
+ # atom_lists = []
61
+ # for i, _ in enumerate(input):
62
+ # print(i)
63
+ # _atom_lists = load_and_query_db(_, atom_types, query, filter_with_elements)
64
+ # for _ in _atom_lists:
65
+ # print(_.formula)
66
+ # atom_lists.extend(_atom_lists)
67
+ # 使用多进程并行加载和查询数据库
68
+ with ProcessPoolExecutor(max_workers=cpu_nums) as executor:
69
+ futures = []
70
+ for db_address in input:
71
+ futures.append(executor.submit(load_and_query_db, db_address, atom_types, query, filter_with_elements))
72
+
73
+ # 收集查询结果
74
+ atom_lists = []
75
+ for future in as_completed(futures):
76
+ atom_lists.append(future.result())
77
+
78
+ # 处理所有结果
79
+ for atom_list in atom_lists:
80
+ if len(atom_list) > 0:
81
+ # for _ in atom_list:
82
+ # print(_.formula)
83
+ self.image_list.extend([to_image(Atoms) for Atoms in atom_list])
84
+
85
+ @staticmethod
86
+ def process_atoms(self, atom_list):
87
+ """处理每个 atom_list 并转换为对象列表"""
88
+ return [to_image(Atoms) for Atoms in atom_list]
89
+
90
+ def load_and_query_db(db_address, atom_types, query, filter_with_elements):
91
+ # 加载数据库
92
+ try:
93
+ dataset = AseDBDataset(config={'src': db_address})
94
+ except Exception as e:
95
+ if "No valid ase data found" in e.args[0]:
96
+ return []
97
+ else:
98
+ return e
99
+ atom_list = []
100
+ for dbs in dataset.dbs:
101
+ if query is None and atom_types is None:
102
+ atom_list.extend(list(dbs.select()))
103
+ elif query is None and atom_types is not None:
104
+ atom_list.extend(list(dbs.select("".join(atom_types), filter=filter_with_elements)))
105
+ elif query is not None and atom_types is not None:
106
+ atom_list.extend(list(dbs.select(query, filter=filter_with_elements)))
107
+ else: # query is not None and atom_types is None
108
+ atom_list.extend(list(dbs.select(query)))
109
+ return atom_list
110
+
111
+ def query_fun(row, elements):
112
+ if elements is None:
113
+ return True
114
+ return sorted(set(row.symbols)) == elements
115
+
116
+ def to_image(Atoms:AtomsRow):
117
+ image = Image(Atoms)
118
+ # image.formula = Atoms.formula
119
+ # image.pbc = to_numpy_array(Atoms.pbc)
120
+ # image.atom_nums = Atoms.natoms
121
+ # type_nums_dict = Counter(Atoms.numbers)
122
+ # image.atom_type = to_numpy_array(list(type_nums_dict.keys()))
123
+ # image.atom_type_num = to_numpy_array(list(type_nums_dict.values()))
124
+ # image.atom_types_image = to_numpy_array(Atoms.numbers)
125
+ # image.lattice = to_numpy_array(Atoms.cell).reshape(3, 3)
126
+ # image.position = to_numpy_array(Atoms.positions)
127
+ # image.cartesian = True
128
+ # image.force = to_numpy_array(Atoms.forces)
129
+ # image.Ep = to_float(Atoms.energy)
130
+
131
+ # 计算 Atomic-Energy
132
+ # atomic_energy, _, _, _ = np.linalg.lstsq([image.atom_type_num], np.array([image.Ep]), rcond=1e-3)
133
+ # atomic_energy = np.repeat(atomic_energy, image.atom_type_num)
134
+ # image.atomic_energy = atomic_energy.tolist()
135
+ # vol = Atoms.volume() # volume is 0 in Molecules
136
+ # virial = (-np.array(Atoms.stress) * vol)
137
+ # image.virial = np.array([
138
+ # [virial[0], virial[5], virial[4]],
139
+ # [virial[5], virial[1], virial[3]],
140
+ # [virial[4], virial[3], virial[2]]
141
+ # ])
142
+ image.format = 'meta/omol'
143
+ return image
144
+
145
+ def read_oMol_data(file_list:list[str], atom_names:list[str]=None, query:str=None, cpu_nums:int=1):
146
+ lmdb_list = []
147
+ for file in file_list:
148
+ _tmp = search_by_format(file, "meta")
149
+ if len(_tmp) > 0:
150
+ lmdb_list.extend(_tmp)
151
+
152
+ if len(lmdb_list) < 1:
153
+ print("The lmdb files in {} is not exists!".format(" ".join(file_list)))
154
+ return
155
+ atom_names = None #["C", "H"]
156
+ query = None
157
+ cpu_nums = 1
158
+
159
+ if atom_names is not None:
160
+ try:
161
+ atom_names = get_atomic_name_from_number(atom_names)
162
+ except Exception as e:
163
+ if check_atom_type_name(atom_names):
164
+ pass
165
+ else:
166
+ raise Exception("The input '-t' or '--atom_types': '{}' is not valid, please check the input".format(" ".join(atom_names)))
167
+
168
+ image_list = META_OMol(lmdb_list, atom_names, query, cpu_nums)
169
+ return image_list
@@ -0,0 +1,82 @@
1
+ import numpy as np
2
+ import os
3
+ from pwdata.utils.format_change import to_numpy_array, to_integer, to_float
4
+ from ase.db.row import AtomsRow
5
+ # 1. initial the image class
6
+ class Molecule():
7
+ def __init__(self, atoms_row:AtomsRow = None, formula = None,
8
+ atom_type = None, atom_type_num = None, atom_nums = None, atom_types_image = None,
9
+ iteration = None, Etot = None, Ep = None, Ek = None, scf = None, lattice = None,
10
+ virial = None, position = None, force = None, atomic_energy = None,
11
+ content = None, image_nums = None, pbc = None, cartesian = None):
12
+ """
13
+ Represents an image in a AIMD trajectory.
14
+
15
+ Args:
16
+ atom_type (str): The type of atom.
17
+ atom_type_num (int): The number of atom types.
18
+ atom_nums (list): The number of atoms.
19
+ atom_types_image (list): The types of atoms in the image.
20
+ iteration (int): The iteration number.
21
+ Etot (float): The total energy.
22
+ Ep (float): The potential energy.
23
+ Ek (float): The kinetic energy.
24
+ scf (float): The index of the self-consistent field.
25
+ lattice (list): The lattice vectors.
26
+ virial (list): The virial tensor.
27
+ position (list): The atomic positions.
28
+ force (list): The atomic forces.
29
+ atomic_energy (list): The atomic energies.
30
+ content (str): The content of the image.
31
+ image_nums (int): The number of images.
32
+ pbc (list): three bool, Periodic boundary conditions flags. Examples: [True, True, False] or [1, 1, 0]. True (1) means periodic, False (0) means non-periodic. Default: [False, False, False].
33
+ """
34
+ # from atoms_row.data which is dict
35
+ self.data = atoms_row.data
36
+ self.source = atoms_row.data['source']
37
+ self.reference_source = atoms_row.data['reference_source']
38
+ self.data_id = atoms_row.data['data_id']
39
+ self.charge = atoms_row.data['charge']
40
+ self.spin = atoms_row.data['spin']
41
+ self.num_atoms = atoms_row.data['num_atoms']
42
+ self.num_electrons = atoms_row.data['num_electrons']
43
+ self.num_ecp_electrons = atoms_row.data['num_ecp_electrons']
44
+ self.n_scf_steps = atoms_row.data['n_scf_steps']
45
+ self.n_basis = atoms_row.data['n_basis']
46
+ self.unrestricted = atoms_row.data['unrestricted']
47
+ self.nl_energy = atoms_row.data['nl_energy']
48
+ self.integrated_densities = atoms_row.data['integrated_densities']
49
+ self.homo_energy = atoms_row.data['homo_energy']
50
+ self.homo_lumo_gap = atoms_row.data['homo_lumo_gap']
51
+ self.s_squared = atoms_row.data['s_squared']
52
+ self.s_squared_dev = atoms_row.data['s_squared_dev']
53
+ self.warnings = atoms_row.data['warnings']
54
+ self.mulliken_charges = atoms_row.data['mulliken_charges']
55
+ self.lowdin_charges = atoms_row.data['lowdin_charges']
56
+ self.composition = atoms_row.data['composition']
57
+
58
+ # for search param from atoms_row
59
+ self.calculator = atoms_row.calculator
60
+ self.calculator_parameters = atoms_row.calculator_parameters
61
+ self.cell = atoms_row.cell
62
+ self.charge = atoms_row.charge
63
+ self.constrained_forces = atoms_row.constrained_forces
64
+ self.constraints = atoms_row.constraints
65
+ self.ctime = atoms_row.ctime
66
+ self.energy = atoms_row.energy
67
+ self.data = atoms_row.data
68
+ self.fmax = atoms_row.fmax
69
+ self.forces = atoms_row.forces
70
+ self.formula = atoms_row.formula
71
+ self.id = atoms_row.id
72
+ self.key_value_pairs = atoms_row.key_value_pairs
73
+ self.mass = atoms_row.mass
74
+ self.mtime = atoms_row.mtime
75
+ self.natoms = atoms_row.natoms
76
+ self.numbers = atoms_row.numbers
77
+ self.pbc = atoms_row.pbc
78
+ self.positions = atoms_row.positions
79
+ self.symbols = atoms_row.symbols
80
+ self.unique_id = atoms_row.unique_id
81
+ self.user = atoms_row.user
82
+ # # end for atoms_row
@@ -60,10 +60,8 @@ class MOVEMENT(object):
60
60
  atom_nums = int(numbers[0])
61
61
  iteration = format(float(numbers[1]), '.2f')
62
62
  Etot, Ep, Ek = float(numbers[2]), float(numbers[3]), float(numbers[4])
63
- if len(numbers) >= 6:
64
- scf = numbers[5]
65
- else:
66
- scf = None
63
+ scf = -1
64
+
67
65
  return {"atom_nums": atom_nums, "iteration": iteration, "Etot": Etot, "Ep": Ep, "Ek": Ek, "scf": scf}
68
66
 
69
67
  def parse_lattice_stress(self, lattice_content):
@@ -0,0 +1,42 @@
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))
@@ -0,0 +1,18 @@
1
+ import os, sys
2
+ from pwdata import Config
3
+
4
+ import argparse
5
+
6
+ def run_convert_configs(cmd_list:list[str]):
7
+ parser = argparse.ArgumentParser(description='This command is used for transferring structural files between different apps. For extxyz format, all configs will save to one file, \nFor pwmlff/npy, configs with same atom types and atom nums in each type will save to one dir.\n')
8
+
9
+ parser.add_argument('-i', '--input', type=str, required=True, 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'")
10
+ parser.add_argument('-s', '--savepath', type=str, required=False, default="MOVEMENT", help="The output dir path, if not provided, the current dir will be used")
11
+ args = parser.parse_args(cmd_list)
12
+ image = Config(data_path=args.input, format="vasp/outcar")
13
+ image.to(format="pwmat/movement", data_path=args.savepath)
14
+ print("covert outcar to movement done!")
15
+
16
+ if __name__=="__main__":
17
+ print(sys.argv)
18
+ run_convert_configs(cmd_list = sys.argv[1:])
@@ -0,0 +1,59 @@
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
@@ -119,7 +119,7 @@ def get_atomic_number_from_name(atomic_names:list[str]):
119
119
  def get_atomic_name_from_number(atomic_number:list[int]):
120
120
  res = []
121
121
  for number in atomic_number:
122
- res.append(ELEMENTTABLE_2[number])
122
+ res.append(ELEMENTTABLE_2[int(number)])
123
123
  return res
124
124
 
125
125
  def get_atomic_name_from_str(atom_strs):
@@ -127,3 +127,6 @@ def get_atomic_name_from_str(atom_strs):
127
127
  return [int(_) for _ in atom_strs]
128
128
  except ValueError:
129
129
  return get_atomic_number_from_name(atom_strs)
130
+
131
+ def check_atom_type_name(atom_types:list[str]):
132
+ return all([_ in ELEMENTTABLE.keys() for _ in atom_types])
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pwdata
3
- Version: 0.5.0
4
- Summary: pwdata is a data pre-processing tool for PWMLFF, which can be used to extract features and labels. It also provides convenient interfaces for data conversion between different software.
3
+ Version: 0.5.2
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
7
7
  Author-email: lonxun@pwmat.com
@@ -16,12 +16,15 @@ pwdata/lammpsdata.py
16
16
  pwdata/lmps.py
17
17
  pwdata/main.py
18
18
  pwdata/meta.py
19
+ pwdata/meta_omol.py
20
+ pwdata/molecule.py
19
21
  pwdata/movement.py
20
22
  pwdata/movement_saver.py
21
23
  pwdata/outcar.py
22
24
  pwdata/poscar.py
23
25
  pwdata/pwmlff.py
24
26
  pwdata/test.py
27
+ pwdata/tmp.py
25
28
  pwdata.egg-info/PKG-INFO
26
29
  pwdata.egg-info/SOURCES.txt
27
30
  pwdata.egg-info/dependency_links.txt
@@ -64,6 +67,8 @@ pwdata/test/matpbe2lmdb.py
64
67
  pwdata/test/matrcan2lmdb.py
65
68
  pwdata/test/mdtrajs2config.py
66
69
  pwdata/test/mptraj2lmdb.py
70
+ pwdata/test/omol25.py
71
+ pwdata/test/outcar2mvms.py
67
72
  pwdata/utils/__init__.py
68
73
  pwdata/utils/constant.py
69
74
  pwdata/utils/format_change.py
@@ -1,4 +1,5 @@
1
- ase
1
+ ase>=3.25.0
2
+ ase-db-backends
2
3
  lmdb
3
4
  numpy
4
5
  orjson
@@ -5,10 +5,10 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name="pwdata",
8
- version="0.5.0",
8
+ version="0.5.2",
9
9
  author="LonxunQuantum",
10
10
  author_email="lonxun@pwmat.com",
11
- description="pwdata is a data pre-processing tool for PWMLFF, which can be used to extract features and labels. It also provides convenient interfaces for data conversion between different software.",
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.",
12
12
  long_description=long_description,
13
13
  long_description_content_type="text/markdown",
14
14
  url="https://github.com/LonxunQuantum/pwdata",
@@ -20,7 +20,8 @@ setuptools.setup(
20
20
  ],
21
21
  python_requires='>=3.9',
22
22
  install_requires=[
23
- "ase",
23
+ "ase>=3.25.0",
24
+ "ase-db-backends",
24
25
  "lmdb",
25
26
  "numpy",
26
27
  "orjson",
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