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.Structure; 024import org.biojava.nbio.structure.StructureException; 025import org.biojava.nbio.structure.StructureIO; 026import org.biojava.nbio.structure.align.util.AtomCache; 027import org.biojava.nbio.structure.io.mmcif.model.PdbxStructAssembly; 028import org.biojava.nbio.structure.io.mmcif.model.PdbxStructAssemblyGen; 029import org.biojava.nbio.structure.io.mmcif.model.PdbxStructOperList; 030import org.biojava.nbio.structure.quaternary.BiologicalAssemblyBuilder; 031import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation; 032 033import java.io.IOException; 034import java.util.ArrayList; 035import java.util.List; 036 037public class MmCifBiolAssemblyProvider implements BioUnitDataProvider { 038 039 private MmCifPDBBiolAssemblyProvider provider; 040 041 // no initialisation here, this gives an opportunity to setAtomCache to initialise it 042 private AtomCache cache; 043 044 public MmCifBiolAssemblyProvider(){ 045 provider = new MmCifPDBBiolAssemblyProvider(); 046 } 047 048 @Override 049 public Structure getAsymUnit(String pdbId){ 050 051 provider.setPdbId(pdbId); 052 053 Structure s1 = provider.getAsymUnit(); 054 return s1; 055 } 056 057 @Override 058 public void setAsymUnit(Structure s){ 059 provider.setAsymUnit(s); 060 } 061 062 @Override 063 public List<BiologicalAssemblyTransformation> getBioUnitTransformationList( 064 String pdbId, int biolAssemblyNr) { 065 066 067 provider.setPdbId(pdbId); 068 069 List<PdbxStructAssembly> psas= provider.getPdbxStructAssemblies(); 070 071 PdbxStructAssembly psa = null; 072 if ( psas.size() >= biolAssemblyNr ){ 073 psa = psas.get(biolAssemblyNr -1); 074 } else { 075 throw new IllegalArgumentException("Requested not existing biolAssemblyNr"); 076 077 } 078 079 // we start counting at 1! 080 //PdbxStructAssembly psa = provider.getPdbxStructAssembly(biolAssemblyNr-1) ; 081 082 List<PdbxStructAssemblyGen> psags = provider.getPdbxStructAssemblyGen(biolAssemblyNr-1); 083 084 if ( psa == null || psags == null) { 085 return null; 086 } 087 //System.out.println(psa); 088 //System.out.println(psags); 089 090 List<PdbxStructOperList> operators = provider.getPdbxStructOperList(); 091 //System.out.println(operators); 092 093 094 /** 095 * Now we start to rebuild the quaternary structure 096 */ 097 098 BiologicalAssemblyBuilder builder = new BiologicalAssemblyBuilder(); 099 100 // these are the transformations that need to be applied to our model 101 List<BiologicalAssemblyTransformation> transformations = builder.getBioUnitTransformationList(psa, psags, operators); 102 //System.out.println(transformations); 103 return transformations; 104 } 105 106 @Override 107 public int getNrBiolAssemblies(String pdbId) { 108 109 provider.setPdbId(pdbId); 110 111 return provider.getNrBiolAssemblies(); 112 } 113 114 @Override 115 public boolean hasBiolAssembly(String pdbId) { 116 117 118 provider.setPdbId(pdbId); 119 120 return provider.hasBiolAssembly(); 121 } 122 123 public Structure getBiolAssembly(String pdbId, int biolAssemblyNr) throws IOException, StructureException { 124 125 126 provider.setPdbId(pdbId); 127 128 if ( ! provider.hasBiolAssembly()){ 129 return null; 130 } 131 132 if ( provider.getNrBiolAssemblies() <= biolAssemblyNr){ 133 return null; 134 } 135 136 // First we read the required data from wherever we get it from (configured in the factory) 137 PdbxStructAssembly psa = provider.getPdbxStructAssembly(biolAssemblyNr) ; 138 139 List<PdbxStructAssemblyGen> psags = provider.getPdbxStructAssemblyGen(biolAssemblyNr); 140 141 142 List<PdbxStructOperList> operators = provider.getPdbxStructOperList(); 143 144 145 // now we start to rebuild the quaternary structure 146 BiologicalAssemblyBuilder builder = new BiologicalAssemblyBuilder(); 147 148 // these are the transformations that need to be applied to our model 149 ArrayList<BiologicalAssemblyTransformation> transformations = builder.getBioUnitTransformationList(psa, psags, operators); 150 151 152 153 Structure asymUnit = null; 154 155 if ( provider instanceof MmCifPDBBiolAssemblyProvider){ 156 MmCifPDBBiolAssemblyProvider mmcifprov = provider; 157 asymUnit = mmcifprov.getAsymUnit(); 158 } else { 159 160 // how to request internal chain IDs? 161 162 asymUnit = StructureIO.getStructure(pdbId); 163 164 } 165 166 return builder.rebuildQuaternaryStructure(asymUnit, transformations); 167 } 168 169 @Override 170 public void setAtomCache(AtomCache cache) { 171 172 this.cache =cache; 173 provider.setAtomCache(cache); 174 } 175 176 @Override 177 public AtomCache getAtomCache() { 178 return cache; 179 } 180 181}