#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division,
                        print_function, unicode_literals)

__author__ = "Yuji Ikeda"

import numpy as np


class VectorsAdjuster(object):
    def __init__(self, scaled_positions):
        self.set_scaled_positions(scaled_positions)

    def set_scaled_positions(self, scaled_positions):
        """

        Args:
            scaled_positions:
                Scaled positions for the (disordered) cell.
        """
        self._scaled_positions = scaled_positions

    def set_q(self, q):
        """

        Args:
            q: Reciprocal space point in fractional coordinates for SC.
        """
        self._q = q

    def recover_Bloch(self, vecs):
        """Recorver the properties of Bloch's waves.

        Args:
            vecs: Vectors to be recovered.

        Returns:
            recovered_vecs: Vectors having the properties of Bloch's waves.
        """
        recovered_vecs = np.zeros_like(vecs) * np.nan
        for i, vec in enumerate(vecs):
            iatom = i // 3
            p = self._scaled_positions[iatom]
            phase = np.exp(2.0j * np.pi * np.dot(p, self._q))
            recovered_vecs[i] = vec * phase
        return recovered_vecs

    def remove_phase_factors(self, vectors, kpoint):
        """
        Remove phase factors from given vectors.

        Parameters
        ----------
        vectors : array
            Vectors whose phase factors are removed.
        kpiont :
            Reciprocal space point in fractional coordinates for SC.
        """
        phases = np.exp(-2.0j * np.pi * np.dot(self._scaled_positions, kpoint))
        phases = np.repeat(phases, 3)
        modified_vectors = phases[:, None] * vectors
        return modified_vectors

@@ -1791,16 +1791,804 @@
 odified_vectors%0A
+%0A    def reduce_vectors_to_primitive(self, vectors, primitive):%0A        %22%22%22%0A        Reduce size of vectors to primitive.%0A%0A        Parameters%0A        ----------%0A        vectors : array%0A            Vectors which will be reduced.%0A            Phase factors must be removed in advance.%0A        primitive : Phonopy Primitive object.%0A%0A        Returns%0A        -------%0A        reduced_vectors : array%0A            Reduced vectors.%0A        %22%22%22%0A        ndim = 3%0A        p2s_map = primitive.get_primitive_to_supercell_map()%0A        print(p2s_map)%0A        num_atoms = vectors.shape%5B0%5D // ndim%0A        tmp = vectors.reshape(ndim, num_atoms, -1)%0A        tmp = tmp%5B:, p2s_map, :%5D%0A        reduced_vectors = tmp.reshape(ndim * len(p2s_map), -1)%0A        print(reduced_vectors)%0A        return reduced_vectors%0A

Add function to reduce vectors