This function measures the residence time of all residues within the cutoff distance from
        the ligand.
        Takes:
            * cutoff * - cutoff distance in angstroms
        Output:
            * self.residue_counts * - dictionary of all residues that have made contact with the
            ligand (i.e. have been within the cutoff distance) and the number of frames of the
            contact

def measure_residence_time(self, cutoff = 3.5):
        """
        This function measures the residence time of all residues within the cutoff distance from
        the ligand.
        Takes:
            * cutoff * - cutoff distance in angstroms
        Output:
            * self.residue_counts * - dictionary of all residues that have made contact with the
            ligand (i.e. have been within the cutoff distance) and the number of frames of the
            contact
        """
        i=0
        data = namedtuple("contacts","frame time ligandatomname ligandatomindex cutoff proteinatomname proteinatomindex resname resid segid")
        for traj in self.trajectory:
            start = timer()
            prog = ProgressBar("Residence_time")
            self.topology_data.load_trajectory(traj)
            selection_of_protein_and_ligand = self.topology_data.universe.select_atoms('protein and not name H* or (segid '+str(self.topology_data.universe.ligand.segids[0])+' and resid '+str(self.topology_data.universe.ligand.resids[0])+')')
            self.contacts_per_timeframe[i]={}
            start1 = timer()
            for frame in self.topology_data.universe.trajectory[self.start_frame_num[i]:self.end_frame_num[i]:self.skip[i]]:
                selection = selection_of_protein_and_ligand.select_atoms("protein and around 3.5 (segid "+str(self.topology_data.universe.ligand.segids[0])+' and resid '+str(self.topology_data.universe.ligand.resids[0])+")")
                residue_list = [(atom.resname, str(atom.resid), atom.segid) for atom in selection.atoms]
                self.contacts_per_timeframe[i][frame.time] = set(residue_list)

                #selection by residues - they can be accessed later to make sure on which chain they are
                #also counter treats each residue as single object - i.e. no problems with multiple chains where
                #there are several residues with the same resid and resname - they will be treated seperately
                prog.update(frame.frame,self.topology_data.universe.trajectory.n_frames)
            # How many frames each individual simulation has? The simulations can be of differing length
            prog.finish(self.topology_data.universe.trajectory.n_frames)
            self.residue_counts[i]=Counter([item for sublist in self.contacts_per_timeframe[i].values() for item in sublist])
            #self.residue_contacts[i] = self.make_table()
            end = timer()

            sys.stdout.write("Residence time: "+ str(end-start))
            #Assert whether there is anything to plot for this simulation
            assert len(self.residue_counts[i])!=0, "Nothing to draw for this ligand (residue number: "+ self.topology_data.universe.ligand.resids[0] +" on the chain "+ self.topology_data.universe.ligand.segids[0] +") - check the position of your ligand within the trajectory."
            i+=1