Exemple #1
0
    def get_structures_from_file(self, files_names):
        pdb_files = []
        for f in files_names:
            pdb_files.append(f)
        if len(self.pdb_files) == 0:
            print "There are no pdb files in the folder!!"
        for pdbfile in pdb_files:
            parser = PDBParser(PERMISSIVE=False, QUIET=True)
            try:
                structure = parser.get_structure(str(pdbfile), pdbfile)
            except:
                raise InputError(
                    "Something is wrong with PDB format in the following file "
                    + pdbfile)
            if len(list(structure.get_residues())) == 0:
                raise InputError(
                    "The file you provided for structure %s is not a valid pdb file"
                    % (structure.id))
            self.structures.append(structure)

        if len(self.structures) == 1:
            print "You are trying to build a complex \
                                            built of one component only!"

        #~ os.chdir(path)
        return self.structures
    def add_covalent_bonds(self, con, pyrycomplex):
        """
        adds information about connections with other complex components by covalent bonds
        connected components are mutated together
        """
        
        #print "--", self.pyrystruct.chain, con.components_indexes, con.linked_components
        #independent component with no covalent bonds, can move independently
        if self.pyrystruct.chain not in con.linked_components.keys():
                self.covalent_bonds = []
        else:
            for covbond in con.linked_components[self.pyrystruct.chain]:
                #check correctness of covalent bonds atoms defined by the user
                if self.pyrystruct.struct[0][self.pyrystruct.chain].has_id((' ', covbond.atom1[0], ' ')):
		    res1 = self.pyrystruct.struct[0][self.pyrystruct.chain][covbond.atom1[0]]
                else:
                    raise InputError("Component %s does not have residue %s"%(self.pyrystruct.chain, covbond.atom1))
                #
                if self.pyrystruct.struct[0][self.pyrystruct.chain].has_id((' ', covbond.atom2[0], ' ')):
                    res2 = self.pyrystruct.struct[0][self.pyrystruct.chain][covbond.atom2[0]]
                else:
                    raise InputError("Component %s does not have residue %s"%(self.pyrystruct.chain, covbond.atom2))
                
                if res2.has_id(covbond.atom1[1]): pass
                else: raise InputError("Residue %s does not have atom %s"%(covbond.atom1[0], covbond.atom1[1]))
                                  
                if res2.has_id(covbond.atom1[1]): pass
                else: raise InputError("Residue %s does not have atom %s"%(covbond.atom2[0], covbond.atom2[1]))
                
                self.covalent_bonds.append(covbond)
                for chain in covbond.chains:
                    covbond.chains_indexes.append(pyrycomplex.get_component_index_by_chain(chain))                #(con.components_indexes[chain])
 def __find_if_dd_in_struct(self, dd_frag_positions):
     
     """
     [[1,2,3], [5,6,7], [10,11]]
     """
     resi_nrs = []
     for resi in self.pyrystruct.struct.get_residues():
         resi_nr = resi.id[1]
         resi_nrs.append(resi_nr)
             
     dd_indexes = []
     for frag in dd_frag_positions:
         for f in frag:
             dd_indexes.append(f)
     
     #print resi_nrs, len(list(self.pyrystruct.struct.get_residues())), len(self.pyrystruct.sequence)
     #print "DDfrag", dd_frag_positions
     #print "Checking", dd_indexes, resi_nrs, len(list(self.pyrystruct.struct.get_residues())), len(resi_nrs)
     for i in xrange(1, len(self.fasta_seq)):
         #if disordered fragment is too long
         if (i in resi_nrs) and (i in dd_indexes):
             raise InputError(str(i)+"residue is duplicated in fasta and pdb sequence. \n FASTA seq:"+self.fasta_seq.seq+"\n SEQ in PDB file"+self.pyrystruct.sequence)
         #if disordered fragment is too short
         if (i not in resi_nrs) and (i not in dd_indexes):
             raise InputError(str(i)+"residue is missing when comparing fasta and pdb sequence in chain "+(self.pyrystruct.chain)+"\n FASTA seq:"+self.fasta_seq.seq+"\n SEQ in PDB file"+self.pyrystruct.sequence)
 def process_line(self,line):
     li = line.split()
     line = li[:17]
     if len(li) == 3 and li[2] == "fixed": return li
     if len(line)<17: raise InputError("You provided to little values for MOVE_STATE %s instead of 16"%(len(line)))
     if not line[-1].isdigit():
         if line[-1] == "NL" or line[-1] == "nl": pass
         elif "." not in line[-1]: raise InputError("You provided to little values for MOVE_STATE %s instead \
                                                 of 16. last value in the raw should be digit, not string"%(len(line)))
     return li[:17]
 def check_rotation_params(self, values):
     
     rot_sums = []
     for val in values:
         if val.upper() == "X": val=10.
         elif val.upper() == "NL": val = 360.0
         elif val.isalpha(): raise InputError("%s value you provided is not a digit or X or NL"%(val))
         elif float(val)> 360: raise InputError("%s value you provided is not in range 0 to 360"%(val))
         elif float(val)< 0: raise InputError("%s value you provided is not in range 0 to 360"%(val))
         else: val = float(val)
     return val
