Ejemplo n.º 1
0
def computeCc(process_n, perSizeLeft, perSizeRight, perSize, listlength, filelist, nmax, rmax):
#compute nlm_cc
  ccArr = []
  start_line_left = process_n*perSizeLeft
  end_line_left = (process_n + 1)*perSizeLeft
  start_line_right = listlength - (process_n+1)*perSizeRight
  end_line_right = listlength - process_n*perSizeRight

  if start_line_right - end_line_left < 0:
    #arrive the stop point, the interval is the last difference of start_line_right and end_line_left
    middle = start_line_right - end_line_left + perSize
    end_line_left = end_line_left - perSizeLeft + int(xmath.ceil(middle / 2))
    start_line_right = end_line_left 

  print "process_n, start_left, end_left, start_right, end_right:",process_n, start_line_left, end_line_left, start_line_right, end_line_right
  for i in (range(start_line_left,end_line_left) + range(start_line_right,end_line_right)):
    for j in range(i+1,listlength):      
      fix_model = model_interface.build_model( filelist[i], "pdb", nmax, rmax )
      mov_model = model_interface.build_model( filelist[j], "pdb", nmax, rmax )
      fix_nlm_array = fix_model.nlm_array
      mov_nlm_array = mov_model.nlm_array
      align_obj = fft_align.align( fix_nlm_array, mov_nlm_array, nmax=nmax,refine=True)
      cc = align_obj.get_cc()
      ccArr.append((i, j, cc))
  return ccArr
Ejemplo n.º 2
0
def computeCc(filelist, nmax, rmax):
    #compute nlm_cc
    fix_model = model_interface.build_model(filelist[0], "pdb", nmax, rmax)
    mov_model = model_interface.build_model(filelist[1], "pdb", nmax, rmax)
    fix_nlm_array = fix_model.nlm_array
    mov_nlm_array = mov_model.nlm_array
    align_obj = fft_align.align(fix_nlm_array,
                                mov_nlm_array,
                                nmax=nmax,
                                refine=True)
    cc = align_obj.get_cc()
    print("when nmax:" + str(nmax) + "----------- cc:" + str(cc))
    return cc
Ejemplo n.º 3
0
def run(args):
    t1 = time.time()
    parser = argparse.ArgumentParser()
    parser.add_argument("-output", help="chi result path", type=str)
    parser.add_argument("-dbpath", help="db path", type=str)
    parser.add_argument("-processnum", help="processnum number", type=int)
    parser.add_argument("-cavitypath", help="cavity path", type=str)
    parser.add_argument("-cavitytype", help="cavity type", type=str)
    parser.add_argument("--nmax", help="nmax", default=20, type=int)
    parser.add_argument("--rmax", help="rmax", type=float)
    args = parser.parse_args()

    # prefix="/home/dongxq/zalign/build/myDB"
    # prefix="/home/dongxq/align_code/myDB/dude2-db"
    targetfile = args.output
    prefix = args.dbpath
    codes = easy_pickle.load(prefix + ".codes")
    nlm_coefs = easy_pickle.load(prefix + ".nlm")
    nl_coefs = easy_pickle.load(prefix + ".nl")
    rmaxs = easy_pickle.load(prefix + ".rmax")

    cavity = args.cavitypath
    cavitytype = args.cavitytype
    nmax = args.nmax
    rmax = args.rmax
    processnum = args.processnum
    cavity_model = model_interface.build_model(cavity, cavitytype, nmax, rmax)
    totalSize = len(nl_coefs)
    perSizeChi = int(xmath.ceil(totalSize / processnum))
    NlRes = []

    #chi process pool
    tnl1 = time.time()
    pool_chi = multiprocessing.Pool(processes=processnum)
    chi_result = pool_chi.map(computeChi, range(processnum))
    for n in range(0, len(chi_result)):
        NlRes += chi_result[n]
    tnl2 = time.time()

    #output
    with open(targetfile, "w") as f:
        for arr in NlRes:
            f.write(str(arr) + "\n")
        t2 = time.time()
