Esempio n. 1
0
 def show(self, message):
     print >> self.log, message
     sol_sel = self.model.solvent_selection()
     xrs_mac_h = self.model.get_xray_structure().select(~sol_sel)
     xrs_sol_h = self.model.get_xray_structure().select(sol_sel)
     hd_sol = self.model.get_hd_selection().select(sol_sel)
     hd_mac = self.model.get_hd_selection().select(~sol_sel)
     xrs_sol = xrs_sol_h.select(~hd_sol)
     xrs_mac = xrs_mac_h.select(~hd_mac)
     scat = xrs_sol.scatterers()
     occ = scat.extract_occupancies()
     b_isos = scat.extract_u_iso_or_u_equiv(
         self.model.get_xray_structure().unit_cell()) * math.pi**2 * 8
     smallest_distances = xrs_mac.closest_distances(
       sites_frac      = xrs_sol.sites_frac(),
       distance_cutoff = self.find_peaks_params.map_next_to_model.\
         max_model_peak_dist).smallest_distances
     number = format_value("%-7d", scat.size())
     b_min = format_value("%-7.2f", flex.min_default(b_isos, None))
     b_max = format_value("%-7.2f", flex.max_default(b_isos, None))
     b_ave = format_value("%-7.2f", flex.mean_default(b_isos, None))
     bl_min = format_value("%-7.2f", self.params.b_iso_min).strip()
     bl_max = format_value("%-7.2f", self.params.b_iso_max).strip()
     o_min = format_value("%-7.2f", flex.min_default(occ, None))
     o_max = format_value("%-7.2f", flex.max_default(occ, None))
     ol_min = format_value("%-7.2f", self.params.occupancy_min).strip()
     ol_max = format_value("%-7.2f", self.params.occupancy_max).strip()
     d_min = format_value("%-7.2f",
                          flex.min_default(smallest_distances, None))
     d_max = format_value("%-7.2f",
                          flex.max_default(smallest_distances, None))
     dl_min = format_value(
         "%-7.2f", self.find_peaks_params.map_next_to_model.
         min_model_peak_dist).strip()
     dl_max = format_value(
         "%-7.2f", self.find_peaks_params.map_next_to_model.
         max_model_peak_dist).strip()
     ani_min = format_value(
         "%-7.2f",
         flex.min_default(scat.anisotropy(unit_cell=xrs_sol.unit_cell()),
                          None))
     ani_min_l = format_value("%-7.2f", self.params.anisotropy_min).strip()
     print >> self.log, "  number           = %s" % number
     print >> self.log, "  b_iso_min        = %s (limit = %s)" % (b_min,
                                                                  bl_min)
     print >> self.log, "  b_iso_max        = %s (limit = %s)" % (b_max,
                                                                  bl_max)
     print >> self.log, "  b_iso_mean       = %s             " % (b_ave)
     print >> self.log, "  anisotropy_min   = %s (limit = %s)" % (ani_min,
                                                                  ani_min_l)
     print >> self.log, "  occupancy_min    = %s (limit = %s)" % (o_min,
                                                                  ol_min)
     print >> self.log, "  occupancy_max    = %s (limit = %s)" % (o_max,
                                                                  ol_max)
     print >> self.log, "  dist_sol_mol_min = %s (limit = %s)" % (d_min,
                                                                  dl_min)
     print >> self.log, "  dist_sol_mol_max = %s (limit = %s)" % (d_max,
                                                                  dl_max)
Esempio n. 2
0
  def angle_deviations_z(self):
    '''
    Calculate rmsz of angles deviations

    Compute rmsz, the Root-Mean-Square of the z-scors for a set of data
    using z_i = {x_i - mu / sigma}  and rmsz = sqrt(mean(z*z))

    Compute rmsz, the Root-Mean-Square of the z-scors for a set of data
    using z_i = {x_i - mu / sigma}  and rmsz = sqrt(mean(z*z))
    x_i: atcual bond angle
    mu: geometry restraints mean
    sigma:  geometry restraints standard deviation
    z_i: z-score for bond i
    z: array of z_i

    The sigma and the (x_i - mu) are model constrains, geometry restraints. They function extracts
    from self, not calculated from data.

    :returns:
    a_rmsz: rmsz, root mean square of the z-scors of all angles
    a_z_min/max: min/max values of z-scors
    '''
    if(self.n_angle_proxies is not None):
      angle_deltas = self.angle_proxies.proxy_select(origin_id=0).deltas(
          sites_cart=self.sites_cart)
      if len(angle_deltas) > 0:
        sigmas = [geometry_restraints.weight_as_sigma(x.weight) for x in self.angle_proxies]
        z_scores = flex.double([(angle_delta/sigma) for angle_delta,sigma in zip(angle_deltas,sigmas)])
        a_rmsz = math.sqrt(flex.mean_default(z_scores*z_scores,0))
        a_z_max = flex.max_default(flex.abs(z_scores), 0)
        a_z_min = flex.min_default(flex.abs(z_scores), 0)
        return a_z_min, a_z_max, a_rmsz
      else:
        return 0,0,0
Esempio n. 3
0
  def bond_deviations_z(self):
    '''
    Calculate rmsz of bond deviations

    Compute rmsz, the Root-Mean-Square of the z-scors for a set of data
    using z_i = {x_i - mu / sigma}  and rmsz = sqrt(mean(z*z))
    x_i: atcual bond length
    mu: geometry restraints mean
    sigma:  geometry restraints standard deviation
    z_i: z-score for bond i
    z: array of z_i

    The sigma and the (x_i - mu) are model constrains, geometry restraints.
    This function extracts from self, not calculated from data.

    :returns:
    b_rmsz: rmsz, root mean square of the z-scors of all bonds
    b_z_min/max: min/max abolute values of z-scors
    '''
    if(self.n_bond_proxies is not None):
      bond_deltas = self.bond_proxies.deltas(
          sites_cart=self.sites_cart, origin_id=0)
      if len(bond_deltas) >0:
        sigmas = [geometry_restraints.weight_as_sigma(x.weight) for x in self.bond_proxies.simple]
        z_scores = flex.double([(bond_delta/sigma) for bond_delta,sigma in zip(bond_deltas,sigmas)])
        b_rmsz = math.sqrt(flex.mean_default(z_scores*z_scores,0))
        b_z_max = flex.max_default(flex.abs(z_scores), 0)
        b_z_min = flex.min_default(flex.abs(z_scores), 0)
        return b_z_min, b_z_max, b_rmsz
      else:
        return 0,0,0
