def test_score_option_change(self): ass=self.assignments score_bmrb1=ScoreFunction(bmrb=1) #what happens if we change the score options orig_score=score_bmrb1(ass) #prepare change of options from methods.BmrbShiftScore import BmrbShiftScoreOptions x0=score_bmrb1.methods['bmrb'].options.x0 new_options=BmrbShiftScoreOptions(x0/2) #change options in place score_bmrb1.methods['bmrb'].options=new_options self.assertNotEqual(orig_score,score_bmrb1(ass)) score_with_x0half=score_bmrb1(ass) #try illegal change of options in place def do_bad(): score_bmrb1.methods['bmrb'].options.x0=new_options.x0 self.assertRaises(TypeError, do_bad ) #now change it by differently from methods.BmrbShiftScore import BmrbShiftScore new_method=BmrbShiftScore(BmrbShiftScoreOptions(x0*2)) score_bmrb1.append(new_method,1.0) self.assertNotEqual(orig_score,score_bmrb1(ass)) self.assertNotEqual(score_with_x0half,score_bmrb1(ass))
def test_local_weights(self): ass=self.assignments score_bmrb1=ScoreFunction(bmrb=1) score_sym1=ScoreFunction(symmetry=1) score_cons1=ScoreFunction(consistency=1) #apply scores to fill local score-info score_bmrb1(ass) score_sym1(ass) score_cons1(ass) cache=ass.scores.atomic key=cache.keys()[0] self.assertEqual(0,score_sym1.evaluate_local_scores(cache[key])) self.assertNotEqual(0,score_bmrb1.evaluate_local_scores(cache[key])) cache=ass.scores.assignments #find a non-zero symmetry entry for key in cache.iterkeys(): if cache[key]['symmetry'].score!=0: break self.assertNotEqual(0,score_sym1.evaluate_local_scores(cache[key])) self.assertEqual(0,score_bmrb1.evaluate_local_scores(cache[key])) cache=ass.scores.atomic key=cache.keys()[0] bmrb1=score_bmrb1.evaluate_local_scores(cache[key]) cons1=score_cons1.evaluate_local_scores(cache[key]) self.assertEqual(bmrb1*0.2+cons1*3.2,ScoreFunction(bmrb=0.2,consistency=3.2).evaluate_local_scores(cache[key])) self.assertEqual(-bmrb1+cons1*3.2,ScoreFunction(bmrb=-1,consistency=3.2).evaluate_local_scores(cache[key]))
parser.add_argument("--starts_with", type=str, help="") parser.add_argument( "--dump_results", default="mc_sampling_results.pickle", type=str, help="results will be dumped as a pickle file" ) # you might need to change it in the future parser.add_argument("--mer", default=9, type=int, help="") parser.add_argument("--verbose", default=False, action="store_true", help="") args = parser.parse_args() print print_args(args) Wts = Weights(args.density_score_wt, args.overlap_score_wt, args.closab_score_wt, args.clash_score_wt) Scorefxn = ScoreFunction( args.density_scorefile, args.overlap_scorefile, args.nonoverlap_scorefile, Wts, args.null_frag_score ) for each_round in range(1, args.round + 1): Pose = Pose() Pose.initialization(Scorefxn.density_score_dict) # default initialize by random Scorefxn.update_pose(Pose) working_temp = args.temperature for each_step in range(args.steps): print "round: %s cycle: %s" % (each_round, each_step) pos = random.sample(Pose.dict.keys(), 1)[0] # pick a residue number to start with
pos_list = list( set([ tag[1] for tag in overlap_score_Dict.keys() ]) ) # inital placement '''selected_frags_Dict = { residue_number : ( ( mer, pos, picker_rank, SHD_rank ), ( boltzmann_prob, total_score ), ( density_score, rmsd ) ) ''' ''' after the first round, every position has a fragment assigned, now we can start do Monte Carlo sampling ''' #selected_frags_Dict = {} # three object are being created etable = ScoreTable( density_score_Dict, overlap_score_Dict, nonoverlap_score_Dict ) wts = Weights( args.density_score_wt, args.overlap_score_wt, args.closab_score_wt, args.clash_score_wt ) scorefxn = ScoreFunction( etable, wts, args.null_frag_score ) for each_round in range( 1, args.round+1 ): scorefxn.clean_selected_frags_dict() #mypose = Pose() if args.starts_with: assert not args.dump_results == args.starts_with print "Initialize with %s" % args.starts_with pkl = open( args.starts_with , "rb" ) scorefxn.selected_frags_dict = pickle.load( pkl ) else: scorefxn.initialize( args.initialization ) for each_step in range( args.steps ): print "round: %s cycle: %s" %( each_round, each_step )
pos_list = list( set([ tag[1] for tag in overlap_score_Dict.keys() ]) ) # inital placement '''selected_frags_Dict = { residue_number : ( ( mer, pos, picker_rank, SHD_rank ), ( boltzmann_prob, total_score ), ( density_score, rmsd ) ) ''' ''' after the first round, every position has a fragment assigned, now we can start do Monte Carlo sampling ''' #selected_frags_Dict = {} # three object are being created etable = ScoreTable( density_score_Dict, overlap_score_Dict, nonoverlap_score_Dict ) wts = Weights( args.density_score_wt, args.overlap_score_wt, args.closab_score_wt, args.clash_score_wt ) scorefxn = ScoreFunction( etable, wts, args.null_frag_score ) for each_round in range( 1, args.round+1 ): scorefxn.clean_selected_frags_dict() if args.starts_with: assert not args.dump_results == args.starts_with print "Initialize with %s" % args.starts_with pkl = open( args.starts_with , "rb" ) scorefxn.selected_frags_dict = pickle.load( pkl ) else: if args.initialization == "lowdens": scorefxn.lowest_density_score_placements() elif args.initialization == "random": scorefxn.randomize_initial_placements() for each_step in range( args.steps ): print "round: %s cycle: %s" %( each_round, each_step )