예제 #1
0
def Traj_2_coor(in_coor_file,traj_file,out_coor_file,atom_list,skip):
    '''
    Reading a trajectory file. output the frames to files like out_coor_file_1.pdb \n
    atom_list : a list of atom serial.\n
    out_coor_file: a file name, in pdb or gro format. a list of file based on the name\
            will be created for output.\n
    skip: a int number like 1,2,3,10. 
    '''
    Alist=Simple_atom.Get_Simple_atom_list(in_coor_file)
    Blist=[]
    for atom in Alist:
        if atom.atom_serial in atom_list:
            Blist.append(atom)
    '''Get the result atom list in Simple_atom class.'''

    u=MDAnalysis.Universe(in_coor_file,traj_file)
    for ts in u.trajectory:
        if ts.frame % skip ==0 :

            a,b=os.path.splitext(out_coor_file)
            temp_out_file=a+"_%d" %(int(ts.frame)/skip) + b
            if os.path.isfile(temp_out_file):
                #print "backup %s to %s" %(temp_out_file,"#"+temp_out_file+"#")
                usage.echo("backup %s to %s\r" %(temp_out_file,"#"+temp_out_file+"#"))

                try:
                    os.rename(temp_out_file,"#"+temp_out_file+"#")
                except OSError,e: 
                    print e
                    print "the file %s will be overwrited!" %temp_out_file
                    pass

            fp=open(temp_out_file,'w+')
            if temp_out_file.endswith(".gro"):
                fp.write("%d\n" %len(Blist))
            else:
                pass

            for atom in Blist:
                temp_class=unit_atom.unit_atom(atom_name=atom.atom_name,\
                        atom_serial=atom.atom_serial,\
                        residue_name=atom.residue_name,\
                        residue_serial=atom.residue_serial)
                temp_class.atom_coor_x=ts._x[atom.atom_serial-1]/10
                temp_class.atom_coor_y=ts._y[atom.atom_serial-1]/10
                temp_class.atom_coor_z=ts._z[atom.atom_serial-1]/10

                if temp_out_file.endswith(".pdb"):
                    fp.write(temp_class.atom_2_PDBformat()+"\n")
                elif temp_out_file.endswith(".gro"):
                    fp.write(temp_class.atom_2_GROformat()+"\n")
                else:
                    pass

          #  print "write frame %5d to %16s" %(ts.frame,temp_out_file)
            usage.echo("write frame %5d to %16s\r" %(ts.frame,temp_out_file))

        else:
            pass
예제 #2
0
                    c2.append(result[1])

                fp = open(output_name[i], 'a')

                if CALCU=="pair":
                    a=DNA_param.base_pair_parameters(r1[0],r2[0],c1[0],c2[0])
                    fp.write("%8.2f    %8.2f    %8.2f    %8.2f    %8.2f    %8.2f\n" %(a[0],a[1],a[2],a[3],a[4],a[5]))
                else:
                    middle_r1,middle_c1=DNA_param.middle_frame(r1[0],r1[1],c1[0],c1[1])
                    middle_r2,middle_c2=DNA_param.middle_frame(r2[0],r2[1],c2[0],c2[1])
                    a=DNA_param.base_step_parameters(middle_r1,middle_r2,middle_c1,middle_c2)
                    fp.write("%8.2f    %8.2f    %8.2f    %8.2f    %8.2f    %8.2f\n" %(a[0],a[1],a[2],a[3],a[4],a[5]))

                if ts.frame % 10 ==0 and i==0:
                    NOW_TIME=Time.time()
                    usage.echo("  analysis frame %6d, time %8.1f ps, time used %8.2f s\r" %(ts.frame, time,NOW_TIME-START_TIME))

                fp.close()

    print "The DNA helical analysis finished"
    print "The result are in file: %s" %output_name

def Get_para_fromTOP( coor_file, base_list_1, base_list_2,CALCU="step",PRINT=True):
    '''
    get pair parameters from coor_file
    '''

    atom_list=Simple_atom.Get_atom_list(coor_file)
    residue_list=Simple_atom.Get_Residue_list(atom_list)
    # print residue_list
    # atom_list=Simple_atom.Get_atom_list(coor_file)
예제 #3
0
                        % (a[0], a[1], a[2], a[3], a[4], a[5]))
                else:
                    middle_r1, middle_c1 = DNA_param.middle_frame(
                        r1[0], r1[1], c1[0], c1[1])
                    middle_r2, middle_c2 = DNA_param.middle_frame(
                        r2[0], r2[1], c2[0], c2[1])
                    a = DNA_param.base_step_parameters(middle_r1, middle_r2,
                                                       middle_c1, middle_c2)
                    fp.write(
                        "%8.2f    %8.2f    %8.2f    %8.2f    %8.2f    %8.2f\n"
                        % (a[0], a[1], a[2], a[3], a[4], a[5]))

                if ts.frame % 10 == 0 and i == 0:
                    NOW_TIME = Time.time()
                    usage.echo(
                        "  analysis frame %6d, time %8.1f ps, time used %8.2f s\r"
                        % (ts.frame, time, NOW_TIME - START_TIME))

                fp.close()

    print "The DNA helical analysis finished"
    print "The result are in file: %s" % output_name