Exemple #6
0
    def __untar_struct_folder(self, packed_folder, mode):
        """
            untars folder with structures    
        Parameters:
        -----------
            paced folder name  
        Returns:
        ---------
            unpaced folder
        Raises:
        --------
            InputError if archive is wrong (not tar or tar.gz)
        """
        arch_type = packed_folder[-3:]
        # ----remove Unpacked folder with structures if exist ---------
        # if os.path.exists(str(packed_folder[:-4])) == True:
        #     rmtree(str(packed_folder[:-4]))
        if arch_type == 'tar':
            try:
                tar = tarfile.open(packed_folder)
            except:
                raise InputError("Wrong archive with strucutres!")

        elif arch_type == 'tar.gz':
            try:
                tar = tarfile.open(packed_folder, "r:gz")
            except:
                raise InputError("Wrong archive with strucutres!")
        else:
            raise InputError(
                "Please change folder file archive into tar or tar.gz format")

        #print "sciezka do folderu ze strukturami", packed_folder

        fpath = os.path.dirname(os.path.abspath(
            packed_folder))  #"".join(packed_folder.split("\\")[:-1])
        #print "aktualna lokalizacja", fpath, packed_folder
        ffilename = os.path.split(packed_folder)
        #print "file with struct", ffilename

        if mode != "ig":
            tar.extractall(path=fpath)
            tar.close()

        if fpath == "": unpacked = ffilename[1].split(".")[0]
        else:
            unpacked = fpath + "/" + ffilename[1].split(".")[
                0]  #packed_folder[:-4]
        return unpacked
 def set_rotations_sum(self,line):
     """
     user defines what is the maximum sum of rotations around xyz axes for given component IN ALL SIMULATION STEPS
     """
     self.xmax_rot_sum = self.check_rotation_params([line[9]])
     self.ymax_rot_sum = self.check_rotation_params([line[10]])
     self.zmax_rot_sum = self.check_rotation_params([line[11]])
     self.lmax_rot_sum = self.check_rotation_params([line[16]])
     
     #self.check_rotation_params([self.xmax_rot_sum, self.ymax_rot_sum, self.zmax_rot_sum, self.lmax_rot_sum])
     
     if float(self.xmax_rot_sum) < float(self.xmax_rot): raise InputError("Rotation angle in single step cannot be larger than max rotation")
     if float(self.ymax_rot_sum) < float(self.ymax_rot): raise InputError("Rotation angle in single step cannot be larger than max rotation")
     if float(self.zmax_rot_sum) < float(self.zmax_rot): raise InputError("Rotation angle in single step cannot be larger than max rotation")
     if float(self.lmax_rot_sum) < float(self.lmax_rot): raise InputError("Rotation angle in single step cannot be larger than max rotation")
Exemple #8
0
    def check_fastanames_duplications(self):
        """
        checks whether names of sequences in FASTA file are not duplicated.
        If so it raises error and asks to change duplicated name!
        """
        components_names = []
        for fastaseq in self.sequences:
            fasta_name = fastaseq.id.split("_")
            if len(fasta_name) == 1:
                if fastaseq.id in components_names:                    raise InputError(fastaseq.id+\
" name has been repeated twice. please provide other name for this component")
                components_names.append(fastaseq.id)
            else:
                if fasta_name[0] in components_names:                    raise InputError(fasta_name[0]+\
" name has been repeated twice. please provide other name for this component")
                components_names.append(fasta_name[0])
 def check_translation_params(self, values):
     for val in values:
         if val.upper() == "X": val = 10.
         elif val.upper() == "NL": val = 1000000000000000000000000000000000000.0
         elif val.isalpha(): raise InputError("%s value you provided is not a digit or X or NL"%(val))
         else: val = float(val)
     return val
