pwtools.crys.angles

pwtools.crys.angles(struct, pbc=False, mask_val=999.0, deg=True)[source]

Wrapper for _flib.angles(), which accepts a Structure. Calculate all angles between atom triples in struct.

Parameters:
  • struct (Structure instance)

  • pbc (bool, optional) – Apply PBC wrapping to distances (minimum image distances)

  • mask_val (float) – Fill value for anglesijk[ii,jj,kk] where ii==jj or ii==kk or jj==kk, i.e. no angle defined. Can be used to create bool mask arrays in numpy. Should be outside of [-1,1] (deg=False) or [0,180] (deg=True).

  • deg (bool) – Return angles in degree (True) or cosine values (False).

Returns:

anglesijk – All angles. See also mask_val.

Return type:

3d array (natoms,natoms,natoms)

Examples

>>> natoms = struct.natoms
>>> mask_val = 999
>>> anglesijk = crys.angles(struct, mask_val=mask_val)
>>> # angleidx holds all ii,jj,kk triples which we would get from:
>>> angleidx = []
... for ii in range(natoms):
...     for jj in range(natoms):
...         for kk in range(natoms):
...             if (ii != jj) and (ii != kk) and (jj != kk):
...                 angleidx.append([ii,jj,kk])
>>> # which is the same as
>>> angleidx2 = [x for x in itertools.permutations(range(natoms),3)]
>>> # or
>>> angleidx3 = np.array(zip(*(anglesijk != mask_val).nonzero()))
>>> # the number of valid angles
>>> len(angleidx) == natoms * (natoms - 1) * (natoms - 2)
>>> len(angleidx) == factorial(natoms) / factorial(natoms - 3)
>>> # angles in 1d array for histogram or whatever
>>> angles1d = anglesijk[anglesijk != mask_val]
>>> y,x = np.histogram(angles1d, bins=100)
>>> plot(x[:-1]+0.5*(x[1]-x[0]), y)