예제 #1
0
 def __init__(self, xray_structure, params, pdb_hierarchy, log=None):
     self.log = log
     self.pdb_hierarchy = pdb_hierarchy
     self.crystal_symmetry = xray_structure.crystal_symmetry()
     if (self.log is None): self.log = sys.stdout
     self.xray_structure = xray_structure
     self.params = params
     asc = self.pdb_hierarchy.atom_selection_cache(
         special_position_settings=crystal.special_position_settings(
             crystal_symmetry=self.crystal_symmetry))
     if (self.params.random_seed is not None):
         random.seed(self.params.random_seed)
         flex.set_random_seed(self.params.random_seed)
     self.top_selection = flex.smart_selection(
         flags=flex.bool(xray_structure.scatterers().size(), True))
     if (self.params.selection is not None):
         self.top_selection = flex.smart_selection(
             flags=asc.selection(self.params.selection))
     self._rotate_about_axis()
     self._process_adp()
     self._process_sites()
     self._process_occupancies()
     self._put_in_box()
     self._change_of_basis()
     # Up to this point we are done with self.xray_structure
     self.pdb_hierarchy.adopt_xray_structure(self.xray_structure)
     # Now only manipulations that use self.pdb_hierarchy are done
     if (self.params.set_chemical_element_simple_if_necessary
             or self.params.rename_chain_id.old_id
             or self.params.renumber_residues
             or self.params.increment_resseq
             or self.params.convert_semet_to_met
             or self.params.convert_met_to_semet
             or self.params.set_charge.charge
             or self.params.truncate_to_polyala
             or self.params.truncate_to_polygly
             or self.params.remove_alt_confs or self.params.move_waters_last
             or self.params.remove_fraction or self.params.keep
             or self.params.remove):
         del self.xray_structure  # it is invalide below this point
         self._set_chemical_element_simple_if_necessary()
         self._rename_chain_id()
         self._renumber_residues()
         self._convert_semet_to_met()
         self._convert_met_to_semet()
         self._set_atomic_charge()
         self._truncate_to_poly_ala()
         self._truncate_to_poly_gly()
         self._remove_alt_confs()
         self._move_waters()
         self._remove_atoms()
         self._apply_keep_remove()
예제 #2
0
 def _process_occupancies(self):
   def check_if_already_modified():
     if(self.top_selection): return
     if (self._occupancies_modified):
       raise Sorry("Can't modify occupancies (already modified).")
     else:
       self._occupancies_modified = True
   for occ in self.params.occupancies:
     if(occ.atom_selection is None):
       selection = self.top_selection
     else:
       asc = self.pdb_hierarchy.atom_selection_cache(
       special_position_settings=crystal.special_position_settings(
           crystal_symmetry = self.crystal_symmetry))
       sel = asc.selection(occ.atom_selection)
       selection = flex.smart_selection(flags=sel)
     if(occ.randomize):
       self._print_action(
         text = "Randomizing occupancies",
         selection = selection)
       check_if_already_modified()
       self.xray_structure.shake_occupancies(selection=selection.flags)
     if(occ.set is not None):
       self._print_action(
         text = "Setting occupancies to: %8.3f"%occ.set, selection = selection)
       check_if_already_modified()
       self.xray_structure.set_occupancies(
           value = occ.set,
           selection = selection.flags)
예제 #3
0
 def _process_sites(self):
   for sites in self.params.sites:
     if (sites.atom_selection is None):
       selection = self.top_selection
     else:
       asc = self.pdb_hierarchy.atom_selection_cache(
       special_position_settings=crystal.special_position_settings(
           crystal_symmetry = self.crystal_symmetry))
       sel = asc.selection(sites.atom_selection)
       selection = flex.smart_selection(flags=sel)
     self._shake_sites(selection=selection, rms_difference=sites.shake)
     self._switch_rotamers(selection=selection, mode=sites.switch_rotamers)
     self._rb_shift(
       selection=selection,
       translate=sites.translate,
       rotate=sites.rotate,
       euler_angle_convention=sites.euler_angle_convention)
