pwtools.crys.align_cart

pwtools.crys.align_cart(obj, x=None, y=None, vecs=None, indices=None, cart=None, eps=1e-05)[source]

Align obj w.r.t. a new cartesian coord sys defined by x,y and z=cross(x,y).

The new coord sys can be defined either by x + y or vecs or indices or cart. Vectors need not be normalized.

Parameters:
  • obj (Structure or Trajectory)

  • x ((3,)) – The two vectors spanning the x-y plane.

  • y ((3,)) – The two vectors spanning the x-y plane.

  • vecs ((3,3)) – Array with 3 vectors as rows [v0, v1, v2] and x = v1 - v0, y = v2 - v0

  • indices (sequence (4,) or (3,)) –

    Indices of atoms in obj with positions v0,v1,v2. Length 4 for obj=Trajectory: indices=[time_step, idx0, idx1, idx2] and length 3 for obj=Structure: [idx0, idx1, idx2] with

    v0 = obj.coords[time_step, idx0, ...] (Trajectory)
    v1 = obj.coords[time_step, idx1, ...]
    v2 = obj.coords[time_step, idx2, ...]

    or

    v0 = obj.coords[idx0, ...] (Structure)
    v1 = obj.coords[idx1, ...]
    v2 = obj.coords[idx2, ...]

  • cart ((3,3)) – new cartesian coord sys [x,y,z], matrix must be orthogonal

  • eps (float) – Threshold for orthogonality check. Use eps <= 0 to disable the check.

Returns:

out

Return type:

Structure or Trajectory

Notes

In case of a Trajectory, the same rotation is applied to all structs, so the relative orientation within the Trajectory is not changed. That is OK if each struct shall be rotated in the same way. If however each struct has a different orientation, then you need to loop over the Trajectory like:

>>> from pwtools.crys import align_cart, concatenate
>>> trnew = concatenate([align_cart(st, cart=...) for st in tr])