def check_sequence(sequence, mol_type):
    """
    checks whether sequence is correct (possess valid residues' names) if not, returns error
    """

    for el in sequence:
        if mol_type == "protein":
            if el.upper() not in AMINOACIDS.keys():
                raise InputError(
                    str(el.upper()) +
                    " does not correspond to known aminoacid's name")
        elif mol_type == "RNA" or mol_type == "DNA":
            if el.upper() not in NUCLEOTIDES.keys():
                raise InputError(
                    str(el.upper()) +
                    " does not correspond to known nucleotide's name")
Exemple #11
0
def disorder_config_check(sim):
	factory = Factory(sim.configuration, sim)
	if(len(sim.mPool[0].with_disorders) == 0 and
			"SimulateDisorder" in factory.configuration.mutation_frequencies and
			factory.configuration.mutation_frequencies["SimulateDisorder"] > 0):
		raise InputError("You cannot apply Simulate Disorder mutation for " +
			"components with no flexible/disordered fragments")
Exemple #12
0
def check_corretness_of_covalent_bonds(con):
    """
    check whether all chains defined in covalent bonds exist in provided structures
    here all components chains names must exist in pdb files provided
    if some components do not have covalent bonds defined they are treated as independent and are mutated alone.
    """
    for chain in con.linked_components.keys():
        if chain not in con.components_indexes.keys():
            raise InputError(
                "chain %s does not occur in structures you provided. please correct covalent bonds list in configuration file"
                % (chain))
        for el in con.linked_components[chain]:
            for e in el.chains:
                if e not in con.components_indexes.keys():
                    raise InputError(
                        "!!chain %s does not occur in structures you provided. please correct covalent bonds list in configuration file"
                        % (e))
    def check_dd_component(self, sequence):
        """
            calls methods which check input data
        Parameters:
        -------------

        """

        #--------------- get component's sequence --------------------------
        #retrieve molecule type!
        seq_name = sequence.id.split("_")
        if len(seq_name) < 2:
            raise InputError(
                str(sequence.id) +
                "Check whether you have component with this name! this is not a proper\
                    name for sequence with no structure. Please use chainname_moleculetype e.g. A_protein"
            )

        if (seq_name) < 1:
            raise InputError(
                str(seq_name.upper()) + " is to short, \
                        please provide molecule type name e.g. protein, RNA or DNA"
            )

        chain_name, mol_type = seq_name[0], seq_name[1]

        if mol_type.lower() != "protein" and mol_type.lower() != "rna" and \
        mol_type.lower() != "dna":            raise InputError(str(mol_type.upper())+\
"is not a correct molecule type name. please provide molecule type name e.g. protein, RNA or DNA")

        if len(chain_name) > 1:
            raise InputError(
                str(seq_name[0].upper()) + " is to long for a chain's name, \
                        please provide chain name as a single character e.g. 'A'"
            )

        check_sequence(sequence, mol_type)

        pyrystruct = PyRyStructure()
        pyrystruct.set_moltype(mol_type)
        pyrystruct.set_chain_name(chain_name)
        pyrystruct.set_sequence(str(sequence.seq))
        return pyrystruct
