Exemple #1
0
def SoupFromNamdPsf(psf, in_coor_pdb, in_vel_pdb):
  soup = Soup(in_coor_pdb)
  load_masses_to_soup(psf, soup)
  vel_soup = Soup(in_vel_pdb)
  for atom, vel_atom in zip(soup.atoms(), vel_soup.atoms()):
    v = vel_atom.pos
    atom.vel.set(v.x, v.y, v.z)
  return soup
Exemple #2
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)
Exemple #3
0
def SoupFromPsf(psf):
  "read a psf and parse into protein chains."

  f = open(psf, "r")
  line = f.readline()
  while 'NATOM' not in line:
    line = f.readline()
  n_atom = int(line[0:8])  
  lines = [f.readline() for i in range(0, n_atom)]
  f.close
  
  # work out the chains in the psf file
  chain_info_list = []
  chain_char = ""
  res_num = -1
  chain_type = ""
  for i, line in enumerate(lines):
    word_list = line.split()
    new_chain_type = word_list[1]
    new_res_num = int(word_list[2])
    if chain_type == "":
      chain_type = new_chain_type
      res_num = new_res_num
      chain_info_list.append([chain_type, i, i+1])
    elif chain_type is "WATERS" and new_chain_type is "WATERS" and \
             res_num <> new_res_num:
      res_num = new_res_num
      chain_info_list.append([chain_type, i, i+1])
    elif chain_type <> new_chain_type:
      chain_type = new_chain_type
      chain_info_list.append([chain_type, i, i+1])
    else:
      chain_info_list[-1][2] = i+1

  # make a list of chains using the objects in protein
  chains = []
  for name, first, last in chain_info_list:
    if "WATERS" in name:
      chain = polymer.Polymer()
    else:
      chain = protein.Protein()
  
    curr_res_num = -1
    for i, line in enumerate(lines[first:last]):
        word_list = line.split()
        atom = molecule.Atom()
        atom.res_num = int(word_list[2])
        atom.res_type = word_list[3][0:3]
        atom.type = word_list[4]
        atom.element = atom.type[0]
        atom.type = atom.type.strip(" ")
        atom.num = i + first
        try:
          atom.mass = float(word_list[7])
        except:
          atom.mass = 0.0

        if curr_res_num != atom.res_num:
          res = polymer.Residue(atom.res_type, atom.chain_id, atom.res_num, '')
          chain.append_residue_no_renum(res)
          curr_res_num = atom.res_num
        
        chain.insert_atom(chain.n_residue()-1, atom)
    chains.append(chain)
    
  soup = Soup()
  for chain in chains:
    soup.append_chain(chain)

  # load masses in [a.m.u.]
  masses = [float(line[47:60]) for line in open(psf, "r") if "CHAIN" in line]
  for a, m in zip(soup.atoms(), masses):
    a.mass = m 

  return soup
Exemple #4
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)