Insert dummy atom into the already built cartesian of exception

def _insert_dummy_cart(self, exception, last_valid_cartesian=None):
        """Insert dummy atom into the already built cartesian of exception
        """
        def get_normal_vec(cartesian, reference_labels):
            b_pos, a_pos, d_pos = cartesian._get_positions(reference_labels)
            BA = a_pos - b_pos
            AD = d_pos - a_pos
            N1 = np.cross(BA, AD)
            n1 = N1 / np.linalg.norm(N1)
            return n1

        def insert_dummy(cartesian, reference_labels, n1):
            cartesian = cartesian.copy()
            b_pos, a_pos, d_pos = cartesian._get_positions(reference_labels)
            BA = a_pos - b_pos
            N2 = np.cross(n1, BA)
            n2 = N2 / np.linalg.norm(N2)
            i_dummy = max(self.index) + 1
            cartesian.loc[i_dummy, 'atom'] = 'X'
            cartesian.loc[i_dummy, ['x', 'y', 'z']] = a_pos + n2
            return cartesian, i_dummy

        if last_valid_cartesian is None:
            last_valid_cartesian = self._metadata['last_valid_cartesian']
        ref_labels = self.loc[exception.index, ['b', 'a', 'd']]
        n1 = get_normal_vec(last_valid_cartesian, ref_labels)
        return insert_dummy(exception.already_built_cartesian, ref_labels, n1)