Esempio n. 1
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. 2
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. 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
from cafysis.file_io.dcd import DcdFile

if len(sys.argv) != 4:
    print('Usage: % SCRIPT [input DCD] [#frame to skip] [output prefix]')
    sys.exit(2)

nskip = int(sys.argv[2])
prefix = sys.argv[-1]

dcd = DcdFile(sys.argv[1])
dcd.open_to_read()
dcd.read_header()

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))
Esempio n. 5
0
    f_rst.write('rep2lab: %5i %5i\n' % (i + 1, label))

#### Step
f_rst.write('# step\n')
f_rst.write('istep_sim:  1\n')
f_rst.write('istep:  %i\n' % (step, ))

#### coordinates of each replicas
for irep in range(1, Nrep + 1):
    f_rst.write('# xyz_mp_rep\n')
    f_rst.write('grep: %i\n' % (irep, ))

    dcd = DcdFile(file_path + '_%04i.dcd' % (irep, ))
    dcd.open_to_read()
    header = dcd.read_header()
    while dcd.has_more_data():
        data = dcd.read_onestep()

    if len(data) != nmp:
        print(('Error len(data) != nmp in replica %i. len(data)=%i' %
               (irep, len(data))))
        sys.exit(2)

    f_rst.write('nmp_all: %i\n' % (nmp, ))
    for imp in range(nmp):
        f_rst.write('%f %f %f\n' % (data[imp][0], data[imp][1], data[imp][2]))

    f_rst.write('# velo_mp\n')
    f_rst.write('grep: %i\n' % (irep, ))
    f_rst.write('nmp_real: %i\n' % (nmp, ))
    for imp in range(nmp):
Esempio n. 6
0
# Check for ev
for v in ev :
    if len(v) != num_dimension :
        print('len(v) != num_dimension, %i' % num_dimension)
        sys.exit(2)

#debug
#for i in xrange(num_ev):
#    print '# ev %i' % i
#    for value in ev[i] :
#        print value

# Calculate average structure (data_ave)
data_ave = [0.0 for i in range(num_dimension)]
num_data = 0
while f_dcd.has_more_data() :
    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_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
    f_out.set_header(header)
    f_out.write_header()
    print(sys.argv[1], 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(2, num_dcd + 1):
        f_in = DcdFile(sys.argv[i])
        f_in.open_to_read()
        f_in.read_header()
        #f_in.skip_onestep()  # skip the first step
        print(sys.argv[i], f_in.get_header().nset)
        while f_in.has_more_data():
            f_out.write_onestep(f_in.read_onestep())
        f_in.close()

    f_out.close()
Esempio n. 8
0
     in_dcd.read_header()
 
     # For the first directory
     if i_dir == 0:
         out_ts.header_lines = in_ts.header_lines
         out_ts.copy_header( in_ts )
         out_ts.write_header()
         out_dcd.set_header( in_dcd.get_header() )
         out_dcd.write_header()
     else:
         # restartの場合は、最初のフレームを除外
         in_ts.read_onestep()
         in_dcd.read_onestep()
 
     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)))
Esempio n. 9
0
else:
    frame_end = args.frame_end

# skip
skipped = dcd.skip_as_many_as_possible_upto(args.frame_begin)
if skipped < args.frame_begin:
    print('Only %i frames could be read from the dcd file, which is less than the one specified as --from %i.' % (skipped, args.frame_begin))
    print('No output file generated.')
    sys.exit(2)

frame_num = frame_end - args.frame_begin + 1
i_orig = args.frame_begin

# read and write
for iframe in range(frame_num) :
    if not dcd.has_more_data() :
        print('The number of frames is invalid.')
        print('Header information:')
        dcd.show_header()
        dcd.close()
        movie.close()
        sys.exit(2)
        
    if iframe % args.frame_stride != 0 :
        dcd.skip(1)
        i_orig += 1
        continue
    
    struct = dcd.read_onestep()

    """ Move to the origin """