Пример #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)
        * mol_file * - MOL 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)
        * sasa * - set this to 1 to turn on solvent accessible surface area calculation (currently only works across whole trajectory)
        * 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__ = "06.2018"
    def __init__(self,topology,trajectory,mol_file,ligand,offset,cutoff,start_frame,end_frame,skip,analysis_cutoff,sasa,diagram_type,output_name,cfg):
        """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 = []
        if mol_file!=None:
            self.mol_file = os.path.abspath(mol_file)
        else:
            self.mol_file = mol_file
        self.ligand = ligand
        self.offset = offset
        self.cutoff = cutoff
        if cfg==False:
            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))]
        else:
            self.start = start_frame
            self.end = end_frame
            self.skip = skip
        self.analysis_cutoff = analysis_cutoff
        self.sasa = sasa
        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 mol 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.mol_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.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):
        """
        The classes and function that deal with protein-ligand interaction analysis.
        """
        self.hbonds = HBonds(self.topol_data,self.trajectory,self.start,self.end,self.skip,self.analysis_cutoff,distance=3)
        self.pistacking = PiStacking(self.topol_data,self.trajectory,self.start,self.end,self.skip, self.analysis_cutoff)
        if self.sasa==1:
            self.sasa = SASA(self.topol_data,self.trajectory)
        self.lig_descr = LigDescr(self.topol_data)
        if self.trajectory!=[]:
            self.rmsf = RMSF_measurements(self.topol_data,self.topology,self.trajectory,self.ligand,self.start,self.end,self.skip)
        self.salt_bridges = SaltBridges(self.topol_data,self.trajectory,self.lig_descr,self.start,self.end,self.skip,self.analysis_cutoff)
    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,data_for_color=None, data_for_size=None, data_for_clouds=None, rot_bonds=None, color_for_clouds="Blues", color_type_color="viridis"):
        """
        Draws molecule through Molecule() and then puts the final figure together with
        Figure().
        """
        self.molecule = Molecule(self.topol_data)

        self.draw = Draw(self.topol_data,self.molecule,self.hbonds,self.pistacking,self.salt_bridges,self.lig_descr)
        self.draw.draw_molecule(data_for_color, data_for_size, data_for_clouds, rot_bonds, color_for_clouds, color_type_color)

        self.figure = Figure(self.molecule,self.topol_data,self.draw)
        self.figure.add_bigger_box()
        self.figure.manage_the_plots()
        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."""
        while True:
            try:
                os.mkdir(self.output_name)
            except Exception as e:
                self.output_name = raw_input("This directory already exists - please enter a new name:")
            else:
                break
        self.workdir = os.getcwd()
        os.chdir(self.workdir+"/"+self.output_name)
    def write_config_file(self, cfg):
        if cfg!=None:
            #copy the config file to results directory
            shutil.copy("../"+cfg, "lintools.config")
        else:
            #If there was no config file, write one
            cfg_dir = {'input':{
                            'topology':self.topology,
                            'trajectory':self.trajectory,
                            'mol file':self.mol_file,
                            'ligand':self.ligand,
                            'traj start':self.start,
                            'traj end':self.end,
                            'traj skip': self.skip,
                            'offset': self.offset,
                            'distance cutoff': self.cutoff,
                            'analysis cutoff': self.analysis_cutoff,
                            'sasa': self.sasa,
                            'diagram type': self.diagram_type,
                            'output name': self.output_name},
                    'representation':{
                            'data to show in color':None,
                            'data to show as size':None,
                            'data to show as cloud':None,
                            'rotatable bonds':None,
                            'cloud color scheme':'Blues',
                            'atom color scheme':'viridis',
                            'clock color scheme':'summer'}
                            }

            with open("lintools.config","wb") as ymlfile:
                yaml.dump(cfg_dir,ymlfile,default_flow_style=False)
    def remove_files(self):
        """Removes intermediate files."""
        file_list = ["molecule.svg","lig.pdb","HIS.pdb","PHE.pdb","TRP.pdb","TYR.pdb","lig.mol","test.xtc"]
        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)
