def generate(self, component=None):
        """
        """
        #        self.grapes[0] = self.findBallPoint(self.masterPoint, self.masterRadius-self.radius)
        self.grapes[0] = self.masterPoint
        if (self.generationMethod == "anchored_chain"):
            if (not self.checkChainDistance()):
                self.generationMethod = "chain"
                print "Warning! Anchored chain distance too big, switching to regular chain"
                logfile.write_file(
                    "Warning! Anchored chain distance too big, switching to regular chain\n"
                )
            else:
                self.startAnchoredChain()

        for i in range(1, self.grapeCount):
            lIterCount = 0
            if (self.generationMethod == "anchored_chain"):
                self.anchoredReposition(i - 1)

            while (
                    lIterCount < 100
            ):  #Try a hundred times before going ahead (last generated grape is left there, even if it collides)
                lIterCount += 1
                if (self.generationMethod == "random"):
                    n = randint(0, i - 1)  #attach to a random one
                elif self.generationMethod == "chain":
                    n = i - 1  #attach new grape to the last one
                elif self.generationMethod == "anchored_chain":
                    #attention! i-2 can be equal -1
                    n = i - 2  #attach new grape to the previous to last one

                if (self.generationMethod == "anchored_chain"):
                    if (i == 1
                        ):  #skip first step, we have the anchor point there
                        continue
                    angle = self.getMaxAngle(self.grapes[n],
                                             self.grapes[n + 1], i)
                    self.grapes[i] = self.findChainPoint(
                        self.grapes[n], 2 * self.radius, 0.75 * angle,
                        0.75 * min(angle, pi / 4), i == self.grapeCount - 1)
                else:
                    self.grapes[i] = self.findSpherePoint(
                        self.grapes[n], 2 * self.radius)

                if (self.collides(i) == 0):
                    if (self.detectCollisions != None):
                        if component:
                            if (self.detectCollisions(component,
                                                      self.grapes[i],
                                                      self.radius) == 0):
                                break
                    else:
                        break

#print "new grape", self.grapes[i]
        if (self.generationMethod == "anchored_chain"):
            self.endAnchoredChain()
        return self.grapes
Exemple #2
0
 def save_logfile(self):
     """
     saves all alphabetically sorted config attributes to logfile
     """
     attribs = self.__dict__
     
     for a in sorted(attribs.keys()):
         logfile.write_file(str(a).upper()+"."*20+" "+str(attribs[a])+"\n")
Exemple #3
0
    def save_simulation_results(self, i, lBestScoreComplex, fname=False):
        """
	Saves results of simulation to trafl file (if requested by the user) and
	to pdb files
	
	results are saved every N steps (defined by the user) and best scored
	complex in last N iterations is saved
	
	start/stop number of iterations to save (requested by the user)
	"""
        if self.traflfile and not self.server:  # and (i not in self.saved_iterations):
            for cx in lBestScoreComplex:
                cx.add_trajectory(i, cx.temp)

        for replica in lBestScoreComplex:
            if replica == None:
                continue
            if replica.simulation_score not in self.scores:
                self.scores.append(replica.simulation_score)
                if self.mReplicaTemperatures:
                    replica.save_pdb(i, replica.reptemp,
                                     fname)  #self.mReplicaTemperatures[j])
                else:
                    replica.save_pdb(i, replica.temp, fname)
                if not self.server:
                    logfile.write_file(\
                        "cx score for iteration "+str(i+1)+" is\t"+str(round(replica.simulation_score,3))\
                        +"\tcomponents: restraints: "+str(round(replica.restraints,3) * replica.restraints_penalty)+" "+\
                        "collisions: "+str(round(replica.clashes,3)    * replica.clashes_penalty)+" "+\
                        "map filling: "+str(round(replica.freespace,3) * replica.freespace_penalty)+" "+\
                        "outbox atoms: "+str(round(replica.outbox,3)     * replica.outbox_penalty)+" "+\
                        "density filling: "+str(round(replica.density,3)  * replica.density_penalty)+" "+\
                        "\tACTUAL WEIGHTS are respectively: "+str(replica.restraints_penalty)+", "+\
                        str(replica.clashes_penalty)+", "+str(replica.freespace_penalty)+", "+\
                        str(replica.outbox_penalty)+", "+str(replica.density_penalty)+"\n")

                if self.plot == True:
                    plot_cx = PlotComplex(replica, i)
                    self.saved_complexes.append(plot_cx)

            else:
                logfile.write_file("Rejected\t" +
                                   str(replica.simulation_score) +
                                   "\titer_nr\t" + str(i + 1) + "\n")