Exemple #14
0
 def build_rotation_matrix(self,point1,point2, angle):
     """
     defines a rotation matrix for toration around line defined by
     points point1 and point2 by angle
     
     source:
     http://inside.mines.edu/~gmurray/ArbitraryAxisRotation/
     """
     u = (point2[0]-point1[0])
     v = (point2[1]-point1[1])
     w = (point2[2]-point1[2])
     
     if u == 0. and v ==0. and w == 0:
         raise InputError("To define line you need two different points in 3D space. Please change coordinated for \
                          COVALENT_BOND definition in configuration file")
     
     uu = u*u
     vv = v*v
     ww = w*w
             
     a,b,c = point1[0], point1[1], point1[2]
     
     cosT = cos(angle)
     sinT = sin(angle)
     oneMinusCosT = 1-cosT
     
     l2 = uu + vv + ww
     l = sqrt(l2)
     
     #Build the matrix entries element by element.
     m1a = (uu + ((vv + ww) * cosT))/l2
     m1b = ((u*v * oneMinusCosT - w*l*sinT))/l2
     m1c = ((u*w * oneMinusCosT + v*l*sinT))/l2
     m1d = (((a*(vv + ww) - u*(b*v + c*w)) * oneMinusCosT\
         + (b*w - c*v)*l*sinT))/l2
     
     m1 = [m1a, m1b, m1c, m1d]
     
     m2a = (u*v * oneMinusCosT + w*l*sinT)/l2
     m2b = (vv + ((uu + ww) * cosT))/l2
     m2c = ((v*w * oneMinusCosT - u*l*sinT))/l2
     m2d = (((b*(uu + ww) - v*(a*u + c*w)) * oneMinusCosT\
         + (c*u - a*w)*l*sinT))/l2
     m2 = [m2a, m2b, m2c, m2d]
     
     m3a = (u*w * oneMinusCosT - v*l*sinT)/l2
     m3b = (v*w * oneMinusCosT + u*l*sinT)/l2
     m3c = (ww + ((uu + vv) * cosT))/l2
     m3d = (((c*(uu + vv) - w*(a*u + b*v)) * oneMinusCosT\
         + (a*v - b*u)*l*sinT))/l2
     m3 = [m3a, m3b, m3c, m3d]
             
     return m1,m2,m3
Exemple #15
0
    def __extract_structures(self, folder_name):
        """ takes folder name and parses all files,
            returns self.structures - a list of Bio.PDB structure object
        Parameters:
        -----------
            unpacked folder name
        Returns:
        --------
            self.all_structures : list (containing all structures as PDB objts)
        """
        #folder_path = folder_name.split("/")

        #print "---folder name with structures", folder_name
        try:
            os.chdir(folder_name)
        except:
            raise InputError(
                "PyRy3D cannot locate unpacked folder with structures. Please check whether the archive was prepared properly"
            )
        self.pdb_files = glob.glob('*.*')  #pdb')
        self.pdb_files.sort()

        if len(self.pdb_files) == 0:
            print "There are no pdb files in the folder!!"
        for pdbfile in self.pdb_files:
            parser = PDBParser(PERMISSIVE=False, QUIET=True)
            try:
                structure = parser.get_structure(str(pdbfile), pdbfile)
            except:
                raise InputError(
                    "Something is wrong with PDB format in the following file"
                    + pdbfile)
            if len(list(structure.get_residues())) == 0:
                raise InputError(
                    "The file you provided for structure %s is not a valid pdb file"
                    % (structure.id))
            self.structures.append(structure)
        if len(self.structures) == 1:
            print "You are trying to build a complex \
Exemple #16
0
 def mutate(self, complex):
     if len(complex.with_disorders) == 0:
         raise InputError(
             "You cannot apply Simulate Disorder mutation for components with no flexible/disordered fragments"
         )
     componentIndex = choice(complex.with_disorders)
     component = complex.components[componentIndex]
     #simulate disorder
     ddstruct = component.simulate_disorder(component.pyrystruct.struct,
                                            "simul")
     if ddstruct:
         if componentIndex not in complex.changes:
             complex.add_simul_change_by_index(componentIndex)
 def __check_number_of_chains(self, component):
     """
         checks whether in there are more than one chain in the pdb file
     Parameters:
     -----------
         structure object
     Raises:
     -------
         InputError : if a structure has more than one chain
     """
     if len(component[0].child_list) >= 2:
         raise InputError("There are more than one chain in the structure:%s, %s"% \
                                     (component, len(component[0].child_list)))
     else:
         return component[0].child_list[0].id
    def check_component(self, sequences, component):
        """
            calls methods which check input data
        Parameters:
        -------------
            sequences   : all sequences provided by the user in fasta file
            component   : single component structure (BioPDB object)
        Returns:
        ----------
            chain   :   chain name of given component
            seq     :   sequence from fasta file for a component
        """
        #for r in component.get_residues():
        #    print "&&&&&", r.id
        self.__check_number_of_models(component)
        component_no_hoh = self.__remove_waters(component)
        chain = self.__check_number_of_chains(component)

        if chain:

            #--------------- get component's sequence --------------------------
            pyry_struct = PyRyStructure(component_no_hoh)

            self.struct_seq = str(pyry_struct.get_mol_sequence())
            moltype = pyry_struct.get_moltype()

            # ---------------get ids of first and last elements ----------------
            first_res_id = list(component.get_residues())[0].get_id()[1]
            last_res_id = first_res_id + len(list(
                component.get_residues())) - 1
            seq_positions = (first_res_id, last_res_id)

            #---------check if data do not contain errors----------------------
            self.__find_fastaseq_for_struct(chain, sequences)
            check_sequence(self.fasta_seq, moltype)
            self.__check_if_seq_part_is_taken(seq_positions)

            #if structure is correct assign it as pyrystructure object and use in program
            pyry_struct.set_pyrystructure()
            return pyry_struct
        else:
            raise InputError(
                "Input data are incorrect, please double check them!")
