-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathase_calc.py
57 lines (43 loc) · 1.48 KB
/
ase_calc.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
from typing import Tuple, List
from ase import Atoms
from ase.optimize import LBFGS
from ase.constraints import FixAtoms
def ase_initialize(model_path: str, device: str) -> None:
"""
Assign the ase calculator to the global calculator variable.
"""
global calculator
from sevenn.sevennet_calculator import SevenNetCalculator
if device is None:
calculator = SevenNetCalculator(model_path)
else:
calculator = SevenNetCalculator(model_path, device=device)
def oneshot(
atomic_numbers: List[int], positions: List[List[float]], cell: List[List[float]]
) -> Tuple[float, List[List[float]]]:
global calculator
atoms = Atoms(
numbers=atomic_numbers, positions=positions, cell=cell, pbc=[True] * 3
)
atoms.calc = calculator
energy = atoms.get_potential_energy(force_consistent=True)
forces = atoms.get_forces().tolist()
return energy, forces
def atom_relax(
atomic_numbers: List[int],
positions: List[List[float]],
cell: List[List[float]],
fix: List[bool],
ftol: float,
) -> Tuple[float, List[List[float]]]:
global calculator
atoms = Atoms(
numbers=atomic_numbers, positions=positions, cell=cell, pbc=[True] * 3
)
atoms.constraints = FixAtoms(mask=fix)
atoms.calc = calculator
opt = LBFGS(atoms, logfile=None)
opt.run(fmax=ftol, steps=10000)
energy = atoms.get_potential_energy(force_consistent=True)
pos = atoms.get_positions().tolist()
return energy, pos