예제 #1
0
  def scat_data(self, d_star_sq=None):

    if d_star_sq is None:
      self.sigma_tot_sq=None
      self.gamma_tot_sigma=None
      self.gamma_tot=None

    if d_star_sq is not None:
      self.sigma_tot_sq = flex.double( d_star_sq.size() )
      gaussians = {}
      for chemical_type, n_atoms in self.asu_contents.items():
        gaussians[chemical_type] = xray_scattering.wk1995(
          chemical_type).fetch()
        f0 = gaussians[chemical_type].at_d_star_sq(d_star_sq)
        self.sigma_tot_sq += f0*f0*n_atoms

      if(d_star_sq.size()>0):
        ## Protein part
        gamma_prot = gamma_protein(d_star_sq)
        self.gamma_prot = gamma_prot.gamma*self.fraction_protein
        ## Nucleotide part; needs to be completed
        gamma_nuc = gamma_nucleic(d_star_sq)
        self.gamma_nuc = gamma_nuc.gamma*self.fraction_nucleic ##
        ## Totals
        self.gamma_tot = self.gamma_prot*self.fraction_protein +\
                         self.gamma_nuc*self.fraction_nucleic
        self.gamma_tot_sigma = (gamma_prot.sigma_gamma*self.fraction_protein)*\
                               (gamma_prot.sigma_gamma*self.fraction_protein)+\
                               (gamma_nuc.sigma_gamma*self.fraction_nucleic)*\
                               (gamma_nuc.sigma_gamma*self.fraction_nucleic)
        self.gamma_tot_sigma = flex.sqrt(  self.gamma_tot_sigma )
예제 #2
0
    def scat_data(self, d_star_sq=None):

        if d_star_sq is None:
            self.sigma_tot_sq = None
            self.gamma_tot_sigma = None
            self.gamma_tot = None

        if d_star_sq is not None:
            self.sigma_tot_sq = flex.double(d_star_sq.size())
            gaussians = {}
            for chemical_type, n_atoms in self.asu_contents.items():
                gaussians[chemical_type] = xray_scattering.wk1995(
                    chemical_type).fetch()
                f0 = gaussians[chemical_type].at_d_star_sq(d_star_sq)
                self.sigma_tot_sq += f0 * f0 * n_atoms

            if (d_star_sq.size() > 0):
                ## Protein part
                gamma_prot = gamma_protein(d_star_sq)
                self.gamma_prot = gamma_prot.gamma * self.fraction_protein
                ## Nucleotide part; needs to be completed
                gamma_nuc = gamma_nucleic(d_star_sq)
                self.gamma_nuc = gamma_nuc.gamma * self.fraction_nucleic  ##
                ## Totals
                self.gamma_tot = self.gamma_prot*self.fraction_protein +\
                                 self.gamma_nuc*self.fraction_nucleic
                self.gamma_tot_sigma = (gamma_prot.sigma_gamma*self.fraction_protein)*\
                                       (gamma_prot.sigma_gamma*self.fraction_protein)+\
                                       (gamma_nuc.sigma_gamma*self.fraction_nucleic)*\
                                       (gamma_nuc.sigma_gamma*self.fraction_nucleic)
                self.gamma_tot_sigma = flex.sqrt(self.gamma_tot_sigma)
예제 #3
0
def main():
    parser = OptionParser(usage="usage: python %prog [options] file_name ...")
    parser.add_option("-c", "--cutoff", type="float", default=6.05, metavar="FLOAT", help="maximum sin(theta)/lambda")
    (options, args) = parser.parse_args()
    if len(args) < 1:
        parser.print_help()
        return
    cutoff = options.cutoff
    for file_name in args:
        tab = read_table(file_name)
        if tab.element == "Es":
            continue
        wk = xray_scattering.wk1995(tab.element, True).fetch()
        sel = tab.x <= cutoff
        tab_x = tab.x.select(sel)
        tab_y = tab.y.select(sel)
        sigmas = flex.double(tab_x.size(), 0.0005)
        wky = wk.at_x(tab_x)
        errors_abs = flex.abs(wky - tab_y)
        fit = scitbx.math.gaussian.fit(tab_x, tab_y, sigmas, wk)
        errors_rel = fit.significant_relative_errors(1.0e-6)
        print tab.element, tab.atomic_number,
        print "max error < %.1fA-1 abs, rel: %7.4f %7.4f" % (cutoff, flex.max(errors_abs), flex.max(errors_rel))
        for x, y, f, ea, er in zip(tab_x, tab_y, wky, errors_abs, errors_rel):
            print "%7.4f %7.4f %7.4f %7.4f %7.4f" % (x, y, f, ea, er)
        print
