Example #1
0
def _load_structures(inp, sys_params,):
	'''load protein/ligand structures needed for calculation'''
	parser = pdb.Big_PDBParser()
	print("now loading structures")

	# Read and/or create pickle files for the structures to save I/O time
	ligand_pkl_filename = os.path.join(inp['rootdir'], "ligand.pkl")
	receptor_pkl_filename = os.path.join(inp['rootdir'], "receptor.pkl")
	receptor_pkl_dry_filename = os.path.join(inp['rootdir'], "receptor_dry.pkl")
	receptor_pkl_dry_pqr_filename = os.path.join(inp['rootdir'], "receptor_dry_pqr.pkl")

	ligand=pickle_or_load(sys_params['lig_pqr_filename'], ligand_pkl_filename, struc_name="ligand", pqr=True)
	#receptor=pickle_or_load(sys_params['rec_pdb_filename'], receptor_pkl_filename, struc_name="receptor", pqr=False)
	receptor_dry=pickle_or_load(sys_params['rec_dry_pdb_filename'], receptor_pkl_dry_filename, struc_name="receptor_dry", pqr=False)
	receptor_dry_pqr=pickle_or_load(sys_params['rec_dry_pqr_filename'], receptor_pkl_dry_pqr_filename, struc_name="receptor_dry_pqr", pqr=True)

	struct={ # all parameters pertaining to structure
		'ligand':ligand,
		#'receptor':receptor,
		'receptor_dry':receptor_dry, # or create a function that will remove all waters, complicated by ions
		'receptor_dry_pqr':receptor_dry_pqr,
		'rec_com':pdb.center_of_mass(receptor_dry), # have to take into account the center of mass of the receptor itself
		'lig_com':pdb.center_of_mass(ligand), # have to take into account the center of mass of the ligand itself
	}

	return struct
Example #2
0
def _parse_pdb(
    filename,
    struct_name="pickle",
):
    parser = pdb.Big_PDBParser()
    struct = parser.get_structure(struct_name,
                                  filename,
                                  pqr=False,
                                  conventional=False)  # load the file
    return struct
Example #3
0
def pickle_or_load(filename, picklename, struc_name="pickle",pqr=False):
	'''for large files, instead of parsing, they can be saved and loaded much more quickly as a pickle. '''
	parser = pdb.Big_PDBParser()
	if os.path.exists(picklename) and os.path.getmtime(picklename) > os.path.getmtime(filename): # if the pickle has been most recently modified
		# load the pickle
		print("reading pickle:", picklename)
		our_file=open(picklename, 'rb')
		our_obj=pickle.load(our_file)
		our_file.close()
	else:
		# then load the file itself and save the pickle
		our_obj=parser.get_structure(struc_name, filename, pqr=pqr, conventional=False) # load the file
		print("writing pickle:", picklename)
		our_file=open(picklename, 'wb')
		pickle.dump(our_obj, our_file, protocol=-1)
		our_file.close()
	return our_obj
Example #4
0
import milestones
import numpy as np
import pdb2 as pdb
from copy import deepcopy  # needed to keep track of separate structure objects
import namd_inputs  # contains all the details for the namd input files
import colvars
import psfmerge
#import MDAnalysis as mda #import *
from adv_template import Adv_template, File_template
import unittest
import positions_orient
import cPickle as pickle

verbose = True

parser = pdb.Big_PDBParser()

self_path = os.path.dirname(
    os.path.realpath(__file__))  # get the path to this script

fwd_rev_template_location = os.path.join(self_path, 'fwd_rev.template')


def amber_building(settings):
    '''the pre-minimization procedure for amber ff simulations'''
    i = settings['index']
    building = settings['md_file_paths'][i]['building']
    working_pdb_base = 'holo'  #settings['working_pdb_base']
    pdbfile = settings['md_file_paths'][i]['wet_holo']
    amber_settings = settings['amber_settings']
    #sources=amber_settings['sources']
