def autoimage_traj(parm_name, trajin_name, trajout_name, box_info, cpptraj_script_location, cpptraj_exe='cpptraj', writing_frames=()): '''Runs the CPPTRAJ autoimage command for a triclinic box simulation. Input: - parm_name: a string representing the filename of a .prmtop or .parm7 AMBER parameter/topology file - trajin_name: a non-imaged trajectory to load for imaging - box_info: a string representing the triclinic box in x,y,z,alpha,beta,gamma format - cpptraj_script_location: string for the location to write the cpptraj script - cpptraj_exe: an optional string representing the OS command to run CPPTRAJ Output: - None ''' cpptraj_template = '''parm $PARMFILE box $BOX_INFO trajin $TRAJIN autoimage trajout $TRAJOUT $FRAME_STR go quit ''' assert len( writing_frames ) < 4, 'When writing the autoimaged trajectory, the format of the writing_frames variable must be: (start, stop, offset)' if len(writing_frames) == 0: # then write all frames frame_str = '' elif len(writing_frames) == 1: frame_str = 'start %d' % writing_frames[0] # only include the start elif len(writing_frames) == 2: frame_str = 'start %d stop %d' % (writing_frames[0], writing_frames[1]) else: # the length is 3 frame_str = 'start %d stop %d offset %d' % ( writing_frames[0], writing_frames[1], writing_frames[2]) cpptraj_dict = { 'PARMFILE': parm_name, 'TRAJIN': trajin_name, 'TRAJOUT': trajout_name, 'BOX_INFO': box_info, 'FRAME_STR': frame_str } # define template dictionary cpptraj_script = Adv_template( cpptraj_template, cpptraj_dict ) # fill in the values into the template from the dictionary extract_file = open(cpptraj_script_location, 'w') # open the script for writing extract_file.write(cpptraj_script.get_output()) # write a cpptraj script extract_file.close() os.system("%s < %s" % (cpptraj_exe, cpptraj_script_location)) # run cpptraj return
def tclforces(settings): '''generates the string that will be included in the NAMD file for the tclforces script''' tcltemplatestring = """ set SCRIPT_INTERVAL $script_interval ;# number of timesteps before script should be evaluated. Examples: 1=script evaluated every timestep. 5=script eval'd every 5th timestep, ... set LIGROT $ligrot ;# whether we care about ligand rotation set RECROT $recrot ;# whether we care about receptor rotation set ABORT_ON_CROSSING $abort_on_crossing ;# whether a job should be aborted right after crossing a milestone set PHASE $phase ;# can be 'forward' or 'reverse' set CARE_ABOUT_SELF $care_about_self ;# whether we care about the milestone's self in this simulation set whoami_const $whoami ;# the index of the milestone we started from set whoami $whoami_const set whoami_rot_const $whoami_rot ;# the index of the rotational milestone we started from set whoami_rot $whoami_rot_const set GRID_EDGE_RAD $grid_edge_rad ;# radius to the edge of the grid from the center set LIGRANGE {$ligrange} ;# the indeces of the atoms that define the ligand set RECRANGE {$recrange} ;# the indeces of the atoms that define the receptor #set RECPA1_LIST {$recpa1_list} ;# the list of relatively immobile atoms that define the receptor's 1st PA. MARKED FOR REMOVAL #set RECPA3_LIST {$recpa3_list} ;# the list of relatively immobile atoms that define the receptor's 3rd PA. MARKED FOR REMOVAL set MILESTONE_LIST $milestone_string ;# a list of milestones to be converted to arrays set SITEID $siteid ;# the ID if the current site set MAX_NUM_STEPS $max_num_steps ;# the maximum number of steps before starting a new crossing phase """ tcltemplate = Adv_template(tcltemplatestring, settings) # fill in the missing values return tcltemplate
def submit(self, my_params, my_template): # make the submission files params = fill_params(self, my_params) #{ 'job_name' : self.name+str(self.number), 'queue':queue,'procs':self.procs, 'time_str':self.time_str, 'acct':acct, 'sys_name':self.system, 'stage':self.name, 'namd_script': self.name+str(self.number)+'.namd', 'namd_output':self.name+str(self.number)+'.out' } script_name = '%s%d_%d.submit' % (self.name, self.procs, self.number) submit_filename = os.path.join(self.dir, script_name) print " writing submit script to location:", submit_filename #BRJ 4/4 _0_ should be changed to rotational milestone number if self.name == "ens_equil": params['job_name']=self.name+"_0_"+str(self.number) else: params['job_name']=self.name+str(self.number) #BRJ4/4 params['curdir']=os.path.join(os.getcwd(), self.dir) submit = Adv_template(my_template, params) submit_file = open(submit_filename,'w') submit_file.write(submit.get_output()) submit_file.close() # submit the files cmd = '%s %s' % (submit_cmd, submit_filename) submit_stdout = self.command(cmd) # print " executing command:", cmd self.status = "submitted"
def quat_tclforces(settings): '''generates the string that will be included in the NAMD file for the quaternion tclforces script for rotational colvars''' tcltemplatestring = """ set FORCE_CONSTANT {$force_constant} set RECROT $recrot set REC_INDECES {$rec_indeces} set REC_PA1_INDECES {$rec_pa1_indeces} set REC_PA3_INDECES {$rec_pa3_indeces} set LIG_PA1_INDECES {$lig_pa1_indeces} set LIG_PA3_INDECES {$lig_pa3_indeces} set LIG_INDECES {$lig_indeces} set ANCHOR_QUAT $anchor_quat set MAIN_NEIGHBOR $main_neighbor set NEIGHBOR_QUATS { """ #for neighbor_quat in settings['neighbor_quats']: neighbor_quat_string = ' '.join(settings['neighbor_quats']) tcltemplatestring += neighbor_quat_string + '}' quat_tcltemplate = Adv_template(tcltemplatestring, settings) # fill in the missing values return quat_tcltemplate
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'])
def main(settings): rec_struct = settings['rec_struct'] lig_struct = settings['lig_struct'] lig_center = pdb.center_of_mass(lig_struct) browndye_bin = settings['browndye_bin_dir'] empty_pqrxml = os.path.abspath(settings['empty_pqrxml_path']) #b surface for FHPD preparation pqrs = [copy.deepcopy(rec_struct), copy.deepcopy(lig_struct)] pqrs[1].struct_id = 'bd_ligand' b_surface_path = settings['b_surface_path'] if not os.path.exists(b_surface_path): os.mkdir(b_surface_path) b_surface_criteria = [] b_surface_criteria.append({ 'centerx': settings['bd_centerx'], 'centery': settings['bd_centery'], 'centerz': settings['bd_centerz'], 'ligx': lig_center[0], 'ligy': lig_center[1], 'ligz': lig_center[2], 'radius': settings['b_surf_distance'], 'index': settings['bd_index'] }) # add every site to the criteria list print("bsurface_criteria:", b_surface_criteria) b_surface_pqrxmls = _write_browndye_input( pqrs, settings, b_surface_criteria, work_dir=b_surface_path, browndye_bin=browndye_bin, start_at_site='false', ) # write input for this part #generate BD milestone files pqrs = [copy.deepcopy(rec_struct), copy.deepcopy(lig_struct)] pqrs[1].struct_id = 'bd_ligand' bd_file_path = settings['bd_milestone_path'] if not os.path.exists(bd_file_path): os.mkdir(bd_file_path) criteria = [] criteria.append({ 'centerx': settings['bd_centerx'], 'centery': settings['bd_centery'], 'centerz': settings['bd_centerz'], 'ligx': lig_center[0], 'ligy': lig_center[1], 'ligz': lig_center[2], 'radius': settings['bd_lower_bound'], 'index': settings['bd_lower_bound_index'] }) # add every site to the criteria list # make BD preparation scripts extract_bd_frames.py and bd_fhpd.pyp #print "settings['starting_surfaces'][i]:", settings['starting_surfaces'][i] # Write the script to extract all frames from the successful b_surface bd trajectories extract_bd_frames_dict = { 'TRAJDIR': "../b_surface", 'WORKDIR': "./trajs", 'PQRXML0': os.path.basename(b_surface_pqrxmls[0]), 'PQRXML1': os.path.basename(b_surface_pqrxmls[1]), 'EMPTY': empty_pqrxml, 'SITENAME': 'milestone_%s' % (settings['bd_index']), 'NUMBER_OF_TRAJS': settings['threads'] } extract_bd_frames = Adv_template(extract_bd_frames_template, extract_bd_frames_dict) extract_file = open(os.path.join(bd_file_path, "extract_bd_frames.py"), 'w') extract_file.write(extract_bd_frames.get_output() ) # write an xml file for the input to bd extract_file.close() # construct the FHPD distribution prep scripts make_fhpd_dict = { 'INPUT_TEMPLATE_FILENAME': 'input.xml', 'RECEPTOR_PQRXML': os.path.basename(b_surface_pqrxmls[0]), 'RXNS': 'rxns.xml', 'NTRAJ': settings['fhpd_numtraj'], 'ARGS': "glob.glob(os.path.join('./trajs','lig*.pqr'))" } # NOTE: should change NTRAJ to be consistent with the number of reaction events in the b_surface phase make_fhpd = Adv_template(make_fhpd_template, make_fhpd_dict) make_fhpd_file = open(os.path.join(bd_file_path, "make_fhpd.py"), 'w') make_fhpd_file.write( make_fhpd.get_output()) # write an xml file for the input to bd make_fhpd_file.close() # Consolidate all result files from the FHPD simulations into one large results.xml file fhpd_consolidate_dict = { 'FHPD_DIR': "fhpd", 'LIG_DIR_GLOB': "lig*/", 'RESULTS_NAME': 'results.xml' } fhpd_consolidate = Adv_template(fhpd_consolidate_template, fhpd_consolidate_dict) fhpd_consolidate_file = open( os.path.join(bd_file_path, "fhpd_consolidate.py"), 'w') fhpd_consolidate_file.write( fhpd_consolidate.get_output()) # write an xml file for the input to bd fhpd_consolidate_file.close() #counter += 1 bd_pqrxmls = _write_browndye_input(pqrs, settings, criteria, work_dir=bd_file_path, browndye_bin=browndye_bin, fhpd_mode=True) return
def main(settings): ''' main function for bd.py takes a list of pqr filenames, reaction coordinate pairs/distances ''' if verbose: print '\n', '#'*40, "\n Now creating BD files using bd.py\n", '#'*40 rec_struct = settings['rec_struct'] #milestones = settings['milestones'] milestone_pos_rot_list = settings['milestone_pos_rot_list'] # NOTE: may want to clean up code referring to this variable if settings['starting_conditions'] == 'configs': lig_configs = settings['lig_configs'] elif settings['starting_conditions'] == 'spheres': # then generate the anchors from random positions/orientations in a sphere # NOTE: there is a random orientation function in positions_orient.py pass else: raise Exception, "option not allowed: %s" % settings['starting_conditions'] bd_file_paths = settings['bd_file_paths'] browndye_bin = settings['browndye_bin_dir'] empty_pqrxml = os.path.abspath(settings['empty_pqrxml_path']) bd_configs = [] # fill the b_surface folder lig_config = lig_configs[0] # get the first config of the ligand lig_center = pdb.center_of_mass(lig_config) pqrs = [copy.deepcopy(rec_struct), copy.deepcopy(lig_config)] #print "PQR1 ID", pqrs[1].struct_id pqrs[1].struct_id='bd_ligand' #print "PQR1 ID", pqrs[1].struct_id b_surface_path = settings['b_surface_path'] if not os.path.exists(b_surface_path): os.mkdir(b_surface_path) b_surface_criteria = [] for site in settings['b_surface_ending_surfaces']: b_surface_criteria.append({'centerx':site['x'], 'centery':site['y'], 'centerz':site['z'], 'ligx':lig_center[0], 'ligy':lig_center[1], 'ligz':lig_center[2], 'radius':site['radius'], 'index':site['index'], 'siteid':site['siteid']}) # add every site to the criteria list print "bsurface_criteria:", b_surface_criteria b_surface_pqrxmls = write_browndye_input(pqrs, settings, b_surface_criteria, work_dir=b_surface_path, browndye_bin=browndye_bin, start_at_site='false', fhpd_mode = False) # write input for this part for bd_file_path in bd_file_paths: if not bd_file_path: pass #bd_configs.append(None) #continue # then don't do BD for this portion #print "bd_file_path:", bd_file_path anchor_folder_name = bd_file_path.split('/')[-2] # reading the file tree to get the index of every existing folder #print "anchor_folder_name:", anchor_folder_name folder_index = anchor_folder_name.split('_')[1] # getting the index out of the folder name bd_configs.append(int(folder_index)) counter = 0 # the index of the loop itself print "bd_file_paths:", bd_file_paths print "bd_configs:", bd_configs for i in bd_configs: #len(milestones) should equal len(lig_configs); the index of the milestone/lig_config #lig_config = lig_configs[i] bd_file_path = bd_file_paths[counter] print "bd_file_path:", bd_file_path pqrs = [copy.deepcopy(rec_struct), copy.deepcopy(lig_config)] pqrs[1].struct_id='bd_ligand' #lig_center = pdb.center_of_mass(lig_config) bd_needed = True m=0 for m in range(len(milestone_pos_rot_list)): # m will represent the proper milestone index if milestone_pos_rot_list[m][0].index == i: break criteria = [] #[[(31.121, 37.153, 35.253), (38.742, 51.710, 68.137), 9.0],] # a list of all reaction criteria for site in settings['starting_surfaces']: #site_center = [site['x'], site['y'],site['z']] #radius = site['radius'] # NOTE: at this time, only spherical reaction criteria are allowed in BrownDye if milestone_pos_rot_list[m][0].siteid == site['siteid']: # then its the same site, we need to go one shell in proper_radius = site['inner_radius'] # the radius in the same site proper_index = site['inner_index'] else: # this is a different site, choose the same radius as starting proper_radius = site['outer_radius'] proper_index = site['outer_index'] criteria.append({'centerx':site['x'], 'centery':site['y'], 'centerz':site['z'], 'ligx':lig_center[0], 'ligy':lig_center[1], 'ligz':lig_center[2], 'radius':proper_radius, 'index':proper_index, 'siteid':site['siteid']}) # add every site to the criteria list #print "pqrs:", pqrs, 'criteria:', criteria site_pqrxmls = write_browndye_input(pqrs, settings, criteria, work_dir=bd_file_path, browndye_bin=browndye_bin,fhpd_mode=True) # make BD preparation scripts extract_bd_frames.py and bd_fhpd.pyp #print "settings['starting_surfaces'][i]:", settings['starting_surfaces'][i] # Write the script to extract all frames from the successful b_surface bd trajectories extract_bd_frames_dict = {'TRAJDIR':"../../b_surface", 'WORKDIR':"./trajs", 'PQRXML0':os.path.basename(b_surface_pqrxmls[0]), 'PQRXML1':os.path.basename(b_surface_pqrxmls[1]), 'EMPTY':empty_pqrxml, 'SITENAME':'%s_%s' % (milestone_pos_rot_list[m][0].siteid,milestone_pos_rot_list[m][0].index), 'NUMBER_OF_TRAJS':settings['threads']} extract_bd_frames = Adv_template(extract_bd_frames_template,extract_bd_frames_dict) extract_file = open(os.path.join(bd_file_path,"extract_bd_frames.py"), 'w') extract_file.write(extract_bd_frames.get_output()) # write an xml file for the input to bd extract_file.close() # construct the FHPD distribution prep scripts make_fhpd_dict = {'INPUT_TEMPLATE_FILENAME':'input.xml', 'RECEPTOR_PQRXML':os.path.basename(b_surface_pqrxmls[0]), 'RXNS':'rxns.xml', 'NTRAJ':settings['fhpd_numtraj'], 'ARGS':"glob.glob(os.path.join('./trajs','lig*.pqr'))"} # NOTE: should change NTRAJ to be consistent with the number of reaction events in the b_surface phase make_fhpd = Adv_template(make_fhpd_template,make_fhpd_dict) make_fhpd_file = open(os.path.join(bd_file_path,"make_fhpd.py"), 'w') make_fhpd_file.write(make_fhpd.get_output()) # write an xml file for the input to bd make_fhpd_file.close() # Consolidate all result files from the FHPD simulations into one large results.xml file fhpd_consolidate_dict = {'FHPD_DIR':"fhpd", 'LIG_DIR_GLOB':"lig*/", 'RESULTS_NAME':'results.xml'} fhpd_consolidate = Adv_template(fhpd_consolidate_template,fhpd_consolidate_dict) fhpd_consolidate_file = open(os.path.join(bd_file_path,"fhpd_consolidate.py"), 'w') fhpd_consolidate_file.write(fhpd_consolidate.get_output()) # write an xml file for the input to bd fhpd_consolidate_file.close() counter += 1
def prep( settings, milestones, stage, inpname, outname='', ): #print("creating %s files" % stage) i = settings['index'] path = settings['md_file_paths'][i][stage] ff = settings['ff'] # forcefield anchor_list = settings['anchor_list'] temperature = settings['master_temperature'] if not outname: outname = stage # provide the default outname get_cell = False if stage == 'equil': stage_settings = settings['equil_settings'] #_prep_colvars(settings, milestones) 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 stage_settings = settings['equil_settings'] if stage == 'prod': stage_settings = settings['prod_settings'] ensemble = stage_settings['ensemble'] namd_settings = stage_settings[ 'namd_settings'] # extra settings to send to the NAMD input file namd_settings['master_temperature'] = temperature #settings['whoami'] = str(pos_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) #namd_settings['bincoordinates']= _make_relative_path(settings['bincoor'],path) #namd_settings['extendedsystem']= _make_relative_path(settings['xsc'],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['watermodel'] = settings['watermodel'] if stage == 'equil': print("creating equilibration files") holo = settings['system_pdb_filename'] namd_settings['inpfilename'] = inpname namd_settings['outfilename'] = outname + "_1" namd_settings['bincoordinates'] = _make_relative_path( settings['bincoor'], path) namd_settings['extendedsystem'] = _make_relative_path( settings['xsc'], path) #print(settings['equil_settings']['namd_settings']['write_freq']) write_freq = settings['equil_settings']['namd_settings']['write_freq'] ensemble = settings['equil_settings']['ensemble'] colvars, colvars_params = namd_inputs._make_colvars_input( milestones, stage, i) colvars_name = os.path.join(path, 'colvars.script') colvars.save(colvars_name) #print(namd_settings) inp, namd_params = namd_inputs._make_input( holo, stage, ff, write_freq, ensemble=ensemble, get_cell=get_cell, settings=namd_settings) #... input_name = os.path.join(path, '%s_1.namd' % (stage)) 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 if stage == 'prod': print("creating production files") holo = settings['system_pdb_filename'] namd_settings['inpfilename'] = inpname namd_settings['outfilename'] = outname + "_1" #print(settings['equil_settings']['namd_settings']['write_freq']) write_freq = settings['prod_settings']['namd_settings']['write_freq'] ensemble = settings['prod_settings']['ensemble'] colvars, colvars_params = namd_inputs._make_colvars_input( milestones, stage, i) colvars_name = os.path.join(path, 'colvars.script') colvars.save(colvars_name) post_string_settings = { 'prod_steps': namd_settings['numsteps'], 'eval_stride': namd_settings['eval_stride'], } anchor_milestone_params = _gen_anchor_milestone_params(milestones, i) ##TODO fix for multiple milestones post_string_settings.update(anchor_milestone_params[0]) post_string_template = '''set crossing 0 set whoami none set incubation_time 0 set max_steps $prod_steps set EVAL_STRIDE $eval_stride set CURR_ANCHOR $curr_anchor set LOWER_ANCHOR $lower_anchor set LOWER_MILESTONE $lower_milestone_index set LOWER_BOUND $lower_bound set UPPER_ANCHOR $upper_anchor set UPPER_MILESTONE $upper_milestone_index set UPPER_BOUND $upper_bound for {set stepnum 0} {$stepnum < $max_steps} {incr stepnum $eval_stride} { run $EVAL_STRIDE set cv_val [cv colvar milestone1 value] if {$cv_val <= $LOWER_BOUND} { if {$rev_last} { print "trajectory stuck" } puts "SEEKR: Cell Collision: current: $CURR_ANCHOR, new: $LOWER_ANCHOR, stepnum: $stepnum" if {$whoami != $LOWER_MILESTONE} { puts "SEEKR: Milestone Transition: anchor: $CURR_ANCHOR, source: $whoami, destination: $LOWER_MILESTONE, stepnum: $stepnum, incubation time: $incubation_time" set incubation_time 0 } revert rescalevels -1 checkpoint set rev_last True set whoami $LOWER_MILESTONE } elseif {$cv_val >= $UPPER_BOUND} { if {$rev_last} { print "trajectory stuck" } puts "SEEKR: Cell Collision: current: $CURR_ANCHOR, new: $UPPER_ANCHOR, stepnum: $stepnum" if {$whoami != $UPPER_MILESTONE} { puts "SEEKR: Milestone Transition: anchor: $CURR_ANCHOR, source: $whoami, destination: $UPPER_MILESTONE, stepnum: $stepnum, incubation time: $incubation_time" set incubation_time 0 } revert rescalevels -1 checkpoint set rev_last True set whoami $UPPER_MILESTONE } else { checkpoint set rev_last False } incr incubation_time $EVAL_STRIDE } ''' post_string = Adv_template( post_string_template, post_string_settings).get_output() # fill in the missing values namd_settings['post_string'] = post_string inp, namd_params = namd_inputs._make_input( holo, stage, ff, write_freq, ensemble=ensemble, get_cell=get_cell, settings=namd_settings) #... input_name = os.path.join(path, '%s_1.namd' % (stage)) 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'])
def build_bd(seekrcalc): ''' build all structures and necessary files for BD calculations takes a list of pqr filenames, reaction coordinate pairs/distances ''' if verbose: print '\n', '#'*40, "\n Now creating BD files using bd.py\n", '#'*40 parser = pdb.Big_PDBParser() rec_struct = parser.get_structure('bd_receptor_dry_pqr', seekrcalc.browndye.rec_dry_pqr_filename, pqr=True) #milestone_pos_rot_list = settings['milestone_pos_rot_list'] # NOTE: may want to clean up code referring to this variable ''' # TODO: marked for removal because feature probably not needed if settings['starting_conditions'] == 'configs': lig_configs = settings['lig_configs'] elif settings['starting_conditions'] == 'spheres': # then generate the anchors from random positions/orientations in a sphere # NOTE: there is a random orientation function in positions_orient.py pass else: raise Exception, "option not allowed: %s" % settings['starting_conditions'] ''' #bd_file_paths = settings['bd_file_paths'] #browndye_bin = settings['browndye_bin_dir'] #if not os.path.exists(empty_pqrxml) bd_configs = [] # fill the b_surface folder lig_config = seekrcalc.browndye.starting_lig_config # get the first config of the ligand lig_center = pdb.center_of_mass(lig_config) pqrs = [copy.deepcopy(rec_struct), copy.deepcopy(lig_config)] pqrs[1].struct_id='bd_ligand' #for site in settings['b_surface_ending_surfaces']: b_surface_criteria = [] starting_surfaces = [] for milestone in seekrcalc.milestones: if milestone.end: b_surface_criteria.append({'centerx':milestone.center_vec[0], 'centery':milestone.center_vec[1], 'centerz':milestone.center_vec[2], 'ligx':lig_center[0], 'ligy':lig_center[1], 'ligz':lig_center[2], 'radius':milestone.radius, 'index':milestone.index, 'siteid':milestone.siteid}) # add every site to the criteria list if milestone.bd: starting_surfaces.append({'site':milestone.siteid, 'radius':milestone.radius, 'index':milestone.index}) print "bsurface_criteria:", b_surface_criteria b_surface_pqrxmls = write_browndye_input(pqrs, seekrcalc, b_surface_criteria, work_dir=seekrcalc.browndye.b_surface_path, browndye_bin=seekrcalc.browndye.browndye_bin, start_at_site='false', fhpd_mode = False) # write input for this part ''' for bd_file_path in bd_file_paths: if not bd_file_path: pass #bd_configs.append(None) #continue # then don't do BD for this portion #print "bd_file_path:", bd_file_path anchor_folder_name = bd_file_path.split('/')[-2] # reading the file tree to get the index of every existing folder #print "anchor_folder_name:", anchor_folder_name folder_index = anchor_folder_name.split('_')[1] # getting the index out of the folder name bd_configs.append(int(folder_index)) ''' counter = 0 # the index of the loop itself for milestone in seekrcalc.milestones: if milestone.bd: lig_config = milestone.config bd_file_path = os.path.join(seekrcalc.project.rootdir, milestone.directory, 'bd') print "bd_file_path:", bd_file_path pqrs = [copy.deepcopy(rec_struct), copy.deepcopy(lig_config)] pqrs[1].struct_id='bd_ligand' bd_needed = True ''' m=0 for m in range(len(milestone_pos_rot_list)): # m will represent the proper milestone index if milestone_pos_rot_list[m][0].index == i: break ''' criteria = [] for surface in starting_surfaces: if surface['site'] == milestone.siteid: proper_radius = milestone.bd_adjacent.radius proper_index = milestone.bd_adjacent.index else: proper_radius = surface['radius'] proper_index = surface['index'] criteria.append({'centerx':milestone.center_vec[0], 'centery':milestone.center_vec[1], 'centerz':milestone.center_vec[2], 'ligx':lig_center[0], 'ligy':lig_center[1], 'ligz':lig_center[2], 'radius':proper_radius, 'index':proper_index, 'siteid':milestone.siteid}) ''' criteria = [] #[[(31.121, 37.153, 35.253), (38.742, 51.710, 68.137), 9.0],] # a list of all reaction criteria for site in settings['starting_surfaces']: #site_center = [site['x'], site['y'],site['z']] #radius = site['radius'] # NOTE: at this time, only spherical reaction criteria are allowed in BrownDye if milestone_pos_rot_list[m][0].siteid == site['siteid']: # then its the same site, we need to go one shell in proper_radius = site['inner_radius'] # the radius in the same site proper_index = site['inner_index'] else: # this is a different site, choose the same radius as starting proper_radius = site['outer_radius'] proper_index = site['outer_index'] criteria.append({'centerx':site['x'], 'centery':site['y'], 'centerz':site['z'], 'ligx':lig_center[0], 'ligy':lig_center[1], 'ligz':lig_center[2], 'radius':proper_radius, 'index':proper_index, 'siteid':site['siteid']}) # add every site to the criteria list ''' #print "pqrs:", pqrs, 'criteria:', criteria site_pqrxmls = write_browndye_input(pqrs, seekrcalc, criteria, work_dir=bd_file_path, browndye_bin=seekrcalc.browndye.browndye_bin,fhpd_mode=True) # make BD preparation scripts extract_bd_frames.py and bd_fhpd.pyp # Write the script to extract all frames from the successful b_surface bd trajectories extract_bd_frames_dict = {'TRAJDIR':"../../b_surface", 'WORKDIR':"./trajs", 'PQRXML0':os.path.basename(b_surface_pqrxmls[0]), 'PQRXML1':os.path.basename(b_surface_pqrxmls[1]), 'EMPTY':empty_pqrxml, 'SITENAME':'%s_%s' % (milestone.siteid, milestone.index), 'NUMBER_OF_TRAJS':seekrcalc.browndye.num_threads} extract_bd_frames = Adv_template(extract_bd_frames_template, extract_bd_frames_dict) extract_file = open(os.path.join(bd_file_path,"extract_bd_frames.py"), 'w') extract_file.write(extract_bd_frames.get_output()) # write an xml file for the input to bd extract_file.close() # construct the FHPD distribution prep scripts make_fhpd_dict = {'INPUT_TEMPLATE_FILENAME':'input.xml', 'RECEPTOR_PQRXML':os.path.basename(b_surface_pqrxmls[0]), 'RXNS':'rxns.xml', 'NTRAJ':seekrcalc.browndye.fhpd_numtraj, 'ARGS':"glob.glob(os.path.join('./trajs','lig*.pqr'))"} # NOTE: should change NTRAJ to be consistent with the number of reaction events in the b_surface phase make_fhpd = Adv_template(make_fhpd_template,make_fhpd_dict) make_fhpd_file = open(os.path.join(bd_file_path,"make_fhpd.py"), 'w') make_fhpd_file.write(make_fhpd.get_output()) # write an xml file for the input to bd make_fhpd_file.close() # Consolidate all result files from the FHPD simulations into one large results.xml file fhpd_consolidate_dict = {'FHPD_DIR':"fhpd", 'LIG_DIR_GLOB':"lig*/", 'RESULTS_NAME':'results.xml'} fhpd_consolidate = Adv_template(fhpd_consolidate_template,fhpd_consolidate_dict) fhpd_consolidate_file = open(os.path.join(bd_file_path,"fhpd_consolidate.py"), 'w') fhpd_consolidate_file.write(fhpd_consolidate.get_output()) # write an xml file for the input to bd fhpd_consolidate_file.close() make_empty_pqrxml(os.path.join(bd_file_path, 'empty.pqrxml')) counter += 1