예제 #4
0
def show_literature_fits(label, n_terms, null_fit, n_points, e_other=None):
  for lib in [xray_scattering.wk1995,
              xray_scattering.it1992,
              xray_scattering.two_gaussian_agarwal_isaacs,
              xray_scattering.two_gaussian_agarwal_1978,
              xray_scattering.one_gaussian_agarwal_1978]:
    if (lib == xray_scattering.wk1995):
      try:
        lib_gaussian = xray_scattering.wk1995(label, True).fetch()
        lib_source = "WK1995"
      except Exception:
        lib_gaussian = None
    elif (lib == xray_scattering.it1992):
      try:
        lib_gaussian = xray_scattering.it1992(label, True).fetch()
        lib_source = "IT1992"
      except Exception:
        lib_gaussian = None
    elif (lib.table.has_key(label)):
      lib_gaussian = lib.table[label]
      lib_source = lib.source_short
    else:
      lib_gaussian = None
    if (lib_gaussian is not None):
      gaussian_fit = scitbx.math.gaussian.fit(
        null_fit.table_x()[:n_points],
        null_fit.table_y()[:n_points],
        null_fit.table_sigmas()[:n_points],
        lib_gaussian)
      e = flex.max(gaussian_fit.significant_relative_errors())
      show_fit_summary(lib_source, label, gaussian_fit, e,
                       e_other, lib_gaussian.n_terms())
예제 #5
0
def main():
    parser = OptionParser(usage="usage: python %prog [options] file_name ...")
    parser.add_option("-c",
                      "--cutoff",
                      type="float",
                      default=6.05,
                      metavar="FLOAT",
                      help="maximum sin(theta)/lambda")
    (options, args) = parser.parse_args()
    if (len(args) < 1):
        parser.print_help()
        return
    cutoff = options.cutoff
    for file_name in args:
        tab = read_table(file_name)
        if (tab.element == "Es"): continue
        wk = xray_scattering.wk1995(tab.element, True).fetch()
        sel = tab.x <= cutoff
        tab_x = tab.x.select(sel)
        tab_y = tab.y.select(sel)
        sigmas = flex.double(tab_x.size(), 0.0005)
        wky = wk.at_x(tab_x)
        errors_abs = flex.abs(wky - tab_y)
        fit = scitbx.math.gaussian.fit(tab_x, tab_y, sigmas, wk)
        errors_rel = fit.significant_relative_errors(1.e-6)
        print(tab.element, tab.atomic_number, end=' ')
        print("max error < %.1fA-1 abs, rel: %7.4f %7.4f" %
              (cutoff, flex.max(errors_abs), flex.max(errors_rel)))
        for x, y, f, ea, er in zip(tab_x, tab_y, wky, errors_abs, errors_rel):
            print("%7.4f %7.4f %7.4f %7.4f %7.4f" % (x, y, f, ea, er))
        print()
예제 #6
0
def show_literature_fits(label, n_terms, null_fit, n_points, e_other=None):
    for lib in [
            xray_scattering.wk1995, xray_scattering.it1992,
            xray_scattering.two_gaussian_agarwal_isaacs,
            xray_scattering.two_gaussian_agarwal_1978,
            xray_scattering.one_gaussian_agarwal_1978
    ]:
        if (lib == xray_scattering.wk1995):
            try:
                lib_gaussian = xray_scattering.wk1995(label, True).fetch()
                lib_source = "WK1995"
            except Exception:
                lib_gaussian = None
        elif (lib == xray_scattering.it1992):
            try:
                lib_gaussian = xray_scattering.it1992(label, True).fetch()
                lib_source = "IT1992"
            except Exception:
                lib_gaussian = None
        elif (lib.table.has_key(label)):
            lib_gaussian = lib.table[label]
            lib_source = lib.source_short
        else:
            lib_gaussian = None
        if (lib_gaussian is not None):
            gaussian_fit = scitbx.math.gaussian.fit(
                null_fit.table_x()[:n_points],
                null_fit.table_y()[:n_points],
                null_fit.table_sigmas()[:n_points], lib_gaussian)
            e = flex.max(gaussian_fit.significant_relative_errors())
            show_fit_summary(lib_source, label, gaussian_fit, e, e_other,
                             lib_gaussian.n_terms())
