pwdata 0.3.3__tar.gz → 0.3.5__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 (66) hide show
  1. {pwdata-0.3.3 → pwdata-0.3.5}/PKG-INFO +1 -1
  2. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/convert_files.py +1 -2
  3. pwdata-0.3.5/pwdata/fairchem/common/__init__.py +6 -0
  4. pwdata-0.3.5/pwdata/fairchem/common/registry.py +296 -0
  5. pwdata-0.3.5/pwdata/fairchem/common/typing.py +19 -0
  6. pwdata-0.3.5/pwdata/fairchem/common/utils.py +758 -0
  7. pwdata-0.3.5/pwdata/fairchem/datasets/__init__.py +23 -0
  8. pwdata-0.3.5/pwdata/fairchem/datasets/_utils.py +40 -0
  9. pwdata-0.3.5/pwdata/fairchem/datasets/ase_datasets.py +569 -0
  10. pwdata-0.3.5/pwdata/fairchem/datasets/base_dataset.py +140 -0
  11. pwdata-0.3.5/pwdata/fairchem/datasets/embeddings/__init__.py +13 -0
  12. pwdata-0.3.5/pwdata/fairchem/datasets/embeddings/atomic_radii.py +111 -0
  13. pwdata-0.3.5/pwdata/fairchem/datasets/embeddings/continuous_embeddings.py +1122 -0
  14. pwdata-0.3.5/pwdata/fairchem/datasets/embeddings/khot_embeddings.py +9414 -0
  15. pwdata-0.3.5/pwdata/fairchem/datasets/embeddings/qmof_khot_embeddings.py +7638 -0
  16. pwdata-0.3.5/pwdata/fairchem/datasets/lmdb_database.py +357 -0
  17. pwdata-0.3.5/pwdata/fairchem/datasets/target_metadata_guesser.py +192 -0
  18. pwdata-0.3.5/pwdata/fairchem/modules/__init__.py +6 -0
  19. pwdata-0.3.5/pwdata/fairchem/modules/transforms.py +38 -0
  20. pwdata-0.3.5/pwdata/fairchem/preprocessing/__init__.py +7 -0
  21. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/main.py +20 -2
  22. pwdata-0.3.5/pwdata/pertub/__init__.py +0 -0
  23. pwdata-0.3.5/pwdata/test/__init__.py +0 -0
  24. pwdata-0.3.5/pwdata/utils/__init__.py +0 -0
  25. pwdata-0.3.5/pwdata/utils/constant.py +128 -0
  26. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata.egg-info/PKG-INFO +1 -1
  27. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata.egg-info/SOURCES.txt +23 -1
  28. {pwdata-0.3.3 → pwdata-0.3.5}/setup.py +1 -1
  29. {pwdata-0.3.3 → pwdata-0.3.5}/LICENSE +0 -0
  30. {pwdata-0.3.3 → pwdata-0.3.5}/README.md +0 -0
  31. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/__init__.py +0 -0
  32. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/atomconfig.py +0 -0
  33. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/build/__init__.py +0 -0
  34. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/build/cell.py +0 -0
  35. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/build/geometry.py +0 -0
  36. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/build/supercells.py +0 -0
  37. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/build/write_struc.py +0 -0
  38. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/calculators/__init__.py +0 -0
  39. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/calculators/const.py +0 -0
  40. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/calculators/unitconvert_lmps.py +0 -0
  41. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/calculators/units.py +0 -0
  42. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/check_envs.py +0 -0
  43. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/config.py +0 -0
  44. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/cp2kdata.py +0 -0
  45. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/datasets_saver.py +0 -0
  46. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/deepmd.py +0 -0
  47. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/dump.py +0 -0
  48. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/extendedxyz.py +0 -0
  49. {pwdata-0.3.3/pwdata/pertub → pwdata-0.3.5/pwdata/fairchem}/__init__.py +0 -0
  50. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/image.py +0 -0
  51. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/lammpsdata.py +0 -0
  52. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/lmps.py +0 -0
  53. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/meta.py +0 -0
  54. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/movement.py +0 -0
  55. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/movement_saver.py +0 -0
  56. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/outcar.py +0 -0
  57. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/pertub/perturbation.py +0 -0
  58. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/pertub/scale.py +0 -0
  59. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/poscar.py +0 -0
  60. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/pwmlff.py +0 -0
  61. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata/test.py +0 -0
  62. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata.egg-info/dependency_links.txt +0 -0
  63. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata.egg-info/entry_points.txt +0 -0
  64. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata.egg-info/requires.txt +0 -0
  65. {pwdata-0.3.3 → pwdata-0.3.5}/pwdata.egg-info/top_level.txt +0 -0
  66. {pwdata-0.3.3 → pwdata-0.3.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pwdata
3
- Version: 0.3.3
3
+ Version: 0.3.5
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
@@ -5,8 +5,7 @@ from pwdata.config import Config
5
5
  from pwdata.build.supercells import make_supercell
6
6
  from pwdata.pertub.perturbation import perturb_structure
7
7
  from pwdata.pertub.scale import scale_cell
8
- from pwdata.utils.constant import FORMAT, ELEMENTTABLE
9
- from pwdata.utils.constant import get_atomic_name_from_number
8
+ from pwdata.utils.constant import FORMAT, ELEMENTTABLE, get_atomic_name_from_number
10
9
  from pwdata.image import Image
11
10
  from collections import Counter
12
11
  from ase.db.row import AtomsRow
@@ -0,0 +1,6 @@
1
+ """
2
+ Copyright (c) Meta, Inc. and its affiliates.
3
+
4
+ This source code is licensed under the MIT license found in the
5
+ LICENSE file in the root directory of this source tree.
6
+ """
@@ -0,0 +1,296 @@
1
+ """
2
+ Copyright (c) Meta, Inc. and its affiliates.
3
+
4
+ This source code is licensed under the MIT license found in the
5
+ LICENSE file in the root directory of this source tree.
6
+
7
+ # Copyright (c) Meta, Inc. and its affiliates.
8
+ # Borrowed from https://github.com/facebookresearch/pythia/blob/master/pythia/common/registry.py.
9
+
10
+ Registry is central source of truth. Inspired from Redux's concept of
11
+ global store, Registry maintains mappings of various information to unique
12
+ keys. Special functions in registry can be used as decorators to register
13
+ different kind of classes.
14
+
15
+ Import the global registry object using
16
+
17
+ ``from fairchem.core.common.registry import registry``
18
+
19
+ Various decorators for registry different kind of classes with unique keys
20
+
21
+ - Register a model: ``@registry.register_model``
22
+ """
23
+
24
+ from __future__ import annotations
25
+
26
+ # import importlib
27
+ from typing import Any, Callable, ClassVar, TypeVar, Union
28
+
29
+ R = TypeVar("R")
30
+ NestedDict = dict[str, Union[str, Callable[..., Any], "NestedDict"]]
31
+
32
+ class Registry:
33
+ r"""Class for registry object which acts as central source of truth."""
34
+
35
+ mapping: ClassVar[NestedDict] = {
36
+ # Mappings to respective classes.
37
+ "task_name_mapping": {},
38
+ "dataset_name_mapping": {},
39
+ "model_name_mapping": {},
40
+ "logger_name_mapping": {},
41
+ "trainer_name_mapping": {},
42
+ "state": {},
43
+ }
44
+
45
+ @classmethod
46
+ def register_task(cls, name: str):
47
+ r"""Register a new task to registry with key 'name'
48
+ Args:
49
+ name: Key with which the task will be registered.
50
+ Usage::
51
+ from fairchem.core.common.registry import registry
52
+ from fairchem.core.tasks import BaseTask
53
+ @registry.register_task("train")
54
+ class TrainTask(BaseTask):
55
+ ...
56
+ """
57
+
58
+ def wrap(func: Callable[..., R]) -> Callable[..., R]:
59
+ cls.mapping["task_name_mapping"][name] = func
60
+ return func
61
+
62
+ return wrap
63
+
64
+ @classmethod
65
+ def register_dataset(cls, name: str):
66
+ r"""Register a dataset to registry with key 'name'
67
+
68
+ Args:
69
+ name: Key with which the dataset will be registered.
70
+
71
+ Usage::
72
+
73
+ from fairchem.core.common.registry import registry
74
+ from fairchem.core.datasets import BaseDataset
75
+
76
+ @registry.register_dataset("qm9")
77
+ class QM9(BaseDataset):
78
+ ...
79
+ """
80
+
81
+ def wrap(func: Callable[..., R]) -> Callable[..., R]:
82
+ cls.mapping["dataset_name_mapping"][name] = func
83
+ return func
84
+
85
+ return wrap
86
+
87
+ @classmethod
88
+ def register_model(cls, name: str):
89
+ r"""Register a model to registry with key 'name'
90
+
91
+ Args:
92
+ name: Key with which the model will be registered.
93
+
94
+ Usage::
95
+
96
+ from fairchem.core.common.registry import registry
97
+ from fairchem.core.modules.layers import CGCNNConv
98
+
99
+ @registry.register_model("cgcnn")
100
+ class CGCNN():
101
+ ...
102
+ """
103
+
104
+ def wrap(func: Callable[..., R]) -> Callable[..., R]:
105
+ cls.mapping["model_name_mapping"][name] = func
106
+ return func
107
+
108
+ return wrap
109
+
110
+ @classmethod
111
+ def register_logger(cls, name: str):
112
+ r"""Register a logger to registry with key 'name'
113
+
114
+ Args:
115
+ name: Key with which the logger will be registered.
116
+
117
+ Usage::
118
+
119
+ from fairchem.core.common.registry import registry
120
+
121
+ @registry.register_logger("wandb")
122
+ class WandBLogger():
123
+ ...
124
+ """
125
+
126
+ def wrap(func: Callable[..., R]) -> Callable[..., R]:
127
+ from fairchem.core.common.logger import Logger
128
+
129
+ assert issubclass(func, Logger), "All loggers must inherit Logger class"
130
+ cls.mapping["logger_name_mapping"][name] = func
131
+ return func
132
+
133
+ return wrap
134
+
135
+ @classmethod
136
+ def register_trainer(cls, name: str):
137
+ r"""Register a trainer to registry with key 'name'
138
+
139
+ Args:
140
+ name: Key with which the trainer will be registered.
141
+
142
+ Usage::
143
+
144
+ from fairchem.core.common.registry import registry
145
+
146
+ @registry.register_trainer("active_discovery")
147
+ class ActiveDiscoveryTrainer():
148
+ ...
149
+ """
150
+
151
+ def wrap(func: Callable[..., R]) -> Callable[..., R]:
152
+ cls.mapping["trainer_name_mapping"][name] = func
153
+ return func
154
+
155
+ return wrap
156
+
157
+ @classmethod
158
+ def register(cls, name: str, obj) -> None:
159
+ r"""Register an item to registry with key 'name'
160
+
161
+ Args:
162
+ name: Key with which the item will be registered.
163
+
164
+ Usage::
165
+
166
+ from fairchem.core.common.registry import registry
167
+
168
+ registry.register("config", {})
169
+ """
170
+ path = name.split(".")
171
+ current = cls.mapping["state"]
172
+
173
+ for part in path[:-1]:
174
+ if part not in current:
175
+ current[part] = {}
176
+ current = current[part]
177
+
178
+ current[path[-1]] = obj
179
+
180
+ @classmethod
181
+ def __import_error(cls, name: str, mapping_name: str) -> RuntimeError:
182
+ kind = mapping_name[: -len("_name_mapping")]
183
+ mapping = cls.mapping.get(mapping_name, {})
184
+ existing_keys: list[str] = list(mapping.keys())
185
+
186
+ if len(existing_keys) == 0:
187
+ raise RuntimeError(
188
+ f"Registry for {mapping_name} is empty. You may have forgot to load a module."
189
+ )
190
+
191
+ existing_cls_path = (
192
+ mapping.get(existing_keys[-1], None) if existing_keys else None
193
+ )
194
+ if existing_cls_path is not None:
195
+ existing_cls_path = (
196
+ f"{existing_cls_path.__module__}.{existing_cls_path.__qualname__}"
197
+ )
198
+ else:
199
+ existing_cls_path = "fairchem.core.trainers.ForcesTrainer"
200
+
201
+ existing_keys = [f"'{name}'" for name in existing_keys]
202
+ existing_keys = ", ".join(existing_keys[:-1]) + " or " + existing_keys[-1]
203
+ existing_keys_str = f" (one of {existing_keys})" if existing_keys else ""
204
+ return RuntimeError(
205
+ f"Failed to find the {kind} '{name}'. "
206
+ f"You may either use a {kind} from the registry{existing_keys_str} "
207
+ f"or provide the full import path to the {kind} (e.g., '{existing_cls_path}')."
208
+ )
209
+
210
+ @classmethod
211
+ def get_class(cls, name: str, mapping_name: str):
212
+ existing_mapping = cls.mapping[mapping_name].get(name, None)
213
+ if existing_mapping is not None:
214
+ return existing_mapping
215
+
216
+ # mapping be class path of type `{module_name}.{class_name}` (e.g., `fairchem.core.trainers.ForcesTrainer`)
217
+ if name.count(".") < 1:
218
+ raise cls.__import_error(name, mapping_name)
219
+
220
+ try:
221
+ return None
222
+ except RuntimeError as e:
223
+ raise cls.__import_error(name, mapping_name) from e
224
+
225
+ @classmethod
226
+ def get_task_class(cls, name: str):
227
+ return cls.get_class(name, "task_name_mapping")
228
+
229
+ @classmethod
230
+ def get_dataset_class(cls, name: str):
231
+ return cls.get_class(name, "dataset_name_mapping")
232
+
233
+ @classmethod
234
+ def get_model_class(cls, name: str):
235
+ return cls.get_class(name, "model_name_mapping")
236
+
237
+ @classmethod
238
+ def get_logger_class(cls, name: str):
239
+ return cls.get_class(name, "logger_name_mapping")
240
+
241
+ @classmethod
242
+ def get_trainer_class(cls, name: str):
243
+ return cls.get_class(name, "trainer_name_mapping")
244
+
245
+ @classmethod
246
+ def get(cls, name: str, default=None, no_warning: bool = False):
247
+ r"""Get an item from registry with key 'name'
248
+
249
+ Args:
250
+ name (string): Key whose value needs to be retrieved.
251
+ default: If passed and key is not in registry, default value will
252
+ be returned with a warning. Default: None
253
+ no_warning (bool): If passed as True, warning when key doesn't exist
254
+ will not be generated. Useful for cgcnn's
255
+ internal operations. Default: False
256
+ Usage::
257
+
258
+ from fairchem.core.common.registry import registry
259
+
260
+ config = registry.get("config")
261
+ """
262
+ original_name = name
263
+ split_name = name.split(".")
264
+ value = cls.mapping["state"]
265
+ for subname in split_name:
266
+ value = value.get(subname, default)
267
+ if value is default:
268
+ break
269
+
270
+ if (
271
+ "writer" in cls.mapping["state"]
272
+ and value == default
273
+ and no_warning is False
274
+ ):
275
+ cls.mapping["state"]["writer"].write(
276
+ f"Key {original_name} is not present in registry, returning default value "
277
+ f"of {default}"
278
+ )
279
+ return value
280
+
281
+ @classmethod
282
+ def unregister(cls, name: str):
283
+ r"""Remove an item from registry with key 'name'
284
+
285
+ Args:
286
+ name: Key which needs to be removed.
287
+ Usage::
288
+
289
+ from fairchem.core.common.registry import registry
290
+
291
+ config = registry.unregister("config")
292
+ """
293
+ return cls.mapping["state"].pop(name, None)
294
+
295
+
296
+ registry = Registry()
@@ -0,0 +1,19 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TypeVar
4
+
5
+ _T = TypeVar("_T")
6
+
7
+
8
+ def assert_is_instance(obj: object, cls: type[_T]) -> _T:
9
+ if obj and not isinstance(obj, cls):
10
+ raise TypeError(f"obj is not an instance of cls: obj={obj}, cls={cls}")
11
+ return obj
12
+
13
+
14
+ def none_throws(x: _T | None, msg: str | None = None) -> _T:
15
+ if x is None:
16
+ if msg:
17
+ raise ValueError(msg)
18
+ raise ValueError("x cannot be None")
19
+ return x