Exemple #1
0
def pdb_to_top_and_crds(force_field, pdb, basename, solvent_buffer=10.0): 
  """
  Creates CHARMM .coor and .psf file for NAMD simulation.
  """
  solv_dir = basename + '.solvate'
  save_dir = os.getcwd()

  pdb = os.path.abspath(pdb)

  util.goto_dir(solv_dir)

  # Remove all but protein heavy atoms in a single clean conformation
  stripped_pdb = basename + '.clean.pdb' 
  pdbtext.clean_pdb(pdb, stripped_pdb)

  # Make input script for psfgen
  psfgen_psf = basename+'.psfgen.psf'
  psfgen_pdb = basename+'.psfgen.pdb'
  script = module_load_script 
  script += make_chain_loading_script(stripped_pdb, basename)
  script += make_disulfide_script(stripped_pdb)
  script += write_script 
  script = script % {
    # load the included CHARMM2 atom topologies
    'topology': os.path.join(data.data_dir, 'charmm22.topology'),
    'out_pdb': psfgen_pdb,
    'out_psf': psfgen_psf
  }

  psfgen_in = basename+".psfgen.in"
  open(psfgen_in, "w").write(script)

  data.binary('psfgen', psfgen_in, basename+'.psfgen')
  util.check_output(psfgen_psf)
  util.check_output(psfgen_pdb)

  solvate_psf(psfgen_psf, psfgen_pdb, basename, solvent_buffer)

  psf = basename+'.psf'
  coor = basename+'.coor'
  pdb = basename+'.pdb'
  os.rename(pdb, coor)
  convert_restart_to_pdb(basename, pdb)
  shutil.copy(psf, save_dir)
  shutil.copy(coor, save_dir)
  shutil.copy(pdb, save_dir)
  
  os.chdir(save_dir)

  return psf, coor
Exemple #2
0
def run_tleap(force_field, pdb, name, solvent_buffer=0.0, excess_charge=0):
    """
  Generates AMBER topology and coordinate files from PDB.

  Depending on whether excess_charge is non-zero, will also generate
  counterions. If solvent_buffer is non-zero, will generate explicit
  waters, otherwise, no waters generated. No waters is used for
  implicit solvent simulations.
  """

    util.check_output(pdb)

    # Remove all but protein heavy atoms in a single clean conformation
    tleap_pdb = name + '.clean.pdb'
    pdbtext.clean_pdb(pdb, tleap_pdb)

    # The restart files to be generated
    top = name + '.top'
    crd = name + '.crd'

    # Dictionary to substitute into tleap scripts
    params = {
        'top': top,
        'crd': crd,
        'pdb': tleap_pdb,
        'data_dir': data.data_dir,
        'solvent_buffer': solvent_buffer,
    }

    # use best force-field for the 2 versions of AMBER author has tested
    if 'AMBER11' in force_field:
        params['amber_ff'] = "leaprc.ff99SB"
    elif 'AMBER8' in force_field:
        params['amber_ff'] = "leaprc.ff96"
    else:
        raise Exception("Don't know which version of AMBER(8|11) to use.")

    # make the tleap input script
    script = force_field_script
    # check for a few non-standard residue that have been included
    residues = [r.type for r in pdbatoms.Soup(tleap_pdb).residues()]
    if 'PHD' in residues:
        leaprc = open("%s/phd.leaprc" % data.data_dir).read()
        script += leaprc
    if 'ZNB' in residues:
        leaprc = open("%s/znb.leaprc" % data.data_dir).read()
        script += leaprc
    script += "pdb = loadpdb %(pdb)s\n"
    script += disulfide_script_and_rename_cysteines(tleap_pdb, tleap_pdb)
    if 'GBSA' not in force_field:
        # Add explicit waters as not GBSA implicit solvent
        if excess_charge != 0:
            # Add script to add counterions, must specify + or -
            if excess_charge > 0:
                script += "addions pdb Cl- 0\n"
            else:
                script += "addions pdb Na+ 0\n"
        solvent_buffer = 10
        params['solvent_buffer'] = solvent_buffer
        script += explicit_water_box_script
    script += save_and_quit_script
    script = script % params

    # Now write script to input file
    tleap_in = name + ".tleap.in"
    open(tleap_in, "w").write(script)

    # Now run tleap with tleap_in
    data.binary('tleap', "-f " + tleap_in, name + '.tleap')

    # Check output is okay
    if os.path.isfile('leap.log'):
        os.rename('leap.log', name + '.tleap.log')
    util.check_output(name + '.tleap.log', ['FATAL'])
    util.check_output(top)
    util.check_output(crd)

    return top, crd