예제 #7
0
def ls_ff_weights(f_obs, atom, B):
    d_star_sq_data = f_obs.d_star_sq().data()
    table = wk1995(atom).fetch()
    ff = table.at_d_star_sq(d_star_sq_data) * flex.exp(
        -B / 4.0 * d_star_sq_data)
    weights = 1.0 / flex.pow2(ff)
    return weights
예제 #8
0
def run():
    wk = xray_scattering.wk1995("O2-")
    gaussian_fit = scitbx.math.gaussian.fit(table_2_stol, table_2_o2minus,
                                            table_2_sigmas, wk.fetch())
    print("max error:", flex.max(gaussian_fit.significant_relative_errors()))
    cctbx.eltbx.gaussian_fit.write_plots(plots_dir="rez_plots",
                                         label=wk.label(),
                                         gaussian_fit=gaussian_fit)
예제 #9
0
 def form_factor(ssi, absent_atom_type):
     table = wk1995(absent_atom_type).fetch()
     a_wk = table.array_of_a()
     b_wk = table.array_of_b()
     c_wk = table.c()
     result_wk = c_wk
     for i in xrange(5):
         result_wk += a_wk[i] * math.exp(-b_wk[i] * ssi / 4.0)
     return result_wk
예제 #10
0
 def form_factor(ssi, absent_atom_type):
   table=wk1995(absent_atom_type).fetch()
   a_wk=table.array_of_a()
   b_wk=table.array_of_b()
   c_wk=table.c()
   result_wk=c_wk
   for i in xrange(5):
     result_wk += a_wk[i]*math.exp(-b_wk[i]*ssi/4.0)
   return result_wk
예제 #11
0
def f_ordered_solvent(f, n_water_atoms_absent, bf_atoms_absent,
                      absent_atom_type):
    nsym = f.space_group().order_z()
    n_lost_w = nsym * n_water_atoms_absent
    data = f.data() * n_lost_w
    d_star_sq_data = f.d_star_sq().data()
    table = wk1995(absent_atom_type).fetch()
    ff = table.at_d_star_sq(d_star_sq_data)
    factor = ff * flex.exp(-bf_atoms_absent / 4.0 * d_star_sq_data)
    f_by_m = miller.array(miller_set=f, data=data * factor)
    return f_by_m
예제 #12
0
 def form_factor(self, ss):
     #
     # W & K form-factor of atom C
     #
     table = wk1995(self.absent_atom_type).fetch()
     a_wk = table.array_of_a()
     b_wk = table.array_of_b()
     c_wk = table.c()
     result_wk = c_wk
     for i in range(5):
         result_wk += a_wk[i] * math.exp(-b_wk[i] * ss / 4.0)
     return result_wk
예제 #13
0
def run():
  wk = xray_scattering.wk1995("O2-")
  gaussian_fit = scitbx.math.gaussian.fit(
    table_2_stol,
    table_2_o2minus,
    table_2_sigmas,
    wk.fetch())
  print "max error:", flex.max(gaussian_fit.significant_relative_errors())
  cctbx.eltbx.gaussian_fit.write_plots(
    plots_dir="rez_plots",
    label=wk.label(),
    gaussian_fit=gaussian_fit)
예제 #14
0
def form_factor(absent_atom_type, ss):
    #
    # W & K form-factor for an atom, B=0.0
    #
    table = wk1995(absent_atom_type).fetch()
    a_wk = table.array_of_a()
    b_wk = table.array_of_b()
    c_wk = table.c()
    result_wk = c_wk
    for i in xrange(5):
        result_wk += a_wk[i] * math.exp(-b_wk[i] * ss / 4.0)
    return result_wk
예제 #15
0
 def form_factor(self,ss):
   #
   # W & K form-factor of atom C
   #
   table=wk1995(self.absent_atom_type).fetch()
   a_wk=table.array_of_a()
   b_wk=table.array_of_b()
   c_wk=table.c()
   result_wk=c_wk
   for i in xrange(5):
      result_wk += a_wk[i]*math.exp(-b_wk[i]*ss/4.0)
   return result_wk
