Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
  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"
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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