-
Notifications
You must be signed in to change notification settings - Fork 12
/
ex05_rattle_atoms.py
66 lines (55 loc) · 1.86 KB
/
ex05_rattle_atoms.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
"""Check how vasp interactive can be applied to a list of randomly rattled atoms
Even if the positions for new atoms are totally random, VaspInteractive still
overperforms classic Vasp calculator, due to internal caching of wavefunction.
"""
import numpy as np
import os
import tempfile
import random
from time import time
from ase.build import molecule
from ase.optimize import BFGS
from vasp_interactive import VaspInteractive
from ase.calculators.vasp import Vasp
# Methane and ethylene molecules
_m = molecule("C2H2", vacuum=5, pbc=True)
mol_seq = []
for i in range(6):
# Rattle the molecule and insert into the sequence
_mm = _m.copy()
_mm.rattle(stdev=0.1, seed=random.randint(1, 1000))
mol_seq.append(_mm)
def seq_run(calc):
"""Run with calculator on current sequence"""
for i, atoms in enumerate(mol_seq):
atoms.calc = calc
e = atoms.get_potential_energy()
iters = calc.read_number_of_iterations()
print(f"{i}\t{e:.4f}\t{iters}")
return
def run_vasp_classic():
"""Run with classic Vasp calculator"""
print("*" * 40)
print("Running classic VASP calculator on molecule sequence")
print("*" * 40)
with tempfile.TemporaryDirectory() as tmpdir:
calc = Vasp(istart=0, xc="pbe", directory=tmpdir)
t_ = time()
seq_run(calc)
print(f"Wall time: {time() - t_:.2f} s")
return
def run_vasp_interactive():
"""Run with classic Vasp calculator"""
print("*" * 40)
print("Running interactive VASP calculator on molecule sequence")
print("*" * 40)
with tempfile.TemporaryDirectory() as tmpdir:
calc = VaspInteractive(istart=0, xc="pbe", directory=tmpdir)
t_ = time()
with calc:
seq_run(calc)
print(f"Wall time: {time() - t_:.2f} s")
return
if __name__ == "__main__":
run_vasp_classic()
run_vasp_interactive()