x = linspace(-4, 4, 4000)
positions = linspace(-0.5, 2.5, 61)

quads1 = []
quads2 = []
quads12 = []

for index, pos in enumerate(positions):
    print(pos)
    # Moving Gaussian
    WP2.set_parameters((1.0j, 1.0, 0.0, 0.0, pos))

    # Transform the nodes
    nodes1 = squeeze(HQ1.transform_nodes(WP1.get_parameters(), WP1.eps))
    nodes2 = squeeze(HQ2.transform_nodes(WP2.get_parameters(), WP2.eps))
    nodes12 = squeeze(IHQ.transform_nodes(Pibra, WP2.get_parameters(), WP1.eps))

    # Compute inner products
    Q1 = IHQ.quadrature(WP1, WP1, summed=True)
    Q2 = IHQ.quadrature(WP2, WP2, summed=True)
    Q12 = IHQ.quadrature(WP1, WP2, summed=True)

    quads1.append(Q1)
    quads2.append(Q2)
    quads12.append(Q12)

    # Evaluate the packets
    y = WP1.evaluate_at(x, prefactor=True, component=0)
    z = WP2.evaluate_at(x, prefactor=True, component=0)

    figure()
    def spawn_basis_projection(self, mother, child, component, order=None):
        """Update the superposition coefficients of mother and
        spawned wavepacket. We do a full basis projection to the
        basis of the spawned wavepacket here.
        """
        c_old = mother.get_coefficients(component=component)

        # Mother packet
        c_new_m = np.zeros(c_old.shape, dtype=np.complexfloating)

        # Spawned packet
        c_new_s = np.zeros((child.get_basis_size(component=component),1), dtype=np.complexfloating)

        # The quadrature
        quadrature = InhomogeneousQuadrature()

        # Quadrature rule. Assure the "right" quadrature is choosen if
        # mother and child have different basis sizes
        if mother.get_basis_size(component=component) > child.get_basis_size(component=component):
            quadrature.set_qr( mother.get_quadrature().get_qr() )
        else:
            quadrature.set_qr( child.get_quadrature().get_qr() )

        # The quadrature nodes and weights
        q0, QS = quadrature.mix_parameters(mother.get_parameters(), child.get_parameters())
        nodes = quadrature.transform_nodes(mother.get_parameters(), child.get_parameters(), mother.eps)
        weights = quadrature.get_qr().get_weights()

        # Basis sets for both packets
        basis_m = mother.evaluate_basis_at(nodes, prefactor=True)
        basis_s = child.evaluate_basis_at(nodes, prefactor=True)

        max_order = min(child.get_basis_size(component=component), self.max_order)

        # Project to the basis of the spawned wavepacket
        # Original, inefficient code for projection
        # R = QR.get_order()
        # for i in xrange(max_order):
        #     # Loop over all quadrature points
        #     tmp = 0.0j
        #     for r in xrange(R):
        #         tmp += np.conj(np.dot( c_old[:,0], basis_m[:,r] )) * basis_s[i,r] * weights[0,r]
        #     c_new_s[i,0] = self.eps * QS * tmp

        # Optimised and vectorised code (in ugly formatting)
        c_new_s[:max_order,:] = self.eps * QS * (
            np.reshape(
                np.sum(
                    np.transpose(
                        np.reshape(
                            np.conj(
                                np.sum(c_old[:,:] * basis_m[:,:],axis=0)
                            ) ,(-1,1)
                        )
                    ) * (basis_s[:max_order,:] * weights[:,:]), axis=1
                ) ,(-1,1)
            ))

        # Reassign the new coefficients
        mother.set_coefficients(c_new_m, component=component)
        child.set_coefficients(c_new_s, component=component)

        return (mother, child)