Esempio n. 1
0
def dcd_fit(filename_dcd, filename_dcd_out, natom_total, serials,
            filename_rmsd):
    f_out = open(filename_rmsd, 'w')

    # Coord1
    pdb = PdbFile('16SCD.cg.pdb')
    pdb.open_to_read()
    ref_chains = pdb.read_all()
    pdb.close()

    #num_atom = 0
    #for chain in ref_chains :
    #    for residue in chain.residues :
    #        num_atom += len(residue.atoms)

    ref = zeros((natom_total, 3), dtype=float64, order='C')

    i = 0
    for chain in ref_chains:
        for residue in chain.residues:
            for atom in residue.atoms:
                (ref[i][0], ref[i][1], ref[i][2]) = atom.xyz.get_as_tuple()
                i += 1

    mask = []
    for i in range(natom_total):
        # the serial ID starts from 1, thus i+1 is the serial ID
        if i + 1 in serials:
            mask.append(1)
        else:
            mask.append(0)

    dcd = DcdFile(filename_dcd)
    dcd.open_to_read()
    dcd.read_header()

    out_dcd = DcdFile(filename_dcd_out)
    out_dcd.open_to_write()
    out_dcd.set_header(dcd.get_header())
    out_dcd.write_header()

    #dcd.show_header()
    k = 0
    while dcd.has_more_data():
        k += 1
        coords_dcd = dcd.read_onestep_np()

        rmsd = superimpose(ref.T, coords_dcd.T, mask)

        f_out.write('{:8d} {:6.2f}\n'.format(k, rmsd))

        out_dcd.write_onestep(coords_dcd)

    dcd.close()
    out_dcd.close()
Esempio n. 2
0
def dcd_concatenate(filepaths):
    n_frames = []  # To return the number of frames

    # Number of input DCD files
    num_dcd = len(filepaths) - 1

    # New DCD file
    f_out = DcdFile(filepaths[-1])
    f_out.open_to_write()

    # Count the total frame number
    num_frame = 1
    for i in range(0, num_dcd - 1):
        f_in = DcdFile(filepaths[i])
        f_in.open_to_read()
        f_in.read_header()
        num_frame += f_in.get_header().nset - 1
        f_in.close()

    # Get the total step number from final DCD file
    f_in = DcdFile(filepaths[num_dcd - 1])
    f_in.open_to_read()
    f_in.read_header()
    num_frame += f_in.get_header().nset - 1
    num_step = f_in.get_header().nstep
    f_in.close()

    f_in = DcdFile(filepaths[0])
    f_in.open_to_read()
    f_in.read_header()
    header = copy(f_in.get_header())
    header.nset = num_frame
    header.nstep = num_step
    f_out.set_header(header)
    f_out.write_header()
    #print filepaths[0], f_in.get_header().nset
    n_frames.append(f_in.get_header().nset)
    while f_in.has_more_data():
        f_out.write_onestep(f_in.read_onestep())
    f_in.close()

    for i in range(1, num_dcd):
        f_in = DcdFile(filepaths[i])
        f_in.open_to_read()
        f_in.read_header()
        f_in.skip_onestep()  # skip the first step
        #print filepaths[i], f_in.get_header().nset - 1
        n_frames.append(f_in.get_header().nset - 1)
        while f_in.has_more_data():
            f_out.write_onestep(f_in.read_onestep())
        f_in.close()

    f_out.close()

    return n_frames
Esempio n. 3
0
def count_frame(path):

    dcd = DcdFile(path)
    dcd.open_to_read()

    dcd.read_header()

    icount = 0
    while dcd.has_more_data():
        try:
            dcd.skip(1)
            icount += 1
        except EOFError:
            icount += 1
            print(
                'There is another frame at the end, that is not written completely.'
            )
            break
        except:
            break

    dcd.close()

    return icount
Esempio n. 4
0
dist_array = []

while dcd.has_more_data():
    ref = dcd.read_onestep_np()
    dcd.set_mark()

    if dcd.has_more_data():
        while dcd.has_more_data():
            data = dcd.read_onestep_np()
            dist_array.append(calcrmsd(ref.T, data.T))
        dcd.go_mark()
    else:
        break

dcd.close()

print(len(dist_array))

#z = scipy.cluster.hierarchy.ward(dist)  # This does not work for some reason
z = scipy.cluster.hierarchy.linkage(dist_array,
                                    method='ward',
                                    metric='euclidean')
## Other methods
#z = scipy.cluster.hierarchy.linkage(data, method='single', metric='euclidean')
#z = scipy.cluster.hierarchy.linkage(data, method='average', metric='euclidean')

f_out = open(prefix + '.dcd.cls.z', 'w')
for iz, zz in enumerate(z):
    f_out.write("%5i %5i %5i %f %i\n" % (iz + 1, zz[0], zz[1], zz[2], zz[3]))
f_out.close()
Esempio n. 5
0
    num_data += 1
    data = f_dcd.read_onestep()
    idx = 0
    for iatom, atom in enumerate(data) :
        if not fil[iatom]:
            continue
        for xyz in atom :
            data_ave[idx] += xyz
            idx += 1
