-
Notifications
You must be signed in to change notification settings - Fork 62
/
settings.py
97 lines (79 loc) · 3.11 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
"""
This file defines any arbitrary global variables used in Materials Project
database building and in the website code, to ensure consistency between
different modules and packages.
"""
import importlib
import json
from typing import Dict, List, Optional
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"))
class EmmetSettings(BaseSettings):
"""
Settings for the emmet- packages
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_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",
)
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