Ejemplo 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()
Ejemplo 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
Ejemplo 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
Ejemplo n.º 4
0
import sys
import scipy.cluster
import numpy as np
from CalcRMSD import calcrmsd
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
Ejemplo n.º 5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
@author: Naoto Hori
'''

import sys
from cafysis.file_io.dcd import DcdFile

if len(sys.argv) < 6:
    print('Usage: % SCRIPT [input dcd] [filter file] [ev file] [,ev file ....] [output average file] [output PC file]')
    sys.exit(2)
    
f_dcd = DcdFile(sys.argv[1])
f_dcd.open_to_read()
f_dcd.read_header()

f_out = open(sys.argv[-1], 'w')
f_ave = open(sys.argv[-2], 'w')

# Read eigen values
num_ev = len(sys.argv) - 5
ev = []
for i in range(num_ev) :
    f_ev = open(sys.argv[i+3], 'r')
    ev_tmp = [] 
    for line in f_ev :
        if line.find('#') != -1: continue
        ev_tmp.append(float(line.strip()))
    ev.append(ev_tmp)
    f_ev.close()
Ejemplo n.º 6
0
    if len(sys.argv) < 4:
        print('Usage: % SCRIPT [DCD1] [DCD2] ([DCD3] ...) [output DCD]')
        sys.exit(2)

    # 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()
Ejemplo n.º 7
0
# Member of cluster
f_out.write('### Members of cluster\n')
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():
Ejemplo n.º 8
0
    # Prepare output files
    out_ts = TsFile( '%s/%s.ts' % (dir_out, name) )
    out_ts.open_to_write()

    out_dcd = DcdFile( '%s/%s.dcd' % (dir_out, name) )
    out_dcd.open_to_write()

    nstep_total_ts = 0
    nstep_total_dcd = 0
    for (i_dir, d) in enumerate(dirs):
        in_ts = TsFile( '%s/%s.ts' % (d, name) )
        in_ts.open_to_read()
        in_ts.read_header()
    
        in_dcd = DcdFile( '%s/%s.dcd' % (d, name) )
        in_dcd.open_to_read()
        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