Exemple #1
0
  def get_HKL(self,cursor):
    name = self.db_experiment_tag
    query = '''SELECT H,K,L,%s_hkls.hkl_id from %s_hkls,%s_isoforms WHERE %s_hkls.isoforms_isoform_id = %s_isoforms.isoform_id AND %s_isoforms.name = "%s"'''%(
            name, name, name, name, name, name, self.params["identified_isoform"])
    cursor.execute(query)
    ALL = cursor.fetchall()
    indices = flex.miller_index([(a[0],a[1],a[2]) for a in ALL])
    miller_id = flex.int([a[3] for a in ALL])
    self.miller_set = mset(crystal_symmetry=self.params["observations"][0].crystal_symmetry(), indices=indices)
    self.miller_set_id = miller_id
    # might have to change this to isoform_id next iteration
    cursor.execute('SELECT isoform_id FROM %s_isoforms WHERE name = "%s"'%(
            name, self.params["identified_isoform"]))

    self.isoform_id = cursor.fetchall()[0][0]
    return indices,miller_id
Exemple #2
0
def application(params, loop=True):
    from cxi_xdr_xes.cftbx.cspad_ana import db as cxidb
    dbobj = cxidb.dbconnect(params.db.host, params.db.name, params.db.user,
                            params.db.password)
    cursor = dbobj.cursor()
    PM = progress_manager(params, cursor)
    PM.setup_isoforms(cursor)
    PM.setup_runtags(cursor)
    isoforms = PM.isoforms
    del dbobj

    while 1:
        dbobj = cxidb.dbconnect(params.db.host, params.db.name, params.db.user,
                                params.db.password)
        cursor = dbobj.cursor()

        results = {}
        print "Looking for data..."

        for tag in params.run_tags.split(','):
            for isoform in isoforms:
                M = PM.get_HKL(cursor, isoform=isoform, run_tags=tag)
                cell = isoforms[isoform]['cell']
                miller_set = mset(
                    anomalous_flag=False,
                    crystal_symmetry=symmetry(
                        unit_cell=cell,
                        space_group_symbol=isoforms[isoform]['lookup_symbol']),
                    indices=M)
                miller_set.show_comprehensive_summary()

                miller_set.setup_binner(d_min=params.resolution,
                                        n_bins=params.n_bins)
                given = miller_set.binner().counts_given()
                ccomplete = miller_set.binner().counts_complete()
                for i_bin in miller_set.binner().range_used():
                    sel = miller_set.binner().selection(i_bin)
                    self_sel = miller_set.select(sel)
                    d_max, d_min = self_sel.d_max_min()
                    compl = self_sel.completeness(d_max=d_max)

                    n_ref = sel.count(True)
                    if ccomplete[i_bin] == 0.:
                        multiplicity = 0.
                    else:
                        res_highest = d_min
                        multiplicity = given[i_bin] / ccomplete[i_bin]
                    d_range = miller_set.binner().bin_legend(
                        i_bin=i_bin, show_bin_number=False, show_counts=True)
                    fmt = "%3d: %-24s %4.2f %6d mult=%4.2f"
                    print fmt % (i_bin, d_range, compl, n_ref, multiplicity)
                print
                if len(tag) > 0:
                    key = "%s %s" % (tag, isoform)
                else:
                    key = isoform
                given_used = flex.int(given).select(
                    flex.size_t(miller_set.binner().range_used()))
                ccomplete_used = flex.int(ccomplete).select(
                    flex.size_t(miller_set.binner().range_used()))
                results[key] = dict(multiplicity=flex.sum(given_used) /
                                    flex.sum(ccomplete_used),
                                    completeness=miller_set.completeness(),
                                    multiplicity_highest=multiplicity,
                                    completeness_highest=compl,
                                    resolution_highest=res_highest)
        del dbobj
        if not loop:
            return results
        time.sleep(10)