Esempio n. 4
0
  def bond_deviations_z(self):
    '''
    Calculate rmsz of bond deviations

    Compute rmsz, the Root-Mean-Square of the z-scors for a set of data
    using z_i = {x_i - mu / sigma}  and rmsz = sqrt(mean(z*z))
    x_i: atcual bond length
    mu: geometry restraints mean
    sigma:  geometry restraints standard deviation
    z_i: z-score for bond i
    z: array of z_i

    The sigma and the (x_i - mu) are model constrains, geometry restraints. They function extracts
    from self, not calculated from data.

    :returns:
    b_rmsz: rmsz, root mean square of the z-scors of all bonds
    b_z_min/max: min/max abolute values of z-scors
    '''
    if(self.n_bond_proxies is not None):
      bond_deltas = self.bond_proxies.deltas(
          sites_cart=self.sites_cart, origin_id=0)
      if len(bond_deltas) >0:
        sigmas = [geometry_restraints.weight_as_sigma(x.weight) for x in self.bond_proxies.simple]
        z_scores = flex.double([(bond_delta/sigma) for bond_delta,sigma in zip(bond_deltas,sigmas)])
        b_rmsz = math.sqrt(flex.mean_default(z_scores*z_scores,0))
        b_z_max = flex.max_default(flex.abs(z_scores), 0)
        b_z_min = flex.min_default(flex.abs(z_scores), 0)
        return b_z_min, b_z_max, b_rmsz
      else:
        return 0,0,0
Esempio n. 5
0
  def angle_deviations_z(self):
    '''
    Calculate rmsz of angles deviations

    Compute rmsz, the Root-Mean-Square of the z-scors for a set of data
    using z_i = {x_i - mu / sigma}  and rmsz = sqrt(mean(z*z))

    Compute rmsz, the Root-Mean-Square of the z-scors for a set of data
    using z_i = {x_i - mu / sigma}  and rmsz = sqrt(mean(z*z))
    x_i: atcual bond angle
    mu: geometry restraints mean
    sigma:  geometry restraints standard deviation
    z_i: z-score for bond i
    z: array of z_i

    The sigma and the (x_i - mu) are model constrains, geometry restraints. They function extracts
    from self, not calculated from data.

    :returns:
    a_rmsz: rmsz, root mean square of the z-scors of all angles
    a_z_min/max: min/max values of z-scors
    '''
    if(self.n_angle_proxies is not None):
      angle_deltas = self.angle_proxies.proxy_select(origin_id=0).deltas(
          sites_cart=self.sites_cart)
      if len(angle_deltas) > 0:
        sigmas = [geometry_restraints.weight_as_sigma(x.weight) for x in self.angle_proxies]
        z_scores = flex.double([(angle_delta/sigma) for angle_delta,sigma in zip(angle_deltas,sigmas)])
        a_rmsz = math.sqrt(flex.mean_default(z_scores*z_scores,0))
        a_z_max = flex.max_default(flex.abs(z_scores), 0)
        a_z_min = flex.min_default(flex.abs(z_scores), 0)
        return a_z_min, a_z_max, a_rmsz
      else:
        return 0,0,0
Esempio n. 6
0
 def peaks_mapped(self):
     if (self.peaks_ is None): return None
     assert self.mapped == False
     max_dist = self.params.map_next_to_model.max_model_peak_dist
     min_dist = self.params.map_next_to_model.min_model_peak_dist
     if (min_dist is None):
         min_dist = 0.
     if (max_dist is None):
         max_dist = float(sys.maxsize)
     xray_structure = self.fmodel.xray_structure.deep_copy_scatterers()
     use_selection = None
     if (not self.params.map_next_to_model.use_hydrogens):
         use_selection = ~xray_structure.hd_selection()
     initial_number_of_sites = self.peaks_.sites.size()
     if (not self.silent):
         print("Filter by distance & map next to the model:", file=self.log)
     result = xray_structure.closest_distances(sites_frac=self.peaks_.sites,
                                               distance_cutoff=max_dist,
                                               use_selection=use_selection)
     smallest_distances_sq = result.smallest_distances_sq
     smallest_distances = result.smallest_distances
     in_box = smallest_distances_sq > 0
     not_too_far = smallest_distances_sq <= max_dist**2
     not_too_close = smallest_distances_sq >= min_dist**2
     selection = (not_too_far & not_too_close & in_box)
     iseqs_of_closest_atoms = result.i_seqs.select(selection)
     peaks = peaks_holder(heights=self.peaks_.heights.select(selection),
                          sites=result.sites_frac.select(selection),
                          iseqs_of_closest_atoms=iseqs_of_closest_atoms)
     sd = flex.sqrt(smallest_distances_sq.select(in_box))
     d_min = flex.min_default(sd, 0)
     d_max = flex.max_default(sd, 0)
     if (not self.silent):
         print("   mapped sites are within: %5.3f - %5.3f" % (d_min, d_max),
               file=self.log)
         print("   number of sites selected in [dist_min=%5.2f, " \
           "dist_max=%5.2f]: %d from: %d" % (min_dist, max_dist, peaks.sites.size(),
           initial_number_of_sites), file=self.log)
     smallest_distances = flex.sqrt(smallest_distances_sq.select(selection))
     d_min = flex.min_default(smallest_distances, 0)
     d_max = flex.max_default(smallest_distances, 0)
     if (not self.silent):
         print("   mapped sites are within: %5.3f - %5.3f" % (d_min, d_max),
               file=self.log)
     self.mapped = True
     self.peaks_ = peaks
     return peaks
Esempio n. 7
0
 def nonbonded_deviations(self):
   if(self.n_nonbonded_proxies is not None):
     nonbonded_deltas = self.nonbonded_distances()
     r_sq  = nonbonded_deltas * nonbonded_deltas
     r_ave = math.sqrt(flex.mean_default(r_sq, 0))
     r_max = math.sqrt(flex.max_default(r_sq, 0))
     r_min = math.sqrt(flex.min_default(r_sq, 0))
     return r_min, r_max, r_ave
