Memory check on PDB file
authoramwaterhouse <Andrew Waterhouse>
Mon, 20 Nov 2006 17:58:03 +0000 (17:58 +0000)
committeramwaterhouse <Andrew Waterhouse>
Mon, 20 Nov 2006 17:58:03 +0000 (17:58 +0000)
src/MCview/PDBfile.java

index 99a0a2b..4d2a8d5 100755 (executable)
@@ -42,6 +42,7 @@ public class PDBfile extends jalview.io.AlignFile {
 \r
     public void parse() throws IOException\r
     {\r
+      try{\r
         chains = new Vector();\r
 \r
         PDBChain tmpchain;\r
@@ -49,80 +50,84 @@ public class PDBfile extends jalview.io.AlignFile {
         boolean modelFlag = false;\r
         boolean terFlag = false;\r
 \r
-\r
         int index = 0;\r
-        while((line = nextLine())!=null)\r
+        while ( (line = nextLine()) != null)\r
         {\r
-           if (line.indexOf("HEADER") == 0)\r
-           {\r
-             id = line.substring(62, 67).trim();\r
-             continue;\r
-           }\r
+          if (line.indexOf("HEADER") == 0)\r
+          {\r
+            id = line.substring(62, 67).trim();\r
+            continue;\r
+          }\r
+\r
+          if (line.indexOf("MODEL") == 0)\r
+            modelFlag = true;\r
+\r
+          if (line.indexOf("TER") == 0)\r
+            terFlag = true;\r
 \r
-           if(line.indexOf("MODEL")==0)\r
-             modelFlag = true;\r
+          if (modelFlag && line.indexOf("ENDMDL") == 0)\r
+            break;\r
 \r
-           if(line.indexOf("TER")==0)\r
-             terFlag = true;\r
+          if (line.indexOf("ATOM") == 0\r
+              || (line.indexOf("HETATM") == 0 && !terFlag)\r
+              )\r
+          {\r
+            terFlag = false;\r
 \r
-           if(modelFlag && line.indexOf("ENDMDL")==0)\r
-             break;\r
+            //Jalview is only interested in CA bonds????\r
+            if (!line.substring(12, 15).trim().equals("CA"))\r
+            {\r
+              continue;\r
+            }\r
 \r
-           if (    line.indexOf("ATOM")==0\r
-               || (line.indexOf("HETATM")==0 && !terFlag)\r
-             )\r
+            Atom tmpatom = new Atom(line);\r
+            tmpchain = findChain(tmpatom.chain);\r
+            if (tmpchain != null)\r
+            {\r
+              tmpchain.atoms.addElement(tmpatom);\r
+            }\r
+            else\r
             {\r
-              terFlag = false;\r
-\r
-\r
-              //Jalview is only interested in CA bonds????\r
-              if (!line.substring(12, 15).trim().equals("CA"))\r
-              {\r
-                continue;\r
-              }\r
-\r
-              Atom tmpatom = new Atom(line);\r
-              tmpchain = findChain(tmpatom.chain);\r
-              if (tmpchain != null)\r
-              {\r
-                tmpchain.atoms.addElement(tmpatom);\r
-              }\r
-              else\r
-              {\r
-                tmpchain = new PDBChain(tmpatom.chain);\r
-                chains.addElement(tmpchain);\r
-                tmpchain.atoms.addElement(tmpatom);\r
-              }\r
+              tmpchain = new PDBChain(tmpatom.chain);\r
+              chains.addElement(tmpchain);\r
+              tmpchain.atoms.addElement(tmpatom);\r
+            }\r
           }\r
-          index ++;\r
+          index++;\r
         }\r
 \r
-       makeResidueList();\r
-       makeCaBondList();\r
+        makeResidueList();\r
+        makeCaBondList();\r
 \r
-       if(id==null)\r
-       {\r
-         id = inFile.getName();\r
-       }\r
-       for (int i = 0; i < chains.size(); i++)\r
-       {\r
-         SequenceI seq = ( (PDBChain) chains.elementAt(i)).\r
-             sequence;\r
-         seq.setName(id + "|" + seq.getName());\r
-         Sequence dataset = new Sequence(seq.\r
-             getName(),\r
-             seq.getSequence().toString(), seq.getStart(), seq.getEnd());\r
-\r
-         PDBEntry entry = new PDBEntry();\r
-         entry.setId(id);\r
-         if(inFile!=null)\r
-           entry.setFile(inFile.getAbsolutePath());\r
-\r
-         seq.setDatasetSequence(dataset);\r
-         dataset.addPDBId(entry);\r
-\r
-         getSeqs().addElement(seq);\r
-       }\r
+        if (id == null)\r
+        {\r
+          id = inFile.getName();\r
+        }\r
+        for (int i = 0; i < chains.size(); i++)\r
+        {\r
+          SequenceI seq = ( (PDBChain) chains.elementAt(i)).\r
+              sequence;\r
+          seq.setName(id + "|" + seq.getName());\r
+          Sequence dataset = new Sequence(seq.\r
+                                          getName(),\r
+                                          seq.getSequence().toString(),\r
+                                          seq.getStart(), seq.getEnd());\r
+\r
+          PDBEntry entry = new PDBEntry();\r
+          entry.setId(id);\r
+          if (inFile != null)\r
+            entry.setFile(inFile.getAbsolutePath());\r
+\r
+          seq.setDatasetSequence(dataset);\r
+          dataset.addPDBId(entry);\r
+\r
+          getSeqs().addElement(seq);\r
+        }\r
+      }catch(OutOfMemoryError er)\r
+      {\r
+        System.out.println("OUT OF MEMORY LOADING PDB FILE");\r
+        throw new IOException("Out of memory loading PDB File");\r
+      }\r
     }\r
 \r
     public void makeResidueList() {\r