Ejemplo n.º 4
0
  with open(targetfile,"w") as f:
    f.truncate()
  tempf = open(targetfile,'w')
  params = get_input(args, master_params, "aligndb", banner, help,tempf)
  tempf.close()

  mov = params.align.mov
  typem = params.align.typem
  nmax = params.align.nmax
  rmax = params.align.rmax
  topn = params.align.topn
  write_map = params.align.write_map
  nlNum = params.align.nlnum
  nlmNum = params.align.nlmnum
  threadNum = params.align.threadnum
  mov_model=model_interface.build_model( mov, typem, nmax, rmax )
  totalSize = len(nl_coefs)
  perSizeChi = int(xmath.ceil( totalSize / threadNum))
  perSizeCc = int(xmath.ceil(nlNum / threadNum))
  chi_arr = []
  cc_arr = []
  threads_chi = []
  threads_cc = []

#chi threads
  tnl1 = time.time()
  for i in range(int(threadNum)):
      threads_chi.append(threading.Thread(target=computeChi, args=(i, chi_arr,)))
  for t in threads_chi:
      t.setDaemon(True)
      t.start()
Ejemplo n.º 5
0
def run(args):
  #targetfile = $SASTBXPATH/modules/cctbx_project/sastbx
  targetfile = os.path.join(os.path.split(sys.path[0])[0],"superpose.txt")
  with open(targetfile,"w") as f:
    f.truncate()
  
  tempf = open(targetfile,'w')
  params = get_input(args, master_params, "align", banner, help,tempf)
  tempf.close()
  if params is None:

    return
  fix = params.align.fix
  typef = params.align.typef
  mov = params.align.mov
  typem = params.align.typem


  num_grid = params.align.num_grid
  nmax = params.align.nmax
  rmax = params.align.rmax
  topn = params.align.topn
  write_map = params.align.write_map

  fix_model=model_interface.build_model( fix, typef, nmax, rmax )
  mov_model=model_interface.build_model( mov, typem, nmax, rmax )


  fix_nlm_array = fix_model.nlm_array
  mov_nlm_array = mov_model.nlm_array
  with open(targetfile,"a") as f:
    f.write("doing alignment\n")
  print "doing alignment"
  align_obj = fft_align.align( fix_nlm_array, mov_nlm_array, nmax=nmax, topn=topn ,refine=True)

  cc = align_obj.get_cc()
  print cc

  mov_model.nlm_array = align_obj.moving_nlm

  rmax = update_rmax( rmax, fix_model, mov_model)
  fix_model.rmax = rmax
  mov_model.rmax = rmax

  shift=(rmax, rmax, rmax)

  with open(targetfile,"a") as f:
    f.write( "#############  SUMMARY of ALIGNMENT  #############\n")
    f.write( "Correlation Coefficient Between two models is: "+str(cc)+"\n")
    f.write("Rmax is                                      : "+str(rmax)+"\n")
   
    f.write("Center of Mass is shifted to                 : "+str(list(shift))+"\n")   
    f.write("OUTPUT files are : "+"\n")
    

  
  print "#############  SUMMARY of ALIGNMENT  #############"
  print "Correlation Coefficient Between two models is: ", cc
  print "Rmax is                                      : ", rmax
  print "Center of Mass is shifted to                 : ", list(shift)
  print "OUTPUT files are : "



  current_is_mov = False

  pdblist = []
  xplorlist = []

  targetpath_fromGUI = ''
  targetpath_fromGUI_file =  os.path.join(base_path,"targetpath_GUI.txt")
  if os.path.isfile(targetpath_fromGUI_file) and (os.stat(targetpath_fromGUI_file).st_size>0):
    with open(targetpath_fromGUI_file,"r") as f:
      targetpath_fromGUI = f.read().strip()

  for model in (fix_model, mov_model):
    if targetpath_fromGUI == '':
      base=model.id
    else:
      
      base = str(model.id.split("/")[-1])
      print "base:   ",base
      targetdir = os.path.join(targetpath_fromGUI,"Model_Superposition")
      base = os.path.join(targetdir,base)


    ##################20170520###########################
    #################change the output dir ###################
    # base = str(model.id.split("/")[-1])
    # dirlist = sys.argv[0].split("sastbx")
    # tmpdir = str(dirlist[0])+"sastbx/gui/sasqt/tmp.txt"
    # with open(tmpdir,"r") as f:
    #   targetdir = str(f.read().strip())
    # base = os.path.join(targetdir,"superpose",base)
    ###############################################################



    # easy_pickle.dump(base+"_za.nlm", model.nlm_array.coefs() )
    # with open(targetfile,"a") as f:
    #   f.write("  "+base+"_za.nlm\n")
    
    # if(write_map):
    #   model.write_map(filename=base+"_za.xplor")
    #   xplorlist.append(base+"_za.xplor")

    #   with open(targetfile,"a") as f:
    #     f.write("   "+base+"_za.xplor\n")
      

    # if( model.vox_obj is not None):  ### Write aligned PDB file ####
    #   out_pdb_name=base+"_za.pdb"
    #   pdblist.append(out_pdb_name)


    #   if(current_is_mov):
    #     ea = align_obj.best_ea
    #     aligned_xyz = model.vox_obj.rotate((-ea[0],ea[1],-ea[2]), False)
    #   else:
    #     aligned_xyz = model.vox_obj.xyz()

    #   aligned_xyz = aligned_xyz + shift  


    
      ### Add the shift, such that the EDM center is the same as PDB
      ###################20170511#####################################
      ################debug for size error############################
      #model.pdb_inp.hierarchy.atoms().set_xyz(aligned_xyz)




    #   sel_cache = model.pdb_inp.hierarchy.atom_selection_cache()
    #   hetero = model.pdb_inp.hierarchy.atoms().extract_hetero()
    #   position = list(hetero)
    #   no_hetero = sel_cache.selection("all")
    #   for i in position:
    #       no_hetero[i]=False
    #   no_hetero_atoms = model.pdb_inp.hierarchy.atoms().select(no_hetero)
    #   no_hetero_atoms.set_xyz(aligned_xyz)
      
    #   model.pdb_inp.hierarchy.write_pdb_file( file_name=out_pdb_name, open_append=False)
    #   with open(targetfile,"a") as f:
    #     f.write("  "+out_pdb_name+'\n')

    #   print out_pdb_name
    
    # current_is_mov = True






  # print "pdblist: ",pdblist
  # print "xplorlist: ", xplorlist

  ############targetpath_fromGUI=='' for commmand line 
  ############else for GUI

  if targetpath_fromGUI != '':
    targetdir = os.path.join(targetpath_fromGUI,"Model_Superposition")
    build_pymol_script.write_pymol_superpose(pdblist,targetdir)
    
  with open(targetfile,"a") as f:
    f.write("#############     END of SUMMARY     #############\n")

  with open(targetfile,"a") as f:
    f.write("__END__")

  print "#############     END of SUMMARY     #############\n"
  print "__END__"
