Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1import numpy as np 

2 

3from ase.optimize.optimize import Optimizer 

4 

5 

6class MDMin(Optimizer): 

7 # default parameters 

8 defaults = {**Optimizer.defaults, 'dt': 0.2} 

9 

10 def __init__(self, atoms, restart=None, logfile='-', trajectory=None, 

11 dt=None, master=None): 

12 """Parameters: 

13 

14 atoms: Atoms object 

15 The Atoms object to relax. 

16 

17 restart: string 

18 Pickle file used to store hessian matrix. If set, file with 

19 such a name will be searched and hessian matrix stored will 

20 be used, if the file exists. 

21 

22 trajectory: string 

23 Pickle file used to store trajectory of atomic movement. 

24 

25 logfile: string 

26 Text file used to write summary information. 

27 

28 master: boolean 

29 Defaults to None, which causes only rank 0 to save files. If 

30 set to true, this rank will save files. 

31 """ 

32 Optimizer.__init__(self, atoms, restart, logfile, trajectory, master) 

33 

34 if dt is None: 

35 self.dt = self.defaults['dt'] 

36 else: 

37 self.dt = dt 

38 

39 def initialize(self): 

40 self.v = None 

41 

42 def read(self): 

43 self.v, self.dt = self.load() 

44 

45 def step(self, f=None): 

46 atoms = self.atoms 

47 

48 if f is None: 

49 f = atoms.get_forces() 

50 

51 if self.v is None: 

52 self.v = np.zeros((len(atoms), 3)) 

53 else: 

54 self.v += 0.5 * self.dt * f 

55 # Correct velocities: 

56 vf = np.vdot(self.v, f) 

57 if vf < 0.0: 

58 self.v[:] = 0.0 

59 else: 

60 self.v[:] = f * vf / np.vdot(f, f) 

61 

62 self.v += 0.5 * self.dt * f 

63 r = atoms.get_positions() 

64 atoms.set_positions(r + self.dt * self.v) 

65 self.dump((self.v, self.dt))