def get_dist_restraints(filename, s, scaler): dists = [] rest_group = [] lines = open(filename).read().splitlines() lines = [line.strip() for line in lines] for line in lines: if not line: dists.append(s.restraints.create_restraint_group(rest_group, 1)) rest_group = [] else: cols = line.split() i = int(cols[0]) name_i = cols[1] j = int(cols[2]) name_j = cols[3] dist = float(cols[4]) / 10. rest = s.restraints.create_restraint('distance', scaler, LinearRamp(0, 100, 0, 1), r1=0.0, r2=0.0, r3=dist, r4=dist + 0.2, k=250, atom_1_res_index=i, atom_2_res_index=j, atom_1_name=name_i, atom_2_name=name_j) rest_group.append(rest) return dists
def make_pairON(g, s, i, j, scaler, CO=True, doing_eco=False, eco_factor=0.0, eco_constant=1.0, eco_linear=0.0): contact_order = abs(i - j) if CO: tmp_scaler = scaler(contact_order, 'strand') else: tmp_scaler = scaler g.append( s.restraints.create_restraint('distance', tmp_scaler, LinearRamp(0, 100, 0, 1), r1=0.0, r2=0.0, r3=0.35, r4=0.50, k=250.0, doing_eco=doing_eco, eco_factor=eco_factor, eco_constant=eco_constant, eco_linear=eco_linear, atom_1_res_index=i, atom_1_name='O', atom_2_res_index=j, atom_2_name='N'))
def get_knob_restraints(filename, s, scaler): dists = [] lines = open(filename).read().splitlines() lines = [line.strip() for line in lines] high = 0 total = 0 for line in lines: cols = line.split() i = int(cols[0]) name_i = cols[2] j = int(cols[3]) name_j = cols[5] dist = float(cols[6]) / 10. sd = float(cols[7]) / 10. accuracy = float(cols[8]) if name_i not in ["CA","CB"]: continue if name_j not in ["CA","CB"]: continue if abs(i-j) < 6: continue if accuracy > 0.5: high = high + 1 total = total + 1 rest = s.restraints.create_restraint('distance', scaler,LinearRamp(0,100,0,1), r1=max(0,dist-sd-0.2), r2=max(0,dist-sd), r3=dist+sd, r4=dist+sd+0.2, k=250, atom_1_res_index=i, atom_2_res_index=j, atom_1_name=name_i, atom_2_name=name_j) #collections are parallel; groups are in one gpu thread dists.append(s.restraints.create_restraint_group([rest], 1)) return dists,float(high)/float(total)*0.95
def make_pairON(g,s,i,j,scaler,CO=True): contact_order = abs(i-j) if CO: tmp_scaler = scaler(contact_order,'strand') else: tmp_scaler = scaler g.append(s.restraints.create_restraint('distance', tmp_scaler,LinearRamp(0,100,0,1), r1=0.0, r2=0.0, r3=0.35, r4=0.50, k=250.0, atom_1_res_index=i, atom_1_name='O', atom_2_res_index=j, atom_2_name='N'))
def setup_system(): # load the sequence sequence = parse.get_sequence_from_AA1(filename='sequence.dat') n_res = len(sequence.split()) # build the system p = system.ProteinMoleculeFromSequence(sequence) b = system.SystemBuilder() s = b.build_system_from_molecules([p]) s.temperature_scaler = system.GeometricTemperatureScaler( 0, 0.4, 300., 550.) # # Secondary Structure # ss_scaler = s.restraints.create_scaler('constant') ss_rests = parse.get_secondary_structure_restraints( filename='ss.dat', system=s, scaler=ss_scaler, torsion_force_constant=2.5, distance_force_constant=2.5) n_ss_keep = int(len(ss_rests) * 0.70) #We enforce 70% of restrains s.restraints.add_selectively_active_collection(ss_rests, n_ss_keep) # # Confinement Restraints # conf_scaler = s.restraints.create_scaler('constant') confinement_rests = [] confinement_dist = (16.9 * np.log(s.residue_numbers[-1]) - 15.8) / 28. for index in range(n_res): rest = s.restraints.create_restraint('confine', conf_scaler, LinearRamp(0, 100, 0, 1), res_index=index + 1, atom_name='CA', radius=confinement_dist, force_const=250.0) confinement_rests.append(rest) s.restraints.add_as_always_active_list(confinement_rests) # # Distance Restraints # # High reliability # dist_scaler = s.restraints.create_scaler('nonlinear', alpha_min=0.4, alpha_max=1.0, factor=4.0) #contact80_dist = get_dist_restraints('target_contacts_over_80.dat', s, dist_scaler) #n_high_keep = int(0.80 * len(contact80_dist)) #s.restraints.add_selectively_active_collection(contact80_dist, n_high_keep) # # Long # #contact60_dist = get_dist_restraints('target_contacts_over_60.dat', s, dist_scaler) #n_high_keep = int(0.60 * len(contact60_dist)) #s.restraints.add_selectively_active_collection(contact60_dist, n_high_keep) # # Heuristic Restraints # subset = np.array(range(n_res)) + 1 # # Hydrophobic # create_hydrophobes(s, scaler=dist_scaler, group_1=subset) # # Strand Pairing # sse, active = make_ss_groups(subset=subset) generate_strand_pairs(s, sse, active, subset=subset) # create the options options = system.RunOptions() options.implicit_solvent_model = 'gbNeck2' options.use_big_timestep = True options.cutoff = 1.8 options.use_amap = True options.amap_beta_bias = 1.0 options.timesteps = 14286 options.minimize_steps = 20000 # create a store store = vault.DataStore(s.n_atoms, N_REPLICAS, s.get_pdb_writer(), block_size=BLOCK_SIZE) store.initialize(mode='w') store.save_system(s) store.save_run_options(options) # create and store the remd_runner l = ladder.NearestNeighborLadder(n_trials=48 * 48) policy = adaptor.AdaptationPolicy(2.0, 50, 50) a = adaptor.EqualAcceptanceAdaptor(n_replicas=N_REPLICAS, adaptation_policy=policy) remd_runner = master_runner.MasterReplicaExchangeRunner(N_REPLICAS, max_steps=N_STEPS, ladder=l, adaptor=a) store.save_remd_runner(remd_runner) # create and store the communicator c = comm.MPICommunicator(s.n_atoms, N_REPLICAS) store.save_communicator(c) # create and save the initial states states = [gen_state(s, i) for i in range(N_REPLICAS)] store.save_states(states, 0) # save data_store store.save_data_store() return s.n_atoms
def setup_system(): # create the system starting from coordinates in template.pdb templates = glob.glob('%s-sep.pdb' % (sys.argv[1])) p = system.ProteinMoleculeFromPdbFile(templates[0]) b = system.SystemBuilder(forcefield="ff14sbside") # load non-standard AA force field params, bonds s = b.build_system_from_molecules([p]) # Create temperature ladder s.temperature_scaler = system.GeometricTemperatureScaler( 0.0, 0.5, 300., 500.) # Keep protein dimer conformation fairly constant dist_scaler = s.restraints.create_scaler('nonlinear', alpha_min=0.4, alpha_max=1.0, factor=4.0) const_scaler = s.restraints.create_scaler('constant') dist = keep_fixed_distance('%s-contacts.dat' % (sys.argv[1]), s, scaler=const_scaler) s.restraints.add_selectively_active_collection(dist, int(len(dist))) # Keep DNA hbonds #Read sequence file sequenceDNA = readSeq('%s-seq.dat' % (sys.argv[1])) #Generate hbondsDNA.dat make_hbond_restraint_file(sequenceDNA, 0) dist_scaler3 = s.restraints.create_scaler('nonlinear', alpha_min=0.9, alpha_max=1.0, factor=4.0) dist = keep_fixed_distance('hbondsDNA.dat', s, scaler=const_scaler) s.restraints.add_selectively_active_collection(dist, int(len(dist))) # Keep DNA close to starting conformation rest = make_cartesian_collections(s, const_scaler, range(1, 43), atoms=[ "C1'", "C2", "C2'", "C3'", "C4", "C4'", "C5", "C5'", "C6", "C7", "C8", "DA3", "N1", "N2", "N3", "N4", "N6", "N7", "N9", "O2", "O3'", "O4", "O4'", "O5'", "O6", "OP1", "OP2", "P" ]) # rest = make_cartesian_collections(s, const_scaler, range(1,16),atoms=["C1'", "C2", "C2'", "C3'", "C4", "C4'", "C5", "C5'", "C6", "N1", "N3", "O3'", "O4'"]) #These are the common atoms to all DNA bases including ends: #C1' C2 C2' C3' C4 C4' C5 C5' C6 N1 N3 O3' O4' O5' s.restraints.add_as_always_active_list(rest) # Create Contacts between protein and DNA dom1 = get_dist_restraints('%s-DNA-contacts.dat' % (sys.argv[1]), s, scaler=dist_scaler) s.restraints.add_selectively_active_collection(dom1, int(len(dom1))) # Find Glycines and Restrain peptide within reasonable distance from DNA names = np.array(s.atom_names) resid = np.array(s.residue_numbers) # resnames = np.array(s.residue_names) select = names == 'CB' non_gly = resid[select] # scaler3 = s.restraints.create_scaler('nonlinear',alpha_min=0.7,alpha_max=1.0, factor=4.0, strength_at_alpha_min=1.0, strength_at_alpha_max=0.5) # conf_rest = [] # group1 = [] # group2 = [] # for i in range(2,21): # group1.append( (i,"O5'") ) # for i in range(22,41): # group1.append( (i,"O5'") ) # for j in non_gly: # group2.append( (j,"CB") ) # positioner = s.restraints.create_scaler('linear_positioner',alpha_min=0.7, alpha_max=1.0, pos_min=10., pos_max=15.) # conf_rest.append(s.restraints.create_restraint('com', scaler3,ramp=LinearRamp(0,100,0,1), # force_const=75.0,group1=group1,group2=group2, # distance =positioner,weights1=None, weights2=None, dims='xyz')) # s.restraints.add_as_always_active_list(conf_rest) dist_scaler2 = s.restraints.create_scaler('nonlinear', alpha_min=0.7, alpha_max=1.0, factor=4.0) res_groups = get_distance_rests('%s-res_groups.dat' % (sys.argv[1]), s, scaler=dist_scaler2) s.restraints.add_selectively_active_collection(res_groups, int(len(res_groups) - 10)) # # Secondary Structure # ss_scaler = s.restraints.create_scaler('constant') ss_rests = parse.get_secondary_structure_restraints( filename='%s-ss.dat' % (sys.argv[1]), system=s, ramp=LinearRamp(0, 100, 0, 1), scaler=ss_scaler, torsion_force_constant=2.5, distance_force_constant=2.5) n_ss_keep = int(len(ss_rests) * 0.96) s.restraints.add_selectively_active_collection(ss_rests, n_ss_keep) # create the options options = system.RunOptions() options.implicit_solvent_model = 'gbNeck2' options.remove_com = False options.use_big_timestep = False # MD timestep (3.3 fs) options.use_bigger_timestep = True # MD timestep (4.0 fs) options.cutoff = 1.8 # cutoff in nm options.soluteDielectric = 1. #options.implicitSolventSaltConc = None options.use_amap = False # correction to FF12SB options.amap_beta_bias = 1.0 options.timesteps = 11111 # number of MD steps per exchange options.minimize_steps = 20000 # init minimization steps # create a store store = vault.DataStore(s.n_atoms, N_REPLICAS, s.get_pdb_writer(), block_size=BLOCK_SIZE) store.initialize(mode='w') store.save_system(s) store.save_run_options(options) # create and store the remd_runner, sets up replica exchange details l = ladder.NearestNeighborLadder(n_trials=48) policy = adaptor.AdaptationPolicy(2.0, 50, 50) a = adaptor.EqualAcceptanceAdaptor(n_replicas=N_REPLICAS, adaptation_policy=policy) remd_runner = master_runner.MasterReplicaExchangeRunner(N_REPLICAS, max_steps=N_STEPS, ladder=l, adaptor=a) store.save_remd_runner(remd_runner) # create and store the communicator c = comm.MPICommunicator(s.n_atoms, N_REPLICAS) store.save_communicator(c) # create and save the initial states # create and save the initial states, initialize each replica with a different template states = [gen_state_templates(i, templates) for i in range(N_REPLICAS)] store.save_states(states, 0) # save data_store store.save_data_store() return s.n_atoms
def setup_system(): # ECO settings #eco_cutoff = 0.8 # the distance (in nm) that qualifies as a connection in the graph eco_cutoff = 1.0 # the distance (in nm) that qualifies as a connection in the graph doing_eco_hydrophobe = True doing_eco_hbond = True doing_eco_2ndary = False doing_eco_strand_pairing = True doing_eco_knob = False doing_eco_evolutionary = False #eco_factor = 4.0 # the factor by which we multiply the eco energy adjustment eco_factor = 1 # the factor by which we multiply the eco energy adjustment eco_constant = 0.0 # In theory, these could be changed for any restraint eco_linear = 0.0 # load the sequence sequence = parse.get_sequence_from_AA1(filename='sequence.dat') n_res = len(sequence.split()) # build the system p = system.ProteinMoleculeFromSequence(sequence) b = system.SystemBuilder(forcefield="ff14sbside") s = b.build_system_from_molecules([p]) s.temperature_scaler = system.GeometricTemperatureScaler( 0, 0.6, 300., 450.) # # Secondary Structure # ss_scaler = s.restraints.create_scaler('constant') ss_rests = parse.get_secondary_structure_restraints( filename='ss.dat', system=s, ramp=LinearRamp(0, 100, 0, 1), scaler=ss_scaler, torsion_force_constant=2.5, distance_force_constant=2.5, doing_eco=doing_eco_2ndary, eco_factor=eco_factor, eco_constant=eco_constant, eco_linear=eco_linear) n_ss_keep = int(len(ss_rests) * 0.70) #We enforce 70% of restrains s.restraints.add_selectively_active_collection(ss_rests, n_ss_keep) # # Confinement Restraints # #conf_scaler = s.restraints.create_scaler('nonlinear', alpha_min=0.4, alpha_max=1.0, factor=4.0,strength_at_alpha_min=0.0, strength_at_alpha_max=1.0) #confinement_rests = [] #confinement_dist = (16.9*np.log(s.residue_numbers[-1])-15.8)/28.*1.2 #for index in range(n_res): # rest = s.restraints.create_restraint('confine', conf_scaler, LinearRamp(0,100,0,1),res_index=index+1, atom_name='CA', radius=confinement_dist, force_const=250.0) # confinement_rests.append(rest) #s.restraints.add_as_always_active_list(confinement_rests) # # Distance Restraints # dist_scaler = s.restraints.create_scaler('nonlinear', alpha_min=0.4, alpha_max=1.0, factor=4.0) # High reliability # # # Create Plateau kind of scalers # low_2 = make_CO_scaler(system=s, scaler_type='plateaunonlinear', alpha_min=0.70, alpha_one=0.85, alpha_two=0.85, alpha_max=1.0, strength_at_alpha_min=1.0, strength_at_alpha_max=0.0) low_4 = make_CO_scaler(system=s, scaler_type='plateaunonlinear', alpha_min=0.55, alpha_one=0.70, alpha_two=0.70, alpha_max=0.85, strength_at_alpha_min=1.0, strength_at_alpha_max=0.0) low_6 = s.restraints.create_scaler('plateaunonlinear', alpha_min=0.40, alpha_one=0.55, alpha_two=0.55, alpha_max=0.7, factor=4.0, strength_at_alpha_min=1.0, strength_at_alpha_max=0.0) low_8 = s.restraints.create_scaler('nonlinear', alpha_min=0.40, alpha_max=0.55, factor=4.0) # # Heuristic Restraints # subset = np.array(range(n_res)) + 1 # # Hydrophobic # create_hydrophobes(s, ContactsPerHydroph=1.2, scaler=dist_scaler, group_1=subset, CO=False, doing_eco=doing_eco_hydrophobe, eco_factor=eco_factor, eco_constant=eco_constant, eco_linear=eco_linear) #create_hydrophobes(s,ContactsPerHydroph=1.2/4.,scaler=low_2,group_1=subset,CO=True) #create_hydrophobes(s,ContactsPerHydroph=1.2/2.,scaler=low_4,group_1=subset,CO=True) #create_hydrophobes(s,ContactsPerHydroph=1.2*3/4.,scaler=low_6,group_1=subset,CO=False) #create_hydrophobes(s,ContactsPerHydroph=1.2,scaler=low_8,group_1=subset,CO=False) # # HBonds # create_HydrogenBond(s, HBPerResidue=0.10, scaler=dist_scaler, group_1=subset, CO=False, doing_eco=doing_eco_hbond, eco_factor=eco_factor, eco_constant=eco_constant, eco_linear=eco_linear) #create_HydrogenBond(s,HBPerResidue=0.10/4.,scaler=low_2,group_1=subset,CO=True) #create_HydrogenBond(s,HBPerResidue=0.10/2.,scaler=low_4,group_1=subset,CO=True) #create_HydrogenBond(s,HBPerResidue=0.10*3/4.,scaler=low_6,group_1=subset,CO=False) #create_HydrogenBond(s,HBPerResidue=0.10,scaler=low_8,group_1=subset,CO=False) # # Strand Pairing # sse, active = make_ss_groups(subset=subset) try: generate_strand_pairs(s, sse, float(active), subset=subset, scaler=dist_scaler, CO=False, doing_eco=doing_eco_strand_pairing, eco_factor=eco_factor, eco_constant=eco_constant, eco_linear=eco_linear) #generate_strand_pairs(s,sse,float(active)/4.,subset=subset,scaler=low_2,CO=True) #generate_strand_pairs(s,sse,float(active)/2.,subset=subset,scaler=low_4,CO=True) #generate_strand_pairs(s,sse,float(active)*3/4.,subset=subset,scaler=low_6,CO=False) #generate_strand_pairs(s,sse,float(active),subset=subset,scaler=low_8,CO=False) except: print "Not using Strand Pairing Heuristic" pass # # Evolutionary restraints # try: create_Evolution(s, scaler=dist_scaler, fname='evolution_contacts.dat', doing_eco=doing_eco_evolutionary, eco_factor=eco_factor, eco_constant=eco_constant, eco_linear=eco_linear) except: print "Not using Evolutionary restraints" pass # # Distance Restraints # # # Knob restraints # try: knobs, knob_accuracy = get_knob_restraints('Knob.data', s, scaler=dist_scaler, doing_eco=doing_eco_knob, eco_factor=eco_factor, eco_constant=eco_constant, eco_linear=eco_linear) n_knobs = int(len(knobs) * knob_accuracy) s.restraints.add_selectively_active_collection(knobs, n_knobs) except: print "Not using Knob-Socket predictions" pass # setup mcmc at startup movers = [] n_atoms = s.n_atoms for i in range(1, n_res + 1): n = s.index_of_atom(i, 'N') - 1 ca = s.index_of_atom(i, 'CA') - 1 c = s.index_of_atom(i, 'C') - 1 mover = mc.DoubleTorsionMover(n, ca, list(range(ca, n_atoms)), ca, c, list(range(c, n_atoms))) movers.append((mover, 1)) sched = mc.MonteCarloScheduler(movers, n_res * 60) # create the options options = system.RunOptions() options.implicit_solvent_model = 'gbNeck2' options.use_big_timestep = False options.use_bigger_timestep = True options.cutoff = 1.8 #options.eco_cutoff = eco_cutoff # set eco_output very high so that log file does not print options.eco_params = { 'eco_cutoff': 1.0, 'eco_output_freq': 10000000, 'print_avg_eco': False, 'print_eco_value_array': False, } options.use_amap = False options.amap_beta_bias = 1.0 options.timesteps = 11111 options.minimize_steps = 20000 options.min_mc = sched options.make_alpha_carbon_list(s.atom_names) print "alpha_carbon_indeces:", options.alpha_carbon_indeces # create a store store = vault.DataStore(s.n_atoms, N_REPLICAS, s.get_pdb_writer(), block_size=BLOCK_SIZE) store.initialize(mode='w') store.save_system(s) store.save_run_options(options) # create and store the remd_runner l = ladder.NearestNeighborLadder(n_trials=48 * 48) policy = adaptor.AdaptationPolicy(2.0, 50, 50) a = adaptor.EqualAcceptanceAdaptor(n_replicas=N_REPLICAS, adaptation_policy=policy) remd_runner = master_runner.MasterReplicaExchangeRunner(N_REPLICAS, max_steps=N_STEPS, ladder=l, adaptor=a) store.save_remd_runner(remd_runner) # create and store the communicator c = comm.MPICommunicator(s.n_atoms, N_REPLICAS) store.save_communicator(c) # create and save the initial states states = [gen_state(s, i) for i in range(N_REPLICAS)] store.save_states(states, 0) # save data_store store.save_data_store() return s.n_atoms
def create_HydrogenBond(s, HBPerResidue=0.10, scaler=None, group_1=np.array([]), group_2=np.array([]), CO=True, doing_eco=False, eco_factor=0.0, eco_constant=1.0, eco_linear=0.0): all_donor = ['N'] all_acceptor = ['O'] acceptors = { "SER": ['OG'], "THR": ['OG1'], "CYS": ['SG'], "TYR": ['OH'], "ASN": ['OD1', 'ND2'], "GLN": ['OE1', 'NE2'], "ASP": ['OD1', 'OD2'], "GLU": ['OE1', 'OE2'], "ARG": ['NE', 'NH1', 'NH2'], "HIE": ['ND1', 'NE2'] } donors = { "SER": ['OG'], "THR": ['OG1'], "CYS": ['SG'], "TYR": ['OH'], "ASN": ['ND2'], "GLN": ['NE2'], "LYS": ['NZ'], "ARG": ['NE', 'NH1', 'NH2'], "HIE": ['NE2'], "LYS": ['NZ'] } #Groups should be 1 centered n_res = s.residue_numbers[-1] group_1 = group_1 if group_1.size else np.array(range(n_res)) + 1 group_2 = group_2 if group_2.size else np.array(range(n_res)) + 1 scaler = scaler if scaler else s.restraints.create_scaler( 'nonlinear', alpha_min=0.4, alpha_max=1.0, factor=4.0) #Get a list of names and residue numbers, if just use names might skip some residues that are two #times in a row #make list 1 centered sequence = [(i, j) for i, j in zip(s.residue_numbers, s.residue_names)] sequence = sorted(set(sequence)) sequence = dict(sequence) pairs = [] HB_restraints = [] for i in group_1: for j in group_2: # don't put the same pair in more than once if ((i, j) in pairs) or ((j, i) in pairs): continue if (i == j): continue #Alpha helices are 1-4, exclude them from this since they have the ss heuristic if (abs(i - j) < 5): continue if (abs(i - j) > 10): continue pairs.append((i, j)) if CO: tmp_scaler = scaler(abs(i - j), 'Hbond') else: tmp_scaler = scaler local_contact = [] #i as donor atoms_i = [] atoms_i.extend(all_donor) try: #some residues do not have donors atoms_i.extend(donors[sequence[i]]) except: pass #j as acceptor atoms_j = [] atoms_j.extend(all_acceptor) try: #some residues do not have donors atoms_j.extend(acceptors[sequence[j]]) except: pass #print "DONORS: ",i,sequence[i],atoms_i #print "ACCEPTORS: ",j,sequence[j],atoms_j for a_i in atoms_i: for a_j in atoms_j: local_contact.append( s.restraints.create_restraint( 'distance', tmp_scaler, LinearRamp(0, 100, 0, 1), r1=0.0, r2=0.0, r3=0.50, r4=0.65, k=250.0, doing_eco=doing_eco, eco_factor=eco_factor, eco_constant=eco_constant, eco_linear=eco_linear, atom_1_res_index=i, atom_1_name=a_i, atom_2_res_index=j, atom_2_name=a_j)) #j as donor atoms_j = [] atoms_j.extend(all_donor) try: #some residues do not have donors atoms_i.extend(donors[sequence[j]]) except: pass #i as acceptor atoms_i = [] atoms_i.extend(all_acceptor) try: #some residues do not have donors atoms_j.extend(acceptors[sequence[j]]) except: pass for a_i in atoms_i: for a_j in atoms_j: local_contact.append( s.restraints.create_restraint( 'distance', tmp_scaler, LinearRamp(0, 100, 0, 1), r1=0.0, r2=0.0, r3=0.50, r4=0.65, k=250.0, doing_eco=doing_eco, eco_factor=eco_factor, eco_constant=eco_constant, eco_linear=eco_linear, atom_1_res_index=i, atom_1_name=a_i, atom_2_res_index=j, atom_2_name=a_j)) HB_restraints.append( s.restraints.create_restraint_group(local_contact, 1)) all_rest = len(HB_restraints) active = int(HBPerResidue * len(group_1)) print "Hydrogen bond:" print active, len(group_1), all_rest s.restraints.add_selectively_active_collection(HB_restraints, active)
def create_hydrophobes(s, ContactsPerHydroph=1.3, scaler=None, group_1=np.array([]), group_2=np.array([]), CO=True, doing_eco=False, eco_factor=0.0, eco_constant=1.0, eco_linear=0.0): atoms = { "ALA": ['CA', 'CB'], "VAL": ['CA', 'CB', 'CG1', 'CG2'], "LEU": ['CA', 'CB', 'CG', 'CD1', 'CD2'], "ILE": ['CA', 'CB', 'CG1', 'CG2', 'CD1'], "PHE": ['CA', 'CB', 'CG', 'CD1', 'CE1', 'CZ', 'CE2', 'CD2'], "TRP": [ 'CA', 'CB', 'CG', 'CD1', 'NE1', 'CE2', 'CZ2', 'CH2', 'CZ3', 'CE3', 'CD2' ], "MET": ['CA', 'CB', 'CG', 'SD', 'CE'], "PRO": ['CD', 'CG', 'CB', 'CA'] } #Groups should be 1 centered n_res = s.residue_numbers[-1] group_1 = group_1 if group_1.size else np.array(range(n_res)) + 1 group_2 = group_2 if group_2.size else np.array(range(n_res)) + 1 scaler = scaler if scaler else s.restraints.create_scaler( 'nonlinear', alpha_min=0.4, alpha_max=1.0, factor=4.0) #Get a list of names and residue numbers, if just use names might skip some residues that are two #times in a row #make list 1 centered sequence = [(i, j) for i, j in zip(s.residue_numbers, s.residue_names)] sequence = sorted(set(sequence)) sequence = dict(sequence) print sequence print hydrophobes_res #Get list of groups with only residues that are hydrophobs group_1 = [res for res in group_1 if (sequence[res] in hydrophobes_res)] group_2 = [res for res in group_2 if (sequence[res] in hydrophobes_res)] pairs = [] hydroph_restraints = [] for i in group_1: for j in group_2: # don't put the same pair in more than once if ((i, j) in pairs) or ((j, i) in pairs): continue if (i == j): continue if (abs(i - j) < 7): continue pairs.append((i, j)) atoms_i = atoms[sequence[i]] atoms_j = atoms[sequence[j]] local_contact = [] for a_i in atoms_i: for a_j in atoms_j: if CO: print i, j, a_i, a_j tmp_scaler = scaler(abs(i - j), 'hydrophobic') else: tmp_scaler = scaler local_contact.append( s.restraints.create_restraint( 'distance', tmp_scaler, LinearRamp(0, 100, 0, 1), r1=0.0, r2=0.0, r3=0.50, r4=0.70, k=250.0, doing_eco=doing_eco, eco_factor=eco_factor, eco_constant=eco_constant, eco_linear=eco_linear, atom_1_res_index=i, atom_1_name=a_i, atom_2_res_index=j, atom_2_name=a_j)) hydroph_restraints.append( s.restraints.create_restraint_group(local_contact, 1)) print 'hydroph:', i, j all_rest = len(hydroph_restraints) active = int(ContactsPerHydroph * len(group_1)) print "Hydrophobic:" print active, len(group_1), all_rest s.restraints.add_selectively_active_collection(hydroph_restraints, active)
def create_Evolution(s, accuracy=0.5, scaler=None, fname='contacts.dat', doing_eco=False, eco_factor=0.0, eco_constant=1.0, eco_linear=0.0): scaler = scaler if scaler else s.restraints.create_scaler( 'nonlinear', alpha_min=0.4, alpha_max=1.0, factor=4.0) Evolution_restraints = [] #Heavy atoms for each residue atoms = { "ALA": ['N', 'C', 'O', 'CA', 'CB'], "VAL": ['N', 'C', 'O', 'CA', 'CB', 'CG1', 'CG2'], "LEU": ['N', 'C', 'O', 'CA', 'CB', 'CG', 'CD1', 'CD2'], "ILE": ['N', 'C', 'O', 'CA', 'CB', 'CG1', 'CG2', 'CD1'], "PHE": ['N', 'C', 'O', 'CA', 'CB', 'CG', 'CD1', 'CE1', 'CZ', 'CE2', 'CD2'], "TRP": [ 'N', 'C', 'O', 'CA', 'CB', 'CG', 'CD1', 'NE1', 'CE2', 'CZ2', 'CH2', 'CZ3', 'CE3', 'CD2' ], "MET": ['N', 'C', 'O', 'CA', 'CB', 'CG', 'SD', 'CE'], "PRO": ['N', 'C', 'O', 'CD', 'CG', 'CB', 'CA'], "ASP": ['N', 'C', 'O', 'CA', 'CB', 'CG', 'OD1', 'OD2'], "GLU": ['N', 'C', 'O', 'CA', 'CB', 'CG', 'CD', 'OE1', 'OE2'], "LYS": ['N', 'C', 'O', 'CA', 'CB', 'CG', 'CD', 'CE', 'NZ'], "ARG": ['N', 'C', 'O', 'CA', 'CB', 'CG', 'CD', 'NE', 'CZ', 'NH1', 'NH2'], "HIS": ['N', 'C', 'O', 'CA', 'CB', 'CG', 'ND1', 'CE1', 'NE2', 'CD2'], "HID": ['N', 'C', 'O', 'CA', 'CB', 'CG', 'ND1', 'CE1', 'NE2', 'CD2'], "HIE": ['N', 'C', 'O', 'CA', 'CB', 'CG', 'ND1', 'CE1', 'NE2', 'CD2'], "HIP": ['N', 'C', 'O', 'CA', 'CB', 'CG', 'ND1', 'CE1', 'NE2', 'CD2'], "GLY": ['N', 'C', 'O', 'CA'], "SER": ['N', 'C', 'O', 'CA', 'CB', 'OG'], "THR": ['N', 'C', 'O', 'CA', 'CB', 'CG2', 'OG1'], "CYS": ['N', 'C', 'O', 'CA', 'CB', 'SG'], "CYX": ['N', 'C', 'O', 'CA', 'CB', 'SG'], "TYR": [ 'N', 'C', 'O', 'CA', 'CB', 'CG', 'CD1', 'CE1', 'CZ', 'OH', 'CE2', 'CD2' ], "ASN": ['N', 'C', 'O', 'CA', 'CB', 'CG', 'OD1', 'ND2'], "GLN": ['N', 'C', 'O', 'CA', 'CB', 'CG', 'CD', 'OE1', 'NE2'] } #s.residue_numbers and s.residue_names have as many instances as atoms #we first use zip to create tuples and then set to create unique (disordered) lists of tuples #the sorted organizes them. Finally the dict creates an instance (one based) of residue to residue name sequence = [(i, j) for i, j in zip(s.residue_numbers, s.residue_names)] sequence = sorted(set(sequence)) sequence = dict(sequence) #Read file, 1 based lines = open(fname).read().splitlines() for i, line in enumerate(lines): cols = line.split() index_i = int(cols[0]) index_j = int(cols[1]) res_i = sequence[index_i] res_j = sequence[index_j] atoms_i = atoms[res_i] atoms_j = atoms[res_j] local_contact = [] for a_i in atoms_i: for a_j in atoms_j: #EvFold paper defines contact as 5angstrong any atom contact. We are only using heavy atoms #Hence, should allow to get closer. local_contact.append( s.restraints.create_restraint('distance', scaler, LinearRamp(0, 100, 0, 1), r1=0.0, r2=0.0, r3=0.60, r4=0.75, k=250.0, doing_eco=doing_eco, eco_factor=eco_factor, eco_constant=eco_constant, eco_linear=eco_linear, atom_1_res_index=index_i, atom_1_name=a_i, atom_2_res_index=index_j, atom_2_name=a_j)) Evolution_restraints.append( s.restraints.create_restraint_group(local_contact, 1)) #print 'Evolution:',index_i,index_j,res_i,res_j all_rest = len(Evolution_restraints) active = int(accuracy * all_rest) print active, all_rest s.restraints.add_selectively_active_collection(Evolution_restraints, active)
def setup_system(): # load the sequence sequence = parse.get_sequence_from_AA1(filename='sequence.dat') n_res = len(sequence.split()) # build the system p = system.ProteinMoleculeFromSequence(sequence) b = system.SystemBuilder(forcefield="ff14sbside") s = b.build_system_from_molecules([p]) s.temperature_scaler = system.GeometricTemperatureScaler(0, 0.6, 300., 450.) # # Secondary Structure # ss_scaler = s.restraints.create_scaler('constant') ss_rests = parse.get_secondary_structure_restraints(filename='ss.dat', system=s,ramp=LinearRamp(0,100,0,1), scaler=ss_scaler, torsion_force_constant=2.5, distance_force_constant=2.5) n_ss_keep = int(len(ss_rests) * 1.0) #We enforce 100% of restrains s.restraints.add_selectively_active_collection(ss_rests, n_ss_keep) # # Distance Restraints # dist_scaler = s.restraints.create_scaler('nonlinear', alpha_min=0.4, alpha_max=1.0, factor=4.0) # High reliability # # old_protocol = s.restraints.create_scaler('nonlinear', alpha_min=0.40, alpha_max=1.00, factor=4.0) # # Heuristic Restraints # subset= np.array(list(range(n_res))) + 1 # # Hydrophobic # create_hydrophobes(s,ContactsPerHydroph=1.2,scaler=old_protocol,group_1=subset,CO=False) # # Strand Pairing # sse,active = make_ss_groups(subset=subset) try: generate_strand_pairs(s,sse,float(active),subset=subset,scaler=old_protocol,CO=False) except: print("Not using Strand Pairing Heuristic") pass # # Evolutionary restraints # try: create_Evolution(s,accuracy=0.7,scaler=dist_scaler,fname='evolution_contacts.dat') except: print("Not using Evolutionary restraints") pass # # Distance Restraints # # # Knob restraints # try: knobs,knob_accuracy = get_knob_restraints('Knob.data',s,scaler=dist_scaler) n_knobs = int(len(knobs) * knob_accuracy) s.restraints.add_selectively_active_collection(knobs,n_knobs) except: print("Not using Knob-Socket predictions") pass # setup mcmc at startup movers = [] n_atoms = s.n_atoms for i in range(1, n_res + 1): n = s.index_of_atom(i, 'N') - 1 ca = s.index_of_atom(i, 'CA') - 1 c = s.index_of_atom(i, 'C') - 1 mover = mc.DoubleTorsionMover(n, ca, list(range(ca, n_atoms)), ca, c, list(range(c, n_atoms))) movers.append((mover, 1)) sched = mc.MonteCarloScheduler(movers, n_res * 60) # create the options options = system.RunOptions() options.implicit_solvent_model = 'gbNeck2' options.use_big_timestep = False options.use_bigger_timestep = True options.cutoff = 1.8 options.use_amap = False options.amap_alpha_bias = 1.0 options.amap_beta_bias = 1.0 options.timesteps = 11111 options.minimize_steps = 20000 # for i in range(30): # print("Heads up! using MC minimizer!") # options.min_mc = sched # create a store store = vault.DataStore(s.n_atoms, N_REPLICAS, s.get_pdb_writer(), block_size=BLOCK_SIZE) store.initialize(mode='w') store.save_system(s) store.save_run_options(options) # create and store the remd_runner l = ladder.NearestNeighborLadder(n_trials=100) policy = adaptor.AdaptationPolicy(2.0, 50, 50) a = adaptor.EqualAcceptanceAdaptor(n_replicas=N_REPLICAS, adaptation_policy=policy) remd_runner = master_runner.MasterReplicaExchangeRunner(N_REPLICAS, max_steps=N_STEPS, ladder=l, adaptor=a) store.save_remd_runner(remd_runner) # create and store the communicator c = comm.MPICommunicator(s.n_atoms, N_REPLICAS) store.save_communicator(c) # create and save the initial states states = [gen_state(s, i) for i in range(N_REPLICAS)] store.save_states(states, 0) # save data_store store.save_data_store() return s.n_atoms