예제 #16
0
def f_ordered_solvent(f,
                      n_water_atoms_absent,
                      bf_atoms_absent,
                      absent_atom_type):
  nsym = f.space_group().order_z()
  n_lost_w = nsym * n_water_atoms_absent
  data = f.data() * n_lost_w
  d_star_sq_data = f.d_star_sq().data()
  table = wk1995(absent_atom_type).fetch()
  ff = table.at_d_star_sq(d_star_sq_data)
  factor = ff * flex.exp(-bf_atoms_absent/4.0*d_star_sq_data)
  f_by_m = miller.array(miller_set = f, data = data*factor)
  return f_by_m
예제 #17
0
def exercise_wk1995():
    e = xray_scattering.wk1995("c1")
    assert e.table() == "WK1995"
    assert e.label() == "C"
    g = e.fetch()
    assert approx_equal(g.array_of_a(),
                        (2.657506, 1.078079, 1.490909, -4.241070, 0.713791))
    assert approx_equal(g.array_of_b(),
                        (14.780758, 0.776775, 42.086842, -0.000294, 0.239535))
    assert approx_equal(g.c(), 4.297983)
    assert approx_equal(g.at_stol_sq(0), 5.99719834328)
    assert approx_equal(g.at_stol_sq(1. / 9), 2.26895371584)
    assert approx_equal(g.at_stol(1. / 9), 4.93735084739)
    assert approx_equal(g.at_d_star_sq(1. / 9), 4.04679561237)
    e = xray_scattering.wk1995("yb2+", True)
    assert e.label() == "Yb2+"
    g = e.fetch()
    assert approx_equal(g.array_of_a()[0], 28.443794)
    assert approx_equal(g.array_of_b()[4], 0.001463)
    assert approx_equal(g.c(), -23.214935)
    e = xray_scattering.wk1995("  yB3+")
    assert e.label() == "Yb3+"
    g = e.fetch()
    assert approx_equal(g.array_of_a()[0], 28.191629)
    n = 0
    for e in xray_scattering.wk1995_iterator():
        n += 1
        if (n == 213):
            assert e.label() == "Pu6+"
        else:
            assert e.label() != "Pu6+"
        d = xray_scattering.wk1995(e.label(), True)
        assert d.label() == e.label()
    assert n == 213
    i = xray_scattering.wk1995_iterator()
    j = iter(i)
    assert i is j
예제 #18
0
def exercise_wk1995():
  e = xray_scattering.wk1995("c1")
  assert e.table() == "WK1995"
  assert e.label() == "C"
  g = e.fetch()
  assert approx_equal(g.array_of_a(),
    (2.657506,1.078079,1.490909,-4.241070,0.713791))
  assert approx_equal(g.array_of_b(),
    (14.780758,0.776775,42.086842,-0.000294,0.239535))
  assert approx_equal(g.c(), 4.297983)
  assert approx_equal(g.at_stol_sq(0), 5.99719834328)
  assert approx_equal(g.at_stol_sq(1./9), 2.26895371584)
  assert approx_equal(g.at_stol(1./9), 4.93735084739)
  assert approx_equal(g.at_d_star_sq(1./9), 4.04679561237)
  e = xray_scattering.wk1995("yb2+", True)
  assert e.label() == "Yb2+"
  g = e.fetch()
  assert approx_equal(g.array_of_a()[0], 28.443794)
  assert approx_equal(g.array_of_b()[4], 0.001463)
  assert approx_equal(g.c(), -23.214935)
  e = xray_scattering.wk1995("  yB3+")
  assert e.label() == "Yb3+"
  g = e.fetch()
  assert approx_equal(g.array_of_a()[0], 28.191629)
  n = 0
  for e in xray_scattering.wk1995_iterator():
    n += 1
    if (n == 213):
      assert e.label() == "Pu6+"
    else:
      assert e.label() != "Pu6+"
    d = xray_scattering.wk1995(e.label(), True)
    assert d.label() == e.label()
  assert n == 213
  i = xray_scattering.wk1995_iterator()
  j = iter(i)
  assert i is j
예제 #19
0
def getXScatteringFactor(el, q):
    """Get the x-ray scattering factor for an element over the q range.
    
    If cctbx is not available, f(q) = 1 is used.

    """
    try:
        import cctbx.eltbx.xray_scattering as xray
        wk1995 = xray.wk1995(el)
        g = wk1995.fetch()
        # at_stol - at sin(theta)/lambda = Q/(4*pi)
        f = numpy.asarray( map( g.at_stol, q/(4*numpy.pi) ) )
        return f
    except ImportError:
        return 1
