pwdata 0.4.7__tar.gz → 0.4.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.
Potentially problematic release.
This version of pwdata might be problematic. Click here for more details.
- {pwdata-0.4.7 → pwdata-0.4.8}/PKG-INFO +1 -1
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/build/write_struc.py +9 -9
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/config.py +26 -26
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/convert_files.py +22 -24
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/cp2kdata.py +23 -22
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/datasets_saver.py +30 -55
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/deepmd.py +6 -8
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/dump.py +8 -7
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/extendedxyz.py +11 -18
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/image.py +49 -37
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/lammpsdata.py +6 -6
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/main.py +3 -250
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/meta.py +21 -65
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/movement.py +11 -11
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/movement_saver.py +4 -3
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/outcar.py +11 -10
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/poscar.py +7 -7
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/pwmlff.py +2 -2
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/test/mdtrajs2config.py +7 -7
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/test.py +2 -2
- pwdata-0.4.8/pwdata/utils/format_change.py +37 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata.egg-info/PKG-INFO +1 -1
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata.egg-info/SOURCES.txt +2 -1
- {pwdata-0.4.7 → pwdata-0.4.8}/setup.py +1 -1
- {pwdata-0.4.7 → pwdata-0.4.8}/LICENSE +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/README.md +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/__init__.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/atomconfig.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/build/__init__.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/build/cell.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/build/geometry.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/build/supercells.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/calculators/__init__.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/calculators/const.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/calculators/unitconvert_lmps.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/calculators/units.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/check_envs.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/fairchem/__init__.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/fairchem/common/__init__.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/fairchem/common/registry.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/fairchem/common/typing.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/fairchem/common/utils.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/fairchem/datasets/__init__.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/fairchem/datasets/_utils.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/fairchem/datasets/ase_datasets.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/fairchem/datasets/base_dataset.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/fairchem/datasets/embeddings/__init__.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/fairchem/datasets/embeddings/atomic_radii.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/fairchem/datasets/embeddings/continuous_embeddings.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/fairchem/datasets/embeddings/khot_embeddings.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/fairchem/datasets/embeddings/qmof_khot_embeddings.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/fairchem/datasets/lmdb_database.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/fairchem/datasets/target_metadata_guesser.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/fairchem/modules/__init__.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/fairchem/modules/transforms.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/fairchem/preprocessing/__init__.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/lmps.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/pertub/__init__.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/pertub/perturbation.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/pertub/scale.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/test/__init__.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/test/mptraj2lmdb.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/utils/__init__.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata/utils/constant.py +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata.egg-info/dependency_links.txt +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata.egg-info/entry_points.txt +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata.egg-info/requires.txt +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/pwdata.egg-info/top_level.txt +0 -0
- {pwdata-0.4.7 → pwdata-0.4.8}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pwdata
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.8
|
|
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,8 +6,8 @@ from pwdata.calculators.const import elements, ELEMENTMASSTABLE
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
def write_config(image,
|
|
9
|
-
|
|
10
|
-
data_name="
|
|
9
|
+
data_path,
|
|
10
|
+
data_name="toatom.config",
|
|
11
11
|
direct=True,
|
|
12
12
|
sort=None,
|
|
13
13
|
symbol_count=None,
|
|
@@ -108,7 +108,7 @@ def write_config(image,
|
|
|
108
108
|
atom_type_num = image.atom_type_num
|
|
109
109
|
|
|
110
110
|
# Write to file
|
|
111
|
-
output_file = open(os.path.join(
|
|
111
|
+
output_file = open(os.path.join(data_path, data_name), 'w')
|
|
112
112
|
output_file.write('%d\n' % atom_nums)
|
|
113
113
|
output_file.write('Lattice vector\n')
|
|
114
114
|
for i in range(3):
|
|
@@ -122,8 +122,8 @@ def write_config(image,
|
|
|
122
122
|
print("Convert to %s successfully!" % data_name)
|
|
123
123
|
|
|
124
124
|
def write_vasp(image,
|
|
125
|
-
|
|
126
|
-
data_name="
|
|
125
|
+
data_path,
|
|
126
|
+
data_name="vasp.poscar",
|
|
127
127
|
direct=False,
|
|
128
128
|
sort=None,
|
|
129
129
|
symbol_count=None,
|
|
@@ -229,7 +229,7 @@ def write_vasp(image,
|
|
|
229
229
|
|
|
230
230
|
atom_type = [elements[_] for _ in atom_type]
|
|
231
231
|
# Write to file
|
|
232
|
-
output_file = open(os.path.join(
|
|
232
|
+
output_file = open(os.path.join(data_path, data_name), 'w')
|
|
233
233
|
output_file.write('Created from %s\n' % data_name)
|
|
234
234
|
output_file.write('1.0\n')
|
|
235
235
|
for i in range(3):
|
|
@@ -254,8 +254,8 @@ def write_vasp(image,
|
|
|
254
254
|
print("Convert to %s successfully!" % data_name)
|
|
255
255
|
|
|
256
256
|
def write_lammps(image,
|
|
257
|
-
|
|
258
|
-
data_name="
|
|
257
|
+
data_path,
|
|
258
|
+
data_name="tolammps.lmp",
|
|
259
259
|
direct=False,
|
|
260
260
|
sort=None,
|
|
261
261
|
symbol_count=None,
|
|
@@ -388,7 +388,7 @@ def write_lammps(image,
|
|
|
388
388
|
LX[i,2] = x[i,2]
|
|
389
389
|
|
|
390
390
|
# Write to file
|
|
391
|
-
output_file = open(os.path.join(
|
|
391
|
+
output_file = open(os.path.join(data_path, data_name), 'w')
|
|
392
392
|
output_file.write('Created from %s\n' % data_name)
|
|
393
393
|
output_file.write("%-12d atoms\n" % (atom_nums))
|
|
394
394
|
output_file.write("%-12d atom types\n" % (len(atom_type)))
|
|
@@ -206,15 +206,15 @@ class Config(object):
|
|
|
206
206
|
image = [image]
|
|
207
207
|
return image, format.lower()
|
|
208
208
|
|
|
209
|
-
def to(self,
|
|
209
|
+
def to(self, data_path, format = None, **kwargs):
|
|
210
210
|
"""
|
|
211
211
|
Write all images (>= 1) object to a new file.
|
|
212
212
|
|
|
213
213
|
Note: Set sort to False for CP2K, because data from CP2K is already sorted!!!. It will result in a wrong order if sort again.
|
|
214
214
|
|
|
215
215
|
Args:
|
|
216
|
-
|
|
217
|
-
|
|
216
|
+
data_path (str): Required. The path to save the file.
|
|
217
|
+
format (str): Required. The format of the file. Default is None.
|
|
218
218
|
|
|
219
219
|
Kwargs:
|
|
220
220
|
|
|
@@ -237,40 +237,40 @@ class Config(object):
|
|
|
237
237
|
* retain_raw (bool): Whether to retain the raw data. Default is False.
|
|
238
238
|
|
|
239
239
|
"""
|
|
240
|
-
assert
|
|
241
|
-
if not os.path.exists(
|
|
242
|
-
os.makedirs(
|
|
240
|
+
assert format is not None, "output file format is not specified"
|
|
241
|
+
if not os.path.exists(data_path):
|
|
242
|
+
os.makedirs(data_path)
|
|
243
243
|
|
|
244
|
-
if
|
|
245
|
-
self.write_image(self.images[0],
|
|
244
|
+
if format in FORMAT.support_config_format:
|
|
245
|
+
self.write_image(self.images[0], data_path, format, **kwargs)
|
|
246
246
|
else:
|
|
247
|
-
self.multi_to(self.images,
|
|
247
|
+
self.multi_to(self.images, data_path, format, **kwargs)
|
|
248
248
|
|
|
249
|
-
def multi_to(self, images,
|
|
249
|
+
def multi_to(self, images, data_path, format, **kwargs):
|
|
250
250
|
"""
|
|
251
251
|
Write multiple images to new files.
|
|
252
252
|
"""
|
|
253
|
-
if
|
|
253
|
+
if format.lower() in ['pwmat/config', 'vasp/poscar', 'lammps/lmp']:
|
|
254
254
|
data_name = kwargs['data_name']
|
|
255
255
|
for i, image in enumerate(images):
|
|
256
256
|
kwargs['data_name'] = data_name + "_{0}".format(i)
|
|
257
|
-
self.write_image(image,
|
|
257
|
+
self.write_image(image, data_path, format, **kwargs)
|
|
258
258
|
else:
|
|
259
|
-
self.write_image(images,
|
|
259
|
+
self.write_image(images, data_path, format, **kwargs)
|
|
260
260
|
|
|
261
|
-
def write_image(self, image,
|
|
262
|
-
if
|
|
263
|
-
write_config(image,
|
|
264
|
-
elif
|
|
265
|
-
write_vasp(image,
|
|
266
|
-
elif
|
|
267
|
-
write_lammps(image,
|
|
268
|
-
elif
|
|
269
|
-
save_to_movement(image,
|
|
270
|
-
elif
|
|
271
|
-
save_to_extxyz(image,
|
|
272
|
-
elif
|
|
273
|
-
save_to_dataset(image,
|
|
261
|
+
def write_image(self, image, data_path, format, **kwargs):
|
|
262
|
+
if format.lower() == 'pwmat/config':
|
|
263
|
+
write_config(image, data_path, **kwargs)
|
|
264
|
+
elif format.lower() == 'vasp/poscar':
|
|
265
|
+
write_vasp(image, data_path, **kwargs)
|
|
266
|
+
elif format.lower() == "lammps/lmp":
|
|
267
|
+
write_lammps(image, data_path, **kwargs)
|
|
268
|
+
elif format.lower() == "pwmat/movement":
|
|
269
|
+
save_to_movement(image, data_path, **kwargs)
|
|
270
|
+
elif format.lower() == "extxyz":
|
|
271
|
+
save_to_extxyz(image, data_path, **kwargs)
|
|
272
|
+
elif format.lower() == "pwmlff/npy":
|
|
273
|
+
save_to_dataset(image, data_path=data_path, **kwargs)
|
|
274
274
|
else:
|
|
275
275
|
raise RuntimeError('Unknown file format')
|
|
276
276
|
|
|
@@ -26,9 +26,9 @@ def do_convert_config(input_file:str,
|
|
|
26
26
|
if savename is None:
|
|
27
27
|
savename = FORMAT.get_filename_by_format(image.format)
|
|
28
28
|
|
|
29
|
-
image.to(
|
|
29
|
+
image.to(data_path = os.path.dirname(os.path.abspath(savename)),
|
|
30
30
|
data_name = os.path.basename(savename),
|
|
31
|
-
|
|
31
|
+
format = output_format,
|
|
32
32
|
direct = direct,
|
|
33
33
|
sort = True)
|
|
34
34
|
return os.path.abspath(savename)
|
|
@@ -50,9 +50,9 @@ def do_scale_cell(input_file:str,
|
|
|
50
50
|
savename = FORMAT.get_filename_by_format(image.format)
|
|
51
51
|
for idx, factor in enumerate(scale_factor):
|
|
52
52
|
scaled_structs = scale_cell(image, factor)
|
|
53
|
-
scaled_structs.to(
|
|
53
|
+
scaled_structs.to(data_path = os.path.dirname(os.path.abspath(savename)),
|
|
54
54
|
data_name = "{}_{}".format(factor, os.path.basename(savename)),
|
|
55
|
-
|
|
55
|
+
format = output_format,
|
|
56
56
|
direct = direct,
|
|
57
57
|
sort = True)
|
|
58
58
|
return os.path.abspath(savename)
|
|
@@ -75,9 +75,9 @@ def do_super_cell(input_file:str,
|
|
|
75
75
|
output_format = FORMAT.pwmat_config if image.format == FORMAT.cp2k_scf else image.format
|
|
76
76
|
if savename is None:
|
|
77
77
|
savename = FORMAT.get_filename_by_format(image.format)
|
|
78
|
-
scaled_structs.to(
|
|
78
|
+
scaled_structs.to(data_path = os.path.dirname(os.path.abspath(savename)),
|
|
79
79
|
data_name = os.path.basename(savename),
|
|
80
|
-
|
|
80
|
+
format = output_format,
|
|
81
81
|
direct = direct,
|
|
82
82
|
sort = True)
|
|
83
83
|
return os.path.abspath(savename)
|
|
@@ -106,9 +106,9 @@ def do_perturb(input_file:str,
|
|
|
106
106
|
if output_format is None:
|
|
107
107
|
output_format = FORMAT.pwmat_config if image.format == FORMAT.cp2k_scf else image.format
|
|
108
108
|
for tmp_perturbed_idx, tmp_pertubed_struct in enumerate(perturbed_structs):
|
|
109
|
-
tmp_pertubed_struct.to(
|
|
109
|
+
tmp_pertubed_struct.to(data_path = save_path,
|
|
110
110
|
data_name = "{}_{}".format(tmp_perturbed_idx, save_name_prefix),
|
|
111
|
-
|
|
111
|
+
format = output_format,
|
|
112
112
|
direct = direct,
|
|
113
113
|
sort = True)
|
|
114
114
|
perturb_files.append("{}_{}".format(tmp_perturbed_idx, save_name_prefix))
|
|
@@ -119,7 +119,6 @@ def do_convert_images(
|
|
|
119
119
|
input_format:str = None,
|
|
120
120
|
savepath = None, #'the/path/pwmlff-datas'
|
|
121
121
|
output_format = None,
|
|
122
|
-
train_valid_ratio = None,
|
|
123
122
|
data_shuffle = None,
|
|
124
123
|
gap = None,
|
|
125
124
|
atom_types:list[str]=None,
|
|
@@ -129,8 +128,7 @@ def do_convert_images(
|
|
|
129
128
|
):
|
|
130
129
|
data_files = search_images(input, input_format)
|
|
131
130
|
image_data = load_files(data_files, input_format, atom_types=atom_types, query=query, cpu_nums=cpu_nums)
|
|
132
|
-
save_images(savepath, image_data, output_format,
|
|
133
|
-
|
|
131
|
+
save_images(savepath, image_data, output_format, data_shuffle, merge)
|
|
134
132
|
|
|
135
133
|
def do_count_images(
|
|
136
134
|
input:list[str],
|
|
@@ -157,13 +155,12 @@ param {*} data_shuffle
|
|
|
157
155
|
return {*}
|
|
158
156
|
author: wuxingxing
|
|
159
157
|
'''
|
|
160
|
-
def save_images(savepath, image_data, output_format,
|
|
158
|
+
def save_images(savepath, image_data, output_format, data_shuffle=False, merge=True):
|
|
161
159
|
if merge is True and output_format == FORMAT.extxyz:
|
|
162
160
|
save_dir = savepath
|
|
163
161
|
image_data.to(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
train_ratio = train_valid_ratio,
|
|
162
|
+
data_path=save_dir,
|
|
163
|
+
format=output_format,
|
|
167
164
|
random=data_shuffle,
|
|
168
165
|
seed = 2024,
|
|
169
166
|
retain_raw = False,
|
|
@@ -175,9 +172,8 @@ def save_images(savepath, image_data, output_format, train_valid_ratio=1, data_s
|
|
|
175
172
|
save_dir = os.path.join(savepath, key)
|
|
176
173
|
image_data.images = images
|
|
177
174
|
image_data.to(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
train_ratio = train_valid_ratio,
|
|
175
|
+
data_path=save_dir,
|
|
176
|
+
format=output_format,
|
|
181
177
|
random=data_shuffle,
|
|
182
178
|
seed = 2024,
|
|
183
179
|
retain_raw = False,
|
|
@@ -185,9 +181,8 @@ def save_images(savepath, image_data, output_format, train_valid_ratio=1, data_s
|
|
|
185
181
|
)
|
|
186
182
|
else: # for pwmlff/mpy
|
|
187
183
|
image_data.to(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
train_ratio = train_valid_ratio,
|
|
184
|
+
data_path=savepath,
|
|
185
|
+
format=output_format,
|
|
191
186
|
random=data_shuffle,
|
|
192
187
|
seed = 2024,
|
|
193
188
|
retain_raw = False,
|
|
@@ -244,8 +239,11 @@ def search_by_format(workDir, format):
|
|
|
244
239
|
if format == FORMAT.pwmlff_npy:
|
|
245
240
|
for root, dirs, files in os.walk(workDir):
|
|
246
241
|
if 'energies.npy' in files:
|
|
247
|
-
|
|
248
|
-
|
|
242
|
+
data_path[FORMAT.pwmlff_npy].append(root)
|
|
243
|
+
# if "train" in os.path.basename(root):
|
|
244
|
+
# data_path[FORMAT.pwmlff_npy].append(os.path.dirname(root))
|
|
245
|
+
# elif "valid" in os.path.basename(root):
|
|
246
|
+
# data_path[FORMAT.pwmlff_npy].append(os.path.dirname(root))
|
|
249
247
|
|
|
250
248
|
if format == FORMAT.extxyz:
|
|
251
249
|
for path, dirList, fileList in os.walk(workDir):
|
|
@@ -289,7 +287,7 @@ def load_files(input_dict:dict, input_format:str=None, atom_types:list[str]=None
|
|
|
289
287
|
else:
|
|
290
288
|
tmp_image_data = Config(input_format, metapaths, atom_names=atom_types, query=query, cpu_nums=cpu_nums)
|
|
291
289
|
image_data.images.extend(tmp_image_data.images)
|
|
292
|
-
print("There are a total of {} aselmdb, and the current progress has been loaded {} %".format(lmdb_nums, np.round(idx*chunk_size/lmdb_nums, 2)))
|
|
290
|
+
# print("There are a total of {} aselmdb, and the current progress has been loaded {} %".format(lmdb_nums, np.round(idx*chunk_size/lmdb_nums, 2)))
|
|
293
291
|
else:
|
|
294
292
|
if len(input_dict[FORMAT.traj]) > 0:# the input is traj files
|
|
295
293
|
for data_path in tqdm(input_dict[FORMAT.traj], total=len(input_dict[FORMAT.traj])):
|
|
@@ -4,6 +4,7 @@ from tqdm import tqdm
|
|
|
4
4
|
from collections import Counter
|
|
5
5
|
from pwdata.image import Image
|
|
6
6
|
from pwdata.calculators.const import ELEMENTTABLE
|
|
7
|
+
from pwdata.utils.format_change import to_numpy_array, to_integer, to_float
|
|
7
8
|
|
|
8
9
|
class CP2KMD(object):
|
|
9
10
|
def __init__(self, stdout_file):
|
|
@@ -66,7 +67,7 @@ class CP2KMD(object):
|
|
|
66
67
|
Ep = float(step_pattern.findall(ii)[0][-1]) # Pot.[a.u.]
|
|
67
68
|
image = self.image_list[iteration]
|
|
68
69
|
image.iteration = iteration
|
|
69
|
-
image.Ep = Ep * 27.2113838565563 # convert to eV
|
|
70
|
+
image.Ep = to_float(Ep * 27.2113838565563) # convert to eV
|
|
70
71
|
# atom_names = []
|
|
71
72
|
# atom_types_image = []
|
|
72
73
|
atom_positions = []
|
|
@@ -92,15 +93,15 @@ class CP2KMD(object):
|
|
|
92
93
|
atom_type = list(sc.keys())
|
|
93
94
|
atom_type_num = list(sc.values())
|
|
94
95
|
image.cartesian = True
|
|
95
|
-
image.atom_nums = atom_nums
|
|
96
|
-
image.atom_types_image = [ELEMENTTABLE[atom] for atom in atom_names]
|
|
97
|
-
image.atom_type = [ELEMENTTABLE[atom] for atom in atom_type]
|
|
98
|
-
image.atom_type_num = atom_type_num
|
|
99
|
-
image.position = position
|
|
96
|
+
image.atom_nums = to_integer(atom_nums)
|
|
97
|
+
image.atom_types_image = to_numpy_array([ELEMENTTABLE[atom] for atom in atom_names])
|
|
98
|
+
image.atom_type = to_numpy_array([ELEMENTTABLE[atom] for atom in atom_type])
|
|
99
|
+
image.atom_type_num = to_numpy_array(atom_type_num)
|
|
100
|
+
image.position = to_numpy_array(position)
|
|
100
101
|
# If Atomic-Energy is not in the file, calculate it from the Ep
|
|
101
102
|
atomic_energy, _, _, _ = np.linalg.lstsq([image.atom_type_num], np.array([image.Ep]), rcond=1e-3)
|
|
102
103
|
atomic_energy = np.repeat(atomic_energy, image.atom_type_num)
|
|
103
|
-
image.atomic_energy = atomic_energy.tolist()
|
|
104
|
+
image.atomic_energy = to_numpy_array(atomic_energy.tolist())
|
|
104
105
|
|
|
105
106
|
def read_xyz(self, traj_file):
|
|
106
107
|
with open(traj_file, "r") as f:
|
|
@@ -122,16 +123,16 @@ class CP2KMD(object):
|
|
|
122
123
|
sc = Counter(atom_names)
|
|
123
124
|
atom_type = list(sc.keys())
|
|
124
125
|
atom_type_num = list(sc.values())
|
|
125
|
-
image.Ep = Ep * 27.2113838565563 # convert to eV
|
|
126
|
-
image.position = position
|
|
127
|
-
image.atom_type = [ELEMENTTABLE[atom] for atom in atom_type]
|
|
128
|
-
image.atom_type_num = atom_type_num
|
|
129
|
-
image.atom_types_image = [ELEMENTTABLE[atom] for atom in atom_names]
|
|
126
|
+
image.Ep = to_float(Ep * 27.2113838565563) # convert to eV
|
|
127
|
+
image.position = to_numpy_array(position)
|
|
128
|
+
image.atom_type = to_numpy_array([ELEMENTTABLE[atom] for atom in atom_type])
|
|
129
|
+
image.atom_type_num = to_numpy_array(atom_type_num)
|
|
130
|
+
image.atom_types_image = to_numpy_array([ELEMENTTABLE[atom] for atom in atom_names])
|
|
130
131
|
image.cartesian = True
|
|
131
132
|
# If Atomic-Energy is not in the file, calculate it from the Ep
|
|
132
133
|
atomic_energy, _, _, _ = np.linalg.lstsq([image.atom_type_num], np.array([image.Ep]), rcond=1e-3)
|
|
133
134
|
atomic_energy = np.repeat(atomic_energy, image.atom_type_num)
|
|
134
|
-
image.atomic_energy = atomic_energy.tolist()
|
|
135
|
+
image.atomic_energy = to_numpy_array(atomic_energy.tolist())
|
|
135
136
|
|
|
136
137
|
def read_label_f(self, label_f_file):
|
|
137
138
|
with open(label_f_file, "r") as f:
|
|
@@ -147,7 +148,7 @@ class CP2KMD(object):
|
|
|
147
148
|
atom_forces = [[float(_) for _ in atom.split()[1:]] for atom in label_f_contents[idx+1:idx+image.atom_nums+1]]
|
|
148
149
|
atom_forces = list(zip(atom_name, atom_forces))
|
|
149
150
|
atom_forces.sort(key=lambda x: x[0]) # Sort atom_forces by atom name
|
|
150
|
-
image.force = [[tmp * 51.42206318571696 for tmp in force] for _, force in atom_forces] # convert to eV/angstrom
|
|
151
|
+
image.force = to_numpy_array([[tmp * 51.42206318571696 for tmp in force] for _, force in atom_forces]) # convert to eV/angstrom
|
|
151
152
|
|
|
152
153
|
|
|
153
154
|
class CP2KSCF(object):
|
|
@@ -188,28 +189,28 @@ class CP2KSCF(object):
|
|
|
188
189
|
image.atom_nums = atom_nums
|
|
189
190
|
elif "ATOMIC COORDINATES IN ANGSTROM" in ii:
|
|
190
191
|
position_info = self.parse_position(stdout_contents[idx+3:idx+3+atom_nums])
|
|
191
|
-
image.position = position_info["position"]
|
|
192
|
-
image.atom_type = position_info["atom_type"]
|
|
193
|
-
image.atom_type_num = position_info["atom_type_num"]
|
|
194
|
-
image.atom_types_image = position_info["atom_types_image"]
|
|
192
|
+
image.position = to_numpy_array(position_info["position"])
|
|
193
|
+
image.atom_type = to_numpy_array(position_info["atom_type"])
|
|
194
|
+
image.atom_type_num = to_numpy_array(position_info["atom_type_num"])
|
|
195
|
+
image.atom_types_image = to_numpy_array(position_info["atom_types_image"])
|
|
195
196
|
image.cartesian = True
|
|
196
197
|
# elif "SCF run converged in" in ii:
|
|
197
198
|
elif "ENERGY| Total FORCE_EVAL" in ii:
|
|
198
199
|
# energy = float(stdout_contents[idx-2].split()[-2]) # Pot.[a.u.]
|
|
199
200
|
energy = float(ii.split()[-1]) # Pot.[a.u.]
|
|
200
|
-
image.Ep = energy * 27.2113838565563 # convert to eV
|
|
201
|
+
image.Ep = to_float(energy * 27.2113838565563) # convert to eV
|
|
201
202
|
atomic_energy, _, _, _ = np.linalg.lstsq([image.atom_type_num], np.array([image.Ep]), rcond=1e-3)
|
|
202
203
|
atomic_energy = np.repeat(atomic_energy, image.atom_type_num)
|
|
203
|
-
image.atomic_energy = atomic_energy.tolist()
|
|
204
|
+
image.atomic_energy = to_numpy_array(atomic_energy.tolist())
|
|
204
205
|
# atomic_energy_dict = dict(zip(image.atom_types_image, atomic_energy))
|
|
205
206
|
# image.atomic_energy = [atomic_energy_dict[atom_type] for atom_type in image.atom_types_image]
|
|
206
207
|
elif "ATOMIC FORCES in [a.u.]" in ii:
|
|
207
208
|
force_info = self.parse_force(stdout_contents[idx+3:idx+3+atom_nums])
|
|
208
|
-
image.force = force_info["force"]
|
|
209
|
+
image.force = to_numpy_array(force_info["force"])
|
|
209
210
|
elif "STRESS| Analytical stress tensor" in ii:
|
|
210
211
|
stress_info = parse_stress(stdout_contents[idx+2:idx+5])
|
|
211
212
|
virial = gpa2ev(stress_info["stress"], volume)
|
|
212
|
-
image.virial = virial
|
|
213
|
+
image.virial = to_numpy_array(virial).reshape(3,3)
|
|
213
214
|
|
|
214
215
|
def parse_position(self, position_content):
|
|
215
216
|
position = [[float(_) for _ in atom.split()[4:7]] for atom in position_content]
|
|
@@ -6,81 +6,56 @@ from collections import defaultdict
|
|
|
6
6
|
from pwdata.calculators.const import elements
|
|
7
7
|
from pwdata.utils.constant import get_atomic_name_from_number, FORMAT
|
|
8
8
|
from pwdata.image import Image
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
from pwdata.utils.format_change import to_numpy_array
|
|
10
|
+
def save_to_dataset(image_data: list, data_path = "./", random = False, seed = None, retain_raw = False, data_name = "PWdata", write_patthen="w"):
|
|
11
11
|
""" Get and process the data from the input file. """
|
|
12
|
+
# sort atom order
|
|
13
|
+
for image in image_data:
|
|
14
|
+
image.sort_by_atomtype()
|
|
12
15
|
image_dict = split_image_by_atomtype_nums(image_data)
|
|
13
16
|
for key, image_datas in image_dict.items():
|
|
14
|
-
save_image(image_datas,
|
|
15
|
-
train_ratio = train_ratio, random = random, seed = 2024, retain_raw = retain_raw, data_name = key, write_patthen=write_patthen)
|
|
16
|
-
|
|
17
|
-
def save_image(image_data: list, datasets_path = "./PWdata", train_data_path = "train", valid_data_path = "valid",
|
|
18
|
-
train_ratio = None, random = True, seed = 2024, retain_raw = False, data_name = None, write_patthen="w"):
|
|
17
|
+
save_image(image_datas, data_path = data_path, random = random, seed = seed, retain_raw = retain_raw, data_name = data_name, write_patthen=write_patthen)
|
|
19
18
|
|
|
19
|
+
def save_image(image_data: list, data_path = None, random = False, seed = None, retain_raw = False, data_name = "PWdata", write_patthen="w"):
|
|
20
20
|
lattice, position, energies, ei, forces, virials, atom_type, atom_types_image, image_nums = get_pw(image_data)
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
data_name = temp_data_name + "_" + str(suffix)
|
|
30
|
-
else:
|
|
31
|
-
pass
|
|
22
|
+
sc = Counter(atom_types_image) # a list sc of (symbol, count) pairs
|
|
23
|
+
temp_atom_name = ''.join([elements[key] + str(count) for key, count in sc.items()])
|
|
24
|
+
atom_name = temp_atom_name
|
|
25
|
+
suffix = 0
|
|
26
|
+
while os.path.exists(os.path.join(data_path, atom_name)):
|
|
27
|
+
suffix += 1
|
|
28
|
+
atom_name = temp_atom_name + "_" + str(suffix)
|
|
32
29
|
|
|
33
|
-
labels_path = os.path.join(
|
|
34
|
-
if not os.path.exists(
|
|
35
|
-
os.makedirs(
|
|
30
|
+
labels_path = os.path.join(data_path, data_name, atom_name)
|
|
31
|
+
if not os.path.exists(data_path):
|
|
32
|
+
os.makedirs(data_path, exist_ok=True)
|
|
36
33
|
if not os.path.exists(labels_path):
|
|
37
34
|
os.makedirs(labels_path, exist_ok=True)
|
|
38
35
|
|
|
39
|
-
if seed:
|
|
36
|
+
if seed is not None:
|
|
40
37
|
np.random.seed(seed)
|
|
41
38
|
indices = np.arange(image_nums) # 0, 1, 2, ..., image_nums-1
|
|
42
39
|
if random:
|
|
43
40
|
np.random.shuffle(indices) # shuffle the indices
|
|
44
|
-
|
|
45
|
-
train_size = ceil(image_nums * train_ratio)
|
|
46
|
-
train_indices = indices[:train_size]
|
|
47
|
-
val_indices = indices[train_size:]
|
|
41
|
+
|
|
48
42
|
# image_nums = [image_nums]
|
|
49
43
|
atom_types_image = atom_types_image.reshape(1, -1)
|
|
50
44
|
|
|
51
|
-
train_data = [lattice[
|
|
52
|
-
forces[
|
|
53
|
-
ei[
|
|
54
|
-
val_data = [lattice[val_indices], position[val_indices], energies[val_indices],
|
|
55
|
-
forces[val_indices], atom_types_image, atom_type,
|
|
56
|
-
ei[val_indices]]
|
|
45
|
+
train_data = [lattice[indices], position[indices], energies[indices],
|
|
46
|
+
forces[indices], atom_types_image, atom_type,
|
|
47
|
+
ei[indices]]
|
|
57
48
|
|
|
58
49
|
if len(virials) != 0:
|
|
59
|
-
train_data.append(virials[
|
|
60
|
-
val_data.append(virials[val_indices])
|
|
50
|
+
train_data.append(virials[indices])
|
|
61
51
|
else:
|
|
62
52
|
train_data.append([])
|
|
63
|
-
val_data.append([])
|
|
64
53
|
|
|
65
|
-
if
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
save_to_raw(train_data, train_data_path)
|
|
71
|
-
save_to_npy(train_data, labels_path)
|
|
72
|
-
else:
|
|
73
|
-
train_path = os.path.join(labels_path, train_data_path)
|
|
74
|
-
val_path = os.path.join(labels_path, valid_data_path)
|
|
75
|
-
if not os.path.exists(train_path):
|
|
76
|
-
os.makedirs(train_path)
|
|
77
|
-
if not os.path.exists(val_path):
|
|
78
|
-
os.makedirs(val_path)
|
|
79
|
-
if retain_raw:
|
|
80
|
-
save_to_raw(train_data, train_path)
|
|
81
|
-
save_to_raw(val_data, val_path)
|
|
82
|
-
save_to_npy(train_data, train_path)
|
|
83
|
-
save_to_npy(val_data, val_path)
|
|
54
|
+
if not os.path.exists(labels_path):
|
|
55
|
+
os.makedirs(labels_path)
|
|
56
|
+
if retain_raw:
|
|
57
|
+
save_to_raw(train_data, labels_path)
|
|
58
|
+
save_to_npy(train_data, labels_path)
|
|
84
59
|
|
|
85
60
|
def save_to_raw(data, directory):
|
|
86
61
|
filenames = ["lattice.dat", "position.dat", "energies.dat", "forces.dat", "image_type.dat", "atom_type.dat", "ei.dat", "virials.dat"]
|
|
@@ -119,8 +94,8 @@ def get_pw(image_data):
|
|
|
119
94
|
else:
|
|
120
95
|
all_virials.append(np.full((3, 3), -1e5))
|
|
121
96
|
image_nums = len(image_data)
|
|
122
|
-
atom_type =
|
|
123
|
-
atom_types_image =
|
|
97
|
+
atom_type = to_numpy_array(image.atom_type)
|
|
98
|
+
atom_types_image = to_numpy_array(image.atom_types_image)
|
|
124
99
|
all_lattices = np.array(all_lattices).reshape(image_nums, 9)
|
|
125
100
|
all_postions = np.array(all_postions).reshape(image_nums, -1)
|
|
126
101
|
all_energies = np.array(all_energies).reshape(image_nums, 1)
|
|
@@ -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.const import ELEMENTTABLE
|
|
7
|
-
|
|
7
|
+
from pwdata.utils.format_change import to_numpy_array, to_integer, to_float
|
|
8
8
|
class DPNPY(object):
|
|
9
9
|
def __init__(self, dp_file):
|
|
10
10
|
self.image_list:list[Image] = []
|
|
@@ -46,7 +46,7 @@ class DPNPY(object):
|
|
|
46
46
|
cartesian=True, image_nums=i)
|
|
47
47
|
atomic_energy, _, _, _ = np.linalg.lstsq([atom_type_num], np.array([image.Ep]), rcond=1e-3)
|
|
48
48
|
atomic_energy = np.repeat(atomic_energy, atom_type_num)
|
|
49
|
-
image.atomic_energy = atomic_energy.tolist()
|
|
49
|
+
image.atomic_energy = to_numpy_array(atomic_energy.tolist())
|
|
50
50
|
self.image_list.append(image)
|
|
51
51
|
|
|
52
52
|
def load_npy(self, npy_files, atom_nums):
|
|
@@ -103,16 +103,13 @@ class DPRAW(object):
|
|
|
103
103
|
box, coord, energy, force, virial, image_nums = self.load_raw(raw_files, atom_nums)
|
|
104
104
|
|
|
105
105
|
for i in range(image_nums):
|
|
106
|
-
|
|
107
|
-
virial_image = virial[i]
|
|
108
|
-
except Exception as e:
|
|
109
|
-
virial_image = None
|
|
106
|
+
virial_image = virial[i] if virial is not None else None
|
|
110
107
|
image = Image(lattice=box[i], position=coord[i], force=force[i], Ep=energy[i], virial=virial_image,
|
|
111
108
|
atom_type=atom_type, atom_nums=atom_nums, atom_types_image=atom_types_image, atom_type_num=atom_type_num,
|
|
112
109
|
cartesian=True, image_nums=i)
|
|
113
110
|
atomic_energy, _, _, _ = np.linalg.lstsq([atom_type_num], np.array([image.Ep]), rcond=1e-3)
|
|
114
111
|
atomic_energy = np.repeat(atomic_energy, atom_type_num)
|
|
115
|
-
image.atomic_energy = atomic_energy.tolist()
|
|
112
|
+
image.atomic_energy = to_numpy_array(atomic_energy.tolist())
|
|
116
113
|
self.image_list.append(image)
|
|
117
114
|
|
|
118
115
|
def load_raw(self, raw_files, atom_nums):
|
|
@@ -138,7 +135,8 @@ class DPRAW(object):
|
|
|
138
135
|
|
|
139
136
|
image_nums = len(data['box'])
|
|
140
137
|
print("Load data %s successfully! \t\t\t\t Image nums: %d" % (raw_files, image_nums))
|
|
141
|
-
|
|
138
|
+
virial = None if 'virial' not in data.keys() else data['force']
|
|
139
|
+
return data['box'], data['coord'], data['energy'], data['force'], virial, image_nums
|
|
142
140
|
|
|
143
141
|
def process_line(line, shape):
|
|
144
142
|
return np.array([list(map(float, line.split())) for line in line]).reshape(*shape)
|
|
@@ -6,6 +6,7 @@ from pwdata.image import Image, elements_to_order
|
|
|
6
6
|
# from calculators.const import elements
|
|
7
7
|
from pwdata.lmps import l2Box
|
|
8
8
|
from pwdata.calculators.unitconvert_lmps import convert
|
|
9
|
+
from pwdata.utils.format_change import to_numpy_array, to_integer, to_float
|
|
9
10
|
|
|
10
11
|
class DUMP(object):
|
|
11
12
|
def __init__(self, dump_file, atom_names: list[str] = None) -> None:
|
|
@@ -62,15 +63,15 @@ class DUMP(object):
|
|
|
62
63
|
traj = [jj.split() for jj in dump_contents[idx+1:idx+image.atom_nums+1]]
|
|
63
64
|
# for jj in dump_contents[idx+1:idx+image.atom_nums+1]:
|
|
64
65
|
info = self.lammps_data_to_config(np.array(traj), colnames, lattice, lattice_disp, atom_nums, self.atom_names)
|
|
65
|
-
image.lattice = info["lattice"]
|
|
66
|
+
image.lattice = to_numpy_array(info["lattice"]).reshape(3,3)
|
|
66
67
|
# image.lattice_disp = info["lattice_disp"]
|
|
67
|
-
image.atom_type = info["atom_type"]
|
|
68
|
-
image.atom_type_num = info["atom_type_num"]
|
|
69
|
-
image.atom_types_image = info["atom_types_image"]
|
|
70
|
-
image.position = info["positions"]
|
|
68
|
+
image.atom_type = to_numpy_array(info["atom_type"])
|
|
69
|
+
image.atom_type_num = to_numpy_array(info["atom_type_num"])
|
|
70
|
+
image.atom_types_image = to_numpy_array(info["atom_types_image"])
|
|
71
|
+
image.position = to_numpy_array(info["positions"])
|
|
71
72
|
if "forces" in info.keys():
|
|
72
|
-
image.force = info["forces"]
|
|
73
|
-
image.pbc = pbc
|
|
73
|
+
image.force = to_numpy_array(info["forces"])
|
|
74
|
+
image.pbc = to_numpy_array(pbc)
|
|
74
75
|
image.cartesian = True
|
|
75
76
|
|
|
76
77
|
def lammps_data_to_config(self,
|
|
@@ -20,36 +20,29 @@ class EXTXYZ(object):
|
|
|
20
20
|
image_list = read_structures(xyz_file)
|
|
21
21
|
self.image_list=image_list
|
|
22
22
|
|
|
23
|
-
def save_to_extxyz(image_data_all: list,
|
|
24
|
-
train_ratio = None, random = True, seed = 2024, retain_raw = False, write_patthen="a"
|
|
23
|
+
def save_to_extxyz(image_data_all: list, data_path: str, data_name=None, random = False, seed = None, retain_raw = False, write_patthen="a"
|
|
25
24
|
):
|
|
26
|
-
if not os.path.exists(
|
|
27
|
-
os.makedirs(
|
|
28
|
-
|
|
25
|
+
if not os.path.exists(data_path):
|
|
26
|
+
os.makedirs(data_path)
|
|
27
|
+
if data_name is None:
|
|
28
|
+
data_name = "train.xyz"
|
|
29
|
+
elif ".xyz" not in data_name:
|
|
30
|
+
data_name += ".xyz"
|
|
31
|
+
train_file = open(os.path.join(data_path, data_name), write_patthen)
|
|
29
32
|
image_nums = image_data_all.__len__()
|
|
30
33
|
if seed:
|
|
31
34
|
np.random.seed(seed)
|
|
32
35
|
indices = np.arange(image_nums) # 0, 1, 2, ..., image_nums-1
|
|
33
36
|
if random:
|
|
34
37
|
np.random.shuffle(indices) # shuffle the indices
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
train_indices = indices[:train_size]
|
|
38
|
-
val_indices = indices[train_size:]
|
|
39
|
-
if len(val_indices) > 0:
|
|
40
|
-
valid_file = open(os.path.join(output_path, valid_data_path), write_patthen)
|
|
41
|
-
for i in range(len(image_data_all)):
|
|
38
|
+
|
|
39
|
+
for i in indices:
|
|
42
40
|
image_data = image_data_all[i]
|
|
43
41
|
if not image_data.cartesian:
|
|
44
42
|
image_data._set_cartesian()
|
|
45
43
|
xyz_content = get_xyz_content(image_data)
|
|
46
|
-
|
|
47
|
-
train_file.write(xyz_content)
|
|
48
|
-
elif i in val_indices:
|
|
49
|
-
valid_file.write(xyz_content)
|
|
44
|
+
train_file.write(xyz_content)
|
|
50
45
|
train_file.close()
|
|
51
|
-
if len(val_indices) > 0:
|
|
52
|
-
valid_file.close()
|
|
53
46
|
# print("Convert to {} and {} successfully!".format(train_data_path, valid_data_path))
|
|
54
47
|
# else:
|
|
55
48
|
# print("Convert to %s successfully!" % train_data_path)
|