Пример #2
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)
Пример #3
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)
        * mol_file * - MOL 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, mol_file, ligand, offset, cutoff,
                 start_frame, end_frame, skip, analysis_cutoff, diagram_type,
                 output_name, cfg):
        """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 = []
        if mol_file != None:
            self.mol_file = os.path.abspath(mol_file)
        else:
            self.mol_file = mol_file
        self.ligand = ligand
        self.offset = offset
        self.cutoff = cutoff
        if cfg == False:
            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))
            ]
        else:
            self.start = start_frame
            self.end = end_frame
            self.skip = skip
        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 mol 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.mol_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.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):
        """
        The classes and function that deal with protein-ligand interaction analysis.
        """
        self.hbonds = HBonds(self.topol_data,
                             self.trajectory,
                             self.start,
                             self.end,
                             self.skip,
                             self.analysis_cutoff,
                             distance=3)
        self.pistacking = PiStacking(self.topol_data, self.trajectory,
                                     self.start, self.end, self.skip,
                                     self.analysis_cutoff)
        self.sasa = SASA(self.topol_data, self.trajectory)
        self.lig_descr = LigDescr(self.topol_data)
        if self.trajectory != []:
            self.rmsf = RMSF_measurements(self.topol_data, self.topology,
                                          self.trajectory, self.ligand,
                                          self.start, self.end, self.skip)
        self.salt_bridges = SaltBridges(self.topol_data, self.trajectory,
                                        self.lig_descr, self.start, self.end,
                                        self.skip, self.analysis_cutoff)

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

    def draw_figure(self,
                    data_for_color=None,
                    data_for_size=None,
                    data_for_clouds=None,
                    rot_bonds=None,
                    color_for_clouds="Blues",
                    color_type_color="viridis"):
        """
        Draws molecule through Molecule() and then puts the final figure together with
        Figure().
        """
        self.molecule = Molecule(self.topol_data)

        self.draw = Draw(self.topol_data, self.molecule, self.hbonds,
                         self.pistacking, self.salt_bridges, self.lig_descr)
        self.draw.draw_molecule(data_for_color, data_for_size, data_for_clouds,
                                rot_bonds, color_for_clouds, color_type_color)

        self.figure = Figure(self.molecule, self.topol_data, self.draw)
        self.figure.add_bigger_box()
        self.figure.manage_the_plots()
        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."""
        while True:
            try:
                os.mkdir(self.output_name)
            except Exception as e:
                self.output_name = raw_input(
                    "This directory already exists - please enter a new name:")
            else:
                break
        self.workdir = os.getcwd()
        os.chdir(self.workdir + "/" + self.output_name)

    def write_config_file(self, cfg):
        if cfg != None:
            #copy the config file to results directory
            shutil.copy("../" + cfg, "lintools.config")
        else:
            #If there was no config file, write one
            cfg_dir = {
                'input': {
                    'topology': self.topology,
                    'trajectory': self.trajectory,
                    'mol file': self.mol_file,
                    'ligand': self.ligand,
                    'traj start': self.start,
                    'traj end': self.end,
                    'traj skip': self.skip,
                    'offset': self.offset,
                    'distance cutoff': self.cutoff,
                    'analysis cutoff': self.analysis_cutoff,
                    'diagram type': self.diagram_type,
                    'output name': self.output_name
                },
                'representation': {
                    'data to show in color': None,
                    'data to show as size': None,
                    'data to show as cloud': None,
                    'rotatable bonds': None,
                    'cloud color scheme': 'Blues',
                    'atom color scheme': 'viridis',
                    'clock color scheme': 'summer'
                }
            }

            with open("lintools.config", "wb") as ymlfile:
                yaml.dump(cfg_dir, ymlfile, default_flow_style=False)

    def remove_files(self):
        """Removes intermediate files."""
        file_list = [
            "molecule.svg", "lig.pdb", "HIS.pdb", "PHE.pdb", "TRP.pdb",
            "TYR.pdb", "lig.mol", "test.xtc"
        ]
        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)
Пример #4
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)