Exemple #1
0
class Lintools(object):
    """This class controls the behaviour of all other classes (Data,Plots,Molecule,Figure) 
     of lintools and inherits and transfers them resulting in a final SVG file that contains
     the protein-ligand interactions.

    It also controls the analysis (Residence_time and HBonds classes).

    Takes:
        * topology * - topology file
        * trajectory * - trajectory file(s)
        * mol2_file * - MOL2 file of the ligand
        * ligand * - MDAnalysis atomgroup of ligand that is going to be analysed
        * offset * - residue offset which determines by how many numbers the protein residue numbering
        should be offset (e.g. with offset = 30 the first residue will be changed from 1 to 30, 2 - 31, etc.)
        * cutoff * - cutoff distance in angstroms that defines the native contacts (default - 3.5A)   
        * start_frame * - start frame(s) for trajectory analysis (can be different for each trajectory)
        * end_frame * - end frame(s) for trajectory analysis (can be different for each trajectory)
        * skip * - number of frames to skip (can be different for each trajectory)
        * analysis_cutoff * - a fraction of time a residue has to fullfil the analysis parameters for (default - 0.3)
        * diagram_type * - string of the selected diagram type (e.g. "amino" or "clocks")
        * output_name * - name of the folder with results and the final SVG file

    """
    __version__ = "09.2016"

    def __init__(self, topology, trajectory, mol2_file, ligand, offset, cutoff,
                 start_frame, end_frame, skip, analysis_cutoff, diagram_type,
                 output_name):
        """Defines the input variables."""
        self.topology = os.path.abspath(topology)
        try:
            self.trajectory = []
            for traj in trajectory:
                self.trajectory.append(os.path.abspath(traj))
        except Exception:
            self.trajectory = []
        self.mol2_file = os.path.abspath(mol2_file)
        self.ligand = ligand
        self.offset = offset
        self.cutoff = cutoff
        self.start = [
            None if start_frame == [None] else int(start_frame[i])
            for i in range(len(trajectory))
        ]
        self.end = [
            None if end_frame == [None] else int(end_frame[i])
            for i in range(len(trajectory))
        ]
        self.skip = [
            None if skip == [None] else int(skip[i])
            for i in range(len(trajectory))
        ]
        self.analysis_cutoff = analysis_cutoff
        self.diagram_type = diagram_type
        self.output_name = output_name

    def data_input_and_res_time_analysis(self):
        """
        Loads the data into Data() - renumbers the residues, imports mol2 file in rdkit. 
        If there are trajectories to analyse, the residues that will be plotted are determined 
        from Residence_time() analysis.
        """
        self.topol_data = Data()
        self.topol_data.load_data(self.topology, self.mol2_file, self.ligand,
                                  self.offset)
        if len(self.trajectory) == 0:
            self.topol_data.analyse_topology(self.topology, self.cutoff)
        else:
            self.res_time = Residence_time(self.topol_data, self.trajectory,
                                           self.start, self.end, self.skip,
                                           self.topology, self.mol2_file,
                                           self.ligand, self.offset)
            self.res_time.measure_residence_time(self.cutoff)
            self.res_time.define_residues_for_plotting_traj(
                self.analysis_cutoff)
            self.topol_data.find_the_closest_atoms(self.topology)

    def analysis_of_prot_lig_interactions(self, hydr_bonds):
        """
        The classes and function that deal with protein-ligand interaction analysis.
        """
        if hydr_bonds != True:
            self.hbonds = HBonds(self.topol_data,
                                 self.trajectory,
                                 self.start,
                                 self.end,
                                 self.skip,
                                 self.analysis_cutoff,
                                 distance=3)
        else:
            self.hbonds = None

    def plot_residues(self):
        """
        Calls Plot() that plots the residues with the required diagram_type.
        """
        self.plots = Plots(self.topol_data, self.diagram_type)

    def draw_figure(self):
        """
        Draws molecule through Molecule() and then puts the final figure together with
        Figure().
        """
        self.molecule = Molecule(self.topol_data)

        self.figure = Figure(self.molecule, self.topol_data, self.hbonds)
        self.figure.add_bigger_box()
        self.figure.manage_the_plots()
        self.figure.draw_hydrogen_bonds()
        self.figure.draw_white_circles()
        self.figure.put_everything_together()
        self.figure.write_final_draw_file(self.output_name)

    def save_files(self):
        """Saves all output from LINTools run in a single directory named after the output name."""
        os.system("mkdir " + self.output_name)
        self.workdir = os.getcwd()
        os.chdir(self.workdir + "/" + self.output_name)

    def remove_files(self):
        """Removes intermediate files."""
        file_list = ["molecule.svg", "LIG.pdb"]
        for residue in self.topol_data.dict_of_plotted_res.keys():
            file_list.append(residue[1] + residue[2] + ".svg")
        for f in file_list:
            if os.path.isfile(f) == True:
                os.remove(f)