File: preconunitcellfilter.py

package info (click to toggle)
python-ase 3.17.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 16,340 kB
  • sloc: python: 117,348; makefile: 91
file content (26 lines) | stat: -rw-r--r-- 853 bytes parent folder | download
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
import numpy as np

from ase.build import bulk
from ase.calculators.lj import LennardJones
from ase.optimize.precon import PreconLBFGS, Exp
from ase.constraints import UnitCellFilter, ExpCellFilter

cu0 = bulk("Cu") * (2, 2, 2)
lj = LennardJones(sigma=cu0.get_distance(0,1))

cu = cu0.copy()
cu.set_cell(1.2*cu.get_cell())
cu.set_calculator(lj)
ucf = UnitCellFilter(cu, constant_volume=True)
opt = PreconLBFGS(ucf, precon=Exp(mu=1.0, mu_c=1.0))
opt.run(fmax=1e-3)
assert abs(np.linalg.det(cu.cell)/np.linalg.det(cu0.cell) - 1.2**3) < 1e-3

# EcpCellFilter allows relaxing to lower tolerance
cu = cu0.copy()
cu.set_cell(1.2*cu.get_cell())
cu.set_calculator(lj)
ecf = ExpCellFilter(cu, constant_volume=True)
opt = PreconLBFGS(ecf, precon=Exp(mu=1.0, mu_c=1.0))
opt.run(fmax=1e-3)
assert abs(np.linalg.det(cu.cell)/np.linalg.det(cu0.cell) - 1.2**3) < 1e-7