Ejemplo n.º 6
0
def run(args):
  t1 = time.time()
  # parser = argparse.ArgumentParser()
  # parser.add_argument("-output", help="cc result path", type=str)
  # parser.add_argument("-chipath", help="sorted chi path", type=str)
  # parser.add_argument("-node", help="node number", type=int)
  # parser.add_argument("-processnum", help="processnum number", type=int)
  # parser.add_argument("-dbpath", help="db path", type=str)
  # parser.add_argument("-cavitypath", help="cavity path", type=str)
  # parser.add_argument("-cavitytype", help="cavity type", type=str)
  # parser.add_argument("--nmax", help="nmax", default=20, type=int)
  # parser.add_argument("--rmax", help="rmax", type=float)
  # args = parser.parse_args()

  # prefix="/home/dongxq/align_code/myDB/dude1-db"
  prefix=args.dbpath
  db_name = os.path.basename(prefix)

  codes=easy_pickle.load(prefix+".codes")
  nlm_coefs=easy_pickle.load(prefix+".nlm")
  nl_coefs=easy_pickle.load(prefix+".nl")
  rmaxs=easy_pickle.load(prefix+".rmax")

  cavity = args.cavitypath
  cavitytype = args.cavitytype
  chipath = args.chipath
  nmax = args.nmax
  rmax = args.rmax
  processnum = args.processnum
  

  sortedNlRes = []
  countline = 0
  for line in open(chipath, 'r').readlines():
    line = line.strip('\n')
    line_tuple = eval(line)
    if line_tuple[-1] == db_name:
      countline += 1
      #can't del value in the tuple,so new one
      new_line = (countline,) + line_tuple[1:]
      sortedNlRes.append(new_line)       
  nlNum = len(sortedNlRes)
  print "------------",nlNum
  cavity_model=model_interface.build_model( cavity, cavitytype, nmax, rmax )
  sortedNlmRes = []

