Example #1
0
    def apply( self, pose, steps, run_tag=None, mer=9 ): # this is silly to put the mer here, as a indicator to name a null_frag_id )
        ''' '''
        assert isinstance( pose, Pose )
        assert pose._initialized

        self._scorefxn.update_pose( pose ) # make sure the pose in the score function to score with is the current one

        for step in range( steps ):
            pos = random.sample( pose._dict.keys(), 1 )[0] 

            boltzmann = Boltzmann( self._temperature )
            candidate_frags = self._scorefxn._density_score_dict[ pos ].keys() # this has included a "null_frag_id" when initialize density_score_dict

            ''' After picking a position to optimize, calculate compatibility scores for all the candidate placements at that residue '''
            for frag_id in candidate_frags:

                container = self._scorefxn.score_evaluator( frag_id )
                boltzmann.probability( container )

            #### end of calculating all the candidate_frags at the residue to the selected ones ####

            # normalize it 
            boltzmann.normalization()

            # pick one frag
            selected_frag_id = boltzmann.pick_frag()
            #print "step %s: frag_id: %s %s got picked!!" %( step, selected_frag_id, boltzmann._norm_dict[ selected_frag_id ] )

            # update pose
            SelectedContainer = self._scorefxn.score_evaluator( selected_frag_id ) # bc this only return scores
            SelectedContainer.update_boltz( boltzmann )

            pose.update_pose_dict_by_rsd( SelectedContainer )
            self._scorefxn.update_pose( pose )
Example #2
0
    def apply( self, pose, steps ): 
        ''' 
        refactor it to take indices - avoid any lookup during the run
        '''
        assert isFragIdxPose( pose )
        self.__scorefxn.update_pose( pose ) # make sure the pose in the score function to score with is the current one

        # for each step, randomly select one pos to optimize
        for step in range( steps ):
            pos = random.sample( pose.positions(), 1 )[0] 
            boltzmann = Boltzmann( self._temperature )

            ''' After picking a position to optimize, calculate compatibility scores for all the candidate placements at that residue '''
            for frag_idx in self.__scorefxn.get_candidate_frags( pos ):
                score = self.__scorefxn( frag_idx ) # evaluate the score here
                #print score, frag_idx
                boltzmann.cal_probability( frag_idx, score ) # the residue is designed for storing scores information in residue for future debugging
            boltzmann.normalization()
            #### end of calculating all the candidate_frags at the residue to the selected ones ####

            # pick one frag, return an Residue object with updated boltzmann which stores probability of all the candidate frags at that residue
            selected_frag_idx = boltzmann.pick_frag() # return frag_idx
            pose.update_residue( pos, selected_frag_idx ) # shall update pos and the selected frag_idx
            self.__scorefxn.update_pose( pose )