Beispiel #1
0
def make_pdbs_png(png,
                  pdbs,
                  bgcolor="white",
                  center_res=None,
                  top_res=None,
                  highlight_res=None,
                  is_sticks=True,
                  is_putty=False,
                  width=480,
                  height=480):

    if 'transparent' in bgcolor:
        script = 'set opaque_background, off\n'
    else:
        script = make_bgcolor_script(bgcolor)

    temp_fnames = []
    if center_res and top_res:
        transform = get_pdb_transform(pdbs[0], center_res, top_res)
        for i in range(len(pdbs)):
            soup = pdbatoms.Soup(pdbs[i])
            soup.transform(transform)
            new_pdb = util.fname_variant(pdbs[i])
            soup.write_pdb(new_pdb)
            temp_fnames.append(new_pdb)
            pdbs[i] = new_pdb
            del soup

    script += make_load_pdbs_script(pdbs)
    script += make_separate_chain_colors_script(pdbs)

    if is_putty:
        script += make_putty_script(get_scale_max(max_bfactor, upper_bfactor))
    else:
        script += cartoon_script

    if not is_sticks:
        script += "hide stick\n"
    else:
        script += "show stick\n"

    script += make_ligands_as_sticks_script(pdbs)

    if highlight_res:
        script += make_highlight_res_script(highlight_res)
    script += hide_backbone_sticks_script

    # script += "clip far, 5\n"
    script += "save %s\n" % png
    script += "quit"

    pml = util.fname_variant('temp.pml')
    open(pml, 'w').write(script)
    run_pymol_script(pml, width, height)
    temp_fnames.append(pml)

    util.clean_fname(*temp_fnames)
Beispiel #2
0
def make_pdbs_png(
    png, pdbs, bgcolor="white", center_res=None, top_res=None,
    highlight_res=None, is_sticks=True, is_putty=False,
    width=480, height=480):

  if 'transparent' in bgcolor:
    script = 'set opaque_background, off\n'
  else: 
    script = make_bgcolor_script(bgcolor)

  temp_fnames = []
  if center_res and top_res:
    transform = get_pdb_transform(pdbs[0], center_res, top_res)
    for i in range(len(pdbs)):
      soup = pdbatoms.Soup(pdbs[i])
      soup.transform(transform)
      new_pdb = util.fname_variant(pdbs[i])
      soup.write_pdb(new_pdb)
      temp_fnames.append(new_pdb)
      pdbs[i] = new_pdb
      del soup

  script += make_load_pdbs_script(pdbs)
  script += make_separate_chain_colors_script(pdbs)

  if is_putty:
    script += make_putty_script(get_scale_max(
        max_bfactor, upper_bfactor))
  else:
    script += cartoon_script

  if not is_sticks:
    script += "hide stick\n"
  else:
    script += "show stick\n"

  script += make_ligands_as_sticks_script(pdbs)

  if highlight_res:
    script += make_highlight_res_script(highlight_res)
  script += hide_backbone_sticks_script

  # script += "clip far, 5\n"
  script += "save %s\n" % png
  script += "quit"

  pml = util.fname_variant('temp.pml')
  open(pml, 'w').write(script)
  run_pymol_script(pml, width, height)
  temp_fnames.append(pml)

  util.clean_fname(*temp_fnames)
Beispiel #3
0
def rescale_positive_negative_bfactors_pdb(
    pdb, lower_bfactor, upper_bfactor):
  """
  Returns max_bfactor after rescale 
  """
  soup = pdbatoms.Soup(pdb)
  bfactors = [a.bfactor for a in soup.atoms()]
  if upper_bfactor is None:
    upper_bfactor = max(bfactors)
  # cut-off max_values
  if upper_bfactor:
    for j in range(len(bfactors)):
      if bfactors[j] > upper_bfactor:
        bfactors[j] = upper_bfactor
      if bfactors[j] < -upper_bfactor:
        bfactors[j] = -upper_bfactor
    # will delete later within pymol script
    add_fake_water_atom(soup, 'XXX', upper_bfactor)
    add_fake_water_atom(soup, 'XXX', -upper_bfactor)
  # cut-off below min_val to zero
  if lower_bfactor:
    for j in range(len(bfactors)):
      if -lower_bfactor < bfactors[j] < lower_bfactor:
        bfactors[j] = 0.0
  for a, bfactor in zip(soup.atoms(), bfactors):
    a.bfactor = bfactor
  new_pdb = util.fname_variant(pdb)
  soup.write_pdb(new_pdb)
  return new_pdb, max(bfactors)
