/** {@inheritDoc} */ @Override public Chain getChainByPDB(String authId, int modelnr) throws StructureException{ Chain c = getPolyChainByPDB(authId, modelnr); if (c==null ) { throw new StructureException("Could not find chain with authId \"" + authId + "\"" + " for PDB id " + pdb_id + ", model "+modelnr); } return c; }
/** * {@inheritDoc} * */ @Override public Group getGroupByPDB(ResidueNumber resNum) throws StructureException { String pdbresnum = resNum.toString(); if ( pdbResnumMap.containsKey(pdbresnum)) { Integer pos = pdbResnumMap.get(pdbresnum); return groups.get(pos); } else { throw new StructureException("unknown PDB residue number " + pdbresnum + " in chain " + authId); } }
public static StructureAlignment getAlgorithm(String name) throws StructureException{ for ( StructureAlignment algo : algorithms){ if (algo.getAlgorithmName().equalsIgnoreCase(name)) { //return algo; // CeCalculator is not thread safe, // avoid issues with this in multi-threaded environments bu // creating a new StructureAlignment every time this is called try { @SuppressWarnings("unchecked") Class<StructureAlignment> c = (Class<StructureAlignment>) Class.forName(algo.getClass().getName()); return c.newInstance(); } catch (ClassNotFoundException e){ logger.error("Exception: ", e); return null; } catch (IllegalAccessException e){ logger.error("Exception: ", e); return null; } catch (InstantiationException e){ logger.error("Exception: ", e); return null; } } } throw new StructureException("Unknown alignment algorithm: " + name); }
/** {@inheritDoc} */ @Override public Chain getChainByPDB(String chainId) throws StructureException{ if(nrModels() < 1 ) { throw new StructureException("No chains are present."); } return getChainByPDB(chainId,0); }
@Override public Structure getStructureById(String pdbId) throws IOException,StructureException { if (pdbId == null || pdbId.length()< 4) throw new StructureException("This does not look like a valid PDB ID! (" + pdbId + ")"); pdbId = pdbId.toLowerCase(); String middle = pdbId.substring(1,3).toLowerCase(); File f = new File(path + fileSeparator + middle + fileSeparator + pdbId + fileSeparator + "pdb" + pdbId + ".ent.gz"); if (! f.exists()){ } InputStreamProvider isp = new InputStreamProvider(); InputStream inputStream = isp.getInputStream(f); PDBFileParser pdbpars = new PDBFileParser(); pdbpars.setFileParsingParameters(params); Structure struc = pdbpars.parsePDBFile(inputStream) ; return struc ; // something is wrong with the file! // it probably should be downloaded again... // TODO: add auto-download functionality... }
private Structure loadCustomStructure(String userPath2, String userChain2) throws StructureException{ StructureIOFile reader = new PDBFileReader(); Structure s = null; try { s = reader.getStructure(userPath2); } catch (IOException e){ //e.printStackTrace(); throw new StructureException(e); } return StructureTools.getReducedStructure(s, userChain2); }
return null; if(pdbId.length() != 4) { throw new StructureException("Unrecognized PDB ID: "+pdbId);
/** * Calculate the rotation angle for a structure * @param afpChain * @return The rotation angle, in radians * @throws StructureException If the alignment doesn't contain any blocks * @throws NullPointerException If the alignment doesn't have a rotation matrix set */ public static double getAngle(AFPChain afpChain) throws StructureException { if(afpChain.getBlockNum() < 1) { throw new StructureException("No aligned residues"); } Matrix rotation = afpChain.getBlockRotationMatrix()[0]; if(rotation == null) { throw new NullPointerException("AFPChain does not contain a rotation matrix"); } return getAngle(rotation); } /**
int res2 = optAln[block][1][pos]; if(map.containsKey(res1)) { throw new StructureException(String.format("Residue %d aligned to both %d and %d.", res1,map.get(res1),res2));
private Map<Integer,Atom> getAtomFromRecord(String name, String altLoc, String resName, String chainID, String resSeq, String iCode) throws StructureException { if (iCode==null || iCode.isEmpty()) { iCode = " "; // an insertion code of ' ' is ignored } Map<Integer, Atom> outMap = new HashMap<>(); ResidueNumber resNum = new ResidueNumber(chainID, Integer.parseInt(resSeq), iCode.charAt(0)); for (int i=0; i<structure.nrModels(); i++){ Chain chain = structure.getChain(chainID,i); Group group = chain.getGroupByPDB(resNum); Group g = group; // there is an alternate location if (!altLoc.isEmpty()) { g = group.getAltLocGroup(altLoc.charAt(0)); if (g==null) throw new StructureException("Could not find altLoc code "+altLoc+" in group "+resSeq+iCode+" of chain "+ chainID); } Atom a = g.getAtom(name); if (a!=null){ outMap.put(i,a); } } return outMap; } }
throw new StructureException(" no model nr " + modelnr + " in this structure. (contains "+models.size()+")"); throw new StructureException("could not find group " + pdbResnum + " in chain " + chainName);
/** * Calculate the rotation axis for the first block of an AFPChain * @param afpChain * @throws StructureException * @throws NullPointerException if afpChain does not contain a valid rotation matrix and shift vector */ public RotationAxis(AFPChain afpChain) throws StructureException { if(afpChain.getAlnLength() < 1) { throw new StructureException("No aligned residues"); } init(afpChain.getBlockRotationMatrix()[0],afpChain.getBlockShiftVector()[0]); }
/** Display an AFPChain alignment * * @param afpChain * @param ca1 * @param ca2 * @return a StructureAlignmentJmol instance * @throws StructureException */ public static StructureAlignmentJmol display(AFPChain afpChain, Atom[] ca1, Atom[] ca2) throws StructureException { if ( ca1.length < 1 || ca2.length < 1){ throw new StructureException("length of atoms arrays is too short! " + ca1.length + "," + ca2.length); } Group[] twistedGroups = AlignmentTools.prepareGroupsForDisplay(afpChain, ca1, ca2); List<Group> hetatms = StructureTools.getUnalignedGroups(ca1); List<Group> hetatms2 = StructureTools.getUnalignedGroups(ca2); return DisplayAFP.display(afpChain, twistedGroups, ca1, ca2, hetatms, hetatms2); }
/** * Calculate the phi angle. * * @param a * an AminoAcid object * @param b * an AminoAcid object * @return a double * @throws StructureException * if aminoacids not connected or if any of the 4 needed atoms * missing */ public static final double getPhi(AminoAcid a, AminoAcid b) throws StructureException { if ( ! isConnected(a,b)){ throw new StructureException( "can not calc Phi - AminoAcids are not connected!"); } Atom a_C = a.getC(); Atom b_N = b.getN(); Atom b_CA = b.getCA(); Atom b_C = b.getC(); // C and N were checked in isConnected already if (b_CA == null) throw new StructureException( "Can not calculate Phi, CA atom is missing"); return torsionAngle(a_C,b_N,b_CA,b_C); }
/** * Calculate the psi angle. * * @param a * an AminoAcid object * @param b * an AminoAcid object * @return a double * @throws StructureException * if aminoacids not connected or if any of the 4 needed atoms * missing */ public static final double getPsi(AminoAcid a, AminoAcid b) throws StructureException { if ( ! isConnected(a,b)) { throw new StructureException( "can not calc Psi - AminoAcids are not connected!"); } Atom a_N = a.getN(); Atom a_CA = a.getCA(); Atom a_C = a.getC(); Atom b_N = b.getN(); // C and N were checked in isConnected already if (a_CA == null) throw new StructureException( "Can not calculate Psi, CA atom is missing"); return torsionAngle(a_N,a_CA,a_C,b_N); }
/** * Rotate a structure. The rotation Matrix must be a pre-multiplication * Matrix. * * @param structure * a Structure object * @param rotationmatrix * an array (3x3) of double representing the rotation matrix. * @throws StructureException * ... */ public static final void rotate(Structure structure, double[][] rotationmatrix) throws StructureException { if ( rotationmatrix.length != 3 ) { throw new StructureException ("matrix does not have size 3x3 !"); } AtomIterator iter = new AtomIterator(structure) ; while (iter.hasNext()) { Atom atom = iter.next() ; Calc.rotate(atom,rotationmatrix); } }
/** * Rotate a Group. The rotation Matrix must be a pre-multiplication Matrix. * * @param group * a group object * @param rotationmatrix * an array (3x3) of double representing the rotation matrix. * @throws StructureException * ... */ public static final void rotate(Group group, double[][] rotationmatrix) throws StructureException { if ( rotationmatrix.length != 3 ) { throw new StructureException ("matrix does not have size 3x3 !"); } AtomIterator iter = new AtomIterator(group) ; while (iter.hasNext()) { Atom atom = null ; atom = iter.next() ; rotate(atom,rotationmatrix); } }
private Group getGroup(StructureGroup num, List<Chain> chains) throws StructureException { for (Chain c : chains){ if ( c.getId().equals(num.getChainId())){ ResidueNumber resNum = new ResidueNumber(); resNum.setSeqNum(num.getResidueNumber()); resNum.setInsCode(num.getInsCode()); return c.getGroupByPDB(resNum); } } throw new StructureException("Could not find residue " + num); }
private static void printXMLEQRKnownPositions(PrettyXMLWriter xml, AFPChain afpChain, int blockNr) throws IOException, StructureException{ int[] optLen = afpChain.getOptLen(); String[][][] pdbAln = afpChain.getPdbAln(); if ( pdbAln == null){ throw new StructureException("Can't convert to XML without known the PDB coordinates. Please provide Ca atoms and call toXML(afpChain,ca1, ca2)"); } for ( int eqrNr = 0 ; eqrNr < optLen[blockNr] ; eqrNr++ ){ String pdbResnum1 = pdbAln[blockNr][0][eqrNr]; String pdbResnum2 = pdbAln[blockNr][1][eqrNr]; //System.out.println(eqrNr + " got resnum: " + pdbResnum1 + " " + pdbResnum2); String[] spl1 = pdbResnum1.split(":"); String[] spl2 = pdbResnum2.split(":"); String chain1 = spl1[0]; String pdbres1 = spl1[1]; String chain2 = spl2[0]; String pdbres2 = spl2[1]; xml.openTag("eqr"); xml.attribute("eqrNr", String.valueOf(eqrNr)); xml.attribute("pdbres1",pdbres1); xml.attribute("chain1", chain1); xml.attribute("pdbres2",pdbres2); xml.attribute("chain2", chain2); xml.closeTag("eqr"); } }
/** Takes an XML representation of the alignment and flips the positions of name1 and name2 * * @param xml String representing the alignment * @return XML representation of the flipped alignment */ public static String flipAlignment(String xml) throws IOException,StructureException{ AFPChain[] afps = parseMultiXML( xml); if ( afps.length < 1 ) return null; if ( afps.length == 1) { AFPChain newChain = AFPChainFlipper.flipChain(afps[0]); if ( newChain.getAlgorithmName() == null) { newChain.setAlgorithmName(DEFAULT_ALGORITHM_NAME); } return AFPChainXMLConverter.toXML(newChain); } throw new StructureException("not Implemented yet!"); }