Skip to content
Snippets Groups Projects
Select Git revision
  • 108c8f0ec55cee80e9fe6912b4e14ff81d45f77d
  • master default protected
  • develop protected
  • conda
  • 3.6.0
  • 3.5.0
  • 3.4.2
  • 3.4.1
  • 3.4.0
  • 3.4.0-rc2
  • 3.4.0-rc
  • 3.3.1
  • 3.3.1-rc
  • 3.3.0
  • 3.3.0-rc2
  • 3.3.0-rc
  • 3.2.1
  • 3.2.1-rc
  • 3.2.0
  • 3.2.0-rc
  • 3.1.1
  • 3.1.1-rc2
  • 3.1.1-rc
  • 3.1.0
24 results

_denovo.py

Blame
  • Gabriel Studer's avatar
    Studer Gabriel authored
    The idea is to make the backbone scoring consistent with the all atom scoring.
    Before, a BackboneList had to be provided for each scoring action. There were
    therefore two types of interactions: interactions towards the scoring environment
    and interactions within the BackboneList. Now, the BackboneList is set to the
    scoring environment before scoring. There are now ONLY interactions towards the
    environment. What remains is: profiling / documentation update
    
    Advantages:
     - If you want to score several loops at once, you have less mess to sort out
       which interactions are towards the environment and which ones are within
       the different loops. (And that was the main goal)
     - Consistent interface between backbone scoring, all atom scoring and
       SidechainReconstructor
     - Less code duplication. The env listeners do some precalculations. These
       precalculations had to be done for the actual loops as well.
    914851d9
    History
    _denovo.py 5.96 KiB
    from promod3 import scoring, loop
    from _modelling import *
    
    def GenerateDeNovoTrajectories(sequence, 
                                   num_trajectories = 200,
                                   avg_sampling_per_position = 600,
                                   profile = None,
                                   psipred_prediction = None,
                                   fragment_handler = None,
                                   scorer = None,
                                   scorer_env = None,
                                   scoring_weights = None):
        '''Example de novo modelling pipeline based on Fragment sampling and
        backbone scoring. Take this as a starting point for more advanced
        de novo procedures.
    
        :param sequence:    The sequence you want to sample
        :type sequence:     :class:`str`
    
        :param num_trajectories:  The number of sampling trajectories you
                                  want to generate 
        :type num_trajectories:   :class:`int`
    
        
        :param avg_sampling_per_position: Number of Monte Carlo sampling steps
                                          the total number is: 
                                          len(**sequence**) * **avg_sampling_per_position** 
    
        :param profile:     The sequence profile for **sequence**. This increases the 
                            fragment search performance.
        :type profile:      :class:`ost.seq.ProfileHandle`
    
        :param psipred_prediction: The psipred prediction for **sequence**. This
                                   increases the fragment search performance
        :type psipred_prediction:  :class:`promod3.loop.PsipredPrediction`
    
        :param fragment_handler: You can provide already initialized fragments.
                                 If you pass this parameter, **profile** and
                                 **psipred_prediction** get neglected and do
                                 not influence the fragment search, the
                                 ones you initialized **fragment_handler** with
                                 get used instead.
        :type fragment_handler:  :class:`promod3.modelling.FraggerHandle`
    
        :param scorer:      Scorer doing the backbone scoring. If not provided, a 
                            default one gets loaded with default objects with
                            following keys: clash, reduced, cb_packing, hbond, cbeta, 
                            torsion and pairwise 
        :type scorer:       :class:`promod3.scoring.BackboneOverallScorer`
    
        :param scorer_env:  The scoring env that relates to **scorer**
                            This environment will be changed! 
        :type scorer_env:   :class:`promod3.scoring.BackboneScoreEnv`
    
        :param scoring_weights: Linear weights for different scores. If not provided,
                                the output of ScoringWeights.GetWeights() is used.
                                Please note, that the weights must be consistent
                                with the keys of the scores in **scorer**
        :type scoring_weights:  :class:`dict`
    
        :returns:           A :class:`promod3.loop.LoopCandidates` object containing
                            **num_trajectories** elements for further processing
        '''
    
        if len(sequence) < 9:
            raise RuntimeError("Seq too short for Denovo sampling (min length 9)")
    
        # check whether profile / psipred_prediction are consistent if present
        if profile != None:
          if profile.sequence != sequence:
              err = "Sequence of profile must match input sequence!"
              raise RuntimeError(err)
    
        if psipred_prediction != None:
            if len(sequence) != len(psipred_prediction):
                err = "psipred_prediction must be consistent with the input sequence!"
                raise RuntimeError(err)
    
        if scorer != None and scorer_env == None:
          raise RuntimeError("Must provide an environment when you provide a scorer!")
    
        if fragment_handler == None:
            # we first have to build our own handler
            fragment_handler = modelling.FraggerHandle(sequence, 
                                                       profile = profile, 
                                                       psipred_pred = psipred_prediction)
        fragger_list = fragment_handler.GetList()
    
        if scorer == None:
            # Lets setup a scorer with empty environment
            scorer = scoring.BackboneOverallScorer()
            scorer_env = scoring.BackboneScoreEnv(sequence)
            scorer["clash"] = scoring.ClashScorer()
            scorer["reduced"] = scoring.LoadReducedScorer()
            scorer["cb_packing"] = scoring.LoadCBPackingScorer()
            scorer["hbond"] = scoring.LoadHBondScorer()
            scorer["cbeta"] = scoring.LoadCBetaScorer()
            scorer["torsion"] = scoring.LoadTorsionScorer()
            scorer["pairwise"] = scoring.PairwiseScorer()
            scorer.AttachEnvironment(scorer_env)
    
        if scoring_weights == None:
            scoring_weights = ScoringWeights.GetWeights()
    
        # the number of 109 is roughly the number of times we have to apply
        # a factor of 0.9 to 100 until it reaches a value of 0.001
        start_temperature = 100
        cooling_factor = 0.9
        sampling_steps = avg_sampling_per_position * len(fragger_list)
        cooling_interval = sampling_steps / 109
    
        mc_sampler = FragmentSampler(sequence, fragger_list, 
                                     init_fragments = 5)
        mc_closer = DeNovoCloser()
        mc_scorer = LinearScorer(scorer, scorer_env, 1, len(sequence), 0, 
                                 scoring_weights)
        mc_cooler = ExponentialCooler(start_temperature,
                                      cooling_interval,
                                      cooling_factor)
    
        candidates = LoopCandidates.FillFromMonteCarloSampler(sequence,
                                                              num_trajectories,
                                                              sampling_steps,
                                                              mc_sampler,
                                                              mc_closer,
                                                              mc_scorer,
                                                              mc_cooler)  
        return candidates