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 

3 

4class FixRotation: 

5 """Remove rotation from an atoms object. 

6  

7 This class is intended as an observer on an atoms class during 

8 a molecular dynamics simulation. When it is called, it removes 

9 any rotation around the center of mass. 

10  

11 It assumes that the system is a (nano)particle with free boundary 

12 conditions. 

13  

14 Bugs: 

15 Should check that the boundary conditions make sense. 

16 """ 

17 def __init__(self, atoms): 

18 self.atoms = atoms 

19 

20 def __call__(self): 

21 atoms = self.atoms 

22 

23 r = atoms.get_positions() - atoms.get_center_of_mass() 

24 v = atoms.get_velocities() 

25 p = atoms.get_momenta() 

26 m = atoms.get_masses() 

27 

28 x = r[:, 0] 

29 y = r[:, 1] 

30 z = r[:, 2] 

31 

32 I11 = np.sum(m * (y**2 + z**2)) 

33 I22 = np.sum(m * (x**2 + z**2)) 

34 I33 = np.sum(m * (x**2 + y**2)) 

35 I12 = np.sum(-m * x * y) 

36 I13 = np.sum(-m * x * z) 

37 I23 = np.sum(-m * y * z) 

38 

39 I = np.array([[I11, I12, I13], 

40 [I12, I22, I23], 

41 [I13, I23, I33]]) 

42 

43 w = np.dot(np.linalg.inv(I), np.sum(np.cross(r, p), axis=0)) 

44 

45 self.atoms.set_velocities(v - np.cross(w, r))