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.xtal; 022 023import org.biojava.nbio.structure.Calc; 024import org.biojava.nbio.structure.Structure; 025import org.biojava.nbio.structure.StructureTools; 026import org.biojava.nbio.structure.contact.BoundingBox; 027 028import javax.vecmath.Matrix4d; 029import javax.vecmath.Vector3d; 030 031/** 032 * A class to contain the BoundingBoxes of all molecules in a full unit cell 033 * 034 * @author duarte_j 035 * 036 */ 037public class UnitCellBoundingBox { 038 039 /** 040 * An array with dimensions numOperatorsSg x numChainsAu to contain all 041 * bounding boxes of all chains of all AUs in unit cell 042 * e.g. chainBbs[0] would be the bounding boxes for all chains in the original AU 043 */ 044 private BoundingBox[][] chainBbs; 045 046 /** 047 * An array with dimensions numOperatorsSg to contain all bounding boxes of 048 * all AUs in unit cell 049 */ 050 private BoundingBox[] auBbs; 051 052 private int numOperatorsSg; // i.e. multiplicity of space group 053 private int numChainsAu; 054 055 public UnitCellBoundingBox(int numOperatorsSg, int numChainsAu) { 056 this.numOperatorsSg = numOperatorsSg; 057 this.numChainsAu = numChainsAu; 058 this.chainBbs = new BoundingBox[numOperatorsSg][numChainsAu]; 059 this.auBbs = new BoundingBox[numOperatorsSg]; 060 } 061 062 public void setBbs(Structure structure, Matrix4d[] ops, boolean includeHetAtoms) { 063 064 setBb(structure, includeHetAtoms, 0); 065 for (int i=1;i<ops.length;i++) { 066 Structure sym = structure.clone(); 067 Calc.transform(sym, ops[i]); 068 setBb(sym, includeHetAtoms, i); 069 } 070 071 } 072 073 private void setBb(Structure s, boolean includeHetAtoms, int i) { 074 chainBbs[i] = new BoundingBox[numChainsAu]; 075 for (int j = 0;j<numChainsAu; j++) { 076 chainBbs[i][j] = new BoundingBox(StructureTools.getAllNonHAtomArray(s.getChain(j), includeHetAtoms)); 077 } 078 auBbs[i] = new BoundingBox(chainBbs[i]); 079 } 080 081 /** 082 * Get the chain BoundingBox for the given cell index (cellIdx=0 would be original AU) 083 * and chain index 084 * @param cellIdx 085 * @param chainIdx 086 * @return 087 */ 088 public BoundingBox getChainBoundingBox(int cellIdx, int chainIdx) { 089 return chainBbs[cellIdx][chainIdx]; 090 } 091 092 /** 093 * Get the AU BoundingBox for the given cell index (cellIdx=0 would be original AU) 094 * The AU BoundingBox is the BoundingBox that bounds all chains belonging to the AU 095 * @param cellIdx 096 * @return 097 */ 098 public BoundingBox getAuBoundingBox(int cellIdx) { 099 return auBbs[cellIdx]; 100 } 101 102 /** 103 * Returns a new BoundingBoxes object containing the same bounds as this 104 * BoundingBoxes object translated by the given translation 105 * @param translation 106 * @return 107 */ 108 public UnitCellBoundingBox getTranslatedBbs(Vector3d translation) { 109 UnitCellBoundingBox translatedBbs = new UnitCellBoundingBox(numOperatorsSg, numChainsAu); 110 111 for (int i=0; i<numOperatorsSg; i++) { 112 for (int j = 0;j<numChainsAu; j++) { 113 translatedBbs.chainBbs[i][j] = new BoundingBox(this.chainBbs[i][j]); 114 translatedBbs.chainBbs[i][j].translate(translation); 115 } 116 translatedBbs.auBbs[i] = new BoundingBox(translatedBbs.chainBbs[i]); 117 } 118 119 return translatedBbs; 120 } 121 122}