Esempio n. 1
0
 def __init__(self,
              pdb_hierarchy,
              params,
              map_coeffs=None,
              difference_map_coeffs=None,
              ccp4_map=None,
              unit_cell=None,
              grid_spacing=0.2,
              sampling_method="linear",
              n_chi_max=4,
              log=None):
     if (log is None): log = sys.stdout
     adopt_init_args(self, locals())
     models = pdb_hierarchy.models()
     if (len(models) > 1):
         raise Sorry("Multi-model PDB files not supported.")
     self.sigma = self.real_map = self.difference_map = None
     if (map_coeffs is not None):
         self.unit_cell = map_coeffs.unit_cell()
         if (params.sampling_method == "direct"):
             self.map_coeffs = self.map_coeffs.expand_to_p1()
             if (not map_coeffs.anomalous_flag()):
                 self.map_coeffs = self.map_coeffs.generate_bijvoet_mates()
         if (sampling_method != "direct") or (params.scaling == "sigma"):
             fft_map = self.map_coeffs.fft_map(
                 resolution_factor=grid_spacing)
             if (params.scaling == "sigma"):
                 self.sigma = fft_map.statistics().sigma()
                 fft_map.apply_sigma_scaling()
             else:
                 fft_map.apply_volume_scaling()
             self.real_map = fft_map.real_map_unpadded()
     else:
         assert (ccp4_map is not None)
         print >> self.log, "CCP4 map statistics:"
         ccp4_map.show_summary(out=self.log, prefix="  ")
         self.real_map = ccp4_map.data.as_double()
         # XXX assume that the map is already scaled properly (in the original
         # unit cell)
         self.sigma = 1  #ccp4_map.statistics().sigma()
         # XXX the unit cell that we need for the non-crystallographic
         # interpolation is not what comes out of the map - it's the
         self.unit_cell = ccp4_map.grid_unit_cell()
     if (difference_map_coeffs is not None):
         if (sampling_method == "direct"):
             self.difference_map_coeffs = self.difference_map_coeffs.expand_to_p1(
             )
             if (not difference_map_coeffs.anomalous_flag()):
                 self.difference_map_coeffs = \
                   self.difference_map_coeffs.generate_bijvoet_mates()
         if (sampling_method != "direct") or (params.scaling == "sigma"):
             fft_map = self.difference_map_coeffs.fft_map(
                 resolution_factor=params.grid_spacing)
             if (params.scaling == "sigma"):
                 fft_map.apply_sigma_scaling()
             else:
                 fft_map.apply_volume_scaling()
             self.difference_map = fft_map.real_map_unpadded()
     results = []
     from mmtbx.rotamer import sidechain_angles
     self.angle_lookup = sidechain_angles.SidechainAngles(False)
     self.sites_cart = pdb_hierarchy.atoms().extract_xyz()
     self.residue_groups = []
     for chain in models[0].chains():
         self.residue_groups.extend(chain.residue_groups())
     if (params.nproc in [None, Auto]) or (params.nproc > 1):
         # this will be a list of lists
         results_ = easy_mp.pool_map(processes=params.nproc,
                                     fixed_func=self.__sample_density,
                                     args=range(len(self.residue_groups)))
         # now flatten it out
         self.results = []
         for result_list in results_:
             self.results.extend(result_list)
     else:
         self.results = []
         for i_res in range(len(self.residue_groups)):
             self.results.extend(self.__sample_density(i_res, verbose=True))
Esempio n. 2
0
# correlations between residues in one ensemble a la MutInf...
#
# Started by Daniel Keedy in May 2013
#
##############################################################

import sys
import os
import iotbx.pdb.hierarchy
from mmtbx.rotamer import rotamer_eval
from mmtbx.rotamer import sidechain_angles
import iotbx.pdb.amino_acid_codes

# These scorers are global variables since they hog memory (I think?)
rotamer_scorer = rotamer_eval.RotamerEval()
sc_angles_measurer = sidechain_angles.SidechainAngles(show_errs=True)

aa_resnames = iotbx.pdb.amino_acid_codes.one_letter_given_three_letter

class StructureEnsemble():
  
  def __init__(self, nm):
    self.name = nm
    self.conf_ensems = {} # CNIT --> ConformerEnsemble

  def add_structures(self, dirname):
    for filename in os.listdir(dirname):
      self.add_structure(filename)
  
  def add_structure(self, filename):
    pdb = iotbx.pdb.hierarchy.input(file_name=filename)
