Ejemplo n.º 1
0
def convert_pdb_to_namd_pdb(standard_pdb, namd_pdb):
  soup = Soup(standard_pdb)
  for res in soup.residues():
    if res.type == "ILE" and res.has_atom('CD1'):
      res.atom('CD1').type = 'CD'
    if res.has_atom('OXT'):
      res.atom('OXT').type = 'OT2'
      if res.has_atom('O'):
        res.atom('O').type = 'OT1'
    for atom in res.atoms():
      if atom.type[0].isdigit() and atom.type[1] == "H":
        atom.type = atom.type[1:] + atom.type[0]
  soup.write_pdb(namd_pdb)
Ejemplo n.º 2
0
def make_namd_from_pdb(pdb, psf, out_pdb): 
  """
  Creates charmm .pdb and .psf file. Can only make NAMD
  generate CHARMM topology files, not OPLS ones - that
  requires XPLOR but I don't care. Still, if OPLS
  topology files are provided - can still run.
  """

  def is_non_water_hetatm(line):
    if not line.startswith("HETATM"):
      return False
    if line[17:20] != 'HOH':
      return True
    return False
    
  in_pdb = util.temp_fname('.pdb')
  txt = open(pdb, 'r').read()
  txt = pdbtext.strip_other_nmr_models(txt)
  txt = pdbtext.strip_lines(txt, is_non_water_hetatm)
  txt = pdbtext.strip_lines(txt, lambda l: l.startswith('ANISOU'))
  txt = pdbtext.strip_lines(txt, lambda l: l.startswith('CONECT'))
  txt = pdbtext.strip_lines(txt, lambda l: l.startswith('MASTER'))
  txt = pdbtext.strip_alternative_atoms(txt)
  txt = pdbtext.strip_hydrogens(txt)
  txt = pdbtext.renumber_residues(txt)
  f = open(in_pdb, 'w')
  f.write(txt)
  f.close()
  
  name = psf.replace('.psf', '')
  psfgen_in = name + ".psfgen.in"
  psfgen_out = name + ".psfgen.out"
  
  replace = { 'pdb': in_pdb, 
              'out_pdb': out_pdb, 
              'psf': psf,
              'module_dir': module_dir,
              'topology': 'parms/charmm22.topology'
             }

  template = _psfgen_template

  soup = Soup(in_pdb)
  chains = soup.chains()

  water_names = ['WAT', "TIP", "TIP3", "HOH"]
  waters = [chain for chain in chains 
            if chain.n_residue() > 0 and chain.residue(0).type in water_names]
  chains = [chain for chain in chains if chain.n_residue() > 0 and chain.residue(0).type not in water_names]
  
  if len(waters) > 0:
    template = template.replace("# insert water", _water_psfgen_template)
    water_pdb = name + ".waters.pdb"
    water_soup = Soup()
    for water in waters:
      water_soup.insert_chain(water)
    water_soup.write_pdb(water_pdb)
    replace['water_pdb'] = water_pdb
    
  chains_template = ""
  for i, chain in enumerate(chains):
    id = 'ch%d' % i
    pdb = name + '.' + id + '.pdb'
    chain_soup = Soup()
    chain_soup.append_chain(chain)
    chain_soup.write_pdb(pdb)

    chain_replace = { 'chain_id': id, 'chain_pdb': pdb }
    chain_template = _chain_psfgen_template
    chains_template += util.replace_dict(chain_template, chain_replace)

  template = template.replace("# insert protein", chains_template)     
    
  template = util.replace_dict(template, replace)
  open(psfgen_in, "w").write(template)
  
  os.system("psfgen %s > %s" % (psfgen_in, psfgen_out))
  os.remove(in_pdb)