Exemple #19
0
    def get_data_from_saxs_file(self, simboxradius, saxsradius):
        """
            calls CCP4_reader and retrieves desired densities
            (of wanted threshold or within assigned volume)
        """
        xcoords, ycoords, zcoords = [], [], []

        saxs = SAXSShape()
        saxs.get_data_from_dammif_file(self.saxsfile)
        self.map_radius = saxsradius
        if self.map_radius <= 0.:
            raise InputError(
                "You must provide SAXSRADIUS in configuration file")

        for da in saxs.dummy_atoms:
            #collect all points within a density map
            x, y, z = da.coord[0], da.coord[1], da.coord[2]
            mappoint = GridCell([x, y, z])
            self.add_mappoint(mappoint)
            if x not in xcoords: xcoords.append(x)
            if y not in ycoords: ycoords.append(y)
            if z not in zcoords: zcoords.append(z)

        return xcoords, ycoords, zcoords
 def __find_fastaseq_for_struct(self, chain, sequences):
     """
         checks if name of fasta sequence and 
         structure chain name are the same
     Parameters:
     -----------
         chain       : name of chain for a given structure
         sequences   : list of all sequences
     Raises:
     -------
         InputError  : if the sequence is missing for given component or
                       the sequence is empty (of length zero)
     """
     found_seq = False
     for seq in sequences:
         seqname = seq.name.split("_")[0]
         if len(seq.seq) == 0:
             raise InputError("Sequence is empty! %s" % (self.fasta_seq))
         if seq.name == "":
             raise InputError("The sequence %s does not have name" % (seq))
         if len(seqname) > 1:
             raise InputError("The sequence %s has too long name!! \
         it should be one letter indicator the same as in corresponding PDB file"
                              % (seqname))
         if seqname not in ALLOWED_CHAIN_NAMES:
             raise InputError(
                 "The sequence name for sequence %s is not allowed" % (seq))
         if chain == seq.name:
             found_seq = True
             self.fasta_seq = seq
     if found_seq == False:
         if chain != "":
             raise InputError("there is no sequence for" + str(chain) +
                              "structure")
         if chain == "":
             raise InputError("there is no chain name for" + str(seqname) +
                              "structure")
Exemple #21
0
 def set_translations_sum(self, line):
     """
     user defines what is the maximum sum of translations around xyz axes for given component IN ALL SIMULATION STEPS
     """
     #self.max_trans_vector_sum = [line[12], line[13],line[14]]
     xtrans = self.check_translation_params([line[12]])
     ytrans = self.check_translation_params([line[13]])
     ztrans = self.check_translation_params([line[14]])
     self.max_trans_vector_sum = [xtrans, ytrans, ztrans]
     
     if float(self.max_trans_vector_sum[0]) < float(self.max_trans_vector[0]): raise InputError("Translation vector in single step cannot be larger than max translation")
     if float(self.max_trans_vector_sum[1]) < float(self.max_trans_vector[1]): raise InputError("Translation vector in single step cannot be larger than max translation")
     if float(self.max_trans_vector_sum[2]) < float(self.max_trans_vector[2]): raise InputError("Translation vector in single step cannot be larger than max translation")