Exemple #3
0
def pdb_to_top_and_crds(force_field, pdb, basename, solvent_buffer=10):
    """
  Converts a PDB file into GROMACS topology and coordinate files,
  and fully converted PDB file. These constitute the restart files
  of a GROMACS simulation.
  """
    util.check_files(pdb)
    full_pdb = os.path.abspath(pdb)
    save_dir = os.getcwd()

    # All intermediate files placed into a subdirectory
    util.goto_dir(basename + '.solvate')

    # Remove all but protein heavy atoms in a single clean conformation
    pdb = basename + '.clean.pdb'
    pdbtext.clean_pdb(full_pdb, pdb)

    # Generate protein topology in pdb2gmx_gro using pdb2gmx
    pdb2gmx_gro = basename + '.pdb2gmx.gro'
    top = basename + '.top'
    itp = basename + '_posre.itp'
    # Choose force field based on GROMACS version
    if 'GROMACS4.5' in force_field:
        ff = 'amber99'
    elif 'GROMACS4.0' in force_field:
        ff = 'G43a1'
    else:
        raise ValueError, "Couldn't work out pdb2gmx for " + force_field
    args = '-ignh -ff %s -water spc -missing -f %s -o %s -p %s -i %s -chainsep id_or_ter -merge all' \
            % (ff, pdb, pdb2gmx_gro, top, itp)
    data.binary('pdb2gmx', args, basename + '.pdb2gmx')
    util.check_files(pdb2gmx_gro)

    # Now add a box with editconf
    box_gro = basename + '.box.gro'
    solvent_buffer_in_nm = solvent_buffer / 10.0
    data.binary(
        'editconf',
        '-f %s -o %s -c -d %f -bt cubic' \
            % (pdb2gmx_gro, box_gro, solvent_buffer_in_nm),
        basename+'.box')
    util.check_files(box_gro)

    # Given box dimensions, can now populate with explict waters
    solvated_gro = basename + '.solvated.gro'
    data.binary(
        'genbox',
        '-cp %s -cs spc216.gro -o %s -p %s' \
            % (box_gro, solvated_gro, top),
         '%s.solvated' % basename)
    util.check_files(solvated_gro)

    # Neutralize with counterions using genion to place ions
    # based on energy parameters processed by grompp
    gro = basename + '.gro'
    neutralize_system_with_salt(top, solvated_gro, basename, force_field)
    util.check_files(gro)

    # Make a reference PDB file from restart files for viewing and restraints
    convert_restart_to_pdb(basename, basename + '.pdb')

    # Copy finished restart files back into original directory
    fnames = util.re_glob(
        '*',
        os.path.basename(basename) + r'[^\.]*\.(pdb|itp|gro|mdp|top)$')
    for fname in fnames:
        shutil.copy(fname, save_dir)

    # Cleanup
    delete_backup_files(basename)
    os.chdir(save_dir)

    return top, gro
