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

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

""" 

This module contains various support/utility functions. 

""" 

import numpy as np 

from ase.geometry import find_mic 

 

 

def get_wrapped_displacements(positions, ideal_positions, cell): 

"""Compute the smallest possible displacements from positions and 

ideal_positions given cell. 

 

Notes 

----- 

* uses `find_mic` from ASE 

* assumes `pbc=[True, True, True]`. 

 

Parameters 

---------- 

positions : array 

positions array 

ideal_positions : array 

ideal positions from which displacements are computed 

cell : array 

cell with shape (3,3) 

 

Returns 

------- 

array 

array with wrapped displacements 

""" 

 

displacements = [] 

for pos, ideal_pos in zip(positions, ideal_positions): 

v_ij = np.array([pos - ideal_pos]) 

displacements.append(find_mic(v_ij, cell, pbc=True)[0][0]) 

return np.array(displacements) 

 

 

def prepare_structures(structures, atoms_ideal, calc): 

""" Prepare a set of structures in the format a StructureContainer likes 

them. Changes structures in place """ 

for atoms in structures: 

atoms.set_calculator(calc) 

forces = atoms.get_forces() 

displacements = get_wrapped_displacements( 

atoms.positions, atoms_ideal.positions, atoms_ideal.cell) 

atoms.positions = atoms_ideal.get_positions() 

atoms.new_array('forces', forces) 

atoms.new_array('displacements', displacements)