pwdata 0.2.5__tar.gz → 0.2.6__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 (37) hide show
  1. {pwdata-0.2.5 → pwdata-0.2.6}/PKG-INFO +1 -1
  2. pwdata-0.2.6/pwdata/deepmd.py +135 -0
  3. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/main.py +5 -0
  4. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata.egg-info/PKG-INFO +1 -1
  5. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata.egg-info/SOURCES.txt +1 -0
  6. {pwdata-0.2.5 → pwdata-0.2.6}/setup.py +1 -1
  7. {pwdata-0.2.5 → pwdata-0.2.6}/LICENSE +0 -0
  8. {pwdata-0.2.5 → pwdata-0.2.6}/README.md +0 -0
  9. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/__init__.py +0 -0
  10. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/atomconfig.py +0 -0
  11. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/build/__init__.py +0 -0
  12. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/build/cell.py +0 -0
  13. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/build/geometry.py +0 -0
  14. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/build/supercells.py +0 -0
  15. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/build/write_struc.py +0 -0
  16. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/calculators/__init__.py +0 -0
  17. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/calculators/const.py +0 -0
  18. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/calculators/unitconvert_lmps.py +0 -0
  19. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/calculators/units.py +0 -0
  20. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/configop.py +0 -0
  21. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/cp2kdata.py +0 -0
  22. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/datasets_saver.py +0 -0
  23. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/dump.py +0 -0
  24. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/extendedxyz.py +0 -0
  25. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/image.py +0 -0
  26. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/lammpsdata.py +0 -0
  27. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/lmps.py +0 -0
  28. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/movement.py +0 -0
  29. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/movement_saver.py +0 -0
  30. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/outcar.py +0 -0
  31. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/pertub/__init__.py +0 -0
  32. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/pertub/perturbation.py +0 -0
  33. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/pertub/scale.py +0 -0
  34. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata/poscar.py +0 -0
  35. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata.egg-info/dependency_links.txt +0 -0
  36. {pwdata-0.2.5 → pwdata-0.2.6}/pwdata.egg-info/top_level.txt +0 -0
  37. {pwdata-0.2.5 → pwdata-0.2.6}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pwdata
3
- Version: 0.2.5
3
+ Version: 0.2.6
4
4
  Summary: pwdata is a data pre-processing tool for PWMLFF, which can be used to extract features and labels. It also provides convenient interfaces for data conversion between different software.
5
5
  Home-page: https://github.com/LonxunQuantum/pwdata
6
6
  Author: LonxunQuantum
