pwdata 0.3.6__tar.gz → 0.4.0__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.
- {pwdata-0.3.6 → pwdata-0.4.0}/PKG-INFO +1 -1
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/__init__.py +1 -1
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/build/supercells.py +5 -5
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/config.py +114 -41
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/convert_files.py +148 -165
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/extendedxyz.py +1 -1
- pwdata-0.4.0/pwdata/main.py +489 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/pertub/perturbation.py +4 -4
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/pertub/scale.py +4 -3
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/test.py +18 -18
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/utils/constant.py +1 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata.egg-info/PKG-INFO +1 -1
- {pwdata-0.3.6 → pwdata-0.4.0}/setup.py +1 -1
- pwdata-0.3.6/pwdata/main.py +0 -491
- {pwdata-0.3.6 → pwdata-0.4.0}/LICENSE +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/README.md +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/atomconfig.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/build/__init__.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/build/cell.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/build/geometry.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/build/write_struc.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/calculators/__init__.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/calculators/const.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/calculators/unitconvert_lmps.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/calculators/units.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/check_envs.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/cp2kdata.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/datasets_saver.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/deepmd.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/dump.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/fairchem/__init__.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/fairchem/common/__init__.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/fairchem/common/registry.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/fairchem/common/typing.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/fairchem/common/utils.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/fairchem/datasets/__init__.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/fairchem/datasets/_utils.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/fairchem/datasets/ase_datasets.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/fairchem/datasets/base_dataset.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/fairchem/datasets/embeddings/__init__.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/fairchem/datasets/embeddings/atomic_radii.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/fairchem/datasets/embeddings/continuous_embeddings.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/fairchem/datasets/embeddings/khot_embeddings.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/fairchem/datasets/embeddings/qmof_khot_embeddings.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/fairchem/datasets/lmdb_database.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/fairchem/datasets/target_metadata_guesser.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/fairchem/modules/__init__.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/fairchem/modules/transforms.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/fairchem/preprocessing/__init__.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/image.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/lammpsdata.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/lmps.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/meta.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/movement.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/movement_saver.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/outcar.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/pertub/__init__.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/poscar.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/pwmlff.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/test/__init__.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata/utils/__init__.py +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata.egg-info/SOURCES.txt +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata.egg-info/dependency_links.txt +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata.egg-info/entry_points.txt +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata.egg-info/requires.txt +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/pwdata.egg-info/top_level.txt +0 -0
- {pwdata-0.3.6 → pwdata-0.4.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pwdata
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
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
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"""Adapted from ase: http://wiki.fysik.dtu.dk/ase """
|
|
2
2
|
import numpy as np
|
|
3
3
|
from pwdata.image import Image
|
|
4
|
-
|
|
4
|
+
from pwdata.config import Config
|
|
5
5
|
class SupercellError(Exception):
|
|
6
6
|
"""Use if construction of supercell fails"""
|
|
7
7
|
|
|
8
|
-
def make_supercell(image_data, supercell_matrix: list, pbc: list = None, wrap=True, tol=1e-5):
|
|
8
|
+
def make_supercell(image_data:Config, supercell_matrix: list, pbc: list = None, wrap=True, tol=1e-5):
|
|
9
9
|
"""Construct supercell from image_data and supercell_matrix
|
|
10
10
|
|
|
11
11
|
Args:
|
|
@@ -13,15 +13,15 @@ def make_supercell(image_data, supercell_matrix: list, pbc: list = None, wrap=Tr
|
|
|
13
13
|
supercell_matrix (list): supercell matrix (3x3)
|
|
14
14
|
pbc (list): Periodic boundary conditions flags.
|
|
15
15
|
"""
|
|
16
|
-
|
|
17
|
-
prim =
|
|
16
|
+
image = image_data.images[0]
|
|
17
|
+
prim = image
|
|
18
18
|
supercell_matrix = np.array(supercell_matrix)
|
|
19
19
|
supercell = clean_matrix(supercell_matrix @ prim.lattice)
|
|
20
20
|
# cartesian lattice points
|
|
21
21
|
lattice_points_frac = lattice_points_in_supercell(supercell_matrix)
|
|
22
22
|
lattice_points = np.dot(lattice_points_frac, supercell)
|
|
23
23
|
|
|
24
|
-
superatoms = Image(lattice=supercell, pbc=pbc, atom_type=
|
|
24
|
+
superatoms = Image(lattice=supercell, pbc=pbc, atom_type=image.atom_type)
|
|
25
25
|
for lp in lattice_points:
|
|
26
26
|
shifted_atoms = prim.copy()
|
|
27
27
|
shifted_atoms.arrays['position'] += lp
|
|
@@ -20,6 +20,7 @@ from pwdata.extendedxyz import EXTXYZ, save_to_extxyz
|
|
|
20
20
|
from pwdata.datasets_saver import save_to_dataset, get_pw, save_to_raw, save_to_npy
|
|
21
21
|
from pwdata.build.write_struc import write_config, write_vasp, write_lammps
|
|
22
22
|
from pwdata.meta import META
|
|
23
|
+
from pwdata.utils.constant import FORMAT
|
|
23
24
|
|
|
24
25
|
class Save_Data(object):
|
|
25
26
|
def __init__(self, data_path, datasets_path = "./PWdata", train_data_path = "train", valid_data_path = "valid",
|
|
@@ -115,7 +116,7 @@ class Save_Data(object):
|
|
|
115
116
|
|
|
116
117
|
|
|
117
118
|
class Config(object):
|
|
118
|
-
def __init__(self, format: str, data_path: str, pbc = None, atom_names = None, index = ':', **kwargs):
|
|
119
|
+
def __init__(self, format: str = None, data_path: str = None, pbc = None, atom_names = None, index = ':', **kwargs):
|
|
119
120
|
self.format = format
|
|
120
121
|
self.data_path = data_path
|
|
121
122
|
self.pbc = pbc
|
|
@@ -125,7 +126,9 @@ class Config(object):
|
|
|
125
126
|
self.images = self._read()
|
|
126
127
|
|
|
127
128
|
def _read(self):
|
|
128
|
-
|
|
129
|
+
images, format = Config.read(self.format, self.data_path, self.pbc, self.atom_names, self.index, **self.kwargs)
|
|
130
|
+
self.format = format # if the input format is None
|
|
131
|
+
return images
|
|
129
132
|
|
|
130
133
|
def append(self, images_obj):
|
|
131
134
|
if not hasattr(self, 'images'):
|
|
@@ -137,7 +140,7 @@ class Config(object):
|
|
|
137
140
|
self.images += images_obj.images
|
|
138
141
|
|
|
139
142
|
@staticmethod
|
|
140
|
-
def read(format: str, data_path: str, pbc = None, atom_names = None, index = ':', **kwargs):
|
|
143
|
+
def read(format: str = None, data_path: str = None, pbc = None, atom_names = None, index = ':', **kwargs):
|
|
141
144
|
""" Read the data from the input file.
|
|
142
145
|
index: int, slice or str
|
|
143
146
|
The last configuration will be returned by default. Examples:
|
|
@@ -161,39 +164,42 @@ class Config(object):
|
|
|
161
164
|
index = string2index(index)
|
|
162
165
|
except ValueError:
|
|
163
166
|
pass
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
elif format.lower() == "vasp/poscar":
|
|
168
|
-
image = POSCAR(data_path, pbc).image_list[0]
|
|
169
|
-
elif format.lower() == "lammps/dump":
|
|
170
|
-
assert atom_names is not None, "atom_names must be set when format is dump"
|
|
171
|
-
image = DUMP(data_path, atom_names).image_list[index]
|
|
172
|
-
elif format.lower() == "lammps/lmp":
|
|
173
|
-
image = LMP(data_path, atom_names, **kwargs).image_list[0]
|
|
174
|
-
elif format.lower() == "pwmat/movement":
|
|
175
|
-
image = MOVEMENT(data_path).image_list[index]
|
|
176
|
-
elif format.lower() == "vasp/outcar":
|
|
177
|
-
image = OUTCAR(data_path).image_list[index]
|
|
178
|
-
elif format.lower() == "extxyz":
|
|
179
|
-
image = EXTXYZ(data_path, index).image_list[index]
|
|
180
|
-
elif format.lower() == "vasp/xml":
|
|
181
|
-
image = None
|
|
182
|
-
elif format.lower() == 'cp2k/md':
|
|
183
|
-
image = CP2KMD(data_path).image_list[index]
|
|
184
|
-
elif format.lower() == 'cp2k/scf':
|
|
185
|
-
image = CP2KSCF(data_path).image_list[0]
|
|
186
|
-
elif format.lower() == 'deepmd/npy':
|
|
187
|
-
image = DPNPY(data_path).image_list[index]
|
|
188
|
-
elif format.lower() == 'deepmd/raw':
|
|
189
|
-
image = DPRAW(data_path).image_list[index]
|
|
190
|
-
elif format.lower() == 'pwmlff/npy':
|
|
191
|
-
image = PWNPY(data_path).image_list[index]
|
|
192
|
-
elif format.lower() == 'meta':
|
|
193
|
-
image = META(data_path, atom_names, **kwargs).image_list[index]
|
|
167
|
+
if format is None:
|
|
168
|
+
image, format = infer_format(data_path, pbc, atom_names, index, **kwargs)
|
|
169
|
+
print("infer the input data format is {}".format(format))
|
|
194
170
|
else:
|
|
195
|
-
|
|
196
|
-
|
|
171
|
+
if format.lower() == "pwmat/config":
|
|
172
|
+
image = CONFIG(data_path, pbc).image_list
|
|
173
|
+
elif format.lower() == "vasp/poscar":
|
|
174
|
+
image = POSCAR(data_path, pbc).image_list
|
|
175
|
+
elif format.lower() == "lammps/dump":
|
|
176
|
+
assert atom_names is not None, "atom_names must be set when format is dump"
|
|
177
|
+
image = DUMP(data_path, atom_names).image_list[index]
|
|
178
|
+
elif format.lower() == "lammps/lmp":
|
|
179
|
+
image = LMP(data_path, atom_names, **kwargs).image_list
|
|
180
|
+
elif format.lower() == "pwmat/movement":
|
|
181
|
+
image = MOVEMENT(data_path).image_list[index]
|
|
182
|
+
elif format.lower() == "vasp/outcar":
|
|
183
|
+
image = OUTCAR(data_path).image_list[index]
|
|
184
|
+
elif format.lower() == "extxyz":
|
|
185
|
+
image = EXTXYZ(data_path, index).image_list[index]
|
|
186
|
+
elif format.lower() == "vasp/xml":
|
|
187
|
+
image = None
|
|
188
|
+
elif format.lower() == 'cp2k/md':
|
|
189
|
+
image = CP2KMD(data_path).image_list[index]
|
|
190
|
+
elif format.lower() == 'cp2k/scf':
|
|
191
|
+
image = CP2KSCF(data_path).image_list
|
|
192
|
+
elif format.lower() == 'deepmd/npy':
|
|
193
|
+
image = DPNPY(data_path).image_list[index]
|
|
194
|
+
elif format.lower() == 'deepmd/raw':
|
|
195
|
+
image = DPRAW(data_path).image_list[index]
|
|
196
|
+
elif format.lower() == 'pwmlff/npy':
|
|
197
|
+
image = PWNPY(data_path).image_list[index]
|
|
198
|
+
elif format.lower() == 'meta':
|
|
199
|
+
image = META(data_path, atom_names, **kwargs).image_list[index]
|
|
200
|
+
else:
|
|
201
|
+
raise Exception("Error! The format of the input file is not supported!")
|
|
202
|
+
return image, format.lower()
|
|
197
203
|
|
|
198
204
|
def to(self, output_path, save_format = None, **kwargs):
|
|
199
205
|
"""
|
|
@@ -230,12 +236,10 @@ class Config(object):
|
|
|
230
236
|
if not os.path.exists(output_path):
|
|
231
237
|
os.makedirs(output_path)
|
|
232
238
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if isinstance(images, list):
|
|
236
|
-
self.multi_to(images, output_path, save_format, **kwargs)
|
|
239
|
+
if save_format in FORMAT.support_config_format:
|
|
240
|
+
self.write_image(self.images[0], output_path, save_format, **kwargs)
|
|
237
241
|
else:
|
|
238
|
-
self.
|
|
242
|
+
self.multi_to(self.images, output_path, save_format, **kwargs)
|
|
239
243
|
|
|
240
244
|
def multi_to(self, images, output_path, save_format, **kwargs):
|
|
241
245
|
"""
|
|
@@ -280,4 +284,73 @@ def string2index(string: str) -> Union[int, slice, str]:
|
|
|
280
284
|
else:
|
|
281
285
|
i.append(int(s))
|
|
282
286
|
i += (3 - len(i)) * [None]
|
|
283
|
-
return slice(*i)
|
|
287
|
+
return slice(*i)
|
|
288
|
+
|
|
289
|
+
def infer_format(data_path: str, pbc = None, atom_names = None, index = ':', **kwargs):
|
|
290
|
+
try:
|
|
291
|
+
image = MOVEMENT(data_path).image_list[index]
|
|
292
|
+
return image, FORMAT.pwmat_movement
|
|
293
|
+
except Exception as e:
|
|
294
|
+
pass
|
|
295
|
+
try:
|
|
296
|
+
image = OUTCAR(data_path).image_list[index]
|
|
297
|
+
return image, FORMAT.vasp_outcar
|
|
298
|
+
except Exception as e:
|
|
299
|
+
pass
|
|
300
|
+
try:
|
|
301
|
+
image = EXTXYZ(data_path, index).image_list[index]
|
|
302
|
+
return image, FORMAT.extxyz
|
|
303
|
+
except Exception as e:
|
|
304
|
+
pass
|
|
305
|
+
try:
|
|
306
|
+
image = CP2KMD(data_path).image_list[index]
|
|
307
|
+
return image, FORMAT.cp2k_md
|
|
308
|
+
except Exception as e:
|
|
309
|
+
pass
|
|
310
|
+
try:
|
|
311
|
+
image = DPNPY(data_path).image_list[index]
|
|
312
|
+
return image, FORMAT.deepmd_npy
|
|
313
|
+
except Exception as e:
|
|
314
|
+
pass
|
|
315
|
+
try:
|
|
316
|
+
image = DPRAW(data_path).image_list[index]
|
|
317
|
+
return image, FORMAT.deepmd_raw
|
|
318
|
+
except Exception as e:
|
|
319
|
+
pass
|
|
320
|
+
try:
|
|
321
|
+
image = PWNPY(data_path).image_list[index]
|
|
322
|
+
return image, FORMAT.pwmlff_npy
|
|
323
|
+
except Exception as e:
|
|
324
|
+
pass
|
|
325
|
+
try:
|
|
326
|
+
image = META(data_path, atom_names, **kwargs).image_list[index]
|
|
327
|
+
return image, FORMAT.meta
|
|
328
|
+
except Exception as e:
|
|
329
|
+
pass
|
|
330
|
+
try:
|
|
331
|
+
image = DUMP(data_path, atom_names).image_list[index]
|
|
332
|
+
return image, FORMAT.lammps_dump
|
|
333
|
+
except Exception as e:
|
|
334
|
+
pass
|
|
335
|
+
try:
|
|
336
|
+
image = CONFIG(data_path, pbc).image_list #
|
|
337
|
+
return image, FORMAT.pwmat_config
|
|
338
|
+
except Exception as e:
|
|
339
|
+
pass
|
|
340
|
+
try:
|
|
341
|
+
image = POSCAR(data_path, pbc).image_list
|
|
342
|
+
return image, FORMAT.vasp_poscar
|
|
343
|
+
except Exception as e:
|
|
344
|
+
pass
|
|
345
|
+
try:
|
|
346
|
+
image = CP2KSCF(data_path).image_list
|
|
347
|
+
return image, FORMAT.cp2k_scf
|
|
348
|
+
except Exception as e:
|
|
349
|
+
pass
|
|
350
|
+
try:
|
|
351
|
+
image = LMP(data_path, atom_names, **kwargs).image_list
|
|
352
|
+
return image, FORMAT.lammps_lmp
|
|
353
|
+
except Exception as e:
|
|
354
|
+
pass
|
|
355
|
+
error_info = "ERROR! Speculation on input data format failed, please explicitly specify the input format. For lammps/dump files, please also specify the element type."
|
|
356
|
+
raise Exception(error_info)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import sys
|
|
3
|
+
import glob
|
|
3
4
|
import numpy as np
|
|
4
5
|
from pwdata.config import Config
|
|
5
6
|
from pwdata.build.supercells import make_supercell
|
|
@@ -14,12 +15,17 @@ from concurrent.futures import ProcessPoolExecutor, as_completed
|
|
|
14
15
|
import multiprocessing
|
|
15
16
|
|
|
16
17
|
def do_convert_config(input_file:str,
|
|
17
|
-
input_format:str,
|
|
18
|
-
atom_types:list[str],
|
|
19
|
-
savename:str,
|
|
20
|
-
output_format:str,
|
|
18
|
+
input_format:str = None,
|
|
19
|
+
atom_types:list[str] = None,
|
|
20
|
+
savename:str = None,
|
|
21
|
+
output_format:str = None,
|
|
21
22
|
direct:bool = True): # True: save as fractional coordinates, False for cartesian coordinates
|
|
22
23
|
image = Config(data_path=input_file, format=input_format, atom_names=atom_types)
|
|
24
|
+
if output_format is None:
|
|
25
|
+
output_format = FORMAT.pwmat_config if image.format == FORMAT.cp2k_scf else image.format
|
|
26
|
+
if savename is None:
|
|
27
|
+
savename = FORMAT.get_filename_by_format(image.format)
|
|
28
|
+
|
|
23
29
|
image.to(output_path = os.path.dirname(os.path.abspath(savename)),
|
|
24
30
|
data_name = os.path.basename(savename),
|
|
25
31
|
save_format = output_format,
|
|
@@ -28,16 +34,20 @@ def do_convert_config(input_file:str,
|
|
|
28
34
|
return os.path.abspath(savename)
|
|
29
35
|
|
|
30
36
|
def do_scale_cell(input_file:str,
|
|
31
|
-
input_format:str,
|
|
32
|
-
atom_types:list[str],
|
|
33
|
-
savename:str,
|
|
34
|
-
output_format:str,
|
|
35
|
-
scale_factor:list[float],
|
|
37
|
+
input_format:str = None,
|
|
38
|
+
atom_types:list[str] = None,
|
|
39
|
+
savename:str = None,
|
|
40
|
+
output_format:str = None,
|
|
41
|
+
scale_factor:list[float] = None,
|
|
36
42
|
direct:bool = True): # True: save as fractional coordinates, False for cartesian coordinates
|
|
37
43
|
# for pwamt/movement movement or MLMD.OUT files
|
|
38
44
|
if not isinstance(scale_factor, list):
|
|
39
45
|
scale_factor = [scale_factor]
|
|
40
46
|
image = Config(data_path=input_file, format=input_format, atom_names=atom_types)
|
|
47
|
+
if output_format is None:
|
|
48
|
+
output_format = FORMAT.pwmat_config if image.format == FORMAT.cp2k_scf else image.format
|
|
49
|
+
if savename is None:
|
|
50
|
+
savename = FORMAT.get_filename_by_format(image.format)
|
|
41
51
|
for idx, factor in enumerate(scale_factor):
|
|
42
52
|
scaled_structs = scale_cell(image, factor)
|
|
43
53
|
scaled_structs.to(output_path = os.path.dirname(os.path.abspath(savename)),
|
|
@@ -48,11 +58,11 @@ def do_scale_cell(input_file:str,
|
|
|
48
58
|
return os.path.abspath(savename)
|
|
49
59
|
|
|
50
60
|
def do_super_cell(input_file:str,
|
|
51
|
-
input_format:str,
|
|
52
|
-
atom_types:list[str],
|
|
53
|
-
savename:str,
|
|
54
|
-
output_format:str,
|
|
55
|
-
supercell_matrix:list[int],
|
|
61
|
+
input_format:str = None,
|
|
62
|
+
atom_types:list[str] = None,
|
|
63
|
+
savename:str = None,
|
|
64
|
+
output_format:str = None,
|
|
65
|
+
supercell_matrix:list[int] = None,
|
|
56
66
|
direct:bool = True,
|
|
57
67
|
pbc:list =[1, 1, 1],
|
|
58
68
|
wrap=True,
|
|
@@ -61,6 +71,10 @@ def do_super_cell(input_file:str,
|
|
|
61
71
|
# for pwamt/movement movement or MLMD.OUT files
|
|
62
72
|
image = Config(data_path=input_file, format=input_format, atom_names=atom_types)
|
|
63
73
|
scaled_structs = make_supercell(image, supercell_matrix, pbc=pbc, wrap=wrap, tol=tol)
|
|
74
|
+
if output_format is None:
|
|
75
|
+
output_format = FORMAT.pwmat_config if image.format == FORMAT.cp2k_scf else image.format
|
|
76
|
+
if savename is None:
|
|
77
|
+
savename = FORMAT.get_filename_by_format(image.format)
|
|
64
78
|
scaled_structs.to(output_path = os.path.dirname(os.path.abspath(savename)),
|
|
65
79
|
data_name = os.path.basename(savename),
|
|
66
80
|
save_format = output_format,
|
|
@@ -69,14 +83,14 @@ def do_super_cell(input_file:str,
|
|
|
69
83
|
return os.path.abspath(savename)
|
|
70
84
|
|
|
71
85
|
def do_perturb(input_file:str,
|
|
72
|
-
input_format:str,
|
|
73
|
-
atom_types:list[str],
|
|
74
|
-
save_path:str,
|
|
75
|
-
save_name_prefix:str,
|
|
76
|
-
output_format:str,
|
|
77
|
-
cell_pert_fraction:float,
|
|
78
|
-
atom_pert_distance:float,
|
|
79
|
-
pert_num:int,
|
|
86
|
+
input_format:str = None,
|
|
87
|
+
atom_types:list[str] = None,
|
|
88
|
+
save_path:str = None,
|
|
89
|
+
save_name_prefix:str = None,
|
|
90
|
+
output_format:str = None,
|
|
91
|
+
cell_pert_fraction:float = None,
|
|
92
|
+
atom_pert_distance:float = None,
|
|
93
|
+
pert_num:int = None,
|
|
80
94
|
direct:bool = True
|
|
81
95
|
): # True: save as fractional coordinates, False for cartesian coordinates
|
|
82
96
|
# for pwamt/movement movement or MLMD.OUT files
|
|
@@ -89,6 +103,8 @@ def do_perturb(input_file:str,
|
|
|
89
103
|
atom_pert_distance = atom_pert_distance)
|
|
90
104
|
|
|
91
105
|
perturb_files = []
|
|
106
|
+
if output_format is None:
|
|
107
|
+
output_format = FORMAT.pwmat_config if image.format == FORMAT.cp2k_scf else image.format
|
|
92
108
|
for tmp_perturbed_idx, tmp_pertubed_struct in enumerate(perturbed_structs):
|
|
93
109
|
tmp_pertubed_struct.to(output_path = save_path,
|
|
94
110
|
data_name = "{}_{}".format(tmp_perturbed_idx, save_name_prefix),
|
|
@@ -99,13 +115,13 @@ def do_perturb(input_file:str,
|
|
|
99
115
|
return perturb_files, perturbed_structs
|
|
100
116
|
|
|
101
117
|
def do_convert_images(
|
|
102
|
-
input:list[str],
|
|
103
|
-
input_format:str,
|
|
104
|
-
savepath, #'the/path/pwmlff-datas'
|
|
105
|
-
output_format,
|
|
106
|
-
train_valid_ratio,
|
|
107
|
-
data_shuffle,
|
|
108
|
-
gap,
|
|
118
|
+
input:list[str],
|
|
119
|
+
input_format:str = None,
|
|
120
|
+
savepath = None, #'the/path/pwmlff-datas'
|
|
121
|
+
output_format = None,
|
|
122
|
+
train_valid_ratio = None,
|
|
123
|
+
data_shuffle = None,
|
|
124
|
+
gap = None,
|
|
109
125
|
atom_types:list[str]=None,
|
|
110
126
|
query:str=None,
|
|
111
127
|
cpu_nums:int=None,
|
|
@@ -165,60 +181,119 @@ def save_images(savepath, image_data, output_format, train_valid_ratio=1, data_s
|
|
|
165
181
|
write_patthen="a"
|
|
166
182
|
)
|
|
167
183
|
|
|
168
|
-
def search_images(input_list:list[str], input_format:str):
|
|
169
|
-
|
|
184
|
+
def search_images(input_list:list[str], input_format:str = None):
|
|
185
|
+
data_path = {}
|
|
186
|
+
data_path[FORMAT.pwmlff_npy] = []
|
|
187
|
+
data_path[FORMAT.extxyz] = []
|
|
188
|
+
data_path[FORMAT.deepmd_npy] = []
|
|
189
|
+
data_path[FORMAT.deepmd_raw] = []
|
|
190
|
+
data_path[FORMAT.meta] = []
|
|
191
|
+
data_path[FORMAT.traj] = []
|
|
170
192
|
for workDir in input_list:
|
|
171
193
|
workDir = os.path.abspath(workDir)
|
|
172
|
-
if os.path.isfile(workDir)
|
|
173
|
-
|
|
194
|
+
if os.path.isfile(workDir) and '.xyz' not in os.path.basename(workDir) and '.aselmdb' not in os.path.basename(workDir):#traj files
|
|
195
|
+
data_path[FORMAT.traj].append(workDir)
|
|
174
196
|
else:
|
|
175
|
-
if input_format
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
197
|
+
if input_format is not None:
|
|
198
|
+
_data_list = search_by_format(workDir, input_format)
|
|
199
|
+
if len(_data_list) > 0:
|
|
200
|
+
data_path[input_format].extend(search_by_format(workDir, input_format))
|
|
201
|
+
else:
|
|
202
|
+
for _format in [FORMAT.pwmlff_npy, FORMAT.extxyz, FORMAT.deepmd_npy, FORMAT.deepmd_raw, FORMAT.meta]:
|
|
203
|
+
_data_list = search_by_format(workDir, _format)
|
|
204
|
+
if len(_data_list) > 0:
|
|
205
|
+
data_path[_format].extend(_data_list)
|
|
180
206
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
207
|
+
format_count = 0
|
|
208
|
+
match_format = []
|
|
209
|
+
for key, value in data_path.items():
|
|
210
|
+
if len(value) > 0:
|
|
211
|
+
match_format.append(key)
|
|
212
|
+
format_count += 1
|
|
213
|
+
if format_count >= 2:
|
|
214
|
+
match_str = " ".join(match_format)
|
|
215
|
+
error_info = "WARNING! Multiple formats '{}' of data have been matched in the input data directory. All matched data will be loaded!".format(match_str)
|
|
216
|
+
print(error_info)
|
|
217
|
+
return data_path
|
|
191
218
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
219
|
+
def search_by_format(workDir, format):
|
|
220
|
+
data_path = {}
|
|
221
|
+
data_path[FORMAT.pwmlff_npy] = []
|
|
222
|
+
data_path[FORMAT.extxyz] = []
|
|
223
|
+
data_path[FORMAT.deepmd_npy] = []
|
|
224
|
+
data_path[FORMAT.deepmd_raw] = []
|
|
225
|
+
data_path[FORMAT.meta] = []
|
|
226
|
+
if '.xyz' in os.path.basename(workDir):
|
|
227
|
+
data_path[FORMAT.extxyz].append(workDir)
|
|
228
|
+
elif '.aselmdb' in os.path.basename(workDir):
|
|
229
|
+
data_path[FORMAT.meta].append(workDir)
|
|
230
|
+
else:
|
|
231
|
+
if format == FORMAT.pwmlff_npy:
|
|
232
|
+
for root, dirs, files in os.walk(workDir):
|
|
233
|
+
if 'energies.npy' in files:
|
|
234
|
+
if "train" in os.path.basename(root):
|
|
235
|
+
data_path[FORMAT.pwmlff_npy].append(os.path.dirname(root))
|
|
236
|
+
|
|
237
|
+
if format == FORMAT.extxyz:
|
|
238
|
+
for path, dirList, fileList in os.walk(workDir):
|
|
239
|
+
for _ in fileList:
|
|
240
|
+
if ".xyz" in _:
|
|
241
|
+
data_path[FORMAT.extxyz].append(os.path.join(path, _))
|
|
242
|
+
|
|
243
|
+
if format == FORMAT.deepmd_npy:
|
|
244
|
+
for root, dirs, files in os.walk(workDir):
|
|
245
|
+
if 'energy.npy' in files:
|
|
246
|
+
data_path[FORMAT.deepmd_npy].append(os.path.dirname(root))
|
|
203
247
|
|
|
204
|
-
|
|
248
|
+
if format == FORMAT.deepmd_raw:
|
|
249
|
+
for root, dirs, files in os.walk(workDir):
|
|
250
|
+
if 'energy.raw' in files:
|
|
251
|
+
if len(glob.glob(os.path.join(root, "*/energy.npy"))) == 0: #
|
|
252
|
+
data_path[FORMAT.deepmd_raw].append(os.path.dirname(root)) #If both npy and raw format data exist, only load npy format
|
|
253
|
+
if format == FORMAT.meta:
|
|
254
|
+
for root, dirs, files in os.walk(workDir):
|
|
255
|
+
for file in files:
|
|
256
|
+
if '.aselmdb' in file:
|
|
257
|
+
data_path[FORMAT.meta].append(root)
|
|
258
|
+
break
|
|
259
|
+
|
|
260
|
+
return data_path[format]
|
|
205
261
|
|
|
206
|
-
|
|
262
|
+
|
|
263
|
+
def load_files(input_dict:dict, input_format:str=None, atom_types:list[str]=None, query:str=None, cpu_nums=None):
|
|
207
264
|
image_data = None
|
|
208
|
-
if input_format
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
image_data.images
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
if
|
|
215
|
-
|
|
216
|
-
|
|
265
|
+
if input_format is not None:
|
|
266
|
+
if input_format == FORMAT.meta:
|
|
267
|
+
image_data = Config(input_format, input_dict[FORMAT.meta], atom_names=atom_types, query=query, cpu_nums=cpu_nums)
|
|
268
|
+
if not isinstance(image_data.images, list): # for the first pwmlff/npy dir only has one picture
|
|
269
|
+
image_data.images = [image_data.images]
|
|
270
|
+
else:
|
|
271
|
+
if len(input_dict[FORMAT.traj]) > 0:# the input is traj files
|
|
272
|
+
for data_path in input_dict[FORMAT.traj]:
|
|
273
|
+
image_data = Config(input_format, data_path, atom_names=atom_types, query=query, cpu_nums=cpu_nums)
|
|
274
|
+
if not isinstance(image_data.images, list): # for the first pwmlff/npy dir only has one picture
|
|
275
|
+
image_data.images = [image_data.images]
|
|
217
276
|
else:
|
|
218
|
-
|
|
277
|
+
for data_path in input_dict[input_format]:
|
|
278
|
+
image_data = Config(input_format, data_path, atom_names=atom_types, query=query, cpu_nums=cpu_nums)
|
|
279
|
+
if not isinstance(image_data.images, list): # for the first pwmlff/npy dir only has one picture
|
|
280
|
+
image_data.images = [image_data.images]
|
|
281
|
+
return image_data
|
|
282
|
+
|
|
283
|
+
else:
|
|
284
|
+
for format, data_list in input_dict.items():
|
|
285
|
+
if len(data_list) == 0:
|
|
286
|
+
continue
|
|
287
|
+
if format == FORMAT.meta:
|
|
288
|
+
image_data = Config(FORMAT.meta, data_list, atom_names=atom_types, query=query, cpu_nums=cpu_nums)
|
|
219
289
|
if not isinstance(image_data.images, list): # for the first pwmlff/npy dir only has one picture
|
|
220
290
|
image_data.images = [image_data.images]
|
|
221
|
-
|
|
291
|
+
else:
|
|
292
|
+
for data_path in data_list:
|
|
293
|
+
image_data = Config(None, data_path, atom_names=atom_types, query=query, cpu_nums=cpu_nums)
|
|
294
|
+
if not isinstance(image_data.images, list): # for the first pwmlff/npy dir only has one picture
|
|
295
|
+
image_data.images = [image_data.images]
|
|
296
|
+
return image_data
|
|
222
297
|
|
|
223
298
|
'''
|
|
224
299
|
description:
|
|
@@ -269,96 +344,4 @@ def make_query(elements:list[str]):
|
|
|
269
344
|
if sorted(set(row.symbols)) == sorted(elements):
|
|
270
345
|
return True
|
|
271
346
|
return False
|
|
272
|
-
return query
|
|
273
|
-
|
|
274
|
-
def do_meta_data(input,
|
|
275
|
-
savepath,
|
|
276
|
-
output_format,
|
|
277
|
-
train_valid_ratio,
|
|
278
|
-
split_rand,
|
|
279
|
-
atom_types:list[str]=None,
|
|
280
|
-
query_str:str=None,
|
|
281
|
-
cpu_nums:int=None):
|
|
282
|
-
image_data = load_meta_datas(input, atom_types, query_str, cpu_nums)
|
|
283
|
-
save_images(savepath, image_data, output_format, train_valid_ratio, split_rand)
|
|
284
|
-
|
|
285
|
-
def load_meta_datas(input, atom_types: list[str] = None, query_str: str = None, cpu_nums: int=None):
|
|
286
|
-
search_dict = {'src': input}
|
|
287
|
-
dataset = AseDBDataset(config=search_dict)
|
|
288
|
-
image_list = []
|
|
289
|
-
for ids, dbs in enumerate(dataset.dbs):
|
|
290
|
-
if query_str is None and atom_types is None:
|
|
291
|
-
atom_list = list(dbs.select())
|
|
292
|
-
elif query_str is None and atom_types is not None:
|
|
293
|
-
atom_list = list(dbs.select("".join(atom_types)))
|
|
294
|
-
elif query_str is not None and atom_types is not None:
|
|
295
|
-
atom_list = list(dbs.select(query_str,filter=make_query))
|
|
296
|
-
else:# query_str is not None and atom_types is None:
|
|
297
|
-
atom_list = list(dbs.select(query_str))
|
|
298
|
-
for Atoms in atom_list:
|
|
299
|
-
image = to_image(Atoms)
|
|
300
|
-
image_list.append(image)
|
|
301
|
-
image_data = Config()
|
|
302
|
-
image_data.images = image_list
|
|
303
|
-
return image_data
|
|
304
|
-
|
|
305
|
-
### ProcessPoolExecutor
|
|
306
|
-
def load_meta_datas_cpus(input, atom_types: list[str] = None, query_str: str = None, cpu_nums: int=None):
|
|
307
|
-
search_dict = {'src': input}
|
|
308
|
-
dataset = AseDBDataset(config=search_dict)
|
|
309
|
-
image_list = []
|
|
310
|
-
# 定义一个辅助函数,用于查询和转换每个数据库中的数据
|
|
311
|
-
def process_dbs(dbs):
|
|
312
|
-
# 根据条件构建 atom_list
|
|
313
|
-
if query_str is None and atom_types is None:
|
|
314
|
-
atom_list = list(dbs.select())
|
|
315
|
-
elif query_str is None and atom_types is not None:
|
|
316
|
-
atom_list = list(dbs.select("".join(atom_types)))
|
|
317
|
-
elif query_str is not None and atom_types is not None:
|
|
318
|
-
atom_list = list(dbs.select(query_str, filter=make_query))
|
|
319
|
-
else:
|
|
320
|
-
atom_list = list(dbs.select(query_str))
|
|
321
|
-
# 对每个原子对象进行转换并返回 image 列表
|
|
322
|
-
return [to_image(Atoms) for Atoms in atom_list]
|
|
323
|
-
|
|
324
|
-
# 使用多进程并行处理每个子数据库
|
|
325
|
-
if cpu_nums is None:
|
|
326
|
-
cpu_nums = multiprocessing.cpu_count()
|
|
327
|
-
with ProcessPoolExecutor(max_workers=cpu_nums) as executor:
|
|
328
|
-
futures = [executor.submit(process_dbs, dbs) for dbs in dataset.dbs]
|
|
329
|
-
for future in as_completed(futures):
|
|
330
|
-
image_list.extend(future.result())
|
|
331
|
-
|
|
332
|
-
image_data = Config()
|
|
333
|
-
image_data.images = image_list
|
|
334
|
-
return image_data
|
|
335
|
-
|
|
336
|
-
def to_image(Atoms):
|
|
337
|
-
image = Image()
|
|
338
|
-
image.formula = Atoms.formula
|
|
339
|
-
image.pbc = Atoms.pbc
|
|
340
|
-
image.atom_nums = Atoms.natoms
|
|
341
|
-
type_nums_dict = Counter(Atoms.numbers)
|
|
342
|
-
image.atom_type = np.array(list(type_nums_dict.keys()))
|
|
343
|
-
image.atom_type_num = np.array(list(type_nums_dict.values()))
|
|
344
|
-
image.atom_types_image = np.array(Atoms.numbers)
|
|
345
|
-
image.lattice = np.array(Atoms.cell)
|
|
346
|
-
image.position = Atoms.positions
|
|
347
|
-
image.cartesian = True
|
|
348
|
-
image.force = Atoms.forces
|
|
349
|
-
image.Ep = Atoms.energy
|
|
350
|
-
|
|
351
|
-
# 计算 Atomic-Energy
|
|
352
|
-
atomic_energy, _, _, _ = np.linalg.lstsq([image.atom_type_num], np.array([image.Ep]), rcond=1e-3)
|
|
353
|
-
atomic_energy = np.repeat(atomic_energy, image.atom_type_num)
|
|
354
|
-
image.atomic_energy = atomic_energy.tolist()
|
|
355
|
-
|
|
356
|
-
vol = Atoms.volume
|
|
357
|
-
virial = (-np.array(Atoms.stress) * vol)
|
|
358
|
-
image.virial = np.array([
|
|
359
|
-
[virial[0], virial[5], virial[4]],
|
|
360
|
-
[virial[5], virial[1], virial[3]],
|
|
361
|
-
[virial[4], virial[3], virial[2]]
|
|
362
|
-
])
|
|
363
|
-
image.format = 'metadata'
|
|
364
|
-
return image
|
|
347
|
+
return query
|
|
@@ -114,7 +114,7 @@ def read_structures(
|
|
|
114
114
|
frames.append(line)
|
|
115
115
|
image = read_one_structures_from_lines(frames)
|
|
116
116
|
image_list.append(image)
|
|
117
|
-
|
|
117
|
+
assert len(image_list) > 0, "extxyz file {} parsing failed".format(file_name)
|
|
118
118
|
return image_list
|
|
119
119
|
|
|
120
120
|
def read_one_structures_from_lines(lines:list[str]):
|