Example #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
Example #6
0
def generate_configs(seekrcalc):
    '''Generates the apo and holo configurations of the receptors and ligands.
  Input:
   - seekrcalc: a SeekrCalculation() object that contains all the settings for
       the SEEKR calculation
  Output:
   - None
  '''
    if verbose: print "Generating structural configurations..."
    parser = pdb.Big_PDBParser()
    if verbose: print "now loading structures"

    # Read and/or create pickle files for the structures to save I/O time
    ligand_pkl_filename = os.path.join(seekrcalc.project.rootdir, "ligand.pkl")
    receptor_pkl_wet_filename = os.path.join(seekrcalc.project.rootdir,
                                             "receptor.pkl")
    #receptor_pkl_dry_filename = os.path.join(seekrcalc.project.rootdir, "receptor_dry.pkl")
    receptor_pkl_dry_pqr_filename = os.path.join(seekrcalc.project.rootdir,
                                                 "receptor_dry_pqr.pkl")

    ligand = pickle_or_load(seekrcalc.building.lig_dry_pqr_filename,
                            ligand_pkl_filename,
                            parser,
                            struc_name="ligand",
                            pqr=True)
    receptor_wet = pickle_or_load(seekrcalc.building.rec_wet_pdb_filename,
                                  receptor_pkl_wet_filename,
                                  parser,
                                  struc_name="receptor_wet",
                                  pqr=False)
    receptor_dry = pickle_or_load(seekrcalc.building.rec_dry_pqr_filename,
                                  receptor_pkl_dry_pqr_filename,
                                  parser,
                                  struc_name="receptor_dry_pqr",
                                  pqr=True)

    seekrcalc.building.ligand = ligand
    seekrcalc.building.rec_wet_pdb_filename = receptor_wet
    seekrcalc.building.rec_dry_pqr_filename = receptor_dry
    milestones = seekrcalc.milestones
    configs = []
    starttime = time.time()
    struct_center = pdb.center_of_mass(ligand)
    if verbose: print "Generating", len(milestones), "ligand configurations"
    for milestone in milestones:
        new_ligand = deepcopy(ligand)  # copy the entire structure
        new_ligand.moveby(
            -struct_center)  # reposition ligand structure over the origin
        new_ligand.moveby(
            milestone.anchor)  # move ligand to the anchor location
        new_ligand.struct_id = milestone.fullname
        configs.append(new_ligand)
    endtime = time.time()
    if verbose:
        "Generate_configs complete. Total number: %d. Elapsed time: %d s" % (
            len(configs),
            endtime - starttime,
        )
        print "Now running through all configurations to combine ligand with receptor."
        if seekrcalc.building.reject_clashes:
            print "Rejecting steric clashes..."
        else:
            print "Ignoring steric clashes..."

    if seekrcalc.project.bd:
        seekrcalc.browndye.starting_lig_config = configs[0]

    for i, milestone in enumerate(
            milestones):  # run thru all the configurations of ligands
        lig_config = configs[i]
        milestone.config = deepcopy(lig_config)
        if seekrcalc.building.reject_clashes:
            if structures_clash(lig_config, receptor_dry, tolerance=0.2):
                continue  # if there's a clash
        if milestone.md:
            #pdb.TER_resnames.append(seekrcalc.building.lig_resname) # TODO: marked for removal
            holo_config_wet, insert_index, last_ligand_index = pdb.ligmerge(
                lig_config, receptor_wet, verbose=False)
            holo_config_wet.struct_id = lig_config.struct_id  # set the structure description to the same as the ligand
            holo_config_wet.renumber_indeces(
            )  # to number the indeces consecutively
            wet_holo_filename = milestone.openmm.wet_holo_pdb_filename
            if verbose: print "writing file:", wet_holo_filename
            holo_config_wet.save(
                wet_holo_filename, amber=True, standard=False
            )  # write the holo structure into the md directory
            last_insert_index = insert_index
            last_last_ligand_index = last_ligand_index
        if milestone.bd:
            holo_config_dry, insert_index, last_ligand_index = pdb.ligmerge(
                lig_config, receptor_dry, verbose=False)
            holo_config_dry.struct_id = lig_config.struct_id  # set the structure description to the same as the ligand
            holo_config_dry.renumber_indeces(
            )  # to number the indeces consecutively
            dry_holo_filename = milestone.openmm.dry_holo_pdb_filename
            if verbose: print "writing file:", dry_holo_filename
            holo_config_dry.save(
                dry_holo_filename, amber=True, standard=False
            )  # write the holo structure into the md directory
    return holo_config_wet, last_insert_index, last_last_ligand_index