예제 #4
0
 def _process_adp(self):
   for adp in self.params.adp:
     if (adp.atom_selection is None):
       selection = self.top_selection
     else:
       asc = self.pdb_hierarchy.atom_selection_cache(
       special_position_settings=crystal.special_position_settings(
           crystal_symmetry = self.crystal_symmetry))
       sel = asc.selection(adp.atom_selection)
       selection = flex.smart_selection(flags=sel)
     if (adp.convert_to_isotropic):
       self._convert_to_isotropic(selection=selection)
     if (adp.convert_to_anisotropic):
       self._convert_to_anisotropic(selection=selection)
     self._set_b_iso(selection=selection, b_iso=adp.set_b_iso)
     self._scale_adp(selection=selection, factor=adp.scale_adp)
     self._shift_b_iso(selection=selection, shift=adp.shift_b_iso)
     if (adp.randomize):
       self._randomize_adp(selection=selection)
예제 #5
0
  def __init__(self, model, params, log = None):
    self.log = log
    self.params = params
    self.model = model
    self._neutralize_scatterers()
    if not model.crystal_symmetry() or not model.crystal_symmetry().unit_cell():
      # Make it up
      from cctbx.maptbx.box import shift_and_box_model
      model = shift_and_box_model(model, shift_model=False)

    self.pdb_hierarchy = model.get_hierarchy()
    self.crystal_symmetry = model.crystal_symmetry()
    if(self.log is None): self.log = sys.stdout
    self.xray_structure = model.get_xray_structure()
    asc = self.pdb_hierarchy.atom_selection_cache(
        special_position_settings=crystal.special_position_settings(
            crystal_symmetry = self.crystal_symmetry))
    if(self.params.random_seed is not None):
      random.seed(self.params.random_seed)
      flex.set_random_seed(self.params.random_seed)
    self.top_selection = flex.smart_selection(
        flags=flex.bool(self.xray_structure.scatterers().size(), True))
    if(self.params.selection is not None):
      self.top_selection = flex.smart_selection(
        flags=asc.selection(self.params.selection))
    self._rotate_about_axis()
    self._process_adp()
    self._process_sites()
    self._process_occupancies()
    self._put_in_box()
    self._change_of_basis()
    # Up to this point we are done with self.xray_structure
    self.model.set_xray_structure(self.xray_structure)
    self.pdb_hierarchy = self.model.get_hierarchy()
    # Now only manipulations that use self.pdb_hierarchy are done
### segID manipulations
    if (params.set_seg_id_to_chain_id):
      if (params.clear_seg_id):
        raise Sorry("Parameter conflict - set_seg_id_to_chain_id=True and "+
          "clear_seg_id=True.  Please choose only one of these options.")
      for atom in self.pdb_hierarchy.atoms():
        labels = atom.fetch_labels()
        atom.segid = "%-4s" % labels.chain_id
    elif (params.clear_seg_id):
      for atom in self.pdb_hierarchy.atoms():
        atom.segid = "    "
    if(self.params.set_chemical_element_simple_if_necessary or
       self.params.rename_chain_id.old_id or
       self.params.renumber_residues or self.params.increment_resseq or
       self.params.convert_semet_to_met or
       self.params.convert_met_to_semet or
       self.params.set_charge.charge or
       self.params.truncate_to_polyala or
       self.params.truncate_to_polygly or
       self.params.remove_alt_confs or
       self.params.move_waters_last or
       self.params.remove_fraction or
       self.params.keep or
       self.params.remove):
      # del self.xray_structure # it is invalide below this point
      self._set_chemical_element_simple_if_necessary()
      self._rename_chain_id()
      self._renumber_residues()
      self._convert_semet_to_met()
      self._convert_met_to_semet()
      self._set_atomic_charge()
      self._truncate_to_poly_ala()
      self._truncate_to_poly_gly()
      self._remove_alt_confs()
      self._move_waters()
      self._remove_atoms()
      self._apply_keep_remove()
      # Here goes really nasty hack. Never repeat it.
      # It is here because I don't have clear idea about how to handle
      # such dramatic changes in number of atoms etc that just was performed
      # for hierarchy.
      self.pdb_hierarchy.reset_atom_i_seqs()
      self.pdb_hierarchy.atoms_reset_serial()
      self.model._pdb_hierarchy = self.pdb_hierarchy
      self.model._xray_structure = self.pdb_hierarchy.extract_xray_structure(
          crystal_symmetry=self.model.crystal_symmetry())
      self.model._update_atom_selection_cache()
      self.model._update_has_hd()
      self.model.get_hierarchy().atoms().reset_i_seq()