Esempio n. 8
0
 def nonbonded_deviations(self):
     if (self.n_nonbonded_proxies is not None):
         nonbonded_deltas = self.nonbonded_distances()
         r_sq = nonbonded_deltas * nonbonded_deltas
         r_ave = math.sqrt(flex.mean_default(r_sq, 0))
         r_max = math.sqrt(flex.max_default(r_sq, 0))
         r_min = math.sqrt(flex.min_default(r_sq, 0))
         return r_min, r_max, r_ave
Esempio n. 9
0
 def peaks_mapped(self):
   if(self.peaks_ is None): return None
   assert self.mapped == False
   max_dist = self.params.map_next_to_model.max_model_peak_dist
   min_dist = self.params.map_next_to_model.min_model_peak_dist
   if (min_dist is None) :
     min_dist = 0.
   if (max_dist is None) :
     max_dist = float(sys.maxint)
   xray_structure = self.fmodel.xray_structure.deep_copy_scatterers()
   use_selection = None
   if(not self.params.map_next_to_model.use_hydrogens):
     use_selection = ~xray_structure.hd_selection()
   initial_number_of_sites = self.peaks_.sites.size()
   if(not self.silent):
     print >> self.log, "Filter by distance & map next to the model:"
   result = xray_structure.closest_distances(sites_frac = self.peaks_.sites,
     distance_cutoff = max_dist, use_selection = use_selection)
   smallest_distances_sq = result.smallest_distances_sq
   smallest_distances = result.smallest_distances
   in_box = smallest_distances_sq > 0
   not_too_far = smallest_distances_sq <= max_dist**2
   not_too_close = smallest_distances_sq >= min_dist**2
   selection = (not_too_far & not_too_close & in_box)
   iseqs_of_closest_atoms = result.i_seqs.select(selection)
   peaks = peaks_holder(
     heights                = self.peaks_.heights.select(selection),
     sites                  = result.sites_frac.select(selection),
     iseqs_of_closest_atoms = iseqs_of_closest_atoms)
   sd = flex.sqrt(smallest_distances_sq.select(in_box))
   d_min = flex.min_default(sd, 0)
   d_max = flex.max_default(sd, 0)
   if(not self.silent):
     print >> self.log,"   mapped sites are within: %5.3f - %5.3f"%(d_min,d_max)
     print >> self.log, "   number of sites selected in [dist_min=%5.2f, " \
       "dist_max=%5.2f]: %d from: %d" % (min_dist, max_dist, peaks.sites.size(),
       initial_number_of_sites)
   smallest_distances = flex.sqrt(smallest_distances_sq.select(selection))
   d_min = flex.min_default(smallest_distances, 0)
   d_max = flex.max_default(smallest_distances, 0)
   if(not self.silent):
     print >> self.log,"   mapped sites are within: %5.3f - %5.3f"%(d_min,d_max)
   self.mapped = True
   self.peaks_ = peaks
   return peaks
Esempio n. 10
0
 def show(self, message):
   print >> self.log, message
   sol_sel = self.model.solvent_selection()
   xrs_mac_h = self.model.xray_structure.select(~sol_sel)
   xrs_sol_h = self.model.xray_structure.select(sol_sel)
   hd_sol = self.model.xray_structure.hd_selection().select(sol_sel)
   hd_mac = self.model.xray_structure.hd_selection().select(~sol_sel)
   xrs_sol = xrs_sol_h.select(~hd_sol)
   xrs_mac = xrs_mac_h.select(~hd_mac)
   scat = xrs_sol.scatterers()
   occ = scat.extract_occupancies()
   b_isos = scat.extract_u_iso_or_u_equiv(
     self.model.xray_structure.unit_cell()) * math.pi**2*8
   smallest_distances = xrs_mac.closest_distances(
     sites_frac      = xrs_sol.sites_frac(),
     distance_cutoff = self.find_peaks_params.map_next_to_model.\
       max_model_peak_dist).smallest_distances
   number = format_value("%-7d",scat.size())
   b_min  = format_value("%-7.2f", flex.min_default( b_isos, None))
   b_max  = format_value("%-7.2f", flex.max_default( b_isos, None))
   b_ave  = format_value("%-7.2f", flex.mean_default(b_isos, None))
   bl_min = format_value("%-7.2f", self.params.b_iso_min).strip()
   bl_max = format_value("%-7.2f", self.params.b_iso_max).strip()
   o_min  = format_value("%-7.2f", flex.min_default(occ, None))
   o_max  = format_value("%-7.2f", flex.max_default(occ, None))
   ol_min = format_value("%-7.2f", self.params.occupancy_min).strip()
   ol_max = format_value("%-7.2f", self.params.occupancy_max).strip()
   d_min  = format_value("%-7.2f", flex.min_default(smallest_distances, None))
   d_max  = format_value("%-7.2f", flex.max_default(smallest_distances, None))
   dl_min = format_value("%-7.2f",
     self.find_peaks_params.map_next_to_model.min_model_peak_dist).strip()
   dl_max = format_value("%-7.2f",
     self.find_peaks_params.map_next_to_model.max_model_peak_dist).strip()
   ani_min = format_value("%-7.2f", flex.min_default(scat.anisotropy(
     unit_cell = xrs_sol.unit_cell()), None))
   ani_min_l = format_value("%-7.2f",self.params.anisotropy_min).strip()
   print >>self.log,"  number           = %s"%number
   print >>self.log,"  b_iso_min        = %s (limit = %s)"%(b_min, bl_min)
   print >>self.log,"  b_iso_max        = %s (limit = %s)"%(b_max, bl_max)
   print >>self.log,"  b_iso_mean       = %s             "%(b_ave)
   print >>self.log,"  anisotropy_min   = %s (limit = %s)"%(ani_min,ani_min_l)
   print >>self.log,"  occupancy_min    = %s (limit = %s)"%(o_min, ol_min)
   print >>self.log,"  occupancy_max    = %s (limit = %s)"%(o_max, ol_max)
   print >>self.log,"  dist_sol_mol_min = %s (limit = %s)"%(d_min, dl_min)
   print >>self.log,"  dist_sol_mol_max = %s (limit = %s)"%(d_max, dl_max)
Esempio n. 11
0
 def chirality_deviations(self):
     if (self.n_chirality_proxies is not None):
         chirality_deltas = geometry_restraints.chirality_deltas(
             sites_cart=self.sites_cart, proxies=self.chirality_proxies)
         c_sq = chirality_deltas * chirality_deltas
         c_ave = math.sqrt(flex.mean_default(c_sq, 0))
         c_max = math.sqrt(flex.max_default(c_sq, 0))
         c_min = math.sqrt(flex.min_default(c_sq, 0))
         return c_min, c_max, c_ave