#cc process pool
  tnlm1 = time.time()
  pool_cc = multiprocessing.Pool(processes=processnum)
  cc_result = pool_cc.map(computeCc, range(processnum))

  for n in range(0,len(cc_result)):
    sortedNlmRes += cc_result[n]
  tnlm2 = time.time()

#merge chi to cc arr
  tmerge1 = time.time()
  for i in range(nlNum):
    indx = sortedNlmRes[i][0]
    chi = list(filter(lambda j: j[1] == indx, sortedNlRes[0:]))[0][2]
    sortedNlmRes[i] += (chi,)
  tmerge2 = time.time()

#output
  targetfile = args.output
  with open(targetfile,"w") as f:
    for arr in sortedNlmRes:
      f.write(str(arr) + "\n")
    t2 = time.time()
Ejemplo n.º 7
0
def run(args):
    # filename = "res" + str(filenum) + ".txt"
    targetfile = os.path.join(os.path.split(sys.path[0])[0], "c5")
    with open(targetfile, "w") as f:
        f.truncate()

    tempf = open(targetfile, 'w')
    print args
    params = get_input(args, master_params, "aligndb", banner, help, tempf)
    tempf.close()
    if params is None:

        return
    fix = params.align.fix
    typef = params.align.typef
    mov = params.align.mov
    typem = params.align.typem

    num_grid = params.align.num_grid
    nmax = params.align.nmax
    rmax = params.align.rmax
    topn = params.align.topn
    write_map = params.align.write_map

    nlNum = params.align.nlnum
    nlmNum = params.align.nlmnum

    #fix_model=model_interface.build_model( fix, typef, nmax, rmax )
    mov_model = model_interface.build_model(mov, typem, nmax, rmax)

    # prefix="/home/dongxq/align_code/dude-actives"
    prefix = "/home/dongxq/zalign/build/myDB"
    codes = easy_pickle.load(prefix + ".codes")
    nlm_coefs = easy_pickle.load(prefix + ".nlm")
    nl_coefs = easy_pickle.load(prefix + ".nl")
    rmaxs = easy_pickle.load(prefix + ".rmax")

    #compute distance
    nlRes = []
    mov_nl_array = mov_model.nl_array
    mov_nl_coefs = mov_model.nl_array.coefs()
    tnl1 = time.time()
    for indx in range(len(nl_coefs)):
        #compute Chi-sequare distance
        mf_coef = numpy.true_divide(nl_coefs[indx], mov_nl_coefs)
        dist = numpy.sum(numpy.square(mov_nl_coefs - mf_coef * nl_coefs[indx]))
        #compute Mahalanobis distance
        # dist = mol2.Mahalanobis(mov_nl_coefs,nl_coefs[indx])
        nlRes.append((indx, dist, codes[indx]))
    sortedNlRes = sorted(nlRes, key=operator.itemgetter(1), reverse=False)
    tnl2 = time.time()

    # compute nl_cc
    #  nl_cc_res = []
    #  mov_nl_array = mov_model.nl_array
    #  mov_nl_coefs = mov_model.nl_array.coefs()
    #  tnl1 = time.time()
    #  for indx in range(len(nl_coefs)):
    #  	nl_cc = pearson.pearson_cc(mov_nl_coefs, nl_coefs[indx])
    # print nl_cc
    # nl_cc_res.append((indx, nl_cc, codes[indx]))
    #  sortedNlRes = sorted(nl_cc_res, key=operator.itemgetter(1), reverse=True)
    #  tnl2 = time.time()

    #compute nlm_cc
    mov_nlm_array = mov_model.nlm_array
    fix_nlm_array = math.nlm_array(nmax)
    nlm = fix_nlm_array.nlm()
    nlm_total = fix_nlm_array.nlm().size()
    nlmRes = []

    tnlm1 = time.time()
    for i in range(nlNum):
        indx = sortedNlRes[i][0]
        fix = nlm_coefs[indx][0:nlm_total]
        fix_nlm_array.load_coefs(nlm, fix)
        align_obj = fft_align.align(fix_nlm_array,
                                    mov_nlm_array,
                                    nmax=nmax,
                                    refine=True)
        cc = align_obj.get_cc()
        nlmRes.append((indx, codes[indx], cc))
    sortedNlmRes = sorted(nlmRes, key=operator.itemgetter(2), reverse=True)
    sortedNlmRes = sortedNlmRes[:nlmNum]
    tnlm2 = time.time()

    #merge chi to cc arr
    tmerge1 = time.time()
    for i in range(nlmNum):
        indx = sortedNlmRes[i][0]
        chi = list(filter(lambda j: j[0] == indx, sortedNlRes[0:]))[0][1]
        sortedNlmRes[i] += (chi, )
    tmerge2 = time.time()
    print "merge time used: ", tmerge2 - tmerge1

    #output
    with open(targetfile, "w") as f:
        f.write("#############  SUMMARY of ALIGNMENT  #############\n")
        f.write(
            "rank indx     name               cc                 chi-square\n")
        rank = 0
        for arr in sortedNlmRes:
            rank += 1
            arr = (rank, ) + arr
            f.write(str(arr) + "\n")
        t3 = time.time()
        f.write("rotation invariant computing time used: " + str(tnl2 - tnl1) +
                "\n")
        f.write("alignment computing time used: " + str(tnlm2 - tnlm1) + "\n")
        f.write("total time used: : " + str(t3 - t1))
