Main analysis function. Analyses each frame in the trajectory in search for pi-pi interactions between previously defined rings on
        protein residues and ligand molecule.

def find_all_pistacking_pairs(self):
        """Main analysis function. Analyses each frame in the trajectory in search for pi-pi interactions between previously defined rings on
        protein residues and ligand molecule. """
        data = namedtuple("pistacking","frame time proteinring ligandring distance angle offset type resname resid segid")
        i=0
        if self.trajectory==[]:
            self.trajectory = [self.topology_data.universe.filename]
            self.start_frame_num=[None]
            self.end_frame_num = [None]
            self.skip =[None]
        for traj in self.trajectory:
            self.timeseries=[]
            self.timesteps=[frame.time for frame in self.topology_data.universe.trajectory[self.start_frame_num[i]:self.end_frame_num[i]:self.skip[i]]]
            start = timer()
            self.topology_data.load_trajectory(traj)
            for prot_ring in self.protein_rings:
                    for ring in self.ligrings:
                        l = self.get_ligand_ring_selection(ring)
                        p = self.protein_rings[prot_ring]
                        for frame in self.topology_data.universe.trajectory[self.start_frame_num[i]:self.end_frame_num[i]:self.skip[i]]:
                            lig_norm_vec = math.prepare_normal_vectors(l)
                            protein_norm_vec = math.prepare_normal_vectors(p)
                            dist = math.euclidean3d(l.center_of_geometry(),p.center_of_geometry())

                            a = math.vecangle(lig_norm_vec,protein_norm_vec)
                            angle = min(a, 180 - a if not 180 - a < 0 else a)

                            #Measure offset
                            proj1 = math.projection(lig_norm_vec,l.center_of_geometry(),p.center_of_geometry())
                            proj2 = math.projection(protein_norm_vec,p.center_of_geometry(),l.center_of_geometry())
                            offset = min(math.euclidean3d(proj1,l.center_of_geometry()), math.euclidean3d(proj2,p.center_of_geometry()))


                            if dist < self.max_distance:
                                if 0 < angle < self.max_angle_dev and offset < self.max_offset:
                                    contacts = data(frame=frame.frame, time=frame.time, proteinring=tuple([a.id for a in p]), ligandring=tuple([a.id for a in l]), distance=dist, angle=angle, offset=offset,
                                                    type="P",resname=self.protein_rings[prot_ring].residues.resnames[0],
                                                    resid=self.protein_rings[prot_ring].residues.resids[0], segid=self.protein_rings[prot_ring].residues.segids[0])
                                    self.timeseries.append(contacts)
                                if 90 - self.max_angle_dev < angle < 90 + self.max_angle_dev and offset < self.max_offset:
                                    contacts = data(frame=frame.frame, time=frame.time, proteinring=tuple([a.id for a in p]), ligandring=tuple([a.id for a in l]), distance=dist, angle=angle, offset=offset,
                                                    type="T",resname=self.protein_rings[prot_ring].residues.resnames[0],
                                                    resid=self.protein_rings[prot_ring].residues.resids[0], segid=self.protein_rings[prot_ring].residues.segids[0])
                                    self.timeseries.append(contacts)
            self.pistacking[i] = self.make_table()

            self.pistacking_by_time[i] = self.count_by_time()
            self.pistacking_by_type[i] = self.count_by_type()
            self.write_output_files(i)
            i+=1
        end = timer()
        print "Pi-Stacking:"+str(end-start)