Esempio n. 12
0
 def parallelity_deviations(self):
     if self.n_parallelity_proxies is not None:
         parallelity_deltas = geometry_restraints.parallelity_deltas(
             sites_cart=self.sites_cart, proxies=self.parallelity_proxies)
         p_sq = parallelity_deltas * parallelity_deltas
         p_ave = math.sqrt(flex.mean_default(p_sq, 0))
         p_max = math.sqrt(flex.max_default(p_sq, 0))
         p_min = math.sqrt(flex.min_default(p_sq, 0))
         return p_min, p_max, p_ave
 def is_water_last(self):
   result = True
   sol_sel = self.model.solvent_selection()
   i_sol_sel = sol_sel.iselection()
   i_mac_sel = (~sol_sel).iselection()
   if(i_sol_sel.size() > 0 and i_mac_sel.size() > 0):
     if(flex.min_default(i_sol_sel,0)-flex.max_default(i_mac_sel,0) != 1):
       result = False
   return result
Esempio n. 14
0
 def isotropic_adp_deviation(self):
     if (self.n_isotropic_adp_proxies is not None):
         isotropic_adp_deltas_rms = adp_restraints.isotropic_adp_deltas_rms(
             u_cart=self.u_cart, proxies=self.isotropic_adp_proxies)
         i_sq = isotropic_adp_deltas_rms * isotropic_adp_deltas_rms
         i_ave = math.sqrt(flex.mean_default(i_sq, 0))
         i_max = math.sqrt(flex.max_default(i_sq, 0))
         i_min = math.sqrt(flex.min_default(i_sq, 0))
         return i_min, i_max, i_ave
Esempio n. 15
0
 def dihedral_deviations(self):
     # !!!XXX!!! Warning! this works wrong because it is not aware of origin_id!
     if (self.n_dihedral_proxies is not None):
         dihedral_deltas = geometry_restraints.dihedral_deltas(
             sites_cart=self.sites_cart, proxies=self.dihedral_proxies)
         d_sq = dihedral_deltas * dihedral_deltas
         d_ave = math.sqrt(flex.mean_default(d_sq, 0))
         d_max = math.sqrt(flex.max_default(d_sq, 0))
         d_min = math.sqrt(flex.min_default(d_sq, 0))
         return d_min, d_max, d_ave
Esempio n. 16
0
 def is_water_last(self):
     result = True
     sol_sel = self.model.solvent_selection()
     i_sol_sel = sol_sel.iselection()
     i_mac_sel = (~sol_sel).iselection()
     if (i_sol_sel.size() > 0 and i_mac_sel.size() > 0):
         if (flex.min_default(i_sol_sel, 0) -
                 flex.max_default(i_mac_sel, 0) != 1):
             result = False
     return result
 def __init__(O, curvs, lim_eps):
   c_pos = curvs.select(curvs > 0)
   O.c_lim = flex.max_default(c_pos, default=0) * lim_eps
   if (O.c_lim == 0):
     O.c_lim = 1
     O.c_rms = 1
   else:
     O.c_rms = flex.mean_sq(c_pos)**0.5
   O.n_below_limit = 0
   O.n_above_limit = 0
Esempio n. 18
0
 def chirality_deviations(self):
   if(self.n_chirality_proxies is not None):
     chirality_deltas = geometry_restraints.chirality_deltas(
       sites_cart = self.sites_cart,
       proxies    = self.chirality_proxies)
     c_sq  = chirality_deltas * chirality_deltas
     c_ave = math.sqrt(flex.mean_default(c_sq, 0))
     c_max = math.sqrt(flex.max_default(c_sq, 0))
     c_min = math.sqrt(flex.min_default(c_sq, 0))
     return c_min, c_max, c_ave
Esempio n. 19
0
 def isotropic_adp_deviation(self):
   if (self.n_isotropic_adp_proxies is not None):
     isotropic_adp_deltas_rms = adp_restraints.isotropic_adp_deltas_rms(
       u_cart=self.u_cart,
       proxies=self.isotropic_adp_proxies)
     i_sq = isotropic_adp_deltas_rms * isotropic_adp_deltas_rms
     i_ave = math.sqrt(flex.mean_default(i_sq, 0))
     i_max = math.sqrt(flex.max_default(i_sq, 0))
     i_min = math.sqrt(flex.min_default(i_sq, 0))
     return i_min, i_max, i_ave
Esempio n. 20
0
 def parallelity_deviations(self):
   if self.n_parallelity_proxies is not None:
     parallelity_deltas = geometry_restraints.parallelity_deltas(
       sites_cart = self.sites_cart,
       proxies    = self.parallelity_proxies)
     p_sq  = parallelity_deltas * parallelity_deltas
     p_ave = math.sqrt(flex.mean_default(p_sq, 0))
     p_max = math.sqrt(flex.max_default(p_sq, 0))
     p_min = math.sqrt(flex.min_default(p_sq, 0))
     return p_min, p_max, p_ave
Esempio n. 21
0
 def __init__(O, curvs, lim_eps):
     c_pos = curvs.select(curvs > 0)
     O.c_lim = flex.max_default(c_pos, default=0) * lim_eps
     if (O.c_lim == 0):
         O.c_lim = 1
         O.c_rms = 1
     else:
         O.c_rms = flex.mean_sq(c_pos)**0.5
     O.n_below_limit = 0
     O.n_above_limit = 0
Esempio n. 22
0
 def planarity_deviations(self):
     # XXX Need update, does not respect origin_id
     # assert 0, "Not counting for origin_id"
     if (self.n_planarity_proxies is not None):
         planarity_deltas = geometry_restraints.planarity_deltas_rms(
             sites_cart=self.sites_cart, proxies=self.planarity_proxies)
         p_sq = planarity_deltas * planarity_deltas
         p_ave = math.sqrt(flex.mean_default(p_sq, 0))
         p_max = math.sqrt(flex.max_default(p_sq, 0))
         p_min = math.sqrt(flex.min_default(p_sq, 0))
         return p_min, p_max, p_ave