Exemple #22
0
    def get_data_from_ccp4_file(self,
                                simboxradius,
                                threshold=False,
                                kmax=False,
                                first_complex=False):
        """
            calls CCP4_reader and retrieves desired densities
            (of wanted threshold or within assigned volume)
        """

        ccp4 = CCP4(self.mapfile)
        count, xcoords, ycoords, zcoords = 0, [], [], []
        index = 0

        if not kmax:
            densities = ccp4.read_volume_fast(threshold)
        else:
            print "-----", kmax
            densities = ccp4.read_simulated_volume_fast(kmax, first_complex)
            threshold = ccp4.get_map_threshold()
            self.set_kvol_threshold(threshold)

        if len(densities.keys()) == 0:
            raise Complex_mapError(
                "The density map threshols does not contain any map points with assigned density value. Please change the threshold!!"
            )

        self.map_threshold = threshold
        self.map_radius = ccp4.width / 2.
        if self.map_radius <= 0.:
            raise InputError(
                "The cell dimensions in CCP$ file are wrong, should be >0")

        for point in densities.keys():
            x, y, z = point[0], point[1], point[2]
            rounded_density = round(densities[point], 4)

            mappoint = GridCell([x, y, z], index)
            mappoint.set_cell_density(rounded_density)
            ##mappoint.set_cell_radius(mappoint_radius)
            self.add_mappoint(mappoint)  #list of all MapPoint objects
            #print "SPHERE, ", str(x), ", ", y, ", ", z, ", ", self.map_radius, ","
            if x not in xcoords: xcoords.append(x)
            if y not in ycoords: ycoords.append(y)
            if z not in zcoords: zcoords.append(z)
            index += 1

#normalize radii according to densities
#sorted(density_vals, reverse=True)
        density_vals = ccp4.dotvalues

        density_vals = sorted(density_vals, reverse=True)
        distrange = [0.1 * self.map_radius, self.map_radius]
        distdif = self.map_radius - 0.1 * self.map_radius

        curr = -1.0
        different_densities = 0
        for i in xrange(0, len(density_vals)):
            if curr != density_vals[i]:
                curr = density_vals[i]
                different_densities += 1

        interval = distdif / different_densities

        ms = sorted(self.mappoints,
                    key=lambda mappoint: mappoint.density,
                    reverse=True)
        #print "mappoints", len(ms), len(densities.keys())
        prev = ms[0]

        act_radius = self.map_radius
        for mp in ms:
            if mp.density != prev.density:
                mp.radius = act_radius - interval
            else:
                mp.radius = act_radius
            prev = mp
            act_radius = mp.radius
#print "----", ms[0].radius, ms[0].density
#print ";;;;;", ms[-1].radius, ms[-1].density

        return xcoords, ycoords, zcoords
Exemple #23
0
def run_simulation(first_complex, simul_params, interactions, density_map,
                   traflfile):
    """
        calls Monte Carlo simulation for complex building
    Parameters:
    -----------
        first_complex       : PyRycomplex object
        interactions        : object of interaction class storing experimental data such as distances, symmetry etc.
        simul_params        : simulation parameters (number of steps,
                              number of out complexes etc.)
        density_map         : map object representing cryo-EM map
        traflfile           : name of traflfile to store trajectory
    Returns:
    ----------
        complexes           : list of PyRyComplexes after simulation (ready models)
    """
    #-----------perform simulation!-------------------------------------------------
    #decide which mutations are available for the system

    if len(first_complex.movable) == 0:
        raise InputError(
            "There are no components to mutate. I have northing to do!")

    set_available_mutations(first_complex, simul_params)

    sim = Simul(simul_params)
    sim.setSimulationMethod(
        simul_params.simmethod)  #@todo Load configuration value
    if simul_params.simmethod == "genetic":  #genetic
        sim.setReductionMethod(simul_params.reductmethod)
        sim.setMaximumPoolSize(simul_params.maxpoolsize)
    elif simul_params.simmethod == "simulatedAnnealing" or \
         simul_params.simmethod == "replicaExchange":
        sim.setTemperature(simul_params.anntemp)
    if simul_params.simmethod == "replicaExchange":
        sim.setReplicaExchangeSteps(simul_params.replica_exchange_freq)
        sim.setReplicaTemperatures(simul_params.replica_temps)

    sim.setParameterScalingBoundries(simul_params.param_scaling_ranges)

    sim.setParameterScalingValues([ \
    simul_params.param_scaling_range1, simul_params.param_scaling_range2, \
    simul_params.param_scaling_range3 ])

    sim.setMutationFrequencies(simul_params.rotation_freq, simul_params.rotation_cov_freq, simul_params.translation_freq, \
                          simul_params.exchange_freq, simul_params.exchangeandsample_freq, simul_params.simul_dd_freq, simul_params.translation_all_freq,\
                          simul_params.rotation_all_freq, simul_params.rotation_whole_freq)

    sim.setReheatingParams(simul_params.reheat, simul_params.reheat_rejections)

    sim.setScalingOption(simul_params.param_scaling)
    sim.setStartingComplex(first_complex)
    sim.setIterationCount(simul_params.simul_steps)
    sim.setIndicators(simul_params)
    sim.setResultCount(simul_params.struct_nr)
    sim.setInteractions(interactions)
    sim.setDensityMap(density_map)
    sim.setStepsToSave(simul_params.niter)
    sim.setTraflfile(traflfile)
    sim.setServer(inp.optimized)
    if inp.scoreplot: sim.setScoresPlot()

    best_complex, last_complex = sim.start()

    #---------take simulation output according to user's wishes---------------------
    #complexes = sim.getResult()
    #logfile.write_message("Number of rejected complexes is "+str(sim.rejected))
    return best_complex, sim, last_complex
