Exemple #1
0
                    type=str,
                    help="output filename prefix")
args = parser.parse_args()

if __name__ == "__main__":

    if args.output is None:
        basename, ext = os.path.splitext(args.file)
        output = basename + "_aligned2xyz"
    else:
        output = args.output

    logging.basicConfig(filename=output + '.log',
                        level=logging.INFO,
                        filemode='w',
                        format='%(asctime)s %(message)s',
                        datefmt='%Y-%m-%d %I:%M:%S %p')
    logging.info('BEGIN')
    logging.info('Script name: %s', sys.argv[0])
    logging.info('DENSS Version: %s', __version__)
    logging.info('Map filename(s): %s', args.file)

    rho, side = saxs.read_mrc(args.file)

    aligned = saxs.align2xyz(rho)

    saxs.write_mrc(aligned, side, output + '.mrc')
    print "%s.mrc written. " % (output, )

    logging.info('END')
Exemple #2
0
            logging.info('PDB reference map resolution: %.2f', args.resolution)
            refbasename, refext = os.path.splitext(args.ref)
            refoutput = refbasename + "_centered.pdb"
            refside = side
            voxel = (refside / movrho.shape)[0]
            halfside = refside / 2
            n = int(refside / voxel)
            dx = refside / n
            x_ = np.linspace(-halfside, halfside, n)
            x, y, z = np.meshgrid(x_, x_, x_, indexing='ij')
            xyz = np.column_stack((x.ravel(), y.ravel(), z.ravel()))
            pdb = saxs.PDB(args.ref)
            if args.center:
                pdb.coords -= pdb.coords.mean(axis=0)
                pdb.write(filename=refoutput)
            refrho = saxs.pdb2map_gauss(pdb, xyz=xyz, sigma=args.resolution)
            refrho = refrho * np.sum(movrho) / np.sum(refrho)
            saxs.write_mrc(refrho, side, filename=refbasename + '_pdb.mrc')
        if args.ref.endswith('.mrc'):
            refrho, refside = saxs.read_mrc(args.ref)
        if (not args.ref.endswith('.mrc')) and (not args.ref.endswith('.pdb')):
            print "Invalid reference filename given. .mrc or .pdb file required"
            sys.exit(1)

    aligned = saxs.principal_axis_alignment(refrho, rho)

    saxs.write_mrc(aligned, side, output + '.mrc')
    print "%s.mrc written. " % (output, )

    logging.info('END')
Exemple #3
0
    if superargs.enan:
        print()
        print(" Selecting best enantiomers...")
        try:
            allrhos, scores = saxs.select_best_enantiomers(
                allrhos, cores=superargs.cores)
        except KeyboardInterrupt:
            sys.exit(1)

    if superargs.ref is None:
        print()
        print(" Generating reference...")
        try:
            refrho = saxs.binary_average(allrhos, superargs.cores)
            saxs.write_mrc(refrho, sides[0], output + "_reference.mrc")
        except KeyboardInterrupt:
            sys.exit(1)

    print()
    print(" Aligning all maps to reference...")
    try:
        aligned, scores = saxs.align_multiple(refrho, allrhos, superargs.cores)
    except KeyboardInterrupt:
        sys.exit(1)

    #filter rhos with scores below the mean - 2*standard deviation.
    mean = np.mean(scores)
    std = np.std(scores)
    threshold = mean - 2 * std
    filtered = np.empty(len(scores), dtype=str)