for i in range(len(data_ave)) :
    data_ave[i] /= float(num_data)
    f_ave.write('%12.5f\n' % data_ave[i])

f_ave.close()
            
f_dcd.close()
f_dcd.open_to_read()
f_dcd.read_header()

# Calculate principal coordinate
while f_dcd.has_more_data() :
    data = f_dcd.read_onestep()
    
    for v in ev :
        x = 0.0
        idx = 0
        for iatom, atom in enumerate(data) :
            if not fil[iatom]:
                continue
            for xyz in atom :
                x += (xyz - data_ave[idx]) * v[idx]
Esempio n. 6
0
# read and write
#imodel = 0
#i_org = 0
while dcd.has_more_data():
    if not ts.has_more_data():
        print('Not enough data in .ts file (1)')
        sys.exit(2)

    tsdata, lines = ts.read_onestep()

    # skip step=1
    if tsdata[0][ts.head_col.step] == 1:
        if not ts.has_more_data():
            print('Not enough data in .ts file (2)')
            sys.exit(2)
        tsdata, lines = ts.read_onestep()

    if tsdata[0][ts.head_col.e_bridge] == '0.0000000':

        dcd_out.write_onestep(dcd.read_onestep())
        #imodel += 1
    else:
        dcd.skip_onestep()

    #i_org += 1

ts.close()
dcd.close()
dcd_out.close()
    # Number of input DCD files
    num_dcd = len(sys.argv) - 2

    # New DCD file
    f_out = DcdFile(sys.argv[-1])
    f_out.open_to_write()

    # Count the total frame number
    num_frame = 1
    for i in range(1, num_dcd):
        f_in = DcdFile(sys.argv[i])
        f_in.open_to_read()
        f_in.read_header()
        num_frame += f_in.get_header().nset
        f_in.close()

    # Get the total step number from final DCD file
    f_in = DcdFile(sys.argv[num_dcd])
    f_in.open_to_read()
    f_in.read_header()
    num_frame += f_in.get_header().nset
    num_step = f_in.get_header().nstep
    f_in.close()

    f_in = DcdFile(sys.argv[1])
    f_in.open_to_read()
    f_in.read_header()
    header = copy(f_in.get_header())
    header.nset = num_frame
    header.nstep = num_step
Esempio n. 8
0
for i in range(1,ncls+1):
    f_out.write('#cluster %i\n' % (i,))
    for iframe, f in enumerate(fcls): 
        if f == i:
            f_out.write("%i %i\n" % (iframe, iframe*nskip))
    f_out.write('\n\n')
f_out.close()



############################# Center
dcd_ref = DcdFile(dcd_ref_filepath)
dcd_ref.open_to_read()
dcd_ref.read_header()
data_ref = dcd_ref.read_onestep_np()
dcd_ref.close()

dcd = DcdFile(dcd_filepath)
dcd.open_to_read()
dcd.read_header()

nmp = dcd._header.nmp_real
cls_centroids = []
for icls in range(ncls):
    cls_centroids.append( np.zeros((nmp,3)) )

k = 0
while dcd.has_more_data():
    data = dcd.read_onestep_np()
    rmsd = superimpose(data_ref.T, data.T)
Esempio n. 9
0
for i in range(NATOM_TOTAL):
    if i in (309-1, 477-1, 519-1):
        mask.append(1)
    else:
        mask.append(0)

dcd = DcdFile('dcd/cM0.0300.dcd')
dcd.open_to_read()
dcd.read_header()

out_dcd = DcdFile('cM0.0300.fit665.dcd')
out_dcd.open_to_write()
out_dcd.set_header(dcd.get_header())
out_dcd.write_header()

#dcd.show_header()
k = 0
while dcd.has_more_data() :
    k += 1
    coords_dcd = dcd.read_onestep_np()
    
    rmsd = superimpose(ref.T, coords_dcd.T, mask)
    
    print(k, rmsd)
    out_dcd.write_onestep(coords_dcd)
        

dcd.close()
out_dcd.close()

Esempio n. 10
0
    
        nstep_dcd = 0
        while in_dcd.has_more_data():
            out_dcd.write_onestep( in_dcd.read_onestep() )
            nstep_dcd += 1
    
        nstep_ts = 0
        while in_ts.has_more_data():
            tsdata, tslines = in_ts.read_onestep()
            out_ts.write_onestep( tslines )
            nstep_ts += 1
        
        if i_dir == 0:
            print(('TS  in %s: #frame = %i' % (d, nstep_ts)))
            print(('DCD in %s: #frame = %i' % (d, nstep_dcd)))
        else:
            print(('TS  in %s: #frame = %i (the first step is eliminated.)' % (d, nstep_ts)))
            print(('DCD in %s: #frame = %i (the first step is eliminated.)' % (d, nstep_dcd)))

        if nstep_ts != nstep_dcd:
            print( 'Warning: nstep_ts != nstep_dcd' )

        nstep_total_ts += nstep_ts
        nstep_total_dcd += nstep_dcd

        in_ts.close()
        in_dcd.close()
    
    print(('Total # of frames in  TS output to %s: %i' % (dir_out, nstep_total_ts)))
    print(('Total # of frames in DCD output to %s: %i' % (dir_out, nstep_total_dcd)))