-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathprepare_inputs.py
More file actions
executable file
·68 lines (52 loc) · 1.73 KB
/
prepare_inputs.py
File metadata and controls
executable file
·68 lines (52 loc) · 1.73 KB
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
#!/usr/bin/env python3
import argparse
from pathlib import Path
import torch
from pyscf import dft, gto
from pyscf.dft import gen_grid
from skala.functional.traditional import LDA
from skala.pyscf.features import generate_features
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument(
"--output-dir",
default=".",
type=Path,
help="Output directory for generated feature files.",
)
parser.add_argument(
"--basis",
default="def2-qzvp",
type=str,
help="Basis set.",
)
args = parser.parse_args()
args.output_dir.mkdir(parents=True, exist_ok=True)
molecule = gto.M(
atom="H 0 0 0; H 0 0 1",
basis=args.basis,
verbose=0,
)
# Create a set of meta-GGA features for this molecule.
dm = get_density_matrix(molecule)
grid = gen_grid.Grids(molecule)
grid.level = 3
grid.build()
features = generate_features(molecule, dm, grid)
# Add a feature called `coarse_0_atomic_coords` containing the atomic coordinates.
features["coarse_0_atomic_coords"] = torch.from_numpy(molecule.atom_coords())
# Save all features as individual .pt files.
for key, value in features.items():
torch.save(value, str(args.output_dir / f"{key}.pt"))
print(f"Saved features to {args.output_dir}")
lda_exc = LDA().get_exc(features)
print(f"For reference, LDAx Exc = {lda_exc.item()}")
def get_density_matrix(mol: gto.Mole) -> torch.Tensor:
"""Computes an example density matrix for a given molecule using PySCF."""
ks = dft.RKS(mol, xc="b3lyp5")
ks = ks.density_fit()
ks.kernel()
dm = torch.from_numpy(ks.make_rdm1())
return dm
if __name__ == "__main__":
main()