예제 #20
0
def getXScatteringFactor(el, q):
    """Get the x-ray scattering factor for an element over the q range.

    If cctbx is not available, f(q) = 1 is used.

    """
    try:
        import cctbx.eltbx.xray_scattering as xray
        wk1995 = xray.wk1995(el)
        g = wk1995.fetch()
        # at_stol - at sin(theta)/lambda = Q/(4*pi)
        f = numpy.asarray( map( g.at_stol, q/(4*numpy.pi) ) )
        return f
    except ImportError:
        return 1
예제 #21
0
def run(args):
  assert len(args) == 0
  sds_it = xray_scattering.it1992("H").fetch()
  sds_wk = xray_scattering.wk1995("H").fetch()
  sds_ng = xray_scattering.n_gaussian_table_entry("H", 6).gaussian()
  iso_it = xray_scattering.it1992("Hiso").fetch()
  iso_wk = xray_scattering.wk1995("Hiso").fetch()
  iso_ng = xray_scattering.n_gaussian_table_entry("Hiso", 6).gaussian()
  print "@with g0"
  print '@ s0 legend "SDS ITC Tab 6.1.1.2"'
  for i,lbl in enumerate(["SDS IT", "SDS WK", "SDS NG",
                          "ISO IT", "ISO WK", "ISO NG"]):
    print '@ s%d legend "%s"' % (i+1, lbl)
  print "@ s0 symbol 1"
  print "@ s0 line linestyle 0"
  for x,y in itc_tab_6112:
    print x, y
  print "&"
  n_samples = 1000
  for g in [sds_it, sds_wk, sds_ng, iso_it, iso_wk, iso_ng]:
    for i_stol in xrange(n_samples+1):
      stol = 6 * i_stol / n_samples
      print stol, g.at_stol(stol)
    print "&"
예제 #22
0
def run(args):
    assert len(args) == 0
    sds_it = xray_scattering.it1992("H").fetch()
    sds_wk = xray_scattering.wk1995("H").fetch()
    sds_ng = xray_scattering.n_gaussian_table_entry("H", 6).gaussian()
    iso_it = xray_scattering.it1992("Hiso").fetch()
    iso_wk = xray_scattering.wk1995("Hiso").fetch()
    iso_ng = xray_scattering.n_gaussian_table_entry("Hiso", 6).gaussian()
    print("@with g0")
    print('@ s0 legend "SDS ITC Tab 6.1.1.2"')
    for i, lbl in enumerate(
        ["SDS IT", "SDS WK", "SDS NG", "ISO IT", "ISO WK", "ISO NG"]):
        print('@ s%d legend "%s"' % (i + 1, lbl))
    print("@ s0 symbol 1")
    print("@ s0 line linestyle 0")
    for x, y in itc_tab_6112:
        print(x, y)
    print("&")
    n_samples = 1000
    for g in [sds_it, sds_wk, sds_ng, iso_it, iso_wk, iso_ng]:
        for i_stol in range(n_samples + 1):
            stol = 6 * i_stol / n_samples
            print(stol, g.at_stol(stol))
        print("&")
예제 #23
0
def ensure_common_symbols():
  lbl_it = []
  for e in xray_scattering.it1992_iterator(): lbl_it.append(e.label())
  lbl_it.sort()
  lbl_wk = []
  for e in xray_scattering.wk1995_iterator(): lbl_wk.append(e.label())
  lbl_wk.sort()
  assert lbl_wk == lbl_it
  lbl_ng = []
  for i_entry in xrange(xray_scattering.n_gaussian_table_size()):
    lbl_ng.append(xray_scattering.n_gaussian_table_entry(i_entry, 6).label())
  lbl_ng.sort()
  assert lbl_ng == lbl_it
  #
  for label in xray_scattering.standard_labels_list():
    it = xray_scattering.it1992(label, True).fetch()
    wk = xray_scattering.wk1995(label, True).fetch()
    ng = xray_scattering.n_gaussian_table_entry(label, 0, 0).gaussian()
    assert approx_equal(wk.at_stol(0)/it.at_stol(0), 1, 5.e-3)
