Beispiel #1
0
def AtomFromPdbLine(line):
  """
  Returns an Atom object from an atom line in a pdb file.
  """
  atom = Atom()
  if line.startswith('HETATM'):
    atom.is_hetatm = True
  else:
    atom.is_hetatm = False
  atom.num = int(line[6:11])
  atom.type = line[12:16].strip(" ")
  atom.alt_conform = line[16]
  atom.res_type = line[17:21].strip()
  atom.element = data.guess_element(atom.res_type, atom.type)
  atom.chain_id = line[21]
  atom.res_num = int(line[22:26])
  atom.res_insert = line[26]
  if atom.res_insert == " ":
    atom.res_insert = ""
  x = float(line[30:38])
  y = float(line[38:46])
  z = float(line[46:54])
  v3.set_vector(atom.pos, x, y, z)
  try:
    atom.occupancy = float(line[54:60])
  except:
    atom.occupancy = 100.0
  try:
    atom.bfactor = float(line[60:66])
  except:
    atom.bfactor = 0.0
  return atom
Beispiel #2
0
def soup_from_psf(psf):
  """
  Returns a Soup from a .psf file
  """
  soup = pdbatoms.Soup()
  curr_res_num = None
  is_header = True
  for line in open(psf):
    if is_header:
      if "NATOM" in line:
        n_atom = int(line.split()[0])
        is_header = False
      continue
    words = line.split()
    atom_num = int(words[0])
    chain_id = words[1]
    res_num = int(words[2])
    res_type = words[3]
    atom_type = words[4]
    charge = float(words[6])
    mass = float(words[7])
    if chain_id.startswith('WT') or chain_id.startswith('ION'):
      is_hetatm = True
      chain_id = " "
    else:
      is_hetatm = False
      chain_id = chain_id[0]
    if curr_res_num != res_num:
      res = pdbatoms.Residue(res_type, chain_id, res_num)
      soup.append_residue(res)
      curr_res_num = res_num
    atom = pdbatoms.Atom()
    atom.vel = v3.vector()
    atom.chain_id = chain_id
    atom.is_hetatm = is_hetatm
    atom.num = atom_num
    atom.res_num = res_num
    atom.res_type = res_type
    atom.type = atom_type
    atom.mass = mass
    atom.charge = charge
    atom.element = data.guess_element(res_type, atom_type)
    soup.insert_atom(-1, atom)
    if len(soup.atoms()) == n_atom:
      break
  convert_to_pdb_atom_names(soup)
  return soup
Beispiel #3
0
def AtomFromGroLine(line):
    """
  Returns an Atom object from a .gro atom line.
  """
    atom = pdbatoms.Atom()
    atom.res_num = int(line[0:5])
    atom.res_type = line[5:8].strip()
    atom.type = line[10:15].strip(" ")
    atom.element = data.guess_element(atom.res_type, line[12:15])
    atom.num = int(line[15:20])
    # 10 x multiplier converts from nm to angstroms
    x = 10.0 * float(line[20:28])
    y = 10.0 * float(line[28:36])
    z = 10.0 * float(line[36:44])
    v3.set_vector(atom.pos, x, y, z)
    if len(line) > 62:
        # 10 x multiplier converts from nm to angstroms
        x = 10.0 * float(line[44:52])
        y = 10.0 * float(line[52:60])
        z = 10.0 * float(line[60:68])
        v3.set_vector(atom.vel, x, y, z)
    return atom
Beispiel #4
0
def AtomFromGroLine(line):
  """
  Returns an Atom object from a .gro atom line.
  """
  atom = pdbatoms.Atom()
  atom.res_num = int(line[0:5])
  atom.res_type = line[5:8].strip()
  atom.type = line[10:15].strip(" ")
  atom.element = data.guess_element(
      atom.res_type, line[12:15])
  atom.num = int(line[15:20])
  # 10 x multiplier converts from nm to angstroms
  x = 10.0*float(line[20:28])
  y = 10.0*float(line[28:36])
  z = 10.0*float(line[36:44])
  v3.set_vector(atom.pos, x, y, z)
  if len(line) > 62:
    # 10 x multiplier converts from nm to angstroms
    x = 10.0*float(line[44:52])
    y = 10.0*float(line[52:60])
    z = 10.0*float(line[60:68])
    v3.set_vector(atom.vel, x, y, z)
  return atom
Beispiel #5
0
def soup_from_topology(topology):
  """
  Returns a Soup from a topology dictionary.
  """
  soup = pdbatoms.Soup()
  chain_id = ''
  n_res = topology['NRES']
  n_atom = topology['NATOM']
  for i_res in range(n_res):
    res_type = topology['RESIDUE_LABEL'][i_res].strip()
    if res_type == "WAT":
      res_type = "HOH"
    res = pdbatoms.Residue(res_type, chain_id, i_res+1)
    soup.append_residue(res)
    res = soup.residue(i_res)
    i_atom_start = topology['RESIDUE_POINTER'][i_res] - 1
    if i_res == n_res-1:
      i_atom_end = n_atom
    else:
      i_atom_end = topology['RESIDUE_POINTER'][i_res+1] - 1
    for i_atom in range(i_atom_start, i_atom_end):
      atom = pdbatoms.Atom()
      atom.vel = v3.vector()
      atom.num = i_atom+1
      atom.res_num = i_res+1
      atom.res_type = res_type
      atom.type = topology['ATOM_NAME'][i_atom].strip()
      atom.mass = topology['MASS'][i_atom]
      atom.charge = topology['CHARGE'][i_atom]/sqrt_of_k
      atom.element = data.guess_element(
          atom.res_type, atom.type)
      soup.insert_atom(-1, atom)
  convert_to_pdb_atom_names(soup)
  if topology['IFBOX'] > 0:
    # create dummy dimension to ensure box dimension recognized
    soup.box_dimension_str = "1.000000 1.0000000 1.000000"
  return soup
Beispiel #6
0
def soup_from_topology(topology):
    """
  Returns a Soup from a topology dictionary.
  """
    soup = pdbatoms.Soup()
    chain_id = ''
    n_res = topology['NRES']
    n_atom = topology['NATOM']
    for i_res in range(n_res):
        res_type = topology['RESIDUE_LABEL'][i_res].strip()
        if res_type == "WAT":
            res_type = "HOH"
        res = pdbatoms.Residue(res_type, chain_id, i_res + 1)
        soup.append_residue(res)
        res = soup.residue(i_res)
        i_atom_start = topology['RESIDUE_POINTER'][i_res] - 1
        if i_res == n_res - 1:
            i_atom_end = n_atom
        else:
            i_atom_end = topology['RESIDUE_POINTER'][i_res + 1] - 1
        for i_atom in range(i_atom_start, i_atom_end):
            atom = pdbatoms.Atom()
            atom.vel = v3.vector()
            atom.num = i_atom + 1
            atom.res_num = i_res + 1
            atom.res_type = res_type
            atom.type = topology['ATOM_NAME'][i_atom].strip()
            atom.mass = topology['MASS'][i_atom]
            atom.charge = topology['CHARGE'][i_atom] / sqrt_of_k
            atom.element = data.guess_element(atom.res_type, atom.type)
            soup.insert_atom(-1, atom)
    convert_to_pdb_atom_names(soup)
    if topology['IFBOX'] > 0:
        # create dummy dimension to ensure box dimension recognized
        soup.box_dimension_str = "1.000000 1.0000000 1.000000"
    return soup