import java.io.*;
import java.util.*;
import java.text.*;

//--------------------------------------------------------------------------------------------------------------------------------------------------
public class KateAug17{

   private static StringBuffer buffer;
   private static BufferedReader input1=null;
   

   public static String [] arrayM1 = new String [10000];
   public static Double [][] coordinates1 = new Double [10000][4];
   public static Double [][] coordinates2 = new Double [10000][10];
   public static String [] arrayM2 = new String [10000];
   
   public static Double [][] coordinatesDiff = new Double [100][100];

   public static Double [] Translate = new Double [10]; 

   
   static DecimalFormat fmt= new DecimalFormat("0.000"); //3 D.P

  
//main method
   public static void main(String args[]) {
   	
   	
   	int rows=0;
   	int i = 0;
    int j = 0;
    
     
   double x=0;
   double y=0;
   double z=0;
   String text1;
   String text2;
int n=0;
  
   
   
   
    try{


    FileInputStream fstream1 = new FileInputStream("D:\\project1\\exp\\proteins\\1A6G.pdb.txt");
    FileInputStream fstream2 = new FileInputStream("D:\\project1\\exp\\proteins\\1A6K.pdb.txt");
    DataInputStream in1 = new DataInputStream(fstream1); // Get the object of DataInputStream
    DataInputStream in2 = new DataInputStream(fstream2); // Get the object of DataInputStream
    BufferedReader br1 = new BufferedReader(new InputStreamReader(in1));
    BufferedReader br2 = new BufferedReader(new InputStreamReader(in2));

    while ((text1 = br1.readLine()) != null)   {  //Read File Line By Line

        if(text1.trim().startsWith("ATOM")) {
        	StringTokenizer s1 = new StringTokenizer(text1," ");

         	int counter1=0;
          	String line1="";

          	while(s1.hasMoreTokens()) {

				String ss1 = s1.nextToken();
		    	counter1++;

		    	if(counter1 == 3){
		    		line1 += ss1;
		    		arrayM1[rows] = ss1;
		    	}
		    }
		    
		    

    		coordinates1[rows][0]= Double.parseDouble(text1.substring(30,38));//X
			coordinates1[rows][1]= Double.parseDouble(text1.substring(38,46));//Y
			coordinates1[rows][2]= Double.parseDouble(text1.substring(46,56));//Z



			rows+=1;
		}//end of if


	} //end of while.

		
			
			
			
	rows=0;

	while ((text2 = br2.readLine()) != null)   {  //Read File Line By Line


        if(text2.trim().startsWith("ATOM")) {
        	StringTokenizer s2 = new StringTokenizer(text2," ");

         	int counter2=0;
          	String line2="";

        	while(s2.hasMoreTokens()) {

				String ss2 = s2.nextToken();
		    	counter2++;

		    	if(counter2 == 3){
		    		line2 += ss2;
		    		arrayM2[rows] = ss2;
		    	}
			}
    
    		coordinates2[rows][0]= Double.parseDouble(text2.substring(30,38));//X
			coordinates2[rows][1]= Double.parseDouble(text2.substring(38,46));//Y
			coordinates2[rows][2]= Double.parseDouble(text2.substring(46,56));//Z
	
		
		rows+=1;	
				
		

			 
		 }//end of if
 
	
	} //end of while.

			}//end of try



			catch( IOException e) {
				e.printStackTrace();
				}//end of catch
					
//------------------------------------------------------END OF 2D ARRAY--------------------------------------------------------------------------------
	



	

//System.out.println(coordinates2[i][0]+"\t"+coordinates2[i][1]+"\t"+coordinates2[i][2]);
	
			for(i=0; i<rows; i++){
			     
			 	   //for(int k=0; k<4; k++){
			 
		
			
		 if((arrayM1[1].equals("CA"))&&(arrayM2[1].equals("CA"))){
				 	
					 	 
					 	 //Difference
					 	 
			coordinatesDiff[0][0] = coordinates1[1][0]/coordinates2[1][0];
			coordinatesDiff[0][1] = coordinates1[1][1]/coordinates2[1][1];
			coordinatesDiff[0][2] = coordinates1[1][2]/coordinates2[1][2];
			
   	System.out.println(coordinates1[i][0]);	 
			//double [][] Translation1={ {x,0,0}, {0,y,0}, {0,0,z} };
			
			  
				
	       // coordinates1[i][j] = coordinates2[i][k]*Translation1[k][j];
		
		
			
	
			
			
			//	}			

		}
   
	
 
}				
					 
		//System.out.println(coordinates2[1][0]+"\t"+coordinates2[1][1]+"\t"+coordinates2[1][2]);		 	
			//System.out.println("\t"+fmt.format(coordinates2[1][0])+"\t"+fmt.format(coordinates2[1][1])+"\t"+fmt.format(coordinates2[1][2])+"\t");
		   //System.out.println(Translate[i]);
				
	




}//end of main

}//end of class