##@TODO: put into separate function
#if self.simul_params.movehistory:
#    for replica in lBestScoreComplex:
#	movehist.write_message("COMPLEX \t"+str(i)+ "\t"+str(replica.simulation_score)+"\t"+str(replica.temp))
#	for component in replica.components:
#	    movehist.write_message(str(component.pyrystruct.chain)+"\tROTATIONS\t"+str(component.rot_history)\
#			+"\tTRANSLATIONS\t"+str(list(component.trans_history)))

        self.saved_iterations.append(i)
Exemple #4
0
 def __check_shape_descriptors(self):
     """
     """
     
     if self.shapedesc:
         if self.kvol_given == False and self.threshold_given == False and self.shapedesc == "map":
             raise ConfigError("You must provide kvol or threshold value when you provide density map as input")
     
     if self.kvol_given and self.threshold_given:
         raise ConfigError("Please provide only one of these two parameters: KVOL or THRESHOLD!")
     
     if self.threshold != None:
         self.kvol = None
     
     if self.is_freespace_defined == False:
         self.freespace_penalty = [0.,0.]
         
     if self.is_density_defined == False:
         self.density_penalty = [0.,0.]
     
     if self.density_penalty[0] != 0. and self.freespace_penalty[0] != 0.:
         print ConfigError("Scoring function will penalyze shape filling twice since you defined two parameters: DENSITY and MAP_FREESPACE!")
         logfile.write_file("Scoring function will penalyze shape filling twice since you defined two parameters: DENSITY and MAP_FREESPACE!\n")
         
     if self.simbox > 10:
         raise ConfigError("The size of the system you want to use is very large. Max simbox value is 10")
     
     #when no file with density map or ab initio model was provided but density filling or mapspace weights were provided
     if self.shapedesc == False and self.is_density_defined == True: #and (self.density_penalty[0] != 0):
         raise ConfigError("Map filling cannot be calculated when no shape descriptor was provided!\n")
         logfile.write_file("Map filling cannot be calculated when no shape descriptor was provided!")
     
     #print "@@@@@@", self.shapedesc, self.is_freespace_defined
     if self.shapedesc == False and self.is_freespace_defined == True: #(self.freespace_penalty[0] != 0):
         #print "****", self.shapedesc, self.is_freespace_defined
         raise ConfigError("Map filling cannot be calculated when no shape descriptor was provided!")
         logfile.write_file("Map filling cannot be calculated when no shape descriptor was provided!\n")
     
     if self.shapedesc == "map" or self.shapedesc == "saxs": self.shapedesc = True
     
     if self.is_chi2_defined == True or self.is_rg_penalty_defined == True:
         if not self.curve:
             raise ConfigError("To verify discrepancy with SAXS/SANS curves you must provide .dat file!")
         else:
             self.crysol_outfile = open("crysol_summary.txt", "w")
             
     if self.representation == "sphere" and self.restraints_penalty[0] == 0 and self.restraints_penalty[1] == 0:
         raise ConfigError ("To validate clashes between spheres PyRy3D calculates violation of distances betweeen\
                            spheres centres. To allow this option penalty for RESTRAINTS must be different than 0 0")
     
     if self.identify_disorders == False and self.simul_dd_freq != 0.:
         raise ConfigError ("You must allow PyRy3D to identify disorders to use simulate disorder mutation. Please set IDENTIFY_DISORDER parameter into True or disable simulate disorder mutation by setting SIMUL_DD_FREQ to 0 0 values")
