-
Notifications
You must be signed in to change notification settings - Fork 62
/
settings.py
129 lines (104 loc) · 4.03 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
"""
Settings for defaults in the core definitions of Materials Project Documents
"""
import importlib
import json
from typing import Dict, List, Optional, Type, TypeVar, Union
import requests
from pydantic import BaseSettings, Field, root_validator, validator
from pydantic.types import Path, PyObject
DEFAULT_CONFIG_FILE_PATH = str(Path.home().joinpath(".emmet.json"))
S = TypeVar("S", bound="EmmetSettings")
class EmmetSettings(BaseSettings):
"""
Settings for the emmet- packages
Non-core packages should subclass this to get settings specific to their needs
The default way to modify these is to modify ~/.emmet.json or set the environment variable
EMMET_CONFIG_FILE to point to the json with emmet settings
"""
config_file: str = Field(
DEFAULT_CONFIG_FILE_PATH, description="File to load alternative defaults from"
)
LTOL: float = Field(
0.2, description="Fractional length tolerance for structure matching"
)
STOL: float = Field(
0.3,
description="Site tolerance for structure matching. Defined as the fraction of the"
" average free length per atom = ( V / Nsites ) ** (1/3)",
)
SYMPREC: float = Field(
0.1, description="Symmetry precision for spglib symmetry finding"
)
ANGLE_TOL: float = Field(
5, description="Angle tolerance for structure matching in degrees."
)
MAX_PIEZO_MILLER: int = Field(
10,
description="Maximum miller allowed for computing strain direction for maximal piezo response",
)
VASP_QUALITY_SCORES: Dict[str, int] = Field(
{"SCAN": 3, "GGA+U": 2, "GGA": 1},
description="Dictionary Mapping VASP calculation run types to rung level for VASP materials builders",
)
VASP_KPTS_TOLERANCE: float = Field(
0.9,
description="Relative tolerance for kpt density to still be a valid task document",
)
VASP_KSPACING_TOLERANCE: float = Field(
0.05,
description="Relative tolerance for kspacing to still be a valid task document",
)
VASP_DEFAULT_INPUT_SETS: Dict[str, PyObject] = Field(
{
"GGA Structure Optimization": "pymatgen.io.vasp.sets.MPRelaxSet",
"GGA+U Structure Optimization": "pymatgen.io.vasp.sets.MPRelaxSet",
},
description="Default input sets for task validation",
)
VASP_CHECKED_LDAU_FIELDS: List[str] = Field(
["LDAUU", "LDAUJ", "LDAUL"], description="LDAU fields to validate for tasks"
)
VASP_MAX_SCF_GRADIENT: float = Field(
100,
description="Maximum upward gradient in the last SCF for any VASP calculation",
)
VASP_DEPRECATED_TAGS: List[str] = Field(
[], description="List of tags to manually deprecate in task validation"
)
class Config:
env_prefix = "emmet_"
extra = "ignore"
@root_validator(pre=True)
def load_default_settings(cls, values):
"""
Loads settings from a root file if available and uses that as defaults in
place of built in defaults
"""
config_file_path: str = values.get("config_file", DEFAULT_CONFIG_FILE_PATH)
new_values = {}
if config_file_path.startswith("http"):
new_values = requests.get(config_file_path).json()
elif Path(config_file_path).exists():
with open(config_file_path) as f:
new_values = json.load(f)
new_values.update(values)
return new_values
@classmethod
def autoload(cls: Type[S], settings: Union[None, dict, S]) -> S:
if settings is None:
return cls()
elif isinstance(settings, dict):
return cls(**settings)
return settings
def as_dict(self):
"""
HotPatch to enable serializing EmmetSettings via Monty
"""
return self.dict(exclude_unset=True, exclude_defaults=True)
@classmethod
def from_dict(cls: Type[S], settings: Dict) -> S:
"""
HotPatch to enable serializing EmmetSettings via Monty
"""
return cls(**settings)