예제 #24
0
def alpha_beta(f_dist, n_atoms_included, n_nonwater_atoms_absent,
               n_water_atoms_absent, bf_atoms_absent, final_error,
               absent_atom_type):
    nsym = f_dist.space_group().order_z()
    ss = 1. / flex.pow2(f_dist.d_spacings().data())
    n_part = nsym * n_atoms_included
    n_lost_p = nsym * n_nonwater_atoms_absent
    n_lost_w = nsym * n_water_atoms_absent
    f_dist_data = flex.abs(f_dist.data())
    a_d = flex.exp(-0.25 * ss * final_error**2 * math.pi**3)
    d_star_sq_data = f_dist.d_star_sq().data()
    assert approx_equal(ss, d_star_sq_data)
    table = wk1995(absent_atom_type).fetch()
    ff = table.at_d_star_sq(d_star_sq_data)
    factor = ff * flex.exp(-bf_atoms_absent / 4.0 * d_star_sq_data)
    b_d = ((1.-a_d*a_d)*n_part+n_lost_p+n_lost_w*(1.-f_dist_data*f_dist_data))*\
                                                                    factor*factor
    alpha = f_dist.array(data=a_d)
    beta = f_dist.array(data=b_d)
    return alpha, beta
예제 #25
0
def ensure_common_symbols():
    lbl_it = []
    for e in xray_scattering.it1992_iterator():
        lbl_it.append(e.label())
    lbl_it.sort()
    lbl_wk = []
    for e in xray_scattering.wk1995_iterator():
        lbl_wk.append(e.label())
    lbl_wk.sort()
    assert lbl_wk == lbl_it
    lbl_ng = []
    for i_entry in range(xray_scattering.n_gaussian_table_size()):
        lbl_ng.append(
            xray_scattering.n_gaussian_table_entry(i_entry, 6).label())
    lbl_ng.sort()
    assert lbl_ng == lbl_it
    #
    for label in xray_scattering.standard_labels_list():
        it = xray_scattering.it1992(label, True).fetch()
        wk = xray_scattering.wk1995(label, True).fetch()
        ng = xray_scattering.n_gaussian_table_entry(label, 0, 0).gaussian()
        assert approx_equal(wk.at_stol(0) / it.at_stol(0), 1, 5.e-3)
예제 #26
0
def alpha_beta(f_dist,
               n_atoms_included,
               n_nonwater_atoms_absent,
               n_water_atoms_absent,
               bf_atoms_absent,
               final_error,
               absent_atom_type):
  nsym = f_dist.space_group().order_z()
  ss = 1./flex.pow2(f_dist.d_spacings().data())
  n_part   = nsym * n_atoms_included
  n_lost_p = nsym * n_nonwater_atoms_absent
  n_lost_w = nsym * n_water_atoms_absent
  f_dist_data = flex.abs(f_dist.data())
  a_d = flex.exp( -0.25 * ss * final_error**2 * math.pi**3 )
  d_star_sq_data = f_dist.d_star_sq().data()
  assert approx_equal(ss,d_star_sq_data)
  table = wk1995(absent_atom_type).fetch()
  ff = table.at_d_star_sq(d_star_sq_data)
  factor = ff * flex.exp(-bf_atoms_absent/4.0*d_star_sq_data)
  b_d = ((1.-a_d*a_d)*n_part+n_lost_p+n_lost_w*(1.-f_dist_data*f_dist_data))*\
                                                                  factor*factor
  alpha = f_dist.array(data = a_d)
  beta  = f_dist.array(data = b_d)
  return alpha, beta
