Exemple #1
0
class Lintools(object):
    def __init__(self, topology, trajectory, ligand_name, offset, cutoff,
                 analysis_cutoff, diagram_type, domain_file, HB_flag,
                 RMSF_flag, debug_flag, resinfo_flag, mol2_file, output_name):
        self.topology = os.path.abspath(topology)
        try:
            self.trajectory = []
            for traj in trajectory:
                self.trajectory.append(os.path.abspath(traj))
        except Exception:
            self.trajectory = trajectory
        self.ligand_name = ligand_name
        self.offset = offset
        self.cutoff = cutoff
        self.analysis_cutoff = analysis_cutoff
        self.diagram_type = diagram_type
        try:
            self.domain_file = os.path.abspath(domain_file)
        except Exception:
            self.domain_file = domain_file
        self.HB_flag = HB_flag
        self.RMSF_flag = RMSF_flag
        self.debug_flag = debug_flag
        self.resinfo_flag = resinfo_flag
        try:
            self.mol2_file = os.path.abspath(mol2_file)
        except Exception:
            self.mol2_file = mol2_file
        self.output_name = output_name
        self.rmsf = None
        self.hbonds = None

    def get_info_about_input_and_analyse(self):
        """This function loads all input files and decides which residues to plot"""
        self.topol_data = Topol_Data(self.topology, self.trajectory,
                                     self.ligand_name, self.offset,
                                     self.mol2_file)
        self.topol_data.define_ligand(self.ligand_name, self.mol2_file)
        if self.trajectory == None:
            self.topol_data.find_res_to_plot(self.cutoff)
        else:
            self.occurrence = Occurrence_analysis(self.topology,
                                                  self.trajectory,
                                                  self.ligand_name,
                                                  self.cutoff, self.offset,
                                                  self.topol_data)
            self.occurrence.get_closest_residues(self.analysis_cutoff)
        if self.HB_flag != True:
            self.hbonds = HBonds(self.topol_data, self.topology,
                                 self.trajectory, self.ligand_name,
                                 self.offset, self.analysis_cutoff)
            self.topol_data.get_closest_ligand_atoms(self.hbonds)
        else:
            self.topol_data.get_closest_ligand_atoms()
        if self.RMSF_flag == True:
            self.rmsf = RMSF_measurements(self.topol_data, self.topology,
                                          self.trajectory, self.ligand_name,
                                          self.offset, self.output_name)

    def plot_residues(self):
        self.plots = Plots(self.topol_data)
        if self.diagram_type == "amino":
            self.plots.define_amino_acids()
            self.plots.plot_amino_diagramms()
        if self.diagram_type == "domains":
            assert len(self.domain_file) > 0, "Provide a file defining domains"
            self.plots.define_domains(self.domain_file, self.offset)
            self.plots.plot_domains_diagramms()
        if self.diagram_type == "clock":
            self.plots.plot_clock_diagramms()

    def draw_molecule_and_figure(self, tests=False):
        self.molecule = Molecule(self.topol_data, self.rmsf)
        self.figure = Figure(self.molecule, self.diagram_type, self.topol_data,
                             self.hbonds, self.plots, self.rmsf, tests)
        if self.HB_flag != True:
            self.figure.draw_hbonds_in_graph(self.diagram_type)
        self.figure.draw_white_circles_at_atoms(self.diagram_type)
        if self.debug_flag == True:
            self.figure.draw_lines_in_graph(
            )  #a function for debugging purposes
        self.figure.put_everything_together()
        self.figure.write_final_draw_file(self.output_name)
        if self.trajectory != None and self.resinfo_flag != True:
            self.res_info = Residue_Info(self.topol_data, self.occurrence,
                                         self.figure)

    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):
        file_list = [
            "molecule.svg", "LIG.pdb", "test.xtc", "rmsf_colorbar.svg"
        ]
        for residue in self.topol_data.dict_of_plotted_res.keys():
            file_list.append(str(residue[3:]) + ".svg")
            for f in file_list:
                if os.path.isfile(f) == True:
                    os.remove(f)