Attachment 'filter.py'
Download 1 """Using filters, trajectories and python dynamics
2 """
3
4 from Dacapo import Dacapo
5 from ASE import Atom, ListOfAtoms
6 from ASE.Filters.Subset import Subset
7 from ASE.Dynamics.ConjugateGradient import ConjugateGradient
8 from ASE.Dynamics.MDMin import MDMin
9 from ASE.Dynamics.LineMinimizers.LM1 import LM1
10 from ASE.Trajectories import NetCDFTrajectory
11 import os
12
13 os.system('rm -f CO_in_a_box.nc CO_in_a_box.txt dynamics.nc dynamics.txt')
14
15 atoms = ListOfAtoms([Atom('C', (2, 2, 2),tag=1),
16 Atom('O', (3.1, 2, 2))],
17 cell=(4, 3.5, 3.5), periodic=1)
18
19 calc = Dacapo(planewavecutoff=300, # in eV
20 nbands=6, # 1 extra empty bands
21 out='CO_in_a_box.nc',txtout='CO_in_a_box.txt')
22
23 atoms.SetCalculator(calc)
24
25 energy = atoms.GetPotentialEnergy()
26 forces = atoms.GetCartesianForces()
27
28 print 'Initial energy:',energy
29 print 'Initial abs force:',max(max(forces))
30
31 calc.SetNetCDFFile('dynamics.nc')
32 calc.SetTxtFile('dynamics.txt')
33
34 # for efficiency keep dacapo running between steps
35 calc.StayAliveOn()
36
37 # Setup the filter constraining the fixed atoms
38 subset = Subset(atoms, mask=[atom.GetTag() != 1 for atom in atoms])
39
40 # Setup the minimizer
41 # use MDMin and not ConjugateGradient because of a
42 # problem combining StayAliveOn and this minimizer,
43 # dyn = ConjugateGradient(subset, fmax=0.05,lineMin=LM1(0.05))
44 # dyn.SetVerbosity(1)
45 dyn = MDMin(subset, fmax=0.2,dt=0.08)
46
47
48 # Create a trajectory for the minimization path
49 path = NetCDFTrajectory('CO-trajectory.nc', atoms)
50 # Put the initial state in the trajectory:
51 path.Update()
52
53 # attach the trajectory to the dynamics
54 dyn.Attach(path)
55
56 # Find the ground state
57 dyn.Converge()
58
59 energy = atoms.GetPotentialEnergy()
60 forces = atoms.GetCartesianForces()
61 print 'Final energy:', energy
62 print 'Final abs forces:',max(max(forces))
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.