Exemple #5
0
    def get_map(self, saxsfile, mapfile, simul_params, first_complex):
        """
            sets Density_map object and assigns attributes  
        Parameters:
        -----------
            mapfile         : file with density map
            cx_volume       : volume of entire complex
            simul_params    : user defined simulation parameters
            vollist         : list of all complex' residues MWs
        Returns:
        --------
            mapcomponent    : Complex_map object
        """
        mapcomponent = Complex_map()
        #no shape descriptor
        if saxsfile == None and mapfile == None:
            mapcomponent.set_simbox_with_no_shape_descriptor(
                first_complex, simul_params.start_orient,
                simul_params.simboxradius, simul_params.simgridtype)
            simul_params.freespace_penalty = [0.0, 0.0]
            #return mapcomponent
        if saxsfile:
            mapcomponent.saxsfile = saxsfile
            #if 0. in simul_params.density_penalty: raise ConfigError ("To score complex compatibility with SAXS shape please use MAP_FREESPACE parameter in a configuration file")
            if simul_params.is_freespace_defined == False:
                print "WARNING! You have not provided penalty value to score a compatibility with complex shape, \
                default weight has been assigned of 1 1"

                logfile.write_file(
                    "WARNING! You have not provided penalty value to score a compatibility with complex shape, \
                default weight has been assigned of 1 1\n")
            if 0. in simul_params.freespace_penalty:
                print "WARNING! Bear in mind that a compatibility with complex shape will not be calculated at least \
                in some parts of the simulations. Check MAP_FREESPACE value in configuration file"

                logfile.write_file(
                    "WARNING! Bear in mind that a compatibility with complex shape will not be calculated at least \
                in some parts of the simulations. Check MAP_FREESPACE value in configuration file\n"
                )

            mapcomponent.set_mapgrid_by_saxs_data(simul_params.simboxradius,
                                                  simul_params.saxsradius,
                                                  simul_params.simgridtype)
        #get data when kmax is defined!
        elif simul_params.threshold == None:  #if threshold
            if mapfile:
                mapcomponent.mapfile = mapfile
                mapcomponent.set_mapgrid_by_volume(simul_params.simboxradius,
                                                   first_complex,
                                                   simul_params.kvol,
                                                   simul_params.simgridtype)
        elif simul_params.kvol == None:
            if mapfile:
                if 0. in simul_params.freespace_penalty and 0. in simul_params.density_penalty:
                    print "WARNING! Bear in mind that a compatibility with complex shape will not be calculated at least in some parts of the simulations.\
                Check MAP_FREESPACE and DENSITY values in configuration file"

                    logfile.write_file(
                        "WARNING! Bear in mind that a compatibility with complex shape will not be calculated at least in some parts of the simulations.\
                Check MAP_FREESPACE and DENSITY values in configuration file")
                if simul_params.is_freespace_defined == False and simul_params.is_density_defined == False:
                    print "WARNING! You have not provided penalty value to score a compatibility with complex shape, default weights have been assigned of 1 1 to MAP_FREESPACE and DENSITY parametrs. \
                                                      Please check whether these values are defined in a configuration file"

                mapcomponent.mapfile = mapfile
                mapcomponent.set_mapgrid_by_threshold(
                    simul_params.simboxradius, simul_params.threshold,
                    simul_params.simgridtype)
        mapcomponent.set_map_obj(simul_params.simbox, simul_params.simgridtype,
                                 simul_params.simboxradius)
        return mapcomponent
Exemple #6
0
# ---------- 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)

    #------------perform simulation!-----------------------------------------------
    #import cProfile

    if con.simul_steps != 0:
        best_complex, sim, last_complex = run_simulation(
            first_complex, con, trans.interactions, density_map, inp.traflfile)
    # best_complex, sim, last_complex = cProfile.run('run_simulation(first_complex, con, trans.interactions, density_map, inp.traflfile)')

    if inp.fullatom_file: save_fullatom_bestmodel(best_complex)

    # ---------- save log messages -------------------------------------------
    logfile.write_file()
    #if inp.movehistory_file: save_movehistory(best_complex, movehist) #movehist.write_file()
    if inp.movehistory_file:
        save_movehistory(last_complex, movehist)  #movehist.write_file()

    if inp.scoreplot: draw_scores_plot(inp.scoreplot, sim)