예제 #27
0
def run(file_name, args, cutoff, params,
        zig_zag=False, six_term=False, full_fits=None,
        plots_dir="itvc_fits_plots", verbose=0):
  tab = itvc_section61_io.read_table6111(file_name)
  chunk_n = 1
  chunk_i = 0
  if (len(args) > 0 and len(args[0].split(",")) == 2):
    chunk_n, chunk_i = [int(i) for i in args[0].split(",")]
    args = args[1:]
  if (not six_term and not zig_zag):
    if (not os.path.isdir(plots_dir)):
      print "No plots because target directory does not exist (mkdir %s)." % \
        plots_dir
      plots_dir = None
    if (chunk_n > 1):
      assert plots_dir is not None
  stols_more = cctbx.eltbx.gaussian_fit.international_tables_stols
  sel = stols_more <= cutoff + 1.e-6
  stols = stols_more.select(sel)
  i_chunk = 0
  for element in tab.elements + ["O2-", "SDS"]:
    if (len(args) > 0 and element not in args): continue
    flag = i_chunk % chunk_n == chunk_i
    i_chunk += 1
    if (not flag):
      continue
    results = {}
    results["fit_parameters"] = params
    if (element == "SDS"):
      wrk_lbl = element
      from cctbx.eltbx.development.hydrogen_plots import fit_input
      fi = fit_input()
      sel = fi.stols <= cutoff + 1.e-6
      null_fit = scitbx.math.gaussian.fit(
        fi.stols.select(sel),
        fi.data.select(sel),
        fi.sigmas.select(sel),
        xray_scattering.gaussian(0, False))
      null_fit_more = scitbx.math.gaussian.fit(
        fi.stols,
        fi.data,
        fi.sigmas,
        xray_scattering.gaussian(0, False))
    else:
      wrk_lbl = xray_scattering.wk1995(element, True)
      if (element != "O2-"):
        entry = tab.entries[element]
        null_fit = scitbx.math.gaussian.fit(
          stols,
          entry.table_y[:stols.size()],
          entry.table_sigmas[:stols.size()],
          xray_scattering.gaussian(0, False))
        null_fit_more = scitbx.math.gaussian.fit(
          stols_more,
          entry.table_y[:stols_more.size()],
          entry.table_sigmas[:stols_more.size()],
          xray_scattering.gaussian(0, False))
      else:
        rrg_stols_more = rez_rez_grant.table_2_stol
        sel = rrg_stols_more <= cutoff + 1.e-6
        rrg_stols = rrg_stols_more.select(sel)
        null_fit = scitbx.math.gaussian.fit(
          rrg_stols,
          rez_rez_grant.table_2_o2minus[:rrg_stols.size()],
          rez_rez_grant.table_2_sigmas[:rrg_stols.size()],
          xray_scattering.gaussian(0, False))
        null_fit_more = scitbx.math.gaussian.fit(
          rrg_stols_more,
          rez_rez_grant.table_2_o2minus[:rrg_stols_more.size()],
          rez_rez_grant.table_2_sigmas[:rrg_stols_more.size()],
          xray_scattering.gaussian(0, False))
    if (zig_zag):
      results[wrk_lbl] = cctbx.eltbx.gaussian_fit.zig_zag_fits(
        label=wrk_lbl,
        null_fit=null_fit,
        null_fit_more=null_fit_more,
        params=params)
    elif (full_fits is not None):
      assert len(full_fits.all[wrk_lbl]) == 1
      results[wrk_lbl] = cctbx.eltbx.gaussian_fit.decremental_fits(
        label=wrk_lbl,
        null_fit=null_fit,
        full_fit=full_fits.all[wrk_lbl][0],
        params=params,
        plots_dir=plots_dir,
        verbose=verbose)
    elif (not six_term):
      results[wrk_lbl] = cctbx.eltbx.gaussian_fit.incremental_fits(
        label=wrk_lbl,
        null_fit=null_fit,
        params=params,
        plots_dir=plots_dir,
        verbose=verbose)
    else:
      best_min = scitbx.math.gaussian_fit.fit_with_golay_starts(
        label=wrk_lbl,
        null_fit=null_fit,
        null_fit_more=null_fit_more,
        params=params)
      g = best_min.final_gaussian_fit
      results[wrk_lbl] = [xray_scattering.fitted_gaussian(
        stol=g.table_x()[-1], gaussian_sum=g)]
    sys.stdout.flush()
    pickle_file_name = "%s_fits.pickle" % identifier(wrk_lbl)
    easy_pickle.dump(pickle_file_name, results)
예제 #28
0
def ls_ff_weights(f_obs, atom, B):
  d_star_sq_data = f_obs.d_star_sq().data()
  table = wk1995(atom).fetch()
  ff = table.at_d_star_sq(d_star_sq_data) * flex.exp(-B/4.0*d_star_sq_data)
  weights = 1.0/flex.pow2(ff)
  return weights
예제 #29
0
def run(file_name,
        args,
        cutoff,
        params,
        zig_zag=False,
        six_term=False,
        full_fits=None,
        plots_dir="itvc_fits_plots",
        verbose=0):
    tab = itvc_section61_io.read_table6111(file_name)
    chunk_n = 1
    chunk_i = 0
    if (len(args) > 0 and len(args[0].split(",")) == 2):
        chunk_n, chunk_i = [int(i) for i in args[0].split(",")]
        args = args[1:]
    if (not six_term and not zig_zag):
        if (not os.path.isdir(plots_dir)):
            print("No plots because target directory does not exist (mkdir %s)." % \
              plots_dir)
            plots_dir = None
        if (chunk_n > 1):
            assert plots_dir is not None
    stols_more = cctbx.eltbx.gaussian_fit.international_tables_stols
    sel = stols_more <= cutoff + 1.e-6
    stols = stols_more.select(sel)
    i_chunk = 0
    for element in tab.elements + ["O2-", "SDS"]:
        if (len(args) > 0 and element not in args): continue
        flag = i_chunk % chunk_n == chunk_i
        i_chunk += 1
        if (not flag):
            continue
        results = {}
        results["fit_parameters"] = params
        if (element == "SDS"):
            wrk_lbl = element
            from cctbx.eltbx.development.hydrogen_plots import fit_input
            fi = fit_input()
            sel = fi.stols <= cutoff + 1.e-6
            null_fit = scitbx.math.gaussian.fit(
                fi.stols.select(sel), fi.data.select(sel),
                fi.sigmas.select(sel), xray_scattering.gaussian(0, False))
            null_fit_more = scitbx.math.gaussian.fit(
                fi.stols, fi.data, fi.sigmas,
                xray_scattering.gaussian(0, False))
        else:
            wrk_lbl = xray_scattering.wk1995(element, True)
            if (element != "O2-"):
                entry = tab.entries[element]
                null_fit = scitbx.math.gaussian.fit(
                    stols, entry.table_y[:stols.size()],
                    entry.table_sigmas[:stols.size()],
                    xray_scattering.gaussian(0, False))
                null_fit_more = scitbx.math.gaussian.fit(
                    stols_more, entry.table_y[:stols_more.size()],
                    entry.table_sigmas[:stols_more.size()],
                    xray_scattering.gaussian(0, False))
            else:
                rrg_stols_more = rez_rez_grant.table_2_stol
                sel = rrg_stols_more <= cutoff + 1.e-6
                rrg_stols = rrg_stols_more.select(sel)
                null_fit = scitbx.math.gaussian.fit(
                    rrg_stols,
                    rez_rez_grant.table_2_o2minus[:rrg_stols.size()],
                    rez_rez_grant.table_2_sigmas[:rrg_stols.size()],
                    xray_scattering.gaussian(0, False))
                null_fit_more = scitbx.math.gaussian.fit(
                    rrg_stols_more,
                    rez_rez_grant.table_2_o2minus[:rrg_stols_more.size()],
                    rez_rez_grant.table_2_sigmas[:rrg_stols_more.size()],
                    xray_scattering.gaussian(0, False))
        if (zig_zag):
            results[wrk_lbl] = cctbx.eltbx.gaussian_fit.zig_zag_fits(
                label=wrk_lbl,
                null_fit=null_fit,
                null_fit_more=null_fit_more,
                params=params)
        elif (full_fits is not None):
            assert len(full_fits.all[wrk_lbl]) == 1
            results[wrk_lbl] = cctbx.eltbx.gaussian_fit.decremental_fits(
                label=wrk_lbl,
                null_fit=null_fit,
                full_fit=full_fits.all[wrk_lbl][0],
                params=params,
                plots_dir=plots_dir,
                verbose=verbose)
        elif (not six_term):
            results[wrk_lbl] = cctbx.eltbx.gaussian_fit.incremental_fits(
                label=wrk_lbl,
                null_fit=null_fit,
                params=params,
                plots_dir=plots_dir,
                verbose=verbose)
        else:
            best_min = scitbx.math.gaussian_fit.fit_with_golay_starts(
                label=wrk_lbl,
                null_fit=null_fit,
                null_fit_more=null_fit_more,
                params=params)
            g = best_min.final_gaussian_fit
            results[wrk_lbl] = [
                xray_scattering.fitted_gaussian(stol=g.table_x()[-1],
                                                gaussian_sum=g)
            ]
        sys.stdout.flush()
        pickle_file_name = "%s_fits.pickle" % identifier(wrk_lbl)
        easy_pickle.dump(pickle_file_name, results)