def generate_concentric_spheres_atom_with_rotations(r, atomid, x, y, z, vx, vy, vz, increment, siteid, site_index, k_off, hedron, startvx = 0.0, startvy = 0.0, startvz = 0.0, absolute='False', r_low=1): vector = np.array([vx,vy,vz]) startvector = np.array([startvx, startvy, startvz]) # the direction in which we go up to the first radius hedron_quats = positions_orient.get_hedron(hedron) # generates the quaternions themselves from the function in positions_orient #print "hedron_quats:", hedron_quats milestones = [] if np.linalg.norm(vector) > 0.0: vector = vector/np.linalg.norm(vector) # normalize the vector if np.linalg.norm(startvector) > 0.0: startvector = startvector/np.linalg.norm(startvector) # normalize the startvector origin = np.array([x,y,z]) sphere_radii = np.arange(r_low,r+increment,increment) lowest_radius = sphere_radii[0] # the lowest radius total_spherical_milestones = 0 spheres_in_site = len(sphere_radii) for i in range(spheres_in_site): # create a position along each increment radius = sphere_radii[i] dimensions = {'center_indeces':atomid, 'radius':radius, 'centerx':x, 'centery':y, 'centerz':z} diff_rad = find_rad_of_skewed_vectors(startvector*lowest_radius, vector, radius) # radius - lowest_radius # the difference between the current radius and the lowest radius anchor = tuple(origin + startvector*lowest_radius + vector*diff_rad) # choose the location on the next surface. milestone = Milestone(anchor=anchor, dimensions=dimensions, index=i, siteid=siteid, center_type='atom') if i > 0: milestone.neighbors.append(i-1) # if we are the furthest milestone in either direction, then include no neighbors else: if not k_off: milestone.end = True if i < len(sphere_radii) - 1: milestone.neighbors.append(i+1) else: # then this is the outermost one, so set BD to true milestone.bd = True milestone.bd_adjacent = milestones[-1] # make the adjacent milestone the previously created md milestone milestone.end = True milestone.md = False #neighbors = [i-1, i+1] # the milestones to either side milestones.append(milestone) milestone.fullname = "%d_%d_%s_%.1f_%.1f_%.1f" % (i+(spheres_in_site*int(site_index)), i, siteid, anchor[0], anchor[1], anchor[2]) total_spherical_milestones += 1 # create the rotational milestones quat_counter = 0 for quat in hedron_quats: anchor = quat dimensions = {} index = total_spherical_milestones + quat_counter milestone = Milestone(anchor=anchor, dimensions=dimensions, index=index, siteid=siteid, center_type="irrelevant", shape='rotational') # add cross and anticross list here... #milestone.rotation = quat #index = i * len(hedron_quats) + quat_counter # need to construct a unique index for even the rotational milestones #new_milestone.fullname = "%d_%d_%s_%.1f_%.1f_%.1f_%d" % (index, i, siteid, anchor[0], anchor[1], anchor[2], quat_counter) # this is a problem... milestone.fullname = "rotation_%d" % index milestones.append(milestone) quat_counter += 1 return milestones
def generate_planar_positions_with_rotations(origx,origy,origz,normx, normy, normz, lowest, highest, increment, siteid, site_index, k_off, hedron, absolute='False'): '''returns a series of planar anchors and their neighbors''' vector = np.array([normx,normy,normz]) vector = vector/np.linalg.norm(vector) # normalize the vector hedron_quats = positions_orient.get_hedron(hedron) # generates the quaternions themselves from the function in positions_orient origin = np.array([origx,origy,origz]) milestones = [] planes = np.arange(lowest, highest+increment, increment) print "planes: ", planes total_planar_milestones = 0 planes_in_site = len(planes) for i in range(planes_in_site): # create a position along each increment plane = planes[i] center = origin + vector * plane dimensions = {'centerx':center[0], 'centery':center[1], 'centerz':center[2], 'distance':plane, 'normal':str(tuple(vector)).replace(' ','').replace(',',' ').replace(')','').replace('(','')} anchor = tuple(center) milestone = Milestone(anchor=anchor, dimensions=dimensions, index=i, siteid=siteid, absolute=absolute, center_type='coord', shape='plane') #milestone.fullname = "%d_%d_%s_%.1f_%.1f_%.1f_%d" % (i, i, siteid, anchor[0], anchor[1], anchor[2], 1) milestone.fullname = "%d_%d_%s_%.1f_%.1f_%.1f" % (i+(planes_in_site*int(site_index)), i, siteid, anchor[0], anchor[1], anchor[2]) if i > 0: milestone.neighbors.append(i-1) # if we are the furthest milestone in either direction, then include no neighbors else: milestone.end = True if i < len(planes) - 1: milestone.neighbors.append(i+1) else: milestone.end = True milestones.append(milestone) total_planar_milestones = 0 index = len(planes) print "number of nonrotational milestones:", index # create the rotational milestones quat_counter = 0 for quat in hedron_quats: anchor = quat dimensions = {} index = total_planar_milestones + quat_counter milestone = Milestone(anchor=anchor, dimensions=dimensions, index=index, siteid=siteid, center_type="irrelevant", shape='rotational') # add cross and anticross list here... #milestone.rotation = quat #index = i * len(hedron_quats) + quat_counter # need to construct a unique index for even the rotational milestones #new_milestone.fullname = "%d_%d_%s_%.1f_%.1f_%.1f_%d" % (index, i, siteid, anchor[0], anchor[1], anchor[2], quat_counter) # this is a problem... milestone.fullname = "rotation_%d" % index milestones.append(milestone) quat_counter += 1 return milestones
def prep( settings, holo, stage, inpname, outname='', temperatures=[], write_freq='1000', ): if verbose: print "creating %s files" % stage i = settings['index'] path = settings['md_file_paths'][i][stage] ff = settings['ff'] # forcefield pos_milestone = settings['milestone_pos_rot_list'][i][0] rot_milestone = settings['milestone_pos_rot_list'][i][1] temperature = settings['master_temperature'] absolute_mode = settings['absolute_mode'] if not outname: outname = stage # provide the default outname get_cell = False if len(temperatures) == 0: temperatures = [settings['master_temperature']] if stage == 'min': stage_settings = settings['min_settings'] if not stage_settings['namd_settings'][ 'extendedsystem']: # if they didn't define a starting XSC file get_cell = settings[ 'cell_shape'] # create the periodic boundary conditions if stage == 'temp_equil': stage_settings = settings['temp_equil_settings'] if stage == 'ens_equil': stage_settings = settings['ensemble_equil_settings'] if stage == 'prod': stage_settings = settings['prod_settings'] if stage == 'fwd_rev': stage_settings = settings['fwd_rev_settings'] ensemble = stage_settings['ensemble'] namd_settings = stage_settings[ 'namd_settings'] # extra settings to send to the NAMD input file if 'constrained' in stage_settings.keys() and stage_settings[ 'constrained']: # if the settings exists and not empty/False fixed = True occ_pdb = deepcopy( holo) # copy the holo structure so we can change the occupancy constrained = stage_settings['constrained'] constraints(occ_pdb, constrained, settings) # constrain the selected atoms fxd_name = os.path.join(path, 'fxd1.pdb') namd_settings['fixedAtoms'] = 'on' namd_settings['fixedAtomsFile'] = 'fxd1.pdb' namd_settings['fixedAtomsCol'] = 'O' occ_pdb.save(fxd_name, amber=True, standard=False) # save the constraint file else: fixed = False if 'restrained' in stage_settings.keys() and stage_settings[ 'restrained']: # if the settings exists and not empty/False const = True occ_pdb = deepcopy( holo) # copy the holo structure so we can change the occupancy restrained = stage_settings['restrained'] restrained_force = stage_settings['restrained_force'] restraints(occ_pdb, restrained, restrained_force, settings) # constrain the selected atoms rest_name = os.path.join(path, 'restrained1.pdb') occ_pdb.save(rest_name, amber=True, standard=False) #ens_namd_settings['fixedatoms'] = 'off' # we may not necessarily want to turn off fixed atoms namd_settings['constraints'] = 'on' namd_settings['consref'] = 'restrained1.pdb' namd_settings['conskfile'] = 'restrained1.pdb' namd_settings['conskcol'] = 'O' else: const = False settings['whoami'] = str(pos_milestone.index) settings['whoami_rot'] = str(rot_milestone.index) settings['siteid'] = str(pos_milestone.siteid) settings[ 'grid_edge_rad'] = '0.0' # temporary value until this can be more effectively predicted; will speed up TCL script evaluation if ff == 'amber': namd_settings['parmfile'] = make_relative_path( settings['prmtop'], path ) # Find the relative location of the prmtop/inpcrd to be used in the mins namd_settings['ambercoor'] = make_relative_path( settings['inpcrd'], path) elif ff == 'charmm': namd_settings['amber'] = 'no' namd_settings['coordinates'] = '../holo_wet.pdb' namd_settings['structure'] = '../building/holo_wet.psf' namd_settings['paratypecharmm'] = 'on' counter = 1 for parameter in settings['charmm_settings']['parameters']: if counter == 1: # we need to make sure the namd input file can get more than one parameter file i = "" else: i = str(counter) namd_settings['parameters%s' % i] = parameter counter += 1 #namd_settings['parameters2'] = '/extra/moana/rswift1/Permeability/Colvar/A/1F/par_all36_lipid.prm' #fhpd_file = 'fhpd.txt' namd_settings['watermodel'] = settings['watermodel'] if stage == 'ens_equil': namd_settings['outfilename'] = outname + "_0_1" if settings['lig_rot']: hedron = positions_orient.get_hedron(settings['quat_hedron']) quat_tclforces_settings = {} quat_tclforces_settings['force_constant'] = settings[ 'quat_force_constant'] quat_tclforces_settings['recrot'] = settings['recrot'] quat_tclforces_settings['rec_indeces'] = settings[ 'quat_rec_indeces'] quat_tclforces_settings['lig_indeces'] = settings[ 'quat_lig_indeces'] #quat_tclforces_settings['lig_pa1_indeces'] = settings['ligpa1_list'] # MARKED FOR REMOVAL #quat_tclforces_settings['lig_pa3_indeces'] = settings['ligpa3_list'] # MARKED FOR REMOVAL #quat_tclforces_settings['rec_pa1_indeces'] = settings['recpa1_list'] # MARKED FOR REMOVAL #quat_tclforces_settings['rec_pa3_indeces'] = settings['recpa3_list'] # MARKED FOR REMOVAL allquats = make_quat_list_in_tcl(hedron) #for i in range(len(allquats)): quat = rot_milestone.rotation tcl_quat = make_quat_list_in_tcl(quat) quat_tclforces_settings['anchor_quat'] = tcl_quat quat_tclforces_settings['neighbor_quats'] = allquats closest_neighbors = make_closest_neighbors(ref_quat=quat, hedron=hedron, tcl_output=False) if len(closest_neighbors) == 0: closest_neighbors = ["None"] number_of_neighbors = len(closest_neighbors) #closest_neighbors = make_quat_list_in_tcl(closest_neighbors) for f in range(number_of_neighbors): quat_tclforces_settings[ 'main_neighbor'] = make_quat_list_in_tcl( closest_neighbors[f]) namd_settings['tclforces'] = 'on' namd_settings['tclforcesscript'] = settings[ 'quatforcesscript'] # the script to be evaluated to keep the ligand forced to the rotational milestone namd_settings['tclforces_vars'] = quat_tclforces( quat_tclforces_settings).get_output() # write namd file here namd_settings['inpfilename'] = inpname namd_settings[ 'outfilename'] = outname + "_neighbor_%d_1" % f # 1st number: number of the neighbor, 2nd number: number of ens_equil simulation inp, namd_params = namd_inputs.make_input( holo, ff, stage, temperature, write_freq, receptor_type=settings['receptor_type'], ensemble=ensemble, fixed=fixed, get_cell=get_cell, constraints=const, settings=namd_settings) #... input_name = os.path.join(path, '%s_%d_1.namd' % (stage, f)) inp.save(input_name) param_filename = (os.path.join(path, 'namd_parameters.pkl')) param_file = open(param_filename, 'wb') pickle.dump(namd_params, param_file) param_file.close() return os.path.join( stage, namd_settings['outfilename']) # return ens_equil else: # then lig_rot is False namd_settings['inpfilename'] = inpname namd_settings['outfilename'] = outname + "_0_1" inp, namd_params = namd_inputs.make_input( holo, ff, stage, temperature, write_freq, receptor_type=settings['receptor_type'], ensemble=ensemble, fixed=fixed, get_cell=get_cell, constraints=const, settings=namd_settings) #... input_name = os.path.join(path, '%s_%d_1.namd' % (stage, 0)) inp.save(input_name) param_filename = (os.path.join(path, 'namd_parameters.pkl')) param_file = open(param_filename, 'wb') pickle.dump(namd_params, param_file) param_file.close() return os.path.join( stage, namd_settings['outfilename']) # return ens_equil hedron = positions_orient.get_hedron(settings['quat_hedron']) allquats = make_quat_list_in_tcl(hedron) quat = rot_milestone.rotation closest_neighbors = make_closest_neighbors(ref_quat=quat, hedron=hedron, tcl_output=False) if len(closest_neighbors) == 0: closest_neighbors = ["None"] number_of_neighbors = len(closest_neighbors) if stage == 'fwd_rev': prelim_string_template = '''set TEMP $temperature set NUM_REVERSALS $num_reversals global REV_FILENAME_BASE; set REV_FILENAME_BASE "REV_COMPLETED.txt" global FWD_FILENAME_BASE; set FWD_FILENAME_BASE "FWD_COMPLETED.txt" global RESTART_FREQ; set RESTART_FREQ $restart_freq global RUN_FREQ; set RUN_FREQ $run_freq set ENS_EQUIL_FIRST_FRAME $begin set ENS_EQUIL_STRIDE $stride set LAUNCHES_PER_CONFIG $launches_per_config set FRAME_CHUNK_SIZE $frame_chunk_size set UMBRELLA_GLOB_DIR "../ens_equil/" ;# the umbrella sampling directory set UMBRELLA_GLOB_NAME "ens_equil_0_?.dcd" ;# the umbrella sampling trajs set nr [numReplicas] set replica_id [myReplica] ;# get the ID of this replica''' hedron = positions_orient.get_hedron(settings['quat_hedron']) settings['care_about_self'] = 'False' settings['phase'] = 'reverse' settings['abort_on_crossing'] = 'True' #settings['fhpd_file'] = '../reverse/fhpd.txt' settings['max_num_steps'] = stage_settings['max_num_steps'] settings['milestone_string'] = make_milestone_list( settings['raw_milestone_list'], hedron) namd_settings['tclforces_vars'] = tclforces(settings).get_output() num_frames = settings['ensemble_equil_settings']['namd_settings'][ 'numsteps'] dcd_write_freq = int( settings['ensemble_equil_settings']['namd_settings']['dcdfreq']) begin = stage_settings['extract_first'] # new parameter end = int(num_frames) / dcd_write_freq + 1 stride = stage_settings['extract_stride'] # new parameter launches_per_config = stage_settings['launches_per_config'] frame_chunk_size = stage_settings['frame_chunk_size'] restart_freq = stage_settings['restart_freq'] # New parameter run_freq = stage_settings['run_freq'] # new parameter num_reversals = int((end - begin) / stride) namd_settings['inpfilename'] = inpname namd_settings['outfilename'] = outname + ".$replica_id" namd_settings[ 'coordinates'] = "../holo_wet.pdb" # this gets overwritten... namd_settings[ 'ambercoor'] = '' # this has to be disabled when coordinates are presented namd_settings['velocities'] = '' if bool(stage_settings['extract_xst']): namd_settings[ 'extendedsystem'] = "../ens_equil/ens_equil_0_1.restart.xsc" namd_settings['bincoordinates'] = "" namd_settings['binvelocities'] = "" namd_settings['temperature'] = temperature namd_settings['replicaUniformPatchGrids'] = 'on' namd_settings['numsteps'] = '' namd_settings['restartfreq'] = '$RESTART_FREQ' #namd_settings['id'] = i prelim_settings = { 'temperature': temperature, 'num_reversals': num_reversals, 'restart_freq': restart_freq, 'run_freq': run_freq, 'begin': begin, 'stride': stride, 'launches_per_config': launches_per_config, 'frame_chunk_size': frame_chunk_size } prelim_string = Adv_template( prelim_string_template, prelim_settings).get_output() # fill in the missing values namd_settings['prelim_string'] = prelim_string post_string_settings = {} namd_settings['post_string'] = File_template( fwd_rev_template_location, post_string_settings).get_output() inp, namd_params = namd_inputs.make_input(holo, ff, stage, temperature, write_freq, fixed=fixed, ensemble=ensemble, get_cell=get_cell, constraints=const, settings=namd_settings) #... input_name = os.path.join(path, 'fwd_rev1.namd') inp.save(input_name) param_filename = (os.path.join(path, 'namd_parameters.pkl')) param_file = open(param_filename, 'wb') pickle.dump(namd_params, param_file) param_file.close() #make_fhpd_script(path, 'forward_template.namd', settings['fhpd_file'], number_of_neighbors=number_of_neighbors) return os.path.join(stage, namd_settings['outfilename']) counter = 1 for temperature in temperatures: namd_settings['inpfilename'] = inpname namd_settings['outfilename'] = outname + str(counter) inp, namd_params = namd_inputs.make_input( holo, ff, stage, temperature, write_freq, receptor_type=settings['receptor_type'], ensemble=ensemble, fixed=fixed, get_cell=get_cell, constraints=const, settings=namd_settings) #... input_name = os.path.join(path, '%s%d.namd' % (stage, counter)) inp.save(input_name) counter += 1 inpname = namd_settings['outfilename'] return os.path.join(stage, namd_settings['outfilename'])