Exemple #4
0
def run_tleap(
    force_field, pdb, name, solvent_buffer=0.0, excess_charge=0): 
  """
  Generates AMBER topology and coordinate files from PDB.

  Depending on whether excess_charge is non-zero, will also generate
  counterions. If solvent_buffer is non-zero, will generate explicit
  waters, otherwise, no waters generated. No waters is used for
  implicit solvent simulations.
  """

  util.check_output(pdb)

  # Remove all but protein heavy atoms in a single clean conformation
  tleap_pdb = name + '.clean.pdb'
  pdbtext.clean_pdb(pdb, tleap_pdb)

  # The restart files to be generated
  top = name + '.top'
  crd = name + '.crd'

  # Dictionary to substitute into tleap scripts
  params = { 
    'top': top, 
    'crd': crd, 
    'pdb': tleap_pdb,
    'data_dir':data.data_dir,
    'solvent_buffer': solvent_buffer,
  }

  # use best force-field for the 2 versions of AMBER author has tested
  if 'AMBER11' in force_field:
    params['amber_ff'] = "leaprc.ff99SB"
  elif 'AMBER14' in force_field:
    params['amber_ff'] = "leaprc.ff14SB"
  elif 'AMBER8' in force_field:
    params['amber_ff'] = "leaprc.ff96"
  else:
    raise Exception("Don't know which version of AMBER(8|11|14) to use.")

  # make the tleap input script
  script = force_field_script
  # check for a few non-standard residue that have been included 
  residues = [r.type for r in pdbatoms.Soup(tleap_pdb).residues()]
  if 'PHD' in residues:
    leaprc = open("%s/phd.leaprc" % data.data_dir).read()
    script += leaprc
  if 'ZNB' in residues:
    leaprc = open("%s/znb.leaprc" % data.data_dir).read()
    script += leaprc
  script += "pdb = loadpdb %(pdb)s\n"
  script += disulfide_script_and_rename_cysteines(tleap_pdb, tleap_pdb)
  if 'GBSA' not in force_field:
    # Add explicit waters as not GBSA implicit solvent
    if excess_charge != 0:
      # Add script to add counterions, must specify + or -
      if excess_charge > 0:
        script += "addions pdb Cl- 0\n"
      else:
        script += "addions pdb Na+ 0\n"
    solvent_buffer = 10
    params['solvent_buffer'] = solvent_buffer
    script += explicit_water_box_script
  script += save_and_quit_script
  script = script % params

  # Now write script to input file
  tleap_in = name + ".tleap.in"
  open(tleap_in, "w").write(script)

  # Now run tleap with tleap_in
  data.binary('tleap', "-f "+tleap_in, name+'.tleap')

  # Check output is okay
  if os.path.isfile('leap.log'):
    os.rename('leap.log', name + '.tleap.log')
  util.check_output(name+'.tleap.log', ['FATAL'])
  util.check_output(top)
  util.check_output(crd)

  return top, crd
Exemple #5
0
def pdb_to_top_and_crds(force_field, pdb, basename, solvent_buffer=10):
  """
  Converts a PDB file into GROMACS topology and coordinate files,
  and fully converted PDB file. These constitute the restart files
  of a GROMACS simulation.
  """
  util.check_files(pdb)
  full_pdb = os.path.abspath(pdb)
  save_dir = os.getcwd()

  # All intermediate files placed into a subdirectory
  util.goto_dir(basename + '.solvate')

  # Remove all but protein heavy atoms in a single clean conformation
  pdb = basename + '.clean.pdb'
  pdbtext.clean_pdb(full_pdb, pdb)

  # Generate protein topology in pdb2gmx_gro using pdb2gmx
  pdb2gmx_gro = basename + '.pdb2gmx.gro'
  top = basename + '.top'
  itp = basename + '_posre.itp'
  # Choose force field based on GROMACS version
  if 'GROMACS4.5' in force_field:
    ff = 'amber99' 
  elif 'GROMACS4.0' in force_field:
    ff = 'G43a1' 
  else:
    raise ValueError, "Couldn't work out pdb2gmx for " + force_field
  args = '-ignh -ff %s -water spc -missing -f %s -o %s -p %s -i %s -chainsep id_or_ter -merge all' \
          % (ff, pdb, pdb2gmx_gro, top, itp)
  data.binary('pdb2gmx', args, basename+'.pdb2gmx')
  util.check_files(pdb2gmx_gro)

  # Now add a box with editconf
  box_gro = basename + '.box.gro'
  solvent_buffer_in_nm = solvent_buffer/10.0 
  data.binary(
      'editconf', 
      '-f %s -o %s -c -d %f -bt cubic' \
          % (pdb2gmx_gro, box_gro, solvent_buffer_in_nm),
      basename+'.box')
  util.check_files(box_gro)

  # Given box dimensions, can now populate with explict waters
  solvated_gro = basename + '.solvated.gro'
  data.binary(
      'genbox',
      '-cp %s -cs spc216.gro -o %s -p %s' \
          % (box_gro, solvated_gro, top),
       '%s.solvated' % basename)
  util.check_files(solvated_gro)

  # Neutralize with counterions using genion to place ions 
  # based on energy parameters processed by grompp 
  gro = basename + '.gro'
  neutralize_system_with_salt(top, solvated_gro, basename, force_field)
  util.check_files(gro)

  # Make a reference PDB file from restart files for viewing and restraints
  convert_restart_to_pdb(basename, basename+'.pdb')

  # Copy finished restart files back into original directory
  fnames = util.re_glob(
      '*', os.path.basename(basename) + r'[^\.]*\.(pdb|itp|gro|mdp|top)$')
  for fname in fnames:
    shutil.copy(fname, save_dir)

  # Cleanup
  delete_backup_files(basename)
  os.chdir(save_dir)

  return top, gro