def Get_para_fromTOP(coor_file,
                     base_list_1,
                     base_list_2,
                     CALCU="step",
                     PRINT=True):
    '''
    get pair parameters from coor_file
예제 #4
0
def Get_twist_in_GDNA(traj_file, coor_file, base_list_1, base_list_2,
                      output_file):
    '''
    Input the layer 1 (G11,G12,G13,G14) and layer 2 (G21,G22,G23,G24),Calculate the angle 
    between G1i-G1(i+1) and G2i-G2(i+1). write the result to output_file.\n
    B{traj_file:} the GMX trajectory file, in trr or xtc format.\n
    B{coor_file:} the GMX coordinate file, in pdb or gro format.\n
    B{base_list_1:} the frist group contain four guanine bases.\n
    B{base_list_2:} the second group contain four guanine bases.\n
    B{output_file:} the output file. 
    '''
    C1_list_1 = []
    C1_list_2 = []
    print " init......"
    fp = open(output_file, "w")
    fp.write("#Group 1: ")
    for i in base_list_1:
        fp.write("%d\t " % i)
    fp.write("\n")
    fp.write("#Group 2: ")
    for i in base_list_2:
        fp.write("%d\t " % i)
    fp.write("\n")
    fp.write("#time\t angle_1 \t angle _2 \t angle _3 \t angle_4\n")
    Atom_list = Simple_atom.Get_Simple_atom_list(coor_file)

    for base in base_list_1:
        atom_list = Simple_atom.Get_Atom_in_residue(Atom_list, base)
        for atom in atom_list:
            if atom.atom_name == "C1'":
                C1_list_1.append(atom.atom_serial)

    for base in base_list_2:
        atom_list = Simple_atom.Get_Atom_in_residue(Atom_list, base)
        for atom in atom_list:
            if atom.atom_name == "C1'":
                C1_list_2.append(atom.atom_serial)


#    print C1_list_1
#    print C1_list_2

    u = MDAnalysis.Universe(coor_file, traj_file)
    for ts in u.trajectory:
        angle = []
        for i in range(4):
            vector1=[ts._x[C1_list_1[(i+1)%4]-1]-ts._x[C1_list_1[i]-1],\
                    ts._y[C1_list_1[(i+1)%4]-1]-ts._y[C1_list_1[i]-1],\
                    ts._z[C1_list_1[(i+1)%4]-1]-ts._z[C1_list_1[i]-1]]
            vector2=[ts._x[C1_list_2[(i+1)%4]-1]-ts._x[C1_list_2[i]-1],\
                    ts._y[C1_list_2[(i+1)%4]-1]-ts._y[C1_list_2[i]-1],\
                    ts._z[C1_list_2[(i+1)%4]-1]-ts._z[C1_list_2[i]-1]]
            vector1 = numpy.array(vector1)
            vector2 = numpy.array(vector2)
            #            print vector1,vector2
            gamma = numpy.dot(vector1, vector2) / (math.sqrt(
                numpy.dot(vector1, vector1) * numpy.dot(vector2, vector2)))
            angle.append(math.acos(gamma) / 3.1416 * 180)

        fp.write("%6.3f \t %6.3f \t %6.3f \t %6.3f \t %6.3f\n" \
                %(ts.time/1000,angle[0],angle[1],angle[2],angle[3]))
        #if ts.frame % 100 ==0:
        #    print " analysis frame %6d......" %ts.frame
        usage.echo(" analysis frame %6d......\r" % ts.frame)
    fp.close()
    print "The result are in the file: ", output_file
예제 #5
0
                            ts._y[C1_list_1[(k+1)%4]-1]-ts._y[C1_list_1[k]-1],\
                            ts._z[C1_list_1[(k+1)%4]-1]-ts._z[C1_list_1[k]-1]]

                    vector2=[ts._x[C1_list_2[(k+1)%4]-1]-ts._x[C1_list_2[k]-1],\
                            ts._y[C1_list_2[(k+1)%4]-1]-ts._y[C1_list_2[k]-1],\
                            ts._z[C1_list_2[(k+1)%4]-1]-ts._z[C1_list_2[k]-1]]

                    vector1 = numpy.array(vector1)

                    vector1_1 = numpy.cross(
                        numpy.cross(orient_group_1, vector1), orient_group_1)

                    vector2 = numpy.array(vector2)

                    vector2_2 = numpy.cross(
                        numpy.cross(orient_group_2, vector2), orient_group_2)

                    #                   print vector1_1,vector2_2
                    gamma = numpy.dot(vector1_1, vector2_2) / (math.sqrt(
                        numpy.dot(vector1_1, vector1_1) *
                        numpy.dot(vector2_2, vector2_2)))
                    angle.append(math.acos(abs(gamma)) / 3.1416 * 180)

                fp = open(output_name[i], 'a')
                fp.write("%6.3f \t %6.3f \t %6.3f \t %6.3f \t %6.3f\n" \
                        %(ts.time/1000,angle[0],angle[1],angle[2],angle[3]))
                if ts.frame % 100 == 0 and i == 0:
                    usage.echo(" analysis frame %6d\r" % ts.frame)
                fp.close()
    print "The result are in the file: ", output_name
예제 #6
0
def Get_twist_in_GDNA(traj_file,coor_file,base_list_1,base_list_2,output_file):
    '''
    Input the layer 1 (G11,G12,G13,G14) and layer 2 (G21,G22,G23,G24),Calculate the angle 
    between G1i-G1(i+1) and G2i-G2(i+1). write the result to output_file.\n
    B{traj_file:} the GMX trajectory file, in trr or xtc format.\n
    B{coor_file:} the GMX coordinate file, in pdb or gro format.\n
    B{base_list_1:} the frist group contain four guanine bases.\n
    B{base_list_2:} the second group contain four guanine bases.\n
    B{output_file:} the output file. 
    '''
    C1_list_1=[]
    C1_list_2=[]
    print " init......"
    fp=open(output_file,"w")
    fp.write("#Group 1: ")
    for i in base_list_1:
        fp.write("%d\t " %i)
    fp.write("\n")
    fp.write("#Group 2: ")
    for i in base_list_2:
        fp.write("%d\t " %i)
    fp.write("\n")
    fp.write("#time\t angle_1 \t angle _2 \t angle _3 \t angle_4\n")
    Atom_list=Simple_atom.Get_Simple_atom_list(coor_file)

    for base in base_list_1:
        atom_list=Simple_atom.Get_Atom_in_residue(Atom_list,base)
        for atom in atom_list:
            if atom.atom_name =="C1'":
                C1_list_1.append(atom.atom_serial)

    for base in base_list_2:
        atom_list=Simple_atom.Get_Atom_in_residue(Atom_list,base)
        for atom in atom_list:
            if atom.atom_name =="C1'":
                C1_list_2.append(atom.atom_serial)

#    print C1_list_1
#    print C1_list_2

    u=MDAnalysis.Universe(coor_file,traj_file)    
    for ts in u.trajectory:
        angle=[]
        for i in range(4):
            vector1=[ts._x[C1_list_1[(i+1)%4]-1]-ts._x[C1_list_1[i]-1],\
                    ts._y[C1_list_1[(i+1)%4]-1]-ts._y[C1_list_1[i]-1],\
                    ts._z[C1_list_1[(i+1)%4]-1]-ts._z[C1_list_1[i]-1]]
            vector2=[ts._x[C1_list_2[(i+1)%4]-1]-ts._x[C1_list_2[i]-1],\
                    ts._y[C1_list_2[(i+1)%4]-1]-ts._y[C1_list_2[i]-1],\
                    ts._z[C1_list_2[(i+1)%4]-1]-ts._z[C1_list_2[i]-1]]
            vector1=numpy.array(vector1)
            vector2=numpy.array(vector2)
#            print vector1,vector2
            gamma=numpy.dot(vector1,vector2)/(math.sqrt(numpy.dot(vector1,vector1)*numpy.dot(vector2,vector2)))
            angle.append(math.acos(gamma)/3.1416*180)

        fp.write("%6.3f \t %6.3f \t %6.3f \t %6.3f \t %6.3f\n" \
                %(ts.time/1000,angle[0],angle[1],angle[2],angle[3]))             
        #if ts.frame % 100 ==0:
        #    print " analysis frame %6d......" %ts.frame
        usage.echo(" analysis frame %6d......\r" %ts.frame)
    fp.close()
    print "The result are in the file: ",output_file
예제 #7
0
                            ts._y[C1_list_1[(k+1)%4]-1]-ts._y[C1_list_1[k]-1],\
                            ts._z[C1_list_1[(k+1)%4]-1]-ts._z[C1_list_1[k]-1]]

                    vector2=[ts._x[C1_list_2[(k+1)%4]-1]-ts._x[C1_list_2[k]-1],\
                            ts._y[C1_list_2[(k+1)%4]-1]-ts._y[C1_list_2[k]-1],\
                            ts._z[C1_list_2[(k+1)%4]-1]-ts._z[C1_list_2[k]-1]]

                    vector1=numpy.array(vector1)

                    vector1_1=numpy.cross(numpy.cross(orient_group_1,vector1),orient_group_1)

                    vector2=numpy.array(vector2)

                    vector2_2=numpy.cross(numpy.cross(orient_group_2,vector2),orient_group_2)

 #                   print vector1_1,vector2_2
                    gamma=numpy.dot(vector1_1,vector2_2)/(math.sqrt(numpy.dot(vector1_1,vector1_1)*numpy.dot(vector2_2,vector2_2)))
                    angle.append(math.acos(abs(gamma))/3.1416*180)
         
                fp=open(output_name[i],'a')
                fp.write("%6.3f \t %6.3f \t %6.3f \t %6.3f \t %6.3f\n" \
                        %(ts.time/1000,angle[0],angle[1],angle[2],angle[3]))             
                if ts.frame % 100 ==0 and i ==0:
                    usage.echo(" analysis frame %6d\r" %ts.frame)
                fp.close()
    print "The result are in the file: ",output_name