Ejemplo n.º 8
0
    # prefix="/home/dongxq/zalign/build/myDB"
    # prefix="/home/wyf/project/align_code/myDB/dude-actives"
    prefix = args.dbpath
    db_name = os.path.basename(prefix)
    codes = easy_pickle.load(prefix + ".codes")
    nlm_coefs = easy_pickle.load(prefix + ".nlm")
    nl_coefs = easy_pickle.load(prefix + ".nn")
    rmaxs = easy_pickle.load(prefix + ".rmax")
    totalSize = len(nl_coefs)
    nmax = args.nmax
    rmax = args.rmax
    processnum = args.processnum
    perSizeChi = int(xmath.ceil(totalSize / processnum))
    perSizeCc = int(xmath.ceil(totalSize / processnum))
    mov_model = model_interface.build_model(args.target_shape,
                                            args.target_type, nmax, rmax)
    sortedNlRes = []
    sortedNnRes = []

    #chi process pool
    tnl1 = time.time()
    pool_chi = multiprocessing.Pool(processes=processnum)
    chi_result = pool_chi.map(computeChi, range(processnum))
    for n in range(0, len(chi_result)):
        sortedNlRes += chi_result[n]
    # sortedNlRes=sorted(sortedNlRes, key=operator.itemgetter(1), reverse=False)[:args.num_fnl_round]
    tnl2 = time.time()

    #cc process pool
    tnlm1 = time.time()
    pool_cc = multiprocessing.Pool(processes=processnum)