List of usage examples for java.lang ArithmeticException getMessage
public String getMessage()
From source file:ffx.algorithms.RotamerOptimization.java
/** * For decomposing the energies of the original (0th) rotamers without * computing the entire energy matrix; can accept a residue list. * * @param residues Residue array to decompose energies of. *//*from w ww .j a va2s.co m*/ public void decomposeOriginal(Residue[] residues) { allResiduesList = new ArrayList<>(); polymers = molecularAssembly.getChains(); for (Polymer polymer : polymers) { ArrayList<Residue> current = polymer.getResidues(); for (Residue residuej : current) { if (residuej != null) { if (residuej.getRotamers(library) != null) { allResiduesList.add(residuej); } else if (useForcedResidues && chain != null) { Polymer setChain = molecularAssembly.getChain(chain); if (setChain.equals(polymer) && checkIfForced(residuej)) { allResiduesList.add(residuej); } } else if (useForcedResidues && checkIfForced(residuej)) { allResiduesList.add(residuej); } } } } numResidues = allResiduesList.size(); allResiduesArray = allResiduesList.toArray(new Residue[numResidues]); int nRes = residues.length; distanceMatrix(); double totalEnergy; double localBackboneEnergy = 0; double localSelfEnergy[] = new double[nRes]; double pairEnergy[][] = new double[nRes][nRes]; double triEnergy[][][] = new double[nRes][nRes][nRes]; double residueEnergy[][] = new double[3][nRes]; for (int i = 0; i < nRes; i++) { turnOnAtoms(residues[i]); } totalEnergy = currentEnergy(allResiduesList); for (int i = 0; i < nRes; i++) { turnOffAtoms(residues[i]); } List<Residue> rList = new ArrayList<>(Collections.nCopies(4, null)); try { localBackboneEnergy = currentEnergy(rList, false); } catch (ArithmeticException ex) { logger.severe(String.format(" FFX shutting down: error in calculation of backbone energy %s", ex.getMessage())); } for (int i = 0; i < nRes; i++) { Residue ri = residues[i]; rList.set(1, ri); turnOnAtoms(ri); localSelfEnergy[i] = currentEnergy(rList) - localBackboneEnergy; logger.info(String.format(" Self %s: %16.5f", ri, localSelfEnergy[i])); residueEnergy[0][i] = localSelfEnergy[i]; turnOffAtoms(ri); } for (int i = 0; i < nRes; i++) { Residue ri = residues[i]; rList.set(0, ri); turnOnAtoms(ri); for (int j = i + 1; j < nRes; j++) { Residue rj = residues[j]; rList.set(1, rj); turnOnAtoms(rj); pairEnergy[i][j] = currentEnergy(rList) - localSelfEnergy[i] - localSelfEnergy[j] - localBackboneEnergy; logger.info(String.format(" Pair %s %s: %16.5f", ri, rj, pairEnergy[i][j])); double halfPair = pairEnergy[i][j] * 0.5; residueEnergy[1][i] += halfPair; residueEnergy[1][j] += halfPair; turnOffAtoms(rj); } turnOffAtoms(ri); } for (int i = 0; i < nRes; i++) { Residue ri = residues[i]; rList.set(0, ri); int indexOfI = allResiduesList.indexOf(ri); turnOnAtoms(ri); for (int j = i + 1; j < nRes; j++) { Residue rj = residues[j]; rList.set(1, rj); int indexOfJ = allResiduesList.indexOf(rj); turnOnAtoms(rj); for (int k = j + 1; k < nRes; k++) { Residue rk = residues[k]; rList.set(2, rk); int indexOfK = allResiduesList.indexOf(rk); double dist = trimerDistance(indexOfI, 0, indexOfJ, 0, indexOfK, 0); if (dist < threeBodyCutoffDist) { turnOnAtoms(rk); triEnergy[i][j][k] = currentEnergy(rList) - localSelfEnergy[i] - localSelfEnergy[j] - localSelfEnergy[k] - pairEnergy[i][j] - pairEnergy[j][k] - pairEnergy[i][k] - localBackboneEnergy; logger.info(String.format(" Tri %s %s %s: %16.5f", ri, rj, rk, triEnergy[i][j][k])); double thirdTrimer = triEnergy[i][j][k] / 3.0; residueEnergy[2][i] += thirdTrimer; residueEnergy[2][j] += thirdTrimer; residueEnergy[2][k] += thirdTrimer; turnOffAtoms(rk); } else if (dist == Double.MAX_VALUE) { logger.info(String.format(" Tri %s %s %s: set to 0.0 at NaN (very long distance)", ri, rj, rk)); triEnergy[i][j][k] = 0.0; } else { logger.info(String.format(" Tri %s %s %s: set to 0.0 at %1.5f Angstroms", ri, rj, rk, dist)); triEnergy[i][j][k] = 0.0; } } turnOffAtoms(rj); } turnOffAtoms(ri); } for (int i = 0; i < nRes; i++) { turnOnAtoms(residues[i]); } decomposePrint(residues, totalEnergy, localBackboneEnergy, residueEnergy); }
From source file:ffx.algorithms.RotamerOptimization.java
/** * Method intended to decompose energies down to quad energies. Mostly for * showing that quads are probably negligible. * * @param quadCutoff/*from w ww . j av a 2s . co m*/ * @param maxQuads */ public void decomposeOriginalQuads(double quadCutoff, int maxQuads) { allResiduesList = new ArrayList<>(); polymers = molecularAssembly.getChains(); for (Polymer polymer : polymers) { ArrayList<Residue> current = polymer.getResidues(); for (Residue residuej : current) { if (residuej != null) { if (residuej.getRotamers(library) != null) { allResiduesList.add(residuej); } else if (useForcedResidues && chain != null) { Polymer setChain = molecularAssembly.getChain(chain); if (setChain.equals(polymer) && checkIfForced(residuej)) { allResiduesList.add(residuej); } } else if (useForcedResidues && checkIfForced(residuej)) { allResiduesList.add(residuej); } } } } numResidues = allResiduesList.size(); allResiduesArray = allResiduesList.toArray(new Residue[numResidues]); Residue residues[] = residueList.toArray(new Residue[residueList.size()]); int nRes = residues.length; distanceMatrix(); double totalEnergy; double localBackboneEnergy = 0; double sumSelf = 0; double sumPair = 0; double sumTri = 0; double sumQuads = 0; double localSelfEnergy[] = new double[nRes]; double pairEnergy[][] = new double[nRes][nRes]; double triEnergy[][][] = new double[nRes][nRes][nRes]; //double quadEnergy[][][][] = new double[nRes][][][]; This array is gigantic and unnecessary. for (int i = 0; i < nRes; i++) { turnOnAtoms(residues[i]); } totalEnergy = currentEnergy(allResiduesList); for (int i = 0; i < nRes; i++) { turnOffAtoms(residues[i]); } List<Residue> rList = new ArrayList<>(Collections.nCopies(4, null)); try { localBackboneEnergy = currentEnergy(rList, false); } catch (ArithmeticException ex) { logger.severe(String.format("FFX shutting down: error in calculation of backbone energy %s", ex.getMessage())); } for (int i = 0; i < nRes; i++) { Residue ri = residues[i]; rList.set(0, ri); turnOnAtoms(ri); localSelfEnergy[i] = currentEnergy(rList) - localBackboneEnergy; logger.info(String.format(" Self %s: %16.5f", ri, localSelfEnergy[i])); sumSelf += localSelfEnergy[i]; turnOffAtoms(ri); } for (int i = 0; i < nRes; i++) { Residue ri = residues[i]; rList.set(0, ri); turnOnAtoms(ri); for (int j = i + 1; j < nRes; j++) { Residue rj = residues[j]; rList.set(0, rj); turnOnAtoms(rj); pairEnergy[i][j] = currentEnergy(rList) - localSelfEnergy[i] - localSelfEnergy[j] - localBackboneEnergy; logger.info(String.format(" Pair %s %s: %16.5f", ri, rj, pairEnergy[i][j])); sumPair += pairEnergy[i][j]; turnOffAtoms(rj); } turnOffAtoms(ri); } for (int i = 0; i < nRes; i++) { Residue ri = residues[i]; rList.set(0, ri); turnOnAtoms(ri); for (int j = i + 1; j < nRes; j++) { Residue rj = residues[j]; rList.set(1, rj); turnOnAtoms(rj); for (int k = j + 1; k < nRes; k++) { Residue rk = residues[k]; rList.set(2, rk); double dist = trimerDistance(i, 0, j, 0, k, 0); if (dist < threeBodyCutoffDist) { turnOnAtoms(rk); triEnergy[i][j][k] = currentEnergy(rList) - localSelfEnergy[i] - localSelfEnergy[j] - localSelfEnergy[k] - pairEnergy[i][j] - pairEnergy[j][k] - pairEnergy[i][k] - localBackboneEnergy; logger.info(String.format(" Tri %s %s %s: %16.5f", ri, rj, rk, triEnergy[i][j][k])); sumTri += triEnergy[i][j][k]; turnOffAtoms(rk); } else if (dist == Double.MAX_VALUE) { logger.info(String.format(" Tri %s %s %s: set to 0.0 at NaN (very long distance)", ri, rj, rk)); triEnergy[i][j][k] = 0.0; } else { logger.info(String.format(" Tri %s %s %s: set to 0.0 at %1.5f Angstroms", ri, rj, rk, dist)); triEnergy[i][j][k] = 0.0; } } turnOffAtoms(rj); } turnOffAtoms(ri); } int numQuadsEvaluated = 0; boolean doBreak = false; for (int i = 0; i < nRes; i++) { Residue ri = residues[i]; rList.set(0, ri); turnOnAtoms(ri); //quadEnergy[i] = new double[nRes][][]; // If for some reason storing quad energies is desired, one can allocate memory on the fly, so that only enough // memory is allocated for the quads you actually evaluate. for (int j = i + 1; j < nRes; j++) { Residue rj = residues[j]; rList.set(1, rj); turnOnAtoms(rj); //quadEnergy[i][j] = new double[nRes][]; for (int k = j + 1; k < nRes; k++) { Residue rk = residues[k]; rList.set(2, rk); turnOnAtoms(rk); //quadEnergy[i][j][k] = new double[nRes]; for (int l = k + 1; l < nRes; l++) { double dist = quadDistance(i, 0, j, 0, k, 0, l, 0); Residue rl = residues[l]; rList.set(3, rl); if (dist < quadCutoff) { turnOnAtoms(rl); /*quadEnergy[i][j][k][l] = currentEnergy() - localSelfEnergy[i] - localSelfEnergy[j] - localSelfEnergy[k] - localSelfEnergy[l] - pairEnergy[i][j] - pairEnergy[i][k] - pairEnergy[i][l] - pairEnergy[j][k] - pairEnergy[j][l] - pairEnergy[k][l] - triEnergy[i][j][k] - triEnergy[i][j][l] - triEnergy[i][k][l] - triEnergy[j][k][l] - localBackboneEnergy;*/ double currentQuad = currentEnergy(rList) - localSelfEnergy[i] - localSelfEnergy[j] - localSelfEnergy[k] - localSelfEnergy[l] - pairEnergy[i][j] - pairEnergy[i][k] - pairEnergy[i][l] - pairEnergy[j][k] - pairEnergy[j][l] - pairEnergy[k][l] - triEnergy[i][j][k] - triEnergy[i][j][l] - triEnergy[i][k][l] - triEnergy[j][k][l] - localBackboneEnergy; logger.info(String.format(" Quad %s %s %s %s: %16.5f at %1.5f Angstroms", ri, rj, rk, rl, currentQuad, dist)); sumQuads += currentQuad; turnOffAtoms(rl); if (++numQuadsEvaluated >= maxQuads) { doBreak = true; break; } } else if (dist == Double.MAX_VALUE) { logger.info( String.format(" Quad %s %s %s %s: set to 0.0 at NaN (very long distance)", ri, rj, rk, rl)); } else { logger.info(String.format(" Quad %s %s %s %s: set to 0.0 at %1.5f Angstroms", ri, rj, rk, rl, dist)); } } turnOffAtoms(rk); if (doBreak) { break; } } turnOffAtoms(rj); if (doBreak) { break; } } turnOffAtoms(ri); if (doBreak) { break; } } logger.info(String.format("\n\n")); logger.info(String.format(" Backbone: %16.5f", localBackboneEnergy)); logger.info(String.format(" Sum Self: %16.5f", sumSelf)); logger.info(String.format(" Sum Pair: %16.5f", sumPair)); logger.info(String.format(" Sum Tri: %16.5f", sumTri)); logger.info(String.format(" Sum Quad: %16.5f", sumQuads)); logger.info(String.format(" Neglected: %16.5f", totalEnergy - sumSelf - sumPair - sumTri - sumQuads - localBackboneEnergy)); logger.info(String.format(" AMOEBA: %16.5f", totalEnergy)); logger.info(String.format("\n\n")); for (int i = 0; i < nRes; i++) { turnOnAtoms(residues[i]); } }