def get_args(inp):
    """
        uses OptionParser to get command line arguments: sequences, structures,
        restraints and a density map file    
    Parameters:
    -----------
        inp             : Input object
    Returns:
    --------
        sequences       : user defined seqs as Bio objects
        structures      : user defined structures as Bio objects
                          will be transformed into Complex_component instance
        restraints      : user defined restraints, will become
                          Distance_Interactions instances
        complex_map     : complex map data which will be transformed
                          into Complex_component instance
        
        """
    parser = OptionParser()
    parser.add_option("-s", "--seq_file", dest="seq_filename",
                  help="input file with sequences in FASTA format",\
                       metavar="FILE")
    parser.add_option("-d", "--dirfile", dest="dirname",
                  help="input file with structure", metavar="FILE")
    parser.add_option("-r", "--restr_file", dest="restr_filename",
                  help="input file with restraints in Filtrest3D format", \
                       metavar="FILE")
    parser.add_option("-m", "--map_file", dest="map_filename",
                  help="input file with complex map", metavar="FILE")
    parser.add_option("-x", "--saxs_file", dest="saxs_filename",
                  help="input file with complex map shape", metavar="FILE")
    parser.add_option("-a", "--auto", dest="auto",
                  help="generate input files automatically from structures", metavar="FILE")
    parser.add_option("-c", "--config", dest="config",
                  help="config file with simulation parameters")
    parser.add_option("-o", "--output", dest="output",
                  help="write output to file")
    parser.add_option("-t", "--traflfile", dest="traflfile",
                  help="write output to trajectory file")
    parser.add_option("-y", "--.dat file with experimental curve from SAXS", dest="curve_filename",
                  help="Verify discrepancy between theoretical and experimental curves from SAXS/SANS. ")
    parser.add_option("-f", "--to full atom model", dest="fullatom",
                  help="write best model in fullatom representation")
    parser.add_option("-v", "--save history of moves", dest="movehistory",
                  help="save all moves into a file")
    parser.add_option("-e", "--save plot with complexes scores", dest="score_plot",
                  help="save plot with complexes scores")
    parser.add_option("--fast", action="store_true", dest="fast", default=False,
                  help="run optimized version, option -v is then disabled")
    #other options???
    (opts, args) = parser.parse_args()
    modelsets = []


#------------optimization-----------------------------------------------
    inp.optimized = opts.fast

#---------------get sequences-------------------------------------
    if opts.seq_filename != None:
        seqs = Sequences()
        inp.sequences = seqs.get_seqs_data(opts.seq_filename)

#---------------get structures-------------------------------------
    if opts.dirname != None:
        structs = Structures()
        inp.structures = structs.get_structures(opts.dirname)
        modelsets.append(PDBDirfile(opts.dirname, structs.pdb_files))
        modelset=CompositeModelSet(modelsets)
    if opts.dirname == None:   
        inp.structures = []
        #raise InputError("No structure folder given, I have nothing to do!")
        
#---------------get restraints-------------------------------------
    if opts.restr_filename != None:
        restrs = PyryRestraints()
        inp.restraints = restrs.get_restraints(opts.restr_filename) #, modelset)
        if opts.restr_filename and inp.restraints == []:
            if inp.symrestraints == []:
                raise InputError("Format of file with restraints is wrong")
    else:
        restraints = []       
    if opts.restr_filename == None:
        #if restraint option is not used, than use empty list of restraints!
        inp.restraints = []
        
