def make_flips_if_necessary_torsion(const_h, flip_h):
  """ 3 times faster than other procedure."""

  const_h.reset_atom_i_seqs()
  flip_h.reset_atom_i_seqs()
  assert const_h.atoms().size() == flip_h.atoms().size()
  flipped_other_selection = flex.size_t([])
  ch_const = const_h.only_model().chains()
  ch_flip = flip_h.only_model().chains()

  for ch_c, ch_f in zip(ch_const, ch_flip):
    for residue, res_flip in zip(ch_c.residues(), ch_f.residues()):
      if (residue.resname in flippable_sidechains
          and should_be_flipped(residue, res_flip)):
        fl_atom_list = flippable_sidechains[residue.resname]
        iseqs = [0]*residue.atoms().size()
        for i, a in enumerate(residue.atoms()):
          try:
            ind = fl_atom_list.index(a.name)
            if ind == 3 or ind == 5:
              iseqs[i+1] = a.i_seq
            elif ind == 4 or ind == 6:
              iseqs[i-1] = a.i_seq
            else:
              iseqs[i] = a.i_seq
          except ValueError:
            iseqs[i] = a.i_seq
        for i in iseqs:
          flipped_other_selection.append(i)
      else:
        for a in residue.atoms():
          flipped_other_selection.append(a.i_seq)
  # print "flipped_other_selection", list(flipped_other_selection)
  assert flipped_other_selection.size() == const_h.atoms().size()
  return flipped_other_selection
Example #2
0
def make_flips_if_necessary_torsion(const_h, flip_h):
  """ 3 times faster than other procedure."""
  assert len(flip_h.models()) == 1, len(flip_h.models())
  assert len(const_h.models()) == 1, len(const_h.models())
  # const_h.write_pdb_file(file_name="const.pdb")
  # flip_h.write_pdb_file(file_name="flip.pdb")
  assert const_h.atoms_size() == flip_h.atoms_size()
  original_atoms_size = const_h.atoms_size()
  flipped_other_selection = flex.size_t([])
  ch_const = const_h.only_model().chains()
  ch_flip = flip_h.only_model().chains()
  for another_ch in ch_const[1:]:
    if another_ch.id == ch_const[0].id:
      for rg in another_ch.residue_groups():
        ch_const[0].append_residue_group(rg.detached_copy())
  for another_ch in ch_flip[1:]:
    if another_ch.id == ch_flip[0].id:
      for rg in another_ch.residue_groups():
        ch_flip[0].append_residue_group(rg.detached_copy())
  ch_c = ch_const[0]
  ch_f = ch_flip[0]
  const_h.reset_atom_i_seqs()
  flip_h.reset_atom_i_seqs()
  # for ch_c, ch_f in zip(ch_const, ch_flip):
  for residue, res_flip in zip(ch_c.residues(), ch_f.residues()):
    if (residue.resname in flippable_sidechains
        and should_be_flipped(residue, res_flip)):
      fl_atom_list = flippable_sidechains[residue.resname]
      iseqs = [0]*residue.atoms_size()
      for i, a in enumerate(residue.atoms()):
        try:
          ind = fl_atom_list.index(a.name)
          if ind == 3 or ind == 5:
            iseqs[i+1] = a.i_seq
          elif ind == 4 or ind == 6:
            iseqs[i-1] = a.i_seq
          else:
            iseqs[i] = a.i_seq
        except ValueError:
          iseqs[i] = a.i_seq
        except IndexError:
          if i == len(iseqs)-1:
            # this is for case where the last atom is not present
            iseqs[i] = a.i_seq
      for i in iseqs:
        flipped_other_selection.append(i)
    else:
      for a in residue.atoms():
        flipped_other_selection.append(a.i_seq)
  assert flipped_other_selection.size() == original_atoms_size, "%d %d" % (
      flipped_other_selection.size(), original_atoms_size)
  # assert flipped_other_selection.size() == const_h.atoms_size()
  return flipped_other_selection
def flip_atoms_in_ncs_groups(hierarchy, ncs_restraints_group_list, mon_lib_srv=None):
  """
  This function will actually modify hierarchy by making necessary flips
  in ncs-related residues. Flip will be made by exchanging atom coordinates.
  Will make all copies consistent with master.
  """
  if mon_lib_srv is None:
    mon_lib_srv = mmtbx.monomer_library.server.server()
  for ncs_gr in ncs_restraints_group_list:
    master_isel = ncs_gr.master_iselection
    chains_master = hierarchy.select(master_isel).only_model().chains()
    for copy in ncs_gr.copies:
      copy_isel = copy.iselection
      chains_copy = hierarchy.select(copy_isel).only_model().chains()
      for ch_m, ch_c in zip(chains_master, chains_copy):
        for r_m, r_c in zip(ch_m.residues(), ch_c.residues()):
          # print "working on ", r_m.id_str(), r_c.id_str()
          if should_be_flipped(r_m, r_c):
            flip_residue(r_c, mon_lib_srv)
Example #4
0
def flip_atoms_in_ncs_groups(hierarchy, ncs_restraints_group_list, mon_lib_srv=None):
  """
  This function will actually modify hierarchy by making necessary flips
  in ncs-related residues. Flip will be made by exchanging atom coordinates.
  Will make all copies consistent with master.
  """
  if mon_lib_srv is None:
    mon_lib_srv = mmtbx.monomer_library.server.server()
  for ncs_gr in ncs_restraints_group_list:
    master_isel = ncs_gr.master_iselection
    chains_master = hierarchy.select(master_isel).only_model().chains()
    for copy in ncs_gr.copies:
      copy_isel = copy.iselection
      chains_copy = hierarchy.select(copy_isel).only_model().chains()
      for ch_m, ch_c in zip(chains_master, chains_copy):
        for r_m, r_c in zip(ch_m.residues(), ch_c.residues()):
          # print "working on ", r_m.id_str(), r_c.id_str()
          if should_be_flipped(r_m, r_c):
            flip_residue(r_c, mon_lib_srv)