Esempio n. 23
0
 def rigid_bond_deviation(self):
     if (self.n_rigid_bond_proxies is not None):
         rigid_bond_deltas = adp_restraints.rigid_bond_deltas(
             sites_cart=self.sites_cart,
             u_cart=self.u_cart,
             proxies=self.rigid_bond_proxies)
         r_sq = rigid_bond_deltas * rigid_bond_deltas
         r_ave = math.sqrt(flex.mean_default(r_sq, 0))
         r_max = math.sqrt(flex.max_default(r_sq, 0))
         r_min = math.sqrt(flex.min_default(r_sq, 0))
         return r_min, r_max, r_ave
Esempio n. 24
0
 def reference_dihedral_deviations(self):
     assert 0, "Not working"
     if (self.n_reference_dihedral_proxies is not None):
         reference_dihedral_deltas = geometry_restraints.reference_dihedral_deltas(
             sites_cart=self.sites_cart,
             proxies=self.reference_dihedral_proxies)
         d_sq = reference_dihedral_deltas * reference_dihedral_deltas
         d_ave = math.sqrt(flex.mean_default(d_sq, 0))
         d_max = math.sqrt(flex.max_default(d_sq, 0))
         d_min = math.sqrt(flex.min_default(d_sq, 0))
         return d_min, d_max, d_ave
Esempio n. 25
0
 def rigid_bond_deviation(self):
   if (self.n_rigid_bond_proxies is not None):
     rigid_bond_deltas = adp_restraints.rigid_bond_deltas(
       sites_cart=self.sites_cart,
       u_cart=self.u_cart,
       proxies=self.rigid_bond_proxies)
     r_sq = rigid_bond_deltas * rigid_bond_deltas
     r_ave = math.sqrt(flex.mean_default(r_sq, 0))
     r_max = math.sqrt(flex.max_default(r_sq, 0))
     r_min = math.sqrt(flex.min_default(r_sq, 0))
     return r_min, r_max, r_ave
Esempio n. 26
0
 def dihedral_deviations(self):
     if (self.n_dihedral_proxies is not None):
         covalent_dihedrals = self.dihedral_proxies.proxy_select(
             origin_id=0)
         dihedral_deltas = geometry_restraints.dihedral_deltas(
             sites_cart=self.sites_cart, proxies=covalent_dihedrals)
         d_sq = dihedral_deltas * dihedral_deltas
         d_ave = math.sqrt(flex.mean_default(d_sq, 0))
         d_max = math.sqrt(flex.max_default(d_sq, 0))
         d_min = math.sqrt(flex.min_default(d_sq, 0))
         return d_min, d_max, d_ave
Esempio n. 27
0
 def dihedral_deviations(self):
   # !!!XXX!!! Warnign! this works wrong because it is not aware of origin_id!
   if(self.n_dihedral_proxies is not None):
     dihedral_deltas = geometry_restraints.dihedral_deltas(
       sites_cart = self.sites_cart,
       proxies    = self.dihedral_proxies)
     d_sq  = dihedral_deltas * dihedral_deltas
     d_ave = math.sqrt(flex.mean_default(d_sq, 0))
     d_max = math.sqrt(flex.max_default(d_sq, 0))
     d_min = math.sqrt(flex.min_default(d_sq, 0))
     return d_min, d_max, d_ave
Esempio n. 28
0
 def reference_dihedral_deviations(self):
   assert 0, "Not working"
   if(self.n_reference_dihedral_proxies is not None):
     reference_dihedral_deltas = geometry_restraints.reference_dihedral_deltas(
       sites_cart = self.sites_cart,
       proxies    = self.reference_dihedral_proxies)
     d_sq  = reference_dihedral_deltas * reference_dihedral_deltas
     d_ave = math.sqrt(flex.mean_default(d_sq, 0))
     d_max = math.sqrt(flex.max_default(d_sq, 0))
     d_min = math.sqrt(flex.min_default(d_sq, 0))
     return d_min, d_max, d_ave
Esempio n. 29
0
 def adp_similarity_deviation(self):
     if (self.n_adp_similarity_proxies is not None):
         adp_similarity_deltas_rms = adp_restraints.adp_similarity_deltas_rms(
             u_cart=self.u_cart,
             u_iso=self.u_iso,
             use_u_aniso=self.use_u_aniso,
             proxies=self.adp_similarity_proxies)
         a_sq = adp_similarity_deltas_rms * adp_similarity_deltas_rms
         a_ave = math.sqrt(flex.mean_default(a_sq, 0))
         a_max = math.sqrt(flex.max_default(a_sq, 0))
         a_min = math.sqrt(flex.min_default(a_sq, 0))
         return a_min, a_max, a_ave
Esempio n. 30
0
 def bond_deviations(self):
     if (self.n_bond_proxies is not None):
         bond_deltas = self.bond_proxies.deltas(sites_cart=self.sites_cart,
                                                origin_id=0)
         if len(bond_deltas) > 0:
             b_sq = bond_deltas * bond_deltas
             b_ave = math.sqrt(flex.mean_default(b_sq, 0))
             b_max = math.sqrt(flex.max_default(b_sq, 0))
             b_min = math.sqrt(flex.min_default(b_sq, 0))
             return b_min, b_max, b_ave
         else:
             return 0, 0, 0
Esempio n. 31
0
 def angle_deviations(self):
     if (self.n_angle_proxies is not None):
         angle_deltas = self.angle_proxies.proxy_select(origin_id=0).deltas(
             sites_cart=self.sites_cart)
         if len(angle_deltas) > 0:
             a_sq = angle_deltas * angle_deltas
             a_ave = math.sqrt(flex.mean_default(a_sq, 0))
             a_max = math.sqrt(flex.max_default(a_sq, 0))
             a_min = math.sqrt(flex.min_default(a_sq, 0))
             return a_min, a_max, a_ave
         else:
             return 0, 0, 0
Esempio n. 32
0
 def planarity_deviations(self):
   # XXX Need update, does not respect origin_id
   # assert 0, "Not counting for origin_id"
   if(self.n_planarity_proxies is not None):
     planarity_deltas = geometry_restraints.planarity_deltas_rms(
       sites_cart = self.sites_cart,
       proxies    = self.planarity_proxies)
     p_sq  = planarity_deltas * planarity_deltas
     p_ave = math.sqrt(flex.mean_default(p_sq, 0))
     p_max = math.sqrt(flex.max_default(p_sq, 0))
     p_min = math.sqrt(flex.min_default(p_sq, 0))
     return p_min, p_max, p_ave