@@ -0,0 +1,135 @@
1
+ import numpy as np
2
+ import os, glob
3
+ from tqdm import tqdm
4
+ from pwdata.image import Image
5
+ from pwdata.calculators.const import ELEMENTTABLE
6
+
7
+ class DPNPY(object):
8
+ def __init__(self, dp_file):
9
+ self.image_list:list[Image] = []
10
+ self.load_dp_file(dp_file)
11
+
12
+ assert len(self.image_list) > 0, "No data loaded!"
13
+
14
+ def get(self):
15
+ return self.image_list
16
+
17
+ def load_dp_file(self, dp_file):
18
+ type_map_raw = os.path.join(dp_file, "type_map.raw")
19
+ type_raw = os.path.join(dp_file, "type.raw")
20
+
21
+ # Search for .npy files in the current directory
22
+ npy_files = glob.glob(os.path.join(dp_file, "*.npy"))
23
+ if not npy_files:
24
+ npy_files = glob.glob(os.path.join(dp_file, "*/*.npy"))
25
+
26
+ with open(type_map_raw, 'r') as f:
27
+ type_map = f.read().splitlines()
28
+ atom_type = [ELEMENTTABLE[atom] for atom in type_map]
29
+
30
+ with open(type_raw, 'r') as f:
31
+ type = f.read().splitlines()
32
+ atom_nums = len(type)
33
+ atom_types_image = [atom_type[int(atom)] for atom in type]
34
+ atom_type_num = [atom_types_image.count(atom) for atom in set(atom_types_image)]
35
+
36
+ box, coord, energy, force, virial, image_nums = self.load_npy(npy_files, atom_nums)
37
+
38
+ for i in range(image_nums):
39
+ image = Image(lattice=box[i], position=coord[i], force=force[i], Ep=energy[i], stress=virial[i],
40
+ atom_type=atom_type, atom_nums=atom_nums, atom_types_image=atom_types_image, atom_type_num=atom_type_num,
41
+ cartesian=True, image_nums=i)
42
+ atomic_energy, _, _, _ = np.linalg.lstsq([atom_type_num], np.array([image.Ep]), rcond=1e-3)
43
+ atomic_energy = np.repeat(atomic_energy, atom_type_num)
44
+ image.atomic_energy = atomic_energy.tolist()
45
+ self.image_list.append(image)
46
+
47
+ def load_npy(self, npy_files, atom_nums):
48
+ for npy_file in tqdm(npy_files, desc="Loading data"):
49
+ if "box" in npy_file:
50
+ box = np.load(npy_file).reshape(-1, 3, 3)
51
+ elif "coord" in npy_file:
52
+ coord = np.load(npy_file).reshape(-1, atom_nums, 3)
53
+ elif "energy" in npy_file:
54
+ energy = np.load(npy_file)
55
+ elif "force" in npy_file:
56
+ force = np.load(npy_file).reshape(-1, atom_nums, 3)
57
+ elif "virial" in npy_file:
58
+ virial = np.load(npy_file).reshape(-1, 3, 3)
59
+
60
+ image_nums = len(box)
61
+ print("Load data %s successfully! \t\t\t\t Image nums: %d" % (npy_files, image_nums))
62
+ return box, coord, energy, force, virial, image_nums
63
+
64
+
65
+ class DPRAW(object):
66
+ def __init__(self, dp_file):
67
+ self.image_list:list[Image] = []
68
+ self.load_dp_file(dp_file)
69
+
70
+ assert len(self.image_list) > 0, "No data loaded!"
71
+
72
+ def get(self):
73
+ return self.image_list
74
+
75
+ def load_dp_file(self, dp_file):
76
+ type_map_raw = os.path.join(dp_file, "type_map.raw")
77
+ type_raw = os.path.join(dp_file, "type.raw")
78
+
79
+ # Search for .raw files in the current directory
80
+ raw_files = glob.glob(os.path.join(dp_file, "*.raw"))
81
+ raw_files.remove(type_map_raw)
82
+ raw_files.remove(type_raw)
83
+
84
+ with open(type_map_raw, 'r') as f:
85
+ type_map = f.read().splitlines()
86
+ atom_type = [ELEMENTTABLE[atom] for atom in type_map]
87
+
88
+ with open(type_raw, 'r') as f:
89
+ type = f.read().splitlines()
90
+ atom_nums = len(type)
91
+ atom_types_image = [atom_type[int(atom)] for atom in type]
92
+ atom_type_num = [atom_types_image.count(atom) for atom in set(atom_types_image)]
93
+
94
+ box, coord, energy, force, virial, image_nums = self.load_raw(raw_files, atom_nums)
95
+
96
+ for i in range(image_nums):
97
+ image = Image(lattice=box[i], position=coord[i], force=force[i], Ep=energy[i], stress=virial[i],
98
+ atom_type=atom_type, atom_nums=atom_nums, atom_types_image=atom_types_image, atom_type_num=atom_type_num,
99
+ cartesian=True, image_nums=i)
100
+ atomic_energy, _, _, _ = np.linalg.lstsq([atom_type_num], np.array([image.Ep]), rcond=1e-3)
101
+ atomic_energy = np.repeat(atomic_energy, atom_type_num)
102
+ image.atomic_energy = atomic_energy.tolist()
103
+ self.image_list.append(image)
104
+
105
+ def load_raw(self, raw_files, atom_nums):
106
+ file_keys_to_load = {
107
+ "box": (process_line, (-1, 3, 3)),
108
+ "coord": (process_line, (-1, atom_nums, 3)),
109
+ "force": (process_line, (-1, atom_nums, 3)),
110
+ "energy": (process_single_line, None),
111
+ "virial": (process_line, (-1, 3, 3))
112
+ }
113
+
114
+ data = {}
115
+ for raw_file in tqdm(raw_files, desc="Loading data"):
116
+ with open(raw_file, 'r') as f:
117
+ lines = f.read().splitlines()
118
+
119
+ for key, (func, shape) in file_keys_to_load.items():
120
+ if key in raw_file:
121
+ if shape is None:
122
+ data[key] = func(lines)
123
+ else:
124
+ data[key] = func(lines, shape)
125
+
126
+ image_nums = len(data['box'])
127
+ print("Load data %s successfully! \t\t\t\t Image nums: %d" % (raw_files, image_nums))
128
+ return data['box'], data['coord'], data['energy'], data['force'], data['virial'], image_nums
129
+
130
+ def process_line(line, shape):
131
+ return np.array([list(map(float, line.split())) for line in line]).reshape(*shape)
132
+
133
+ def process_single_line(line):
134
+ return np.array([float(line) for line in line])
135
+
@@ -14,6 +14,7 @@ from pwdata.atomconfig import CONFIG
14
14
  from pwdata.dump import DUMP
15
15
  from pwdata.lammpsdata import LMP
16
16
  from pwdata.cp2kdata import CP2KMD, CP2KSCF
17
+ from pwdata.deepmd import DPNPY, DPRAW
17
18
  from pwdata.movement_saver import save_to_movement
18
19
  from pwdata.extendedxyz import save_to_extxyz
19
20
  from pwdata.datasets_saver import save_to_dataset, get_pw, save_to_raw, save_to_npy
@@ -175,6 +176,10 @@ class Config(object):
175
176
  image = CP2KMD(data_path).image_list[index]
176
177
  elif format.lower() == 'cp2k/scf':
177
178
  image = CP2KSCF(data_path).image_list[0]
179
+ elif format.lower() == 'deepmd/npy':
180
+ image = DPNPY(data_path).image_list[index]
181
+ elif format.lower() == 'deepmd/raw':
182
+ image = DPRAW(data_path).image_list[index]
178
183
  else:
179
184
  raise Exception("Error! The format of the input file is not supported!")
180
185
  return image
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pwdata
3
- Version: 0.2.5
3
+ Version: 0.2.6
4
4
  Summary: pwdata is a data pre-processing tool for PWMLFF, which can be used to extract features and labels. It also provides convenient interfaces for data conversion between different software.
5
5
  Home-page: https://github.com/LonxunQuantum/pwdata
6
6
  Author: LonxunQuantum
@@ -6,6 +6,7 @@ pwdata/atomconfig.py
6
6
  pwdata/configop.py
7
7
  pwdata/cp2kdata.py
8
8
  pwdata/datasets_saver.py
9
+ pwdata/deepmd.py
9
10
  pwdata/dump.py
10
11
  pwdata/extendedxyz.py
11
12
  pwdata/image.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.2.5",
8
+ version="0.2.6",
9
9
  author="LonxunQuantum",
10
10
  author_email="lonxun@pwmat.com",
11
11
  description="pwdata is a data pre-processing tool for PWMLFF, which can be used to extract features and labels. It also provides convenient interfaces for data conversion between different software.",
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