#---------------get density map or saxs shape----------------------------------
    if opts.map_filename != None:   
        map = ShapeDescriptor()
        inp.mapfile = map.get_density_map(opts.map_filename)
    if opts.saxs_filename != None:
        saxs = ShapeDescriptor()
        inp.saxsfile = saxs.get_saxs_shape(opts.saxs_filename)
    if opts.curve_filename != None:   
        map = ShapeDescriptor()
        inp.curvefile = map.get_curve(opts.curve_filename)
    elif (opts.map_filename == None) and (opts.saxs_filename == None) and (opts.curve_filename == None):
        print "MODELING MODE WITH NO SHAPE DESCRIPTOR!!!"
    
#---------------get config file name-------------------------------------
    if opts.config != None:   
        inp.config = opts.config
    elif opts.config == None:
        inp.config = ""
        #raise InputError("No config file name was given, please provide one!")
        
#---------------get output name-------------------------------------
    if opts.output != None:   
        inp.outname = opts.output
    elif opts.output == None:
        #if no output folder is provided create pyryresults folder in actual localization
        inp.outname = "pyryresults"
        
#------------write trajectory file -----------------------------------
    if opts.traflfile != None:   
        inp.traflfile = opts.traflfile
    elif opts.traflfile == None:
        print "Data will not be added to trajectory file!!"
        
#------------fullatom file -----------------------------------
    if opts.fullatom != None:   
        inp.fullatom_file = opts.fullatom
    elif opts.fullatom == None:
        inp.fullatom_file = ""
        
#------------save history of moves to output file-------------------------
    if opts.movehistory != None:   
        inp.movehistory_file = opts.movehistory
    elif opts.movehistory == None:
        inp.movehist_file = ""
        
#------------print penalties plot -------------------------
    if opts.score_plot != None:   
        inp.scoreplot = opts.score_plot
    elif opts.score_plot == None:
        inp.scoreplot = ""

    if not any([opts.map_filename, opts.saxs_filename, opts.curve_filename, opts.restr_filename]):
        raise InputError("To run simulations you have to provide a shape descriptor or restraints.")

#----------- allow auto module ----------------------------
    if opts.auto is not None:
        inp.autofolder = opts.auto
        if opts.config == None: InConfig().generate_pyry_inconfig("config_file.txt")    
        instr = InStructures()
        instr.generate_pyry_instructures(str(opts.auto), str(opts.auto)+"_out")
        
        structs = Structures()
        path = str(opts.auto)+"_out.tar"
        inp.structures = structs.get_structures(path, "ig")
        modelsets.append(PDBDirfile(str(opts.auto)+"_out.tar", structs.pdb_files))
        modelset=CompositeModelSet(modelsets)

        with open('%s.fasta' % opts.auto, 'w+b') as f:
            InSequences().generate_pyry_insequences(f, instr.structures)
            f.seek(0)
            inp.sequences = Sequences().get_seqs_data_from_handle(f)
    else:
        if opts.seq_filename is None:
            with tempfile.SpooledTemporaryFile() as f:
                InSequences().generate_pyry_insequences(f, inp.structures, mode="ig")
                f.seek(0)
                inp.sequences = Sequences().get_seqs_data_from_handle(f)

    return opts
Exemple #25
0
    else:
        if inp.mapfile: shape_descriptor = "map"
        else: shape_descriptor = "saxs"

    con.parse_config_file(inp.config, inp.curvefile, shape_descriptor)

    con.set_movehistory_file(inp.movehistory_file)

    if inp.movehistory_file:
        con.movehistory = inp.movehistory_file

#---geting sequences, structures, restraints and density map provided by the user
    get_input_data(inp, con, trans)
    if options.seq_filename == None and con.identify_disorders == True:
        raise InputError(
            "To identify disordered regions in components you have to provide fasta file with full-length sequences"
        )

# ---------- create first complex --------------------------
    first_complex = create_first_complex(trans.components, con, inp.traflfile)
    #------------generate interactions between complex components
    density_map = trans.get_map(inp.saxsfile, inp.mapfile, con, first_complex)

    trans.get_interactions(inp.restraints, inp.symrestraints, trans.components,
                           density_map)
    #first_complex.interactions = trans.interactions

    #------------locate components randomly inside the density map----------
    calculate_simulbox_statistics(first_complex, density_map, inp, trans, con)
    arrange_components_inside_simulbox(first_complex, density_map, trans, con)