Esempio n. 33
0
 def bond_deviations(self):
   if(self.n_bond_proxies is not None):
     bond_deltas = self.bond_proxies.deltas(
         sites_cart=self.sites_cart, origin_id=0)
     if len(bond_deltas) >0:
       b_sq  = bond_deltas * bond_deltas
       b_ave = math.sqrt(flex.mean_default(b_sq, 0))
       b_max = math.sqrt(flex.max_default(b_sq, 0))
       b_min = math.sqrt(flex.min_default(b_sq, 0))
       return b_min, b_max, b_ave
     else:
       return 0,0,0
Esempio n. 34
0
 def adp_similarity_deviation(self):
   if (self.n_adp_similarity_proxies is not None):
     adp_similarity_deltas_rms = adp_restraints.adp_similarity_deltas_rms(
       u_cart=self.u_cart,
       u_iso=self.u_iso,
       use_u_aniso=self.use_u_aniso,
       proxies=self.adp_similarity_proxies)
     a_sq = adp_similarity_deltas_rms * adp_similarity_deltas_rms
     a_ave = math.sqrt(flex.mean_default(a_sq, 0))
     a_max = math.sqrt(flex.max_default(a_sq, 0))
     a_min = math.sqrt(flex.min_default(a_sq, 0))
     return a_min, a_max, a_ave
Esempio n. 35
0
 def angle_deviations(self):
   if(self.n_angle_proxies is not None):
     angle_deltas = self.angle_proxies.proxy_select(origin_id=0).deltas(
         sites_cart=self.sites_cart)
     if len(angle_deltas) > 0:
       a_sq  = angle_deltas * angle_deltas
       a_ave = math.sqrt(flex.mean_default(a_sq, 0))
       a_max = math.sqrt(flex.max_default(a_sq, 0))
       a_min = math.sqrt(flex.min_default(a_sq, 0))
       return a_min, a_max, a_ave
     else:
       return 0,0,0
Esempio n. 36
0
 def bond_deviations_weighted(self):
   if(self.n_bond_proxies is not None):
     bond_deltas = self.bond_proxies.deltas(
         sites_cart=self.sites_cart, origin_id=0)
     if len(bond_deltas) >0:
       sigmas = flex.double([geometry_restraints.weight_as_sigma(x.weight) for x in self.bond_proxies.simple])
       sigma_mean = flex.mean_default(sigmas, 0)
       z_scores = flex.double([(bond_delta/sigma*sigma_mean) for bond_delta,sigma in zip(bond_deltas,sigmas)])
       b_rmsz = math.sqrt(flex.mean_default(z_scores*z_scores,0))
       b_z_max = flex.max_default(flex.abs(z_scores), 0)
       b_z_min = flex.min_default(flex.abs(z_scores), 0)
       return b_z_min, b_z_max, b_rmsz
     else:
       return 0,0,0
Esempio n. 37
0
 def angle_deviations_weighted(self):
   if(self.n_angle_proxies is not None):
     angle_deltas = self.angle_proxies.proxy_select(origin_id=0).deltas(
         sites_cart=self.sites_cart)
     if len(angle_deltas) > 0:
       sigmas = flex.double([geometry_restraints.weight_as_sigma(x.weight) for x in self.angle_proxies])
       sigma_mean = flex.mean_default(sigmas, 0)
       z_scores = flex.double([(angle_delta/sigma*sigma_mean) for angle_delta,sigma in zip(angle_deltas,sigmas)])
       a_rmsz = math.sqrt(flex.mean_default(z_scores*z_scores,0))
       a_z_max = flex.max_default(flex.abs(z_scores), 0)
       a_z_min = flex.min_default(flex.abs(z_scores), 0)
       return a_z_min, a_z_max, a_rmsz
     else:
       return 0,0,0
Esempio n. 38
0
 def collect(self, model,
                   fmodel,
                   step,
                   wilson_b = None,
                   rigid_body_shift_accumulator = None):
   global time_collect_and_process
   t1 = time.time()
   if(self.sites_cart_start is None):
     self.sites_cart_start = model.xray_structure.sites_cart()
   sites_cart_curr = model.xray_structure.sites_cart()
   if(sites_cart_curr.size()==self.sites_cart_start.size()):
     self.shifts.append(
       flex.mean(flex.sqrt((self.sites_cart_start-sites_cart_curr).dot())))
   else: self.shifts.append("n/a")
   if(wilson_b is not None): self.wilson_b = wilson_b
   self.steps.append(step)
   self.r_works.append(fmodel.r_work())
   self.r_frees.append(fmodel.r_free())
   use_amber = False
   if hasattr(self.params, "amber"): # loaded amber scope
     use_amber = self.params.amber.use_amber
     self.is_amber_monitor=use_amber
   ignore_hd = True
   if self.neutron_refinement or use_amber:
     ignore_hd = False
   use_afitt = False
   if hasattr(self.params, "afitt"): # loaded amber scope
     use_afitt = self.params.afitt.use_afitt
   general_selection = None
   if use_afitt:
     from mmtbx.geometry_restraints import afitt
     if 0:
       general_selection = afitt.get_afitt_selection(model.restraints_manager,
                                                     model.xray_structure,
                                                     ignore_hd)
       afitt_geom = model.geometry_statistics(
         ignore_hd = ignore_hd,
         cdl_restraints=self.params.pdb_interpretation.restraints_library.cdl,
         general_selection=general_selection,
         )
       afitt_geom.show()
     general_selection = afitt.get_non_afitt_selection(
       model.restraints_manager,
       model.xray_structure.sites_cart(),
       model.xray_structure.hd_selection(),
       ignore_hd)
   geom = model.geometry_statistics(
     ignore_hd = ignore_hd,
     cdl_restraints=self.params.pdb_interpretation.restraints_library.cdl,
     general_selection=general_selection,
     )
   if(geom is not None): self.geom.append(geom)
   hd_sel = None
   if(not self.neutron_refinement and not self.is_neutron_monitor):
     hd_sel = model.xray_structure.hd_selection()
   b_isos = model.xray_structure.extract_u_iso_or_u_equiv() * math.pi**2*8
   if(hd_sel is not None): b_isos = b_isos.select(~hd_sel)
   self.bs_iso_max_a.append(flex.max_default( b_isos, 0))
   self.bs_iso_min_a.append(flex.min_default( b_isos, 0))
   self.bs_iso_ave_a.append(flex.mean_default(b_isos, 0))
   self.n_solv.append(model.number_of_ordered_solvent_molecules())
   if (len(self.geom)>0 and
       getattr(self.geom[0], "b", None) and
       getattr(self.geom[0], "a", None)
       ):
     if([self.bond_start,self.angle_start].count(None) == 2):
       if(len(self.geom)>0):
         self.bond_start  = self.geom[0].b[2]
         self.angle_start = self.geom[0].a[2]
     if(len(self.geom)>0):
       self.bond_final  = self.geom[len(self.geom)-1].b[2]
       self.angle_final = self.geom[len(self.geom)-1].a[2]
     elif(len(self.geom)==1):
       self.bond_final  = self.geom[0].b[2]
       self.angle_final = self.geom[0].a[2]
   if(rigid_body_shift_accumulator is not None):
     self.rigid_body_shift_accumulator = rigid_body_shift_accumulator
   t2 = time.time()
   time_collect_and_process += (t2 - t1)
   self.call_back(model, fmodel, method=step)
