001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 * Created on 16.03.2004
021 * @author Andreas Prlic
022 *
023 *
024 */
025package org.biojava.nbio.structure.io;
026
027import org.biojava.nbio.structure.Structure;
028import org.biojava.nbio.structure.align.util.UserConfiguration;
029import java.io.IOException;
030import java.io.InputStream;
031
032/**
033 * <p>
034 *  The wrapper class for parsing a PDB file.
035 *  </p>
036 *
037 *
038 *  <p>
039 *  Several flags can be set for this class
040 *  <ul>
041 *
042 * <li> {@link #setAutoFetch(boolean)} - if the PDB file can not be found locally, should it be fetched
043 *  from the PDB ftp servers? (default:false)</li>
044 *  <li> Other parameters can be set using the {@link #setFileParsingParameters(FileParsingParameters)}</li>
045 *  </ul>
046 *  </p>
047 *
048 *
049 *
050 *<h2>Example</h2>
051 * <p>
052 * Q: How can I get a Structure object from a PDB file?
053 * </p>
054 * <p>
055 * A:
056 * <pre>
057 * public {@link Structure} loadStructure(String pathToPDBFile){
058 *      {@link PDBFileReader} pdbreader = new {@link PDBFileReader}();
059 *
060 *      {@link Structure} structure = null;
061 *      try{
062 *              structure = pdbreader.getStructure(pathToPDBFile);
063 *              System.out.println(structure);
064 *      } catch (IOException e) {
065 *              e.printStackTrace();
066 *      }
067 *      return structure;
068 * }
069 * </pre>
070 *
071 * Access PDB files from a directory, take care of compressed PDB files
072 * <pre>
073 * public {@link Structure} loadStructureById() {
074 *      String path = "/path/to/PDB/directory/";
075 *
076 *      {@link PDBFileReader} pdbreader = new {@link PDBFileReader}();
077 *      pdbreader.setPath(path);
078 *      {@link Structure} structure = null;
079 *      try {
080 *              structure = pdbreader.getStructureById("5pti");
081 *      } catch (IOException e){
082 *              e.printStackTrace();
083 *      }
084 *      return structure;
085 *
086 * }
087 * </pre>
088 *
089 *
090 * @author Andreas Prlic
091 *
092 */
093public class PDBFileReader extends LocalPDBDirectory {
094
095        //private static final Logger logger = LoggerFactory.getLogger(PDBFileReader.class);
096
097        public static final String[] PDB_SPLIT_DIR    = new String[]{"data","structures","divided" ,"pdb"};
098        public static final String[] PDB_OBSOLETE_DIR = new String[]{"data","structures","obsolete","pdb"};
099
100
101        /**
102         * Constructs a new PDBFileReader, initializing the extensions member variable.
103         * The path is initialized in the same way as {@link UserConfiguration},
104         * i.e. to system property/environment variable {@link UserConfiguration#PDB_DIR}.
105         * Both autoFetch and splitDir are initialized to false
106         */
107        public PDBFileReader() {
108                this(null);
109        }
110
111        /**
112         * Constructs a new PDBFileReader, initializing the extensions member variable.
113         * The path is initialized to the given path, both autoFetch and splitDir are initialized to false.
114         *
115         * <p>If path is null, initialize using the system property/environment variable
116         * {@link UserConfiguration#PDB_DIR}.
117         * @param path Path to the PDB file directory
118         */
119        public PDBFileReader(String path) {
120                super(path);
121
122                addExtension(".ent");
123                addExtension(".pdb");
124                addExtension(".ent.gz");
125                addExtension(".pdb.gz");
126                addExtension(".ent.Z");
127                addExtension(".pdb.Z");
128        }
129
130        @Override
131        protected String getFilename(String pdbId) {
132                return "pdb"+pdbId.toLowerCase()+".ent.gz";
133        }
134
135        @Override
136        public Structure getStructure(InputStream inStream) throws IOException {
137                PDBFileParser pdbpars = new PDBFileParser();
138                pdbpars.setFileParsingParameters(getFileParsingParameters());
139
140                Structure struc = pdbpars.parsePDBFile(inStream) ;
141                return struc ;
142        }
143
144        @Override
145        protected String[] getSplitDirPath() {
146                return PDB_SPLIT_DIR;
147        }
148
149        @Override
150        protected String[] getObsoleteDirPath() {
151                return PDB_OBSOLETE_DIR;
152        }
153
154
155
156}