Esempio n. 3
0
  def __init__ (self,
                pdb_hierarchy,
                params,
                map_coeffs=None,
                crystal_symmetry_model=None,
                difference_map_coeffs=None,
                ccp4_map=None,
                unit_cell=None,
                grid_spacing=0.2,
                sampling_method="linear",
                n_chi_max=4,
                log=None) :
    if (log is None) : log = sys.stdout
    adopt_init_args(self, locals())
    models = pdb_hierarchy.models()
    if (len(models) > 1) :
      raise Sorry("Multi-model PDB files not supported.")
    self.sigma = self.real_map = self.difference_map = None
    if (map_coeffs is not None) :
      self.unit_cell = map_coeffs.unit_cell()
      if (params.sampling_method == "direct") :
        self.map_coeffs = self.map_coeffs.expand_to_p1()
        if (not map_coeffs.anomalous_flag()) :
          self.map_coeffs = self.map_coeffs.generate_bijvoet_mates()
      if (sampling_method != "direct") or (params.scaling == "sigma") :
        fft_map = self.map_coeffs.fft_map(resolution_factor=grid_spacing)
        if (params.scaling == "sigma") :
          self.sigma = fft_map.statistics().sigma()
          fft_map.apply_sigma_scaling()
        else :
          fft_map.apply_volume_scaling()
        self.real_map = fft_map.real_map_unpadded()
    else :
      assert (ccp4_map is not None)
      print >> self.log, "CCP4 map statistics:"
      ccp4_map.show_summary(out=self.log, prefix="  ")
      space_group_number = ccp4_map.space_group_number
      from cctbx import crystal
      crystal_symmetry_map = crystal.symmetry(ccp4_map.unit_cell().parameters(), space_group_number)
      if not crystal_symmetry_model:
        print >> self.log, """Warning: the model does not contain symmetry information. Using map information."""
      elif not crystal_symmetry_map.is_similar_symmetry(crystal_symmetry_model):
        print >> self.log, """Warning: The map and model appear to have different crystal symmetry information.
          EMRinger will assume the map symmetry data is correct and process."""
      # If map space group is P1, then check that model space group is also either not present or is P1.
      # If both are p1 or model symmetry is not present, then do the shift. Otherwise, no shift.
      if space_group_number == 1 and not (crystal_symmetry_model and crystal_symmetry_model.space_group() and crystal_symmetry_model.space_group().info().type().number() != 1):
        import mmtbx.utils
        shift_manager = mmtbx.utils.shift_origin(
        map_data = ccp4_map.data.as_double(),
        pdb_hierarchy = pdb_hierarchy,
        crystal_symmetry = crystal_symmetry_map)
        if not shift_manager.shift_cart == None:
          print >> self.log, "Warning: Model and Map use different origin. Applying origin shift to compensate."
        pdb_hierarchy = shift_manager.pdb_hierarchy # gives you shifted model

        self.real_map = shift_manager.map_data # gives you shifted map
      else:
        print >> self.log, """Warning: Structure is not P1, so automatic origin shifts cannot currently be applied"""
        self.real_map = ccp4_map.data.as_double()
      # XXX assume that the map is already scaled properly (in the original
      # unit cell)
      models = pdb_hierarchy.models()
      self.sigma = 1 #ccp4_map.statistics().sigma()
      # XXX the unit cell that we need for the non-crystallographic
      # interpolation is not what comes out of the map - it's the
      self.unit_cell = ccp4_map.grid_unit_cell()
    if (difference_map_coeffs is not None) :
      if (sampling_method == "direct") :
        self.difference_map_coeffs = self.difference_map_coeffs.expand_to_p1()
        if (not difference_map_coeffs.anomalous_flag()) :
          self.difference_map_coeffs = \
            self.difference_map_coeffs.generate_bijvoet_mates()
      if (sampling_method != "direct") or (params.scaling == "sigma") :
        fft_map = self.difference_map_coeffs.fft_map(
          resolution_factor=params.grid_spacing)
        if (params.scaling == "sigma") :
          fft_map.apply_sigma_scaling()
        else :
          fft_map.apply_volume_scaling()
        self.difference_map = fft_map.real_map_unpadded()
    results = []
    from mmtbx.rotamer import sidechain_angles
    self.angle_lookup = sidechain_angles.SidechainAngles(False)
    self.sites_cart = pdb_hierarchy.atoms().extract_xyz()
    self.residue_groups = []
    for chain in models[0].chains() :
      self.residue_groups.extend(chain.residue_groups())
    if (params.nproc in [None,Auto]) or (params.nproc > 1) :
      # this will be a list of lists
      results_ = easy_mp.pool_map(
        processes=params.nproc,
        fixed_func=self.__sample_density,
        args=range(len(self.residue_groups)))
      # now flatten it out
      self.results = []
      for result_list in results_ : self.results.extend(result_list)
    else :
      self.results = []
      for i_res in range(len(self.residue_groups)) :
        self.results.extend(self.__sample_density(i_res, verbose=True))
    if len(self.results) == 0:
      raise Sorry("""No residues could be scanned by EMRinger, so scores cannot be generated.
      There are a few problems that can lead to this, including not having
      modeled side chains (poly-A or poly-G models), mismatches between the map
      and model grid, or corrupted map density values. These problems can often
      be assessed with molecular graphics tools such as pymol or coot.""")