Esempio n. 39
0
 def mmmd(self, values, eps = None):
   if(eps is not None): values = values * eps
   return flex.min_default(values, None), \
          flex.max_default(values, None), \
          flex.mean_default(values, None)
 def __init__(self,
              refiner,
              xray_structure,
              start_trial_weight_value = 50.,
              weight_sample_rate = 10,
              rms_bonds_limit = 0.03,
              rms_angles_limit = 3.0,
              optimize_weight = True):
   self.rms_angles_start = None
   self.rms_bonds_start = None
   self.refiner = refiner
   self.weight_start=start_trial_weight_value
   sites_cart_start = xray_structure.sites_cart()
   self.rms_bonds_start, self.rms_angles_start  = \
     self.rmsds(sites_cart=xray_structure.sites_cart())
   self.weight_sample_rate = weight_sample_rate
   # results
   self.weight_final = None
   self.sites_cart_result = None
   self.rms_bonds_final,self.rms_angles_final = None,None
   #
   pool = {}
   bonds = flex.double()
   angles = flex.double()
   weights = flex.double()
   #
   weight = start_trial_weight_value
   weight_last = weight
   self.adjust_weight_sample_rate(weight=weight)
   if(optimize_weight):
     while True:
       self.rmsds(sites_cart=sites_cart_start) # DUMMY
       self.adjust_weight_sample_rate(weight=weight_last)
       tmp = xray_structure.deep_copy_scatterers()
       #tmp.shake_sites_in_place(
       #  rms_difference = None,
       #  mean_distance  = 0.5)
       refiner.refine(
         xray_structure = tmp,#xray_structure.deep_copy_scatterers(), # XXX
         weight     = weight)
       sites_cart_result = refiner.sites_cart()
       bd, ad = self.rmsds(sites_cart=sites_cart_result)
       bonds.append(bd)
       angles.append(ad)
       weights.append(weight)
       pool.setdefault(weight,[]).append([sites_cart_result.deep_copy(),bd,ad])
       if(refiner.geometry_restraints_manager is None): break
       weight_last = weight
       if(ad>rms_angles_limit or bd > rms_bonds_limit):
         weight -= self.weight_sample_rate
       else:
         weight += self.weight_sample_rate
       if(weight<0 or abs(weight)<1.e-6):
         self.adjust_weight_sample_rate(weight=weight)
         weight = weight_last
         weight -= self.weight_sample_rate
       #print ">>> ", "%8.4f %8.4f"%(weight, weight_last), "%6.4f %5.2f"%(bd, ad),\
       #  self.weight_sample_rate, "  f (start/final):", refiner.refined.f_start, refiner.refined.f_final
       if((weight<0 or weight>1000) or weight in weights): break
       l = bonds.size()-1
       if(bonds.size()>5 and
          abs(bonds[l]-bonds[l-1])<0.0005 and
          abs(bonds[l]-bonds[l-2])<0.0005 and
          abs(bonds[l]-bonds[l-3])<0.0005 and
          abs(bonds[l]-bonds[l-4])<0.0005 and
          abs(bonds[l]-bonds[l-5])<0.0005): break
   else:
     refiner.refine(
       xray_structure = xray_structure.deep_copy_scatterers(), # XXX
       weight     = weight)
     sites_cart_result = refiner.sites_cart()
   # select results
   if(optimize_weight):
     delta = bonds-rms_bonds_limit
     ind = (delta == flex.max_default(delta.select(delta<=0),
       flex.min(delta))).iselection()[0]
     self.weight_final = weights[ind]
     self.sites_cart_result = pool[self.weight_final][0][0]
     self.rms_bonds_final,self.rms_angles_final = \
       self.rmsds(sites_cart=self.sites_cart_result)
     assert approx_equal(pool[self.weight_final][0][2], angles[ind])
     assert approx_equal(pool[self.weight_final][0][1], bonds[ind])
     assert approx_equal(self.rms_angles_final, angles[ind])
     assert approx_equal(self.rms_bonds_final, bonds[ind])
   else:
     self.weight_final = self.weight_start
     self.sites_cart_result = sites_cart_result