How do I get my coordinates1[j] & coordinates? I need the whole full array. It's a i x 3 array. When I print the above, I get weird values. I didn't get the original value.

I meant coordinates1[j] & coordinates2[j]?

What values do you get when you print them? Where in your code you print them?

What values do you get when you print them? Where in your code you print them?

Print around line 164.
The values are from the original file. I can print row by rowcoordinates([0], coordinates[1], coordinates[2]) but I just can't seem to print the whole array: coordinates1[j]. I'm stuck at this part.
The out put should be something like this:(There are about at thousand over lines of these, everyfile possess different rows, thus I can't initialize a fixed no. for the no. of rows, but the no. of colums will always be the same: 3)

x,y,z
coordinates[0] coordinates[1] coordinates[2]

-4.040 15.048 13.602
-3.621 15.574 14.908
-2.766 14.564 15.637

Member Avatar for coil

I think you're asking how to print out each element in a 2D array. You're on the right track...use a nested for loop.

For-loop:

for(int i=0; i<coordinates1.length; i++) { //For each coordinates[i]...
	for(int j=0; j<coordinates1[i].length; j++) { //For each element in coordinates[i]...
		System.out.println(coordinates1[i][j]); //Print it out
	}
}

I think you're asking how to print out each element in a 2D array. You're on the right track...use a nested for loop.

For-loop:

for(int i=0; i<coordinates1.length; i++) { //For each coordinates[i]...
	for(int j=0; j<coordinates1[i].length; j++) { //For each element in coordinates[i]...
		System.out.println(coordinates1[i][j]); //Print it out
	}
}

Thank you! But there are plenty of nulls after the values. Because coordinates1 size is 10000, but the rows are 1000+ only. So is there any possible way where it can print out the actual no. of rows?

So is there any possible way where it can print out the actual no. of rows

Do you want to see just the number of rows, not the contents of the rows?
The length attribute of an array will give you its size(no. of rows).

Do you want to see just the number of rows, not the contents of the rows?
The length attribute of an array will give you its size(no. of rows).

I want to see the values in the no. of rows that are used. but if the rows aren't used, I dont wish to see it.

That sounds like a good place to use an if test.
if the value is null, don't print it. I assume that unused elements are null

That sounds like a good place to use an if test.
if the value is null, don't print it. I assume that unused elements are null

Thank you! I think I got it! My output is all in a single colum in order but the values are right. It should be a 3x3 matrix right?

t should be a 3x3 matrix right?

Its your program. What output do you want?

Its your program. What output do you want?

I want my output to be something where i can see my coordinates[j] an i x 3 matrix so that it is easier for me to see and compute some values later on.

Member Avatar for coil

If you want a matrix, insert a System.out.println("\n"); in the outer for-loop, after the inner for loop. By the way, '\n' is an expression that outputs a new line.

Pseudo code:

for(int i=0; ...) {
    for(int j=0; ...) {
        if(value!=null) 
            <print out>
    }
    System.out.println("\n");
}

I want my output to be something where i can see my coordinates[j] an i x 3 matrix

Can you show an example of what you want?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.