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 */ 021package org.biojava.nbio.structure.quaternary.io; 022 023import org.biojava.nbio.structure.PDBHeader; 024import org.biojava.nbio.structure.Structure; 025import org.biojava.nbio.structure.StructureException; 026import org.biojava.nbio.structure.StructureTools; 027import org.biojava.nbio.structure.align.util.AtomCache; 028import org.biojava.nbio.structure.io.FileParsingParameters; 029import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation; 030import org.biojava.nbio.core.util.SoftHashMap; 031 032import java.io.IOException; 033import java.util.List; 034 035 036/** A BioUnitDataProvider that extracts the necessary info from PDB files 037 * 038 * @author Andreas Prlic 039 * 040 */ 041public class PDBBioUnitDataProvider implements BioUnitDataProvider{ 042 043 044 private SoftHashMap<String, PDBHeader> headerCache = new SoftHashMap<String, PDBHeader>(0); 045 046 private Structure s; 047 048 // no initialisation here, this gives an opportunity to setAtomCache to initialise it 049 private AtomCache cache; 050 051 public PDBHeader loadPDB(String pdbId){ 052 053 054 FileParsingParameters params = null; 055 056 if ( cache == null) 057 cache = new AtomCache(); 058 059 params = cache.getFileParsingParams(); 060 061 if ( params == null) 062 params = new FileParsingParameters(); 063 064 params.setParseBioAssembly(true); 065 params.setAlignSeqRes(true); 066 067 PDBHeader header = null; 068 try { 069 s = cache.getStructure(pdbId); 070 071 header = s.getPDBHeader(); 072 headerCache.put(s.getPDBCode(),header); 073 } catch (IOException e) { 074 e.printStackTrace(); 075 } catch (StructureException e) { 076 e.printStackTrace(); 077 } 078 079 080 return header ; 081 } 082 083 @Override 084 public Structure getAsymUnit(String pdbId){ 085 086 if (s == null ||( ! s.getPDBCode().equalsIgnoreCase(pdbId))) { 087 loadPDB(pdbId); 088 } 089 090 if ( s.nrModels() > 1) { 091 s = StructureTools.removeModels(s); 092 } 093 094 095 return s; 096 } 097 @Override 098 public void setAsymUnit(Structure s){ 099 this.s = s; 100 } 101 102 @Override 103 public List<BiologicalAssemblyTransformation> getBioUnitTransformationList( 104 String pdbId, int biolAssemblyNr) { 105 106 107 PDBHeader header = headerCache.get(pdbId); 108 109 if ( header == null) { 110 header = loadPDB(pdbId); 111 } 112 113 return header.getBioAssemblies().get(biolAssemblyNr).getTransforms(); 114 115 116 } 117 118 @Override 119 public int getNrBiolAssemblies(String pdbId) { 120 PDBHeader header = headerCache.get(pdbId); 121 122 if ( header == null) { 123 header = loadPDB(pdbId); 124 } 125 126 return header.getNrBioAssemblies(); 127 } 128 129 @Override 130 public boolean hasBiolAssembly(String pdbId) { 131 PDBHeader header = headerCache.get(pdbId); 132 133 if ( header == null) { 134 header = loadPDB(pdbId); 135 } 136 137 if ( header.getNrBioAssemblies() > 0) { 138 return true; 139 } 140 141 return false; 142 143 } 144 145 @Override 146 public void setAtomCache(AtomCache cache) { 147 this.cache = cache; 148 149 } 150 151 @Override 152 public AtomCache getAtomCache() { 153 return cache; 154 } 155 156}