Beispiel #4
0
def transform_pdbs_to_residues_of_first_pdb(pdbs, center_res, top_res):
  transform = get_pdb_transform(pdbs[0], center_res, top_res)
  new_pdbs = []
  for pdb in pdbs:
    new_pdb = util.fname_variant(pdb)
    soup = pdbatoms.Soup(pdb)
    soup.transform(transform)
    soup.write_pdb(new_pdb)
    new_pdbs.append(new_pdb)
  return new_pdbs
Beispiel #5
0
def transform_pdbs_to_residues_of_first_pdb(pdbs, center_res, top_res):
    transform = get_pdb_transform(pdbs[0], center_res, top_res)
    new_pdbs = []
    for pdb in pdbs:
        new_pdb = util.fname_variant(pdb)
        soup = pdbatoms.Soup(pdb)
        soup.transform(transform)
        soup.write_pdb(new_pdb)
        new_pdbs.append(new_pdb)
    return new_pdbs
Beispiel #6
0
def pdb_to_bfactor_png(bfactor_pdb,
                       png,
                       lower_bfactor=None,
                       upper_bfactor=None,
                       highlight_res=None,
                       is_putty=False,
                       is_sticks=True,
                       center_res=None,
                       top_res=None,
                       height=480,
                       width=480):
    """
  Generates a bfactor-colored .png using the standard white-to-red
  color scheme with a useful set of options. highlight_res, 
  center_res & top_res follow the 'A:10' style of residue naming.
  """

    pdb, max_bfactor = rescale_positive_bfactors_pdb(bfactor_pdb,
                                                     lower_bfactor,
                                                     upper_bfactor)
    temp_fnames = [pdb]

    if center_res or top_res:
        pdb = get_pdb_transform(pdb, center_res, top_res)
        temp_fnames.append(pdb)

    script = ""

    script += bfactor_script(pdb, lower_bfactor, upper_bfactor, max_bfactor,
                             is_putty)

    if highlight_res is not None:
        pymol_res_id = get_pymol_id_from_res_tag(highlight_res)
        script += make_highlight_res_script(pymol_res_id)
        script += hide_backbone_sticks_script

    script += "clip far, -20\n"
    script += "save %s\n" % png
    script += "quit"

    pml = util.fname_variant('temp.pml')
    open(pml, 'w').write(script)
    run_pymol_script(pml, width, height)
    temp_fnames.append(pml)

    util.clean_fname(*temp_fnames)
Beispiel #7
0
def get_best_alignment(pdb1, pdb2, segments1, segments2, atom_types):
  """Returns rmsd and filename of transformed pdb2."""
  polymer1 = polymer.Polymer(pdb1)
  atoms1 = get_superposable_atoms(polymer1, segments1, atom_types)
  polymer2 = polymer.Polymer(pdb2)
  atoms2 = get_superposable_atoms(polymer2, segments2, atom_types)

  center1 = molecule.get_center(atoms1)
  polymer1.transform(vector3d.Translation(-center1))
  polymer2.transform(vector3d.Translation(-molecule.get_center(atoms2)))
  polymer2.transform(calculate_superposition_matrix(atoms1, atoms2))

  rmsd = sum_rmsd(atoms1, atoms2)
  
  temp_pdb2 = util.fname_variant(pdb2)
  polymer2.transform(vector3d.Translation(center1))
  polymer2.write_pdb(temp_pdb2)
  
  return rmsd, temp_pdb2
