1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
//Attributs
public static ArrayList<AcideAmine> aaList;
public static File fichier;
public static float[] centre;
Molecule(File fic){ // <------ CONSTRUCTEUR
aaList = new ArrayList<AcideAmine>();
fichier = fic;
centre = new float[] {0,0,0};
aaList = lireMol();
System.out.println("*-*-*-*-*-*-*-*-*-*-*-*-");
aaList.get(3).print(); // <---- Affichage pas bon
System.out.println("*-*-*-*-*-*-*-*-*-*-*-*-");
}
public ArrayList<AcideAmine> lireMol(){
ArrayList<AcideAmine> aaArrayList = new ArrayList<AcideAmine>();
aaArrayList.clear();
aaList.clear();
String ligne;
char[] atomname;
float x , y , z, xsum, ysum, zsum, nbatom;
xsum = ysum = zsum = nbatom =0;
int noAA;
// Déclaration de la source
try {
InputStream is = new FileInputStream(fichier);
Reader r = new InputStreamReader(is);
BufferedReader br = new BufferedReader(r);
System.out.println("Début d'annalyse");
ligne = br.readLine(); // <-------- Je lis la premiere ligne
//Parcours du fichier entier
while (ligne != null){ // <-------- Tant qu'il reste des lignes
if ((ligne.startsWith("ATOM")) & (ligne.charAt(16)!='B') ){ // <--- Petit filtre pour eliminer les mauvaises lignes
noAA = Integer.valueOf(ligne.substring(23,26).trim());
//Nouvel acide amine
AcideAmine currentAA = new AcideAmine(ligne.substring(17,20).toCharArray());
while ((Integer.valueOf(ligne.substring(23,26).trim()) == noAA) & (ligne.startsWith("ATOM"))){ /// < -------- Tant que je suis dans le meme acide amine
//Creation d'un objet Atom
atomname = ligne.substring(13,16).toCharArray();
x = Float.valueOf(ligne.substring(32,38));
y = Float.valueOf(ligne.substring(40,46));
z = Float.valueOf(ligne.substring(48,54));
Atom atomTrouve = new Atom(x,y,z,atomname);
//Ajout de l'atome dans l'AA courant
currentAA.addAtom(atomTrouve); // <------ J'ajoute l'atome dans l'acide amine
//Centrage de la molecule
xsum+=x;
ysum+=y;
zsum+=z;
nbatom++;
ligne = br.readLine(); // <------ Ligne suivante
}
currentAA.setBondList();// <-------- remplit un tableau dans l'objet cirrentAA
System.out.print("CurrentAA = ");
currentAA.print(); // <-------------*** AFFICHAGE CORRECT !!! ***
aaArrayList.add(currentAA); // <------- ERREUR ICI ???
currentAA = null ; //au cas ou
}
if (ligne.startsWith("ATOM")== false ){
ligne = br.readLine();
}
}
centre[0]= xsum/nbatom;
centre[1]= ysum/nbatom;
centre[2]= zsum/nbatom;
System.out.println("Fin d'annalyse");
is.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return aaArrayList; // <----- Tableau mal rempli ici
} |
Partager