Exemple #4
0
 nmaps = len(args.files)
 rhos = []
 for file in args.files:
     sys.stdout.write("\r% 5i / % 5i" % (n, nmaps))
     sys.stdout.flush()
     n += 1
     rho, side = saxs.read_mrc(file)
     rhos.append(rho)
     if rhosum is None:
         rhosum = rho
     else:
         rhosum += rho
 print()
 rhos = np.array(rhos)
 average_rho = rhosum / nmaps
 saxs.write_mrc(average_rho, side, output + "_avg.mrc")
 print("%s_avg.mrc written." % output)
 """
 #split maps into 2 halves--> enan, align, average independently with same refrho
 avg_rho1 = np.mean(aligned[::2],axis=0)
 avg_rho2 = np.mean(aligned[1::2],axis=0)
 fsc = saxs.calc_fsc(avg_rho1,avg_rho2,sides[0])
 np.savetxt(args.output+'_fsc.dat',fsc,delimiter=" ",fmt="%.5e",header="qbins, FSC")
 """
 #rather than compare two halves, average all fsc's to the reference
 fscs = []
 for map in range(nmaps):
     fscs.append(saxs.calc_fsc(rhos[map], average_rho, side))
 fscs = np.array(fscs)
 fsc = np.mean(fscs, axis=0)
 np.savetxt(args.output + '_fsc.dat',
Exemple #5
0
    else:
        n = max((int(newside / vx), int(newside / vy), int(newside / vz)))
        if n % 2 == 1: n += 1

    newshape = (n, n, n)

    rho = saxs.pad_rho(rho, newshape)
    a, b, c = vx * newshape[0], vy * newshape[1], vz * newshape[2]
    print "postpad"
    print "Shape:  ", rho.shape
    print "Sides:  ", a, b, c
    print "Voxels: ", vx, vy, vz

    #rescale map after interpolation
    if args.ne is not None:
        ne = args.ne
    rho *= ne / np.sum(rho)

    #convert to density in e-/A^3 for thresholding
    rho /= vx * vy * vz

    if args.threshold is not None:
        rho[rho < args.threshold] = 0

    rho *= ne / np.sum(rho)  #rescale to the total number of electrons
    rho /= vx * vy * vz  #now divide by total volume to convert to electron density

    print rho.sum() * vx * vy * vz

    saxs.write_mrc(rho, (a, b, c), filename=output + '.mrc')
    rho, side = saxs.read_mrc(args.file)

    if args.ref is not None:
        #allow input of reference for enantiomer selection
        if args.ref.endswith('.mrc'):
            refrho, refside = saxs.read_mrc(args.ref)
        else:
            print("Invalid reference filename given. .mrc file required")
            sys.exit(1)

        rho_nsamples = rho.shape[0]
        rho_voxel = side / rho_nsamples
        ref_nsamples = refrho.shape[0]
        ref_voxel = refside / ref_nsamples

        if (not np.isclose(side, refside)
                or not np.isclose(rho_voxel, ref_voxel)
                or not np.isclose(rho_nsamples, ref_nsamples)):
            print("reference density dimensions do not match given options.")
            sys.exit()
    else:
        print("reference file required")
        sys.exit(1)

    print(" Selecting best enantiomer...")
    try:
        best_enan, score = saxs.select_best_enantiomer(refrho=refrho, rho=rho)
        saxs.write_mrc(best_enan, side, output + '.mrc')
    except KeyboardInterrupt:
        sys.exit(1)
Exemple #7
0
        F = np.fft.fftn(rho)
        I3D = np.abs(F)**2
        Imean = ndimage.mean(I3D,
                             labels=qbin_labels,
                             index=np.arange(0,
                                             qbin_labels.max() + 1))

    qmax_to_use = np.max(qx_)
    print("qmax to use: %f" % qmax_to_use)
    qbinsc_to_use = qbinsc[qbinsc < qmax_to_use]
    Imean_to_use = Imean[qbinsc < qmax_to_use]

    qbinsc = np.copy(qbinsc_to_use)
    Imean = np.copy(Imean_to_use)

    Iq = np.vstack((qbinsc, Imean, Imean * .03)).T

    np.savetxt(output + '.dat', Iq, delimiter=' ', fmt='% .16e')

    if args.save_mrc:
        saxs.write_mrc(rho, side, output + '_mod.mrc')

    if args.plot:
        print('Actual dq = %.4f' % (2 * np.pi / side))
        plt.plot(qbinsc_to_use,
                 Imean_to_use,
                 label='Actual dq = %.4f' % (2 * np.pi / side))
        plt.semilogy()
        plt.legend()
        plt.show()
Exemple #8
0
        sides.append(side)
    allrhos = np.array(allrhos)
    sides = np.array(sides)

    if args.ref is not None:
        #allow input of reference for enantiomer selection
        if args.ref.endswith('.mrc'):
            refrho, refside = saxs.read_mrc(args.ref)
        if (not args.ref.endswith('.mrc')):
            print("Invalid reference filename given. .mrc file required")
            sys.exit(1)

    print(" Selecting best enantiomers...")
    try:
        if args.ref:
            allrhos, scores = saxs.select_best_enantiomers(allrhos,
                                                           refrho=refrho,
                                                           cores=args.cores)
        else:
            allrhos, scores = saxs.select_best_enantiomers(allrhos,
                                                           refrho=allrhos[0],
                                                           cores=args.cores)
    except KeyboardInterrupt:
        sys.exit(1)

    #save each selected enantiomer
    for i in range(nmaps):
        basename, ext = os.path.splitext(args.files[i])
        ioutput = basename + "_enan"
        saxs.write_mrc(allrhos[i], sides[0], ioutput + '.mrc')
Exemple #9
0
            voxel = (refside/allrhos[0].shape)[0]
            halfside = refside/2
            n = int(refside/voxel)
            dx = refside/n
            x_ = np.linspace(-halfside,halfside,n)
            x,y,z = np.meshgrid(x_,x_,x_,indexing='ij')
            xyz = np.column_stack((x.ravel(),y.ravel(),z.ravel()))
            pdb = saxs.PDB(args.ref)
            if args.center:
                pdb.coords -= pdb.coords.mean(axis=0)
                pdb.write(filename=refoutput)
            #use the new fastgauss function
            #refrho = saxs.pdb2map_gauss(pdb,xyz=xyz,sigma=args.resolution)
            refrho = saxs.pdb2map_fastgauss(pdb,x=x,y=y,z=z,sigma=args.resolution,r=args.resolution*2)
            refrho = refrho*np.sum(allrhos[0])/np.sum(refrho)
            saxs.write_mrc(refrho,sides[0],filename=refbasename+'_pdb.mrc')
        if args.ref.endswith('.mrc'):
            refrho, refside = saxs.read_mrc(args.ref)
        if (not args.ref.endswith('.mrc')) and (not args.ref.endswith('.pdb')):
            print("Invalid reference filename given. .mrc or .pdb file required")
            sys.exit(1)

    if args.enan:
        print(" Selecting best enantiomers...")
        try:
            if args.ref:
                allrhos, scores = saxs.select_best_enantiomers(allrhos, refrho=refrho, cores=args.cores)
            else:
                allrhos, scores = saxs.select_best_enantiomers(allrhos, refrho=allrhos[0], cores=args.cores)
        except KeyboardInterrupt:
            sys.exit(1)
Exemple #10
0
        basename, ext = os.path.splitext(args.files[0])
        output = basename
    else:
        output = args.output

    nmaps = len(args.files)

    allrhos = []
    sides = []
    for file in args.files:
        rho, side = saxs.read_mrc(file)
        allrhos.append(rho)
        sides.append(side)
    allrhos = np.array(allrhos)
    sides = np.array(sides)

    if nmaps<2:
        print("Not enough maps to generate reference. Please input more maps again...")
        sys.exit(1)

    print(" Generating reference...")
    try:
        refrho = saxs.binary_average(allrhos, args.cores)
        saxs.write_mrc(refrho, sides[0], output+"_reference.mrc")
    except KeyboardInterrupt:
        sys.exit(1)




Exemple #11
0
    if args.mode == "fast":
        #rho = saxs.pdb2map_gauss(pdb,xyz=xyz,sigma=args.resolution,mode="fast",eps=1e-6)
        rho = saxs.pdb2map_fastgauss(pdb,
                                     x=x,
                                     y=y,
                                     z=z,
                                     sigma=args.resolution,
                                     r=args.resolution * 2)
    elif args.mode == "slow":
        print("slow mode doesn't exist anymore. Use fast mode.")
        #not even going to bother with this version anymore. fastgauss is the
        #same function as slow, so just as accurate, but it way, way faster
        #rho = saxs.pdb2map_gauss(pdb,xyz=xyz,sigma=args.resolution,mode="slow")
    else:
        print(
            "Note: Using FFT method results in severe truncation ripples in map."
        )
        print(
            "This will also run a quick refinement of phases to attempt to clean this up."
        )
        rho, pdbidx = saxs.pdb2map_FFT(pdb, x=x, y=y, z=z, radii=None)
        rho = saxs.denss_3DFs(rho_start=rho,
                              dmax=side,
                              voxel=dx,
                              oversampling=1.,
                              shrinkwrap=False,
                              support=pdbidx)
    print()
    saxs.write_mrc(rho, side, output + ".mrc")