Beispiel #8
0
def get_best_alignment(pdb1, pdb2, segments1, segments2, atom_types):
    """Returns rmsd and filename of transformed pdb2."""
    polymer1 = polymer.Polymer(pdb1)
    atoms1 = get_superposable_atoms(polymer1, segments1, atom_types)
    polymer2 = polymer.Polymer(pdb2)
    atoms2 = get_superposable_atoms(polymer2, segments2, atom_types)

    center1 = molecule.get_center(atoms1)  # centruje pierwsza
    polymer1.transform(vector3d.Translation(-center1))
    polymer2.transform(vector3d.Translation(-molecule.get_center(atoms2)))
    polymer2.transform(calculate_superposition_matrix(atoms1, atoms2))

    rmsd = sum_rmsd(atoms1, atoms2)

    temp_pdb2 = util.fname_variant(pdb2)
    polymer2.transform(vector3d.Translation(center1))
    polymer2.write_pdb(temp_pdb2)

    return rmsd, temp_pdb2
Beispiel #9
0
def rescale_positive_bfactors_pdb(pdb, lower_bfactor, upper_bfactor):
  """
  Returns max_bfactor after rescale (needed for worm
  calculation)
  """
  soup = pdbatoms.Soup(pdb)
  bfactors = [a.bfactor for a in soup.atoms()]
  # cut-off max_values
  if upper_bfactor:
    bfactors = [upper_bfactor if b > upper_bfactor else b 
                for b in bfactors]
    # will delete later within pymol script
    add_fake_water_atom(soup, 'XXX', upper_bfactor)
  # cut-off below min_val to zero
  if lower_bfactor:
    for j in range(len(bfactors)):
      bfactors = [0 if b < lower_bfactor else b for b in bfactors]
  for a, bfactor in zip(soup.atoms(), bfactors):
    a.bfactor = bfactor
  new_pdb = util.fname_variant(pdb)
  soup.write_pdb(new_pdb)
  return new_pdb, max(bfactors)
Beispiel #10
0
def pdb_to_bfactor_png(
    bfactor_pdb, png, lower_bfactor=None, upper_bfactor=None, 
    highlight_res=None, is_putty=False, is_sticks=True,
    center_res=None, top_res=None, height=480, width=480):
  """
  Generates a bfactor-colored .png using the standard white-to-red
  color scheme with a useful set of options. highlight_res, 
  center_res & top_res follow the 'A:10' style of residue naming.
  """

  pdb, max_bfactor = rescale_positive_bfactors_pdb(
      bfactor_pdb, lower_bfactor, upper_bfactor)
  temp_fnames = [pdb]

  if center_res or top_res:
    pdb = get_pdb_transform(pdb, center_res, top_res)
    temp_fnames.append(pdb)

  script = ""

  script += bfactor_script(
       pdb, lower_bfactor, upper_bfactor,
       max_bfactor, is_putty)

  if highlight_res is not None:
    pymol_res_id = get_pymol_id_from_res_tag(highlight_res)
    script += make_highlight_res_script(pymol_res_id)
    script += hide_backbone_sticks_script

  script += "clip far, -20\n"
  script += "save %s\n" % png
  script += "quit"

  pml = util.fname_variant('temp.pml')
  open(pml, 'w').write(script)
  run_pymol_script(pml, width, height)
  temp_fnames.append(pml)

  util.clean_fname(*temp_fnames)
Beispiel #11
0
def strip_solvent_pdb(pdb):
  new_pdb = util.fname_variant(pdb)
  txt = pdbtext.strip_solvent(open(pdb).read())
  open(new_pdb, 'w').write(txt)
  return new_pdb
Beispiel #12
0
def strip_solvent_pdb(pdb):
    new_pdb = util.fname_variant(pdb)
    txt = pdbtext.strip_solvent(open(pdb).read())
    open(new_pdb, 'w').write(txt)
    return new_pdb