Esempio n. 41
0
 def collect(self,
             model,
             fmodel,
             step,
             wilson_b=None,
             rigid_body_shift_accumulator=None):
     global time_collect_and_process
     t1 = time.time()
     if (self.sites_cart_start is None):
         self.sites_cart_start = model.xray_structure.sites_cart()
     sites_cart_curr = model.xray_structure.sites_cart()
     if (sites_cart_curr.size() == self.sites_cart_start.size()):
         self.shifts.append(
             flex.mean(
                 flex.sqrt(
                     (self.sites_cart_start - sites_cart_curr).dot())))
     else:
         self.shifts.append("n/a")
     if (wilson_b is not None): self.wilson_b = wilson_b
     self.steps.append(step)
     self.r_works.append(fmodel.r_work())
     self.r_frees.append(fmodel.r_free())
     use_amber = False
     if hasattr(self.params, "amber"):  # loaded amber scope
         use_amber = self.params.amber.use_amber
         self.is_amber_monitor = use_amber
     ignore_hd = True
     if self.neutron_refinement or use_amber:
         ignore_hd = False
     use_afitt = False
     if hasattr(self.params, "afitt"):  # loaded amber scope
         use_afitt = self.params.afitt.use_afitt
     general_selection = None
     if use_afitt:
         from mmtbx.geometry_restraints import afitt
         if 0:
             general_selection = afitt.get_afitt_selection(
                 model.restraints_manager, model.xray_structure, ignore_hd)
             afitt_geom = model.geometry_statistics(
                 ignore_hd=ignore_hd,
                 cdl_restraints=self.params.pdb_interpretation.
                 restraints_library.cdl,
                 general_selection=general_selection,
             )
             afitt_geom.show()
         general_selection = afitt.get_non_afitt_selection(
             model.restraints_manager, model.xray_structure.sites_cart(),
             model.xray_structure.hd_selection(), ignore_hd)
     geom = model.geometry_statistics(
         ignore_hd=ignore_hd,
         cdl_restraints=self.params.pdb_interpretation.restraints_library.
         cdl,
         general_selection=general_selection,
     )
     if (geom is not None): self.geom.append(geom)
     hd_sel = None
     if (not self.neutron_refinement and not self.is_neutron_monitor):
         hd_sel = model.xray_structure.hd_selection()
     b_isos = model.xray_structure.extract_u_iso_or_u_equiv(
     ) * math.pi**2 * 8
     if (hd_sel is not None): b_isos = b_isos.select(~hd_sel)
     self.bs_iso_max_a.append(flex.max_default(b_isos, 0))
     self.bs_iso_min_a.append(flex.min_default(b_isos, 0))
     self.bs_iso_ave_a.append(flex.mean_default(b_isos, 0))
     self.n_solv.append(model.number_of_ordered_solvent_molecules())
     if (len(self.geom) > 0 and getattr(self.geom[0], "b", None)
             and getattr(self.geom[0], "a", None)):
         if ([self.bond_start, self.angle_start].count(None) == 2):
             if (len(self.geom) > 0):
                 self.bond_start = self.geom[0].b[2]
                 self.angle_start = self.geom[0].a[2]
         if (len(self.geom) > 0):
             self.bond_final = self.geom[len(self.geom) - 1].b[2]
             self.angle_final = self.geom[len(self.geom) - 1].a[2]
         elif (len(self.geom) == 1):
             self.bond_final = self.geom[0].b[2]
             self.angle_final = self.geom[0].a[2]
     if (rigid_body_shift_accumulator is not None):
         self.rigid_body_shift_accumulator = rigid_body_shift_accumulator
     t2 = time.time()
     time_collect_and_process += (t2 - t1)
     self.call_back(model, fmodel, method=step)
Esempio n. 42
0
 def mmmd(self, values, eps = None):
   if(eps is not None): values = values * eps
   return flex.min_default(values, None), \
          flex.max_default(values, None), \
          flex.mean_default(values, None)
Esempio n. 43
0
 def __init__(self,
              refiner,
              xray_structure,
              start_trial_weight_value = 50.,
              weight_sample_rate = 10,
              rms_bonds_limit = 0.03,
              rms_angles_limit = 3.0,
              optimize_weight = True):
   self.rms_angles_start = None
   self.rms_bonds_start = None
   self.refiner = refiner
   self.weight_start=start_trial_weight_value
   sites_cart_start = xray_structure.sites_cart()
   self.rms_bonds_start, self.rms_angles_start  = \
     self.rmsds(sites_cart=xray_structure.sites_cart())
   self.weight_sample_rate = weight_sample_rate
   # results
   self.weight_final = None
   self.sites_cart_result = None
   self.rms_bonds_final,self.rms_angles_final = None,None
   #
   pool = {}
   bonds = flex.double()
   angles = flex.double()
   weights = flex.double()
   #
   weight = start_trial_weight_value
   weight_last = weight
   self.adjust_weight_sample_rate(weight=weight)
   if(optimize_weight):
     while True:
       self.rmsds(sites_cart=sites_cart_start) # DUMMY
       self.adjust_weight_sample_rate(weight=weight_last)
       tmp = xray_structure.deep_copy_scatterers()
       #tmp.shake_sites_in_place(
       #  rms_difference = None,
       #  mean_distance  = 0.5)
       refiner.refine(
         xray_structure = tmp,#xray_structure.deep_copy_scatterers(), # XXX
         weight     = weight)
       sites_cart_result = refiner.sites_cart()
       bd, ad = self.rmsds(sites_cart=sites_cart_result)
       bonds.append(bd)
       angles.append(ad)
       weights.append(weight)
       pool.setdefault(weight,[]).append([sites_cart_result.deep_copy(),bd,ad])
       if(refiner.geometry_restraints_manager is None): break
       weight_last = weight
       if(ad>rms_angles_limit or bd > rms_bonds_limit):
         weight -= self.weight_sample_rate
       else:
         weight += self.weight_sample_rate
       if(weight<0 or abs(weight)<1.e-6):
         self.adjust_weight_sample_rate(weight=weight)
         weight = weight_last
         weight -= self.weight_sample_rate
       #print ">>> ", "%8.4f %8.4f"%(weight, weight_last), "%6.4f %5.2f"%(bd, ad),\
       #  self.weight_sample_rate, "  f (start/final):", refiner.refined.f_start, refiner.refined.f_final
       if((weight<0 or weight>1000) or weight in weights): break
       l = bonds.size()-1
       if(bonds.size()>5 and
          abs(bonds[l]-bonds[l-1])<0.0005 and
          abs(bonds[l]-bonds[l-2])<0.0005 and
          abs(bonds[l]-bonds[l-3])<0.0005 and
          abs(bonds[l]-bonds[l-4])<0.0005 and
          abs(bonds[l]-bonds[l-5])<0.0005): break
   else:
     refiner.refine(
       xray_structure = xray_structure.deep_copy_scatterers(), # XXX
       weight     = weight)
     sites_cart_result = refiner.sites_cart()
   # select results
   if(optimize_weight):
     delta = bonds-rms_bonds_limit
     ind = (delta == flex.max_default(delta.select(delta<=0),
       flex.min(delta))).iselection()[0]
     self.weight_final = weights[ind]
     self.sites_cart_result = pool[self.weight_final][0][0]
     self.rms_bonds_final,self.rms_angles_final = \
       self.rmsds(sites_cart=self.sites_cart_result)
     assert approx_equal(pool[self.weight_final][0][2], angles[ind])
     assert approx_equal(pool[self.weight_final][0][1], bonds[ind])
     assert approx_equal(self.rms_angles_final, angles[ind])
     assert approx_equal(self.rms_bonds_final, bonds[ind])
   else:
     self.weight_final = self.weight_start
     self.sites_cart_result = sites_cart_result