Exemple #3
0
def run_job():
    from cctbx.crystal import symmetry
    from cctbx.uctbx import unit_cell
    from cctbx.sgtbx import space_group
    sym = symmetry(unit_cell=unit_cell((78.68, 78.68, 265.33, 90, 90, 120)),
                   space_group="P6522")
    millers = flex.miller_index()
    for ref, exp in from_files():
        idx = ref["miller_index"]
        millers.extend(idx)
    from cctbx.miller import set as mset, array
    MM = mset(crystal_symmetry=sym, anomalous_flag=True,
              indices=millers)  # make miller set from all obs
    MA = MM.map_to_asu()  # map to asu
    #dval = MA.unit_cell().d(MA.indices())
    #order = flex.sort_permutation(dval, reverse=True)
    #MAsort = MA.select(order)
    #for item in MAsort.indices(): print(item)
    #print (MAsort.indices().size(), len(set(MAsort.indices())))
    #ZZ = MAsort.array(data=flex.double(MAsort.size(),1.))
    MAobs = MA.array(data=flex.double(MA.size(), 1.))
    ME = MAobs.merge_equivalents()
    new_red = ME.redundancies(
    )  # all observations with multiplicity of measurement
    z = new_red.complete_array(
        d_max=100000., new_data_value=0)  # fill in missing observations
    dval = z.unit_cell().d(z.indices())
    order = flex.sort_permutation(dval, reverse=True)
    MAsort = z.select(order)
    print("d_min is %.3f" % (flex.min(MA.d_spacings().data())))
    print("there are altogether %d measurements" % MA.indices().size())
    print("this is uniqueness : %d measurements" % new_red.indices().size())
    print("total in asymmetric unit %d" % MAsort.indices().size())
    print("maximum multiplicity is %d" % (flex.max(MAsort.data())))
    print("the mean multiplicity is %.2f" %
          (flex.mean(MAsort.data().as_double())))
    zeroes = (MAsort.data() == 0).count(True)
    print("unmeasured %d or %.2f%% of total" %
          (zeroes, 100. * zeroes / MAsort.indices().size()))

    MAd = MA.select(MA.d_spacings().data() > 1.63)
    new_redd = new_red.select(new_red.d_spacings().data() > 1.63)
    MAsortd = MAsort.select(MAsort.d_spacings().data() > 1.63)
    print("Cut, there are altogether %d measurements" % MAd.indices().size())
    print("Cut, this is uniqueness : %d measurements" %
          new_redd.indices().size())
    print("Cut, total in asymmetric unit %d" % MAsortd.indices().size())
    print("Cut, maximum multiplicity is %d" % (flex.max(MAsortd.data())))
    print("Cut, the mean multiplicity is %.2f" %
          (flex.mean(MAsortd.data().as_double())))
    zeroes = (MAsortd.data() == 0).count(True)
    print("Cut, unmeasured %d or %.2f%% of total" %
          (zeroes, 100. * zeroes / MAsortd.indices().size()))

    if True:
        from matplotlib import pyplot as plt
        plt.plot(range(MAsort.indices().size()), MAsort.data(), "r.")
        plt.plot(range(MAsortd.indices().size()),
                 MAsortd.data().as_double() - 0.1, "b.")
        plt.title("Redundant measurement vs. Bragg spot position")
        plt.xlabel("Spots ordered by increasing Bragg angle →")
        plt.ylabel("Multiplicity of strong spot obs (Group A)")
        plt.show()
def application(params, loop = True):
  from cxi_xdr_xes.cftbx.cspad_ana import db as cxidb
  dbobj = cxidb.dbconnect(params.db.host, params.db.name, params.db.user, params.db.password)
  cursor = dbobj.cursor()
  PM = progress_manager(params, cursor)
  PM.setup_isoforms(cursor)
  PM.setup_runtags(cursor)
  isoforms = PM.isoforms
  del dbobj

  while 1:
    dbobj = cxidb.dbconnect(params.db.host, params.db.name, params.db.user, params.db.password)
    cursor = dbobj.cursor()

    results = {}
    print "Looking for data..."

    for tag in params.run_tags.split(','):
      for isoform in isoforms:
        M = PM.get_HKL(cursor,isoform=isoform,run_tags=tag)
        cell = isoforms[isoform]['cell']
        miller_set = mset(anomalous_flag = False, crystal_symmetry=symmetry(unit_cell=cell, space_group_symbol=isoforms[isoform]['lookup_symbol']), indices=M)
        miller_set.show_comprehensive_summary()

        miller_set.setup_binner(d_min=params.resolution, n_bins=params.n_bins)
        given = miller_set.binner().counts_given()
        ccomplete = miller_set.binner().counts_complete()
        for i_bin in miller_set.binner().range_used():
            sel         = miller_set.binner().selection(i_bin)
            self_sel    = miller_set.select(sel)
            d_max,d_min = self_sel.d_max_min()
            compl       = self_sel.completeness(d_max = d_max)

            n_ref       = sel.count(True)
            if ccomplete[i_bin] == 0.:
              multiplicity = 0.
            else:
              res_highest   = d_min
              multiplicity  = given[i_bin]/ccomplete[i_bin]
            d_range     = miller_set.binner().bin_legend(
                   i_bin = i_bin, show_bin_number = False, show_counts = True)
            fmt = "%3d: %-24s %4.2f %6d mult=%4.2f"
            print fmt % (i_bin,d_range,compl,n_ref,
                          multiplicity)
        print
        if len(tag) > 0:
          key = "%s %s"%(tag, isoform)
        else:
          key = isoform
        given_used = flex.int(given).select(flex.size_t(miller_set.binner().range_used()))
        ccomplete_used = flex.int(ccomplete).select(flex.size_t(miller_set.binner().range_used()))
        results[key] = dict(
          multiplicity = flex.sum(given_used)/flex.sum(ccomplete_used),
          completeness = miller_set.completeness(),
          multiplicity_highest = multiplicity,
          completeness_highest = compl,
          resolution_highest = res_highest
        )
    del dbobj
    if not loop:
      return results
    time.sleep(10)