List of usage examples for java.util Collections nCopies
public static <T> List<T> nCopies(int n, T o)
From source file:org.joox.test.JOOXTest.java
License:asdf
@Test public void testRename() throws Exception { assertEquals(Collections.nCopies(8, "xx"), $.find("book").rename("xx").tags()); assertTrue($.find("book").isEmpty()); assertFalse($.find("book").isNotEmpty()); assertEquals(8, $.find("xx").size()); assertEquals(8, $.find("books").children().size()); assertEquals(8, $.find("books").children("xx").size()); assertEquals(asList("b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8"), $.find("xx").rename(new Content() { @Override//from w w w . j a v a2 s . c o m public String content(Context context) { return "b" + (context.matchIndex() + 1); } }).tags()); assertEquals(asList("b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8"), $.find("books").children().tags()); }
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. *//* www. ja v a 2 s . c o 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
/** * For decomposing the energies of the original (0th) rotamers without * computing the entire energy matrix.//from ww w .j a v a2 s .c o m */ public void decomposeOriginalParallel() { 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 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); logIfMaster(String.format(" AMOEBA: %16.5f", totalEnergy)); 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())); } logIfMaster(String.format(" Backbone: %16.5f", localBackboneEnergy)); decomposeOriginal = true; allocateEliminationMemory(allResiduesArray); rotamerEnergies(allResiduesArray); if (master) { for (int i = 0; i < nRes; i++) { Residue ri = residues[i]; localSelfEnergy[i] = selfEnergy[i][0]; residueEnergy[0][i] = localSelfEnergy[i]; logger.info(String.format(" Self %s: %16.5f", ri, localSelfEnergy[i])); } for (int i = 0; i < nRes; i++) { Residue ri = residues[i]; for (int j = i + 1; j < nRes; j++) { Residue rj = residues[j]; pairEnergy[i][j] = twoBodyEnergy[i][0][j][0]; 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; } } if (threeBodyTerm) { for (int i = 0; i < nRes; i++) { Residue ri = residues[i]; for (int j = i + 1; j < nRes; j++) { Residue rj = residues[j]; for (int k = j + 1; k < nRes; k++) { Residue rk = residues[k]; double dist = trimerDistance(i, 0, j, 0, k, 0); triEnergy[i][j][k] = threeBodyEnergy[i][0][j][0][k][0]; double thirdTrimer = triEnergy[i][j][k] / 3.0; residueEnergy[2][i] += thirdTrimer; residueEnergy[2][j] += thirdTrimer; residueEnergy[2][k] += thirdTrimer; if (triEnergy[i][j][k] != 0.0) { logger.info( String.format(" Tri %s %s %s: %16.5f", ri, rj, rk, triEnergy[i][j][k])); } 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 if (dist > threeBodyCutoffDist) { 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; } else { String m = String.format( " Zero trimer energy inside cutoff: %s %s %s at %1.5f Angstroms.", ri, rj, rk, dist); logger.warning(m); } } } } } for (int i = 0; i < nRes; i++) { turnOnAtoms(residues[i]); } decomposePrint(residues, totalEnergy, localBackboneEnergy, residueEnergy); } decomposeOriginal = false; }
From source file:org.broadinstitute.gatk.utils.variant.GATKVariantContextUtils.java
/** * Synchronized code to ensure that {@link #NOCALL_LISTS} has enough entries beyod the requested ploidy * @param capacity the requested ploidy. *//*www . ja v a 2 s . co m*/ private static synchronized void ensureNoCallListsCapacity(final int capacity) { final int currentCapacity = NOCALL_LISTS.length - 1; if (currentCapacity >= capacity) return; NOCALL_LISTS = Arrays.copyOf(NOCALL_LISTS, Math.max(capacity, currentCapacity << 1) + 1); for (int i = currentCapacity + 1; i < NOCALL_LISTS.length; i++) NOCALL_LISTS[i] = Collections.nCopies(i, Allele.NO_CALL); }
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 w w.j a va2 s. com * @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]); } }
From source file:org.finra.herd.service.BusinessObjectDefinitionServiceIndexTest.java
@Test public void testUpdateSearchIndexDocumentBusinessObjectDefinitionUpdateIdListSizeGreaterThanChunkSize() throws Exception { // Create two lists of business object definition entities. List<List<BusinessObjectDefinitionEntity>> businessObjectDefinitionEntities = Arrays.asList( Collections.singletonList(businessObjectDefinitionDaoTestHelper .createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, businessObjectDefinitionServiceTestHelper.getNewAttributes())), Collections.singletonList( businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE_2, BDEF_NAME_2, DATA_PROVIDER_NAME_2, BDEF_DESCRIPTION_2, businessObjectDefinitionServiceTestHelper.getNewAttributes2()))); // Create a list of business object definition ids that would require to be processed in chunks. List<Integer> businessObjectDefinitionIds = new ArrayList<>(); businessObjectDefinitionIds.addAll(Collections .nCopies(BusinessObjectDefinitionServiceImpl.UPDATE_SEARCH_INDEX_DOCUMENT_CHUNK_SIZE + 1, ID)); // Mock the external calls. when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_INDEX_NAME, String.class)) .thenReturn(SEARCH_INDEX_NAME); when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)) .thenReturn(SEARCH_INDEX_DOCUMENT_TYPE); when(businessObjectDefinitionDao.getAllBusinessObjectDefinitionsByIds(businessObjectDefinitionIds.subList(0, BusinessObjectDefinitionServiceImpl.UPDATE_SEARCH_INDEX_DOCUMENT_CHUNK_SIZE))) .thenReturn(businessObjectDefinitionEntities.get(0)); when(businessObjectDefinitionDao.getAllBusinessObjectDefinitionsByIds(businessObjectDefinitionIds.subList( BusinessObjectDefinitionServiceImpl.UPDATE_SEARCH_INDEX_DOCUMENT_CHUNK_SIZE, businessObjectDefinitionIds.size()))).thenReturn(businessObjectDefinitionEntities.get(1)); when(businessObjectDefinitionHelper/*from www. j a va 2 s . co m*/ .safeObjectMapperWriteValueAsString(businessObjectDefinitionEntities.get(0).get(0))) .thenReturn(JSON_STRING); when(businessObjectDefinitionHelper .safeObjectMapperWriteValueAsString(businessObjectDefinitionEntities.get(1).get(0))) .thenReturn(JSON_STRING); // Call the method under test. businessObjectDefinitionService.updateSearchIndexDocumentBusinessObjectDefinition( new SearchIndexUpdateDto(MESSAGE_TYPE_BUSINESS_OBJECT_DEFINITION_UPDATE, businessObjectDefinitionIds, SEARCH_INDEX_UPDATE_TYPE_UPDATE)); // Verify the external calls. verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_INDEX_NAME, String.class); verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); verify(businessObjectDefinitionDao).getAllBusinessObjectDefinitionsByIds(businessObjectDefinitionIds .subList(0, BusinessObjectDefinitionServiceImpl.UPDATE_SEARCH_INDEX_DOCUMENT_CHUNK_SIZE)); verify(businessObjectDefinitionDao).getAllBusinessObjectDefinitionsByIds(businessObjectDefinitionIds .subList(BusinessObjectDefinitionServiceImpl.UPDATE_SEARCH_INDEX_DOCUMENT_CHUNK_SIZE, businessObjectDefinitionIds.size())); verify(businessObjectDefinitionHelper) .safeObjectMapperWriteValueAsString(businessObjectDefinitionEntities.get(0).get(0)); verify(businessObjectDefinitionHelper) .safeObjectMapperWriteValueAsString(businessObjectDefinitionEntities.get(1).get(0)); verify(indexFunctionsDao, times(2)).updateIndexDocuments(eq(SEARCH_INDEX_NAME), eq(SEARCH_INDEX_DOCUMENT_TYPE), Matchers.<Map<String, String>>any()); verifyNoMoreInteractionsHelper(); }
From source file:ffx.algorithms.RotamerOptimization.java
private double independent(List<Residue> residues) { if (x == null) { Atom atoms[] = molecularAssembly.getAtomArray(); int nAtoms = atoms.length; x = new double[nAtoms * 3]; }//from www. j a v a2 s . c om double e = Double.MAX_VALUE; List<Residue> rList = new ArrayList<>(Collections.nCopies(1, null)); for (Residue residue : residues) { rList.set(0, residue); logger.info(String.format(" Optimizing %s side-chain.", residue)); Rotamer[] rotamers = residue.getRotamers(library); potential.getCoordinates(x); e = Double.MAX_VALUE; int bestRotamer = -1; for (int j = 0; j < rotamers.length; j++) { Rotamer rotamer = rotamers[j]; RotamerLibrary.applyRotamer(residue, rotamer); if (algorithmListener != null) { algorithmListener.algorithmUpdate(molecularAssembly); } double newE = currentEnergy(rList); if (newE < e) { bestRotamer = j; } } if (bestRotamer > -1) { Rotamer rotamer = rotamers[bestRotamer]; RotamerLibrary.applyRotamer(residue, rotamer); } if (algorithmListener != null) { algorithmListener.algorithmUpdate(molecularAssembly); } if (terminate) { logger.info(String.format("\n Terminating after residue %s.\n", residue)); break; } } return e; }
From source file:ffx.algorithms.RotamerOptimization.java
/** * Turn off non-bonded contributions from all residues except for one. * Compute the self-energy for each residue relative to the backbone * contribution./*from w ww .j ava 2 s . c o m*/ * * @param residues A list of residues that we undergo rotamer optimization. * @return template energy */ private double rotamerEnergies(Residue residues[]) { if (residues == null) { logger.warning(" Attempt to compute rotamer energies for an empty array of residues."); return 0.0; } int nResidues = residues.length; Atom atoms[] = molecularAssembly.getAtomArray(); int nAtoms = atoms.length; /** * Initialize all atoms to be used. */ for (int i = 0; i < nAtoms; i++) { atoms[i].setUse(true); } if (parallelEnergies) { if (!usingBoxOptimization) { energiesToWrite = Collections.synchronizedList(new ArrayList<String>()); receiveThread = new ReceiveThread(residues); receiveThread.start(); if (master && writeEnergyRestart && printFiles) { energyWriterThread = new EnergyWriterThread(receiveThread); energyWriterThread.start(); } } int loaded = 0; if (loadEnergyRestart) { if (usingBoxOptimization) { loaded = loadEnergyRestart(energyRestartFile, residues, boxLoadIndex, boxLoadCellIndices); } else { loaded = loadEnergyRestart(energyRestartFile, residues); } } SinglesEnergyRegion singlesRegion = new SinglesEnergyRegion(energyWorkerTeam.getThreadCount(), residues); PairsEnergyRegion pairsRegion = new PairsEnergyRegion(energyWorkerTeam.getThreadCount(), residues); TriplesEnergyRegion triplesRegion = new TriplesEnergyRegion(energyWorkerTeam.getThreadCount(), residues); QuadsEnergyRegion quadsRegion = new QuadsEnergyRegion(energyWorkerTeam.getThreadCount(), residues); try { if (loaded < 1) { jobMapSingles.clear(); // allocate selfEnergy int singleJobIndex = 0; selfEnergy = new double[nResidues][]; for (int i = 0; i < nResidues; i++) { Residue resi = residues[i]; Rotamer roti[] = resi.getRotamers(library); selfEnergy[i] = new double[roti.length]; for (int ri = 0; ri < roti.length; ri++) { if (!check(i, ri)) { //logIfMaster(String.format("(sdl %d) singleJob %d: %d %d", BOXNUM, singleJobIndex, i, ri)); Integer selfJob[] = { i, ri }; if (decomposeOriginal && ri != 0) { continue; } jobMapSingles.put(singleJobIndex++, selfJob); } } } } // broadcast that this proc is done with startup and allocation; ready for singles boolean thisProcReady = true; BooleanBuf thisProcReadyBuf = BooleanBuf.buffer(thisProcReady); multicastBuf(thisProcReadyBuf); // launch parallel singles calculation while (!readyForSingles) { Thread.sleep(POLLING_FREQUENCY); } energyWorkerTeam.execute(singlesRegion); if (loaded < 2) { jobMapPairs.clear(); // allocate twoBodyEnergy and create jobs int pairJobIndex = 0; twoBodyEnergy = new double[nResidues][][][]; for (int i = 0; i < nResidues; i++) { Residue resi = residues[i]; Rotamer roti[] = resi.getRotamers(library); twoBodyEnergy[i] = new double[roti.length][][]; for (int ri = 0; ri < roti.length; ri++) { if (check(i, ri)) { continue; } twoBodyEnergy[i][ri] = new double[nResidues][]; for (int j = i + 1; j < nResidues; j++) { Residue resj = residues[j]; Rotamer rotj[] = resj.getRotamers(library); twoBodyEnergy[i][ri][j] = new double[rotj.length]; for (int rj = 0; rj < rotj.length; rj++) { /*if (check(j, rj) || check(i, ri, j, rj)) { continue; }*/ if (checkToJ(i, ri, j, rj)) { continue; } //logIfMaster(String.format("(sdl %d) pairJob %d: %d %d %d %d", BOXNUM, pairJobIndex, i, ri, j, rj)); Integer pairJob[] = { i, ri, j, rj }; if (decomposeOriginal && (ri != 0 || rj != 0)) { continue; } jobMapPairs.put(pairJobIndex++, pairJob); } } } } } // broadcast that this proc is done with pruning and allocation; ready for pairs multicastBuf(thisProcReadyBuf); // launch parallel twoBody calculation while (!readyForPairs) { Thread.sleep(POLLING_FREQUENCY); } energyWorkerTeam.execute(pairsRegion); if (threeBodyTerm) { if (loaded < 3) { jobMapTrimers.clear(); // allocate threeBodyEnergy and create jobs int trimerJobIndex = 0; threeBodyEnergy = new double[nResidues][][][][][]; for (int i = 0; i < nResidues; i++) { Residue resi = residues[i]; Rotamer roti[] = resi.getRotamers(library); threeBodyEnergy[i] = new double[roti.length][][][][]; for (int ri = 0; ri < roti.length; ri++) { if (check(i, ri)) { continue; } threeBodyEnergy[i][ri] = new double[nResidues][][][]; for (int j = i + 1; j < nResidues; j++) { Residue resj = residues[j]; Rotamer rotj[] = resj.getRotamers(library); threeBodyEnergy[i][ri][j] = new double[rotj.length][][]; for (int rj = 0; rj < rotj.length; rj++) { /*if (check(j, rj) || check(i, ri, j, rj)) { continue; }*/ if (checkToJ(i, ri, j, rj)) { continue; } threeBodyEnergy[i][ri][j][rj] = new double[nResidues][]; for (int k = j + 1; k < nResidues; k++) { Residue resk = residues[k]; Rotamer rotk[] = resk.getRotamers(library); threeBodyEnergy[i][ri][j][rj][k] = new double[rotk.length]; for (int rk = 0; rk < rotk.length; rk++) { /*if (check(k, rk) || check(i, ri, k, rk) || check(j, rj, k, rk) || check(i, ri, j, rj, k, rk)) { continue; }*/ if (checkToK(i, ri, j, rj, k, rk)) { continue; } //logIfMaster(String.format("(sdl %d) trimerJob %d: %d %d %d %d %d %d", BOXNUM, trimerJobIndex, i, ri, j, rj, k, rk)); Integer trimerJob[] = { i, ri, j, rj, k, rk }; if (decomposeOriginal && (ri != 0 || rj != 0 || rk != 0)) { continue; } jobMapTrimers.put(trimerJobIndex++, trimerJob); } } } } } } } // broadcast that this proc is done with pruning and allocation; ready for trimers multicastBuf(thisProcReadyBuf); // launch parallel threeBody calculation while (!readyForTrimers) { Thread.sleep(POLLING_FREQUENCY); } energyWorkerTeam.execute(triplesRegion); } if (computeQuads) { logger.info(" Creating quad jobs..."); jobMapQuads.clear(); boolean maxedOut = false; // create quad jobs (no memory allocation) int quadJobIndex = 0; for (int i = 0; i < nResidues; i++) { Residue resi = residues[i]; Rotamer roti[] = resi.getRotamers(library); for (int ri = 0; ri < roti.length; ri++) { if (check(i, ri)) { continue; } for (int j = i + 1; j < nResidues; j++) { Residue resj = residues[j]; Rotamer rotj[] = resj.getRotamers(library); for (int rj = 0; rj < rotj.length; rj++) { /*if (check(j, rj) || check(i, ri, j, rj)) { continue; }*/ if (checkToJ(i, ri, j, rj)) { continue; } for (int k = j + 1; k < nResidues; k++) { Residue resk = residues[k]; Rotamer rotk[] = resk.getRotamers(library); for (int rk = 0; rk < rotk.length; rk++) { /*if (check(k, rk) || check(i, ri, k, rk) || check(j, rj, k, rk) || check(i, ri, j, rj, k, rk)) { continue; }*/ if (checkToK(i, ri, j, rj, k, rk)) { continue; } for (int l = k + 1; l < nResidues; l++) { Residue resl = residues[l]; Rotamer rotl[] = resl.getRotamers(library); for (int rl = 0; rl < rotl.length; rl++) { /*if (check(l, rl) || check(i, ri, l, rl) || check(j, rj, l, rl) || check(k, rk, l, rl) || check(i, ri, j, rj, l, rl) || check(i, ri, k, rk, l, rl) || check(j, rj, k, rk, l, rl)) { continue; }*/ if (checkToL(i, ri, j, rj, k, rk, l, rl)) { continue; } Integer quadJob[] = { i, ri, j, rj, k, rk, l, rl }; if (decomposeOriginal && (ri != 0 || rj != 0 || rk != 0 || rl != 0)) { continue; } jobMapQuads.put(quadJobIndex++, quadJob); if (jobMapQuads.size() > quadMaxout) { maxedOut = true; break; } } if (maxedOut) { break; } } if (maxedOut) { break; } } if (maxedOut) { break; } } if (maxedOut) { break; } } if (maxedOut) { break; } } if (maxedOut) { break; } } if (maxedOut) { break; } } // broadcast that this proc is done with pruning and allocation; ready for quads // logger.info(String.format(" Proc %d broadcasting ready for quads.", world.rank())); multicastBuf(thisProcReadyBuf); // launch parallel threeBody calculation int waiting = 0; while (!readyForQuads) { Thread.sleep(POLLING_FREQUENCY); } logger.info(String.format(" Running quads: %d jobs.", jobMapQuads.size())); energyWorkerTeam.execute(quadsRegion); } } catch (Exception ex) { String message = " Exception computing rotamer energies in parallel."; logger.log(Level.SEVERE, message, ex); } finally { // stop receive and energyWriter threads // receiveThread.die(); } // Turn on all atoms. for (int i = 0; i < atoms.length; i++) { atoms[i].setUse(true); } // Print the energy with all rotamers in their default conformation. if (verboseEnergies && master) { double defaultEnergy = currentEnergy(residues); logger.info( String.format(" Energy of the system with rotamers in their default conformation: %16.8f", defaultEnergy)); } return backboneEnergy; } // endif(parallelEnergies) // TODO: deprecate the rest of the rotamerEnergies() method; the parallel form should work (better) in all scenarios // Store coordinates: will be useful for nucleic acids. ArrayList<Residue> currentResidueList = new ArrayList<>(); currentResidueList.addAll(Arrays.asList(residues)); ResidueState[] origCoordinates = ResidueState.storeAllCoordinates(currentResidueList); //double[][][] originalAtomicCoordinates = storeCoordinates(currentResidueList); for (int i = 0; i < nResidues; i++) { Residue residue = residues[i]; Rotamer rotamers[] = residue.getRotamers(library); /* * Place each AA residue into its zeroth rotamer. * * The default state of NA residues will be original coordinates. * These original coordinates are usually BUT NOT ALWAYS default PDB * coordinates. The reason for this is that the zeroth rotamer for * nucleic acids is frequently a very poor baseline, so one gets * enormous backbone and self energies. * * This would not affect the rigor of the DEE algorithm, but it * makes it difficult to tell when the program is going berserk and * throwing crazy energies. * * The primary exception: if increment is smaller than window size, * some NA residues will be in rotamers assigned by the prior window. * This is still a fairly reasonable baseline. */ switch (residue.getResidueType()) { case NA: break; case AA: default: RotamerLibrary.applyRotamer(residue, rotamers[0]); break; } // RotamerLibrary.applyRotamer(residue, rotamers[0]); // Turn off all side-chain atoms that will be optimized. turnOffAtoms(residue); } /** * Initialize all atoms to be used. */ boolean useOrigCoordsRot = library.getUsingOrigCoordsRotamer(); // Compute the backbone energy. List<Residue> rList = new ArrayList<>(Collections.nCopies(4, null)); try { backboneEnergy = currentEnergy(rList, false); } catch (ArithmeticException ex) { logger.severe(String.format("FFX shutting down: error in calculation of backbone energy %s", ex.getMessage())); } logger.info(String.format(" Backbone energy: %16.8f\n", backboneEnergy)); // Compute the self-energy for each rotamer of each residue selfEnergy = new double[nResidues][]; for (int i = 0; i < nResidues; i++) { Residue residue = residues[i]; rList.set(0, residue); Rotamer rotamers[] = residue.getRotamers(library); int nrot = rotamers.length; // Create space for this residue's rotamer self-energies. selfEnergy[i] = new double[nrot]; // Turn on this residue's side-chain atoms turnOnAtoms(residue); // Loop over rotamers computing self-energies. double minEnergy = Double.MAX_VALUE; for (int ri = 0; ri < nrot; ri++) { if (pruneClashes && check(i, ri) && !(useOrigCoordsRot && ri == 0)) { continue; } Rotamer rotamer = rotamers[ri]; RotamerLibrary.applyRotamer(residue, rotamer); selfEnergy[i][ri] = currentEnergy(rList) - backboneEnergy; logger.info(String.format(" Self-energy %s %d: %16.8f", residue, ri, self(i, ri))); if (algorithmListener != null) { algorithmListener.algorithmUpdate(molecularAssembly); } if (self(i, ri) < minEnergy) { minEnergy = self(i, ri); } } if (pruneClashes) { for (int ri = 0; ri < nrot; ri++) { if (residue.getResidueType() == NA) { if (!check(i, ri) && (self(i, ri) > (minEnergy + (clashThreshold * pruningFactor * singletonNAPruningFactor)))) { logger.info(String.format(" Clash for rotamer %s %d: %16.8f >> %16.8f", residue, ri, self(i, ri), minEnergy)); eliminateRotamer(residues, i, ri, print); } } else if (!check(i, ri) && (self(i, ri) > (minEnergy + clashThreshold))) { // don't prune orig-coords rotamers if (!(useOrigCoordsRot && ri == 0)) { logger.info(String.format(" Clash for rotamer %s %d: %16.8f >> %16.8f", residue, ri, self(i, ri), minEnergy)); eliminateRotamer(residues, i, ri, print); } } } } // Reset the residue to its default conformation. if (residue.getResidueType() == NA) { residue.revertState(origCoordinates[i]); //revertSingleResidueCoordinates(residue, originalAtomicCoordinates[i]); } else { RotamerLibrary.applyRotamer(residue, rotamers[0]); } // Turn off the side-chain turnOffAtoms(residue); } // Compute the pair-energy for each pair of rotamers twoBodyEnergy = new double[nResidues][][][]; for (int i = 0; i < nResidues - 1; i++) { Residue residuei = residues[i]; rList.set(0, residuei); Rotamer rotamersi[] = residuei.getRotamers(library); int indexI = allResiduesList.indexOf(residuei); // Turn on residue i turnOnAtoms(residuei); int ni = rotamersi.length; twoBodyEnergy[i] = new double[ni][][]; for (int ri = 0; ri < ni; ri++) { if (pruneClashes && check(i, ri) && !(useOrigCoordsRot && ri == 0)) { continue; } Rotamer rotameri = rotamersi[ri]; RotamerLibrary.applyRotamer(residuei, rotameri); twoBodyEnergy[i][ri] = new double[nResidues][]; for (int j = i + 1; j < nResidues; j++) { Residue residuej = residues[j]; rList.set(1, residuej); Rotamer rotamersj[] = residuej.getRotamers(library); int indexJ = allResiduesList.indexOf(residuej); turnOnAtoms(residuej); // Loop over residue j's rotamers and compute pairwise energies. int nj = rotamersj.length; twoBodyEnergy[i][ri][j] = new double[nj]; for (int rj = 0; rj < nj; rj++) { // don't prune orig-coords rotamers if (pruneClashes && (check(j, rj) || check(i, ri, j, rj)) && !(useOrigCoordsRot && ri == 0 && rj == 0)) { continue; } Rotamer rotamerj = rotamersj[rj]; RotamerLibrary.applyRotamer(residuej, rotamerj); if (distanceMatrix != null) { double dist = checkDistanceMatrix(indexI, ri, indexJ, rj); if (dist < superpositionThreshold) { twoBodyEnergy[i][ri][j][rj] = 1.0E100; logger.info(String.format( " Pair energy %s %d, %s %d: set to 1.0E100 at distance %13.6f Ang < %5.3f Ang", residuei, ri, residuej, rj, dist, superpositionThreshold)); } else { twoBodyEnergy[i][ri][j][rj] = currentEnergy(rList) - self(i, ri) - self(j, rj) - backboneEnergy; logger.info( String.format(" Pair energy %s %d, %s %d: %16.8f at distance %10.3f Ang", residuei, ri, residuej, rj, pair(i, ri, j, rj), dist)); } } else { twoBodyEnergy[i][ri][j][rj] = currentEnergy(rList) - self(i, ri) - self(j, rj) - backboneEnergy; logger.info(String.format(" Pair energy %s %d, %s %d: %16.8f.", residuei, ri, residuej, rj, pair(i, ri, j, rj))); } if (algorithmListener != null) { algorithmListener.algorithmUpdate(molecularAssembly); } } // Reset the residue to its default conformation. if (residuej.getResidueType() == NA) { residuej.revertState(origCoordinates[j]); //revertSingleResidueCoordinates(residuej, originalAtomicCoordinates[j]); } else { RotamerLibrary.applyRotamer(residuej, rotamersj[0]); } // RotamerLibrary.applyRotamer(residuej, rotamersj[0]); turnOffAtoms(residuej); } } // Reset the residue to its default conformation. if (residuei.getResidueType() == NA) { residuei.revertState(origCoordinates[i]); //revertSingleResidueCoordinates(residuei, originalAtomicCoordinates[i]); } else { RotamerLibrary.applyRotamer(residuei, rotamersi[0]); } turnOffAtoms(residuei); } if (prunePairClashes) { prunePairClashes(residues); } // Prune each rotamer that clashes with all rotamers from a 2nd residue. /*if (prunePairClashes) { for (int i = 0; i < nResidues - 1; i++) { Residue resi = residues[i]; Rotamer[] roti = resi.getRotamers(library); int ni = roti.length; for (int j = i + 1; j < nResidues; j++) { Residue resj = residues[j]; Rotamer[] rotj = resj.getRotamers(library); int nj = rotj.length; double minPair = Double.MAX_VALUE; for (int ri = 0; ri < ni; ri++) { if (check(i, ri)) { continue; } for (int rj = 0; rj < nj; rj++) { if (check(j, rj)) { continue; } if (minPair > (pair(i, ri, j, rj) + self(i, ri) + self(j, rj))) { minPair = (pair(i, ri, j, rj) + self(i, ri) + self(j, rj)); } } } // Check for elimination of any rotamer ri. for (int ri = 0; ri < ni; ri++) { if (check(i, ri)) { continue; } double eliminate = Double.MAX_VALUE; for (int rj = 0; rj < nj; rj++) { if (check(j, rj)) { continue; } if ((pair(i, ri, j, rj) + self(i, ri) + self(j, rj)) < eliminate) { eliminate = (pair(i, ri, j, rj) + self(i, ri) + self(j, rj)); } } // Prune based on clash threshold and the appropriate // pruning factor (1.0 for AA pairs, pF for NA pairs, // arithmetic mean for AA-NA pairs). if (resi.getResidueType() == NA && resj.getResidueType() == NA) { if (eliminate > (minPair + (pairClashThreshold * pruningFactor))) { logger.info(String.format( " Pruning rotamer %s %d that clashes with all %s rotamers %16.8f >> %16.8f.", resi, ri, resj, eliminate, minPair + (pairClashThreshold * pruningFactor))); eliminateRotamer(residues, i, ri, print); } } else if (resi.getResidueType() == NA || resj.getResidueType() == NA) { if (eliminate > (minPair + (pairClashThreshold * pairHalfPruningFactor))) { logger.info(String.format( " Pruning rotamer %s %d that clashes with all %s rotamers %16.8f >> %16.8f.", resi, ri, resj, eliminate, minPair + (pairClashThreshold * pairHalfPruningFactor))); eliminateRotamer(residues, i, ri, print); } } else { if (eliminate > (minPair + pairClashThreshold)) { // don't prune orig-coords rotamers if (!(useOrigCoordsRot && ri == 0)) { logger.info(String.format( " Pruning rotamer %s %d that clashes with all %s rotamers %16.8f >> %16.8f.", resi, ri, resj, eliminate, minPair + pairClashThreshold)); eliminateRotamer(residues, i, ri, print); } } } } // Check for elimination of any rotamer rj. for (int rj = 0; rj < nj; rj++) { if (check(j, rj)) { continue; } double eliminate = Double.MAX_VALUE; for (int ri = 0; ri < ni; ri++) { if (check(i, ri)) { continue; } if ((pair(i, ri, j, rj) + self(i, ri) + self(j, rj)) < eliminate) { eliminate = (pair(i, ri, j, rj) + self(i, ri) + self(j, rj)); } } if (resi.getResidueType() == NA && resj.getResidueType() == NA) { if (eliminate > (minPair + (pairClashThreshold * pruningFactor))) { logger.info(String.format( " Pruning rotamer %s %d that clashes with all %s rotamers %16.8f >> %16.8f.", resj, rj, resi, eliminate, minPair + (pairClashThreshold * pruningFactor))); eliminateRotamer(residues, j, rj, print); } } else if (resi.getResidueType() == NA || resj.getResidueType() == NA) { if (eliminate > (minPair + (pairClashThreshold * pairHalfPruningFactor))) { logger.info(String.format( " Pruning rotamer %s %d that clashes with all %s rotamers %16.8f >> %16.8f.", resj, rj, resi, eliminate, minPair + (pairClashThreshold * pairHalfPruningFactor))); eliminateRotamer(residues, j, rj, print); } } else { if (eliminate > (minPair + pairClashThreshold)) { // don't prune orig-coords rotamers if (!(useOrigCoordsRot && rj == 0)) { logger.info(String.format( " Pruning rotamer %s %d that clashes with all %s rotamers %16.8f >> %16.8f.", resj, rj, resi, eliminate, minPair + pairClashThreshold)); eliminateRotamer(residues, j, rj, print); } } } } } } } */ // Compute the trimer-energy for each pair of rotamers if (threeBodyTerm) { double[][][][] localDistanceMatrix = new double[nResidues][][][]; if (distance <= 0) { logger.info(" Calculating local distance matrix using non-eliminated rotamers."); localSequentialDistanceMatrix(residues, localDistanceMatrix); } threeBodyEnergy = new double[nResidues][][][][][]; for (int i = 0; i < nResidues - 2; i++) { Residue residuei = residues[i]; rList.set(0, residuei); Rotamer rotamersi[] = residuei.getRotamers(library); turnOnAtoms(residuei); int ni = rotamersi.length; threeBodyEnergy[i] = new double[ni][][][][]; int indexOfI = allResiduesList.indexOf(residuei); for (int ri = 0; ri < ni; ri++) { if (pruneClashes && check(i, ri) && !(ri == 0 && useOrigCoordsRot)) { continue; } Rotamer rotameri = rotamersi[ri]; RotamerLibrary.applyRotamer(residuei, rotameri); //int npairs = residues.length - (i + 1); // TODO: reduce memory use. threeBodyEnergy[i][ri] = new double[nResidues][][][]; for (int j = i + 1; j < nResidues - 1; j++) { Residue residuej = residues[j]; rList.set(1, residuej); Rotamer rotamersj[] = residuej.getRotamers(library); turnOnAtoms(residuej); // Loop over residue j's rotamers and compute pair-wise energies. int nj = rotamersj.length; threeBodyEnergy[i][ri][j] = new double[nj][][]; int indexOfJ = allResiduesList.indexOf(residuej); for (int rj = 0; rj < nj; rj++) { if ((pruneClashes && (check(j, rj)) || (prunePairClashes && check(i, ri, j, rj))) && !(useOrigCoordsRot && (ri == 0 && rj == 0))) { continue; } Rotamer rotamerj = rotamersj[rj]; RotamerLibrary.applyRotamer(residuej, rotamerj); threeBodyEnergy[i][ri][j][rj] = new double[nResidues][]; for (int k = j + 1; k < nResidues; k++) { Residue residuek = residues[k]; rList.set(2, residuek); Rotamer rotamersk[] = residuek.getRotamers(library); turnOnAtoms(residuek); int nk = rotamersk.length; threeBodyEnergy[i][ri][j][rj][k] = new double[nk]; int indexOfK = allResiduesList.indexOf(residuek); for (int rk = 0; rk < nk; rk++) { if ((pruneClashes && (check(k, rk)) || (prunePairClashes && check(i, ri, k, rk)) || (prunePairClashes && check(j, rj, k, rk))) && !(useOrigCoordsRot && (ri == 0 && rj == 0 && rk == 0))) { continue; } double dij; double dik; double djk; if (distance > 0) { /* * Distance matrix is asymmetric (it will have 4-6, but * not 6-4 stored). The present implementation sorts * windows beforehand, but this double-checks to ensure * the proper address in distanceMatrix is being called. */ dij = checkDistanceMatrix(indexOfI, ri, indexOfJ, rj); dik = checkDistanceMatrix(indexOfI, ri, indexOfK, rk); djk = checkDistanceMatrix(indexOfJ, rj, indexOfK, rk); /* if (indexOfI > indexOfJ) { dij = distanceMatrix[indexOfJ][rj][indexOfI][ri]; } else { dij = distanceMatrix[indexOfI][ri][indexOfJ][rj]; } if (indexOfI > indexOfK) { dik = distanceMatrix[indexOfK][rk][indexOfI][ri]; } else { dik = distanceMatrix[indexOfI][ri][indexOfK][rk]; } if (indexOfJ > indexOfK) { djk = distanceMatrix[indexOfK][rk][indexOfJ][rj]; } else { djk = distanceMatrix[indexOfJ][rj][indexOfK][rk]; } */ } else { dij = localDistanceMatrix[i][ri][j][rj]; dik = localDistanceMatrix[i][ri][k][rk]; djk = localDistanceMatrix[j][rj][k][rk]; } double dist = Math.min(dij, Math.min(dik, djk)); if (!threeBodyCutoff || (dist < threeBodyCutoffDist)) { if (dist < superpositionThreshold) { threeBodyEnergy[i][ri][j][rj][k][rk] = 1.0E100; logger.info(String.format( " Trimer energy %s %d, %s %d, %s %d: set to 1.0E100 at %13.6f Ang < %5.3f Ang.", residuei, ri, residuej, rj, residuek, rk, dist, superpositionThreshold)); } else { Rotamer rotamerk = rotamersk[rk]; RotamerLibrary.applyRotamer(residuek, rotamerk); threeBodyEnergy[i][ri][j][rj][k][rk] = currentEnergy(rList) - self(i, ri) - self(j, rj) - self(k, rk) - pair(i, ri, j, rj) - pair(i, ri, k, rk) - pair(j, rj, k, rk) - backboneEnergy; logger.info(String.format( " Trimer energy %s %d, %s %d, %s %d: %16.8f at %10.3f Ang.", residuei, ri, residuej, rj, residuek, rk, threeBodyEnergy[i][ri][j][rj][k][rk], dist)); if (algorithmListener != null) { algorithmListener.algorithmUpdate(molecularAssembly); } } } else { logger.info(String.format( " Trimer energy %s %d, %s %d, %s %d: %16.8f at %10.3f Ang.", residuei, ri, residuej, rj, residuek, rk, 0.0, threeBodyCutoffDist)); } } // Reset the residue to its default conformation. if (residuek.getResidueType() == NA) { residuek.revertState(origCoordinates[k]); //revertSingleResidueCoordinates(residuek, originalAtomicCoordinates[k]); } else { RotamerLibrary.applyRotamer(residuek, rotamersk[0]); } turnOffAtoms(residuek); } } // Reset the residue to its default conformation. if (residuej.getResidueType() == NA) { residuej.revertState(origCoordinates[j]); //revertSingleResidueCoordinates(residuej, originalAtomicCoordinates[j]); } else { RotamerLibrary.applyRotamer(residuej, rotamersj[0]); } turnOffAtoms(residuej); } } // Reset the residue to its default conformation. if (residuei.getResidueType() == NA) { residuei.revertState(origCoordinates[i]); //revertSingleResidueCoordinates(residuei, originalAtomicCoordinates[i]); } else { RotamerLibrary.applyRotamer(residuei, rotamersi[0]); } turnOffAtoms(residuei); } } // Turn on all atoms. for (int i = 0; i < nAtoms; i++) { atoms[i].setUse(true); } // Print the energy with all rotamers in their default conformation. if (verboseEnergies) { double defaultEnergy = currentEnergy(residues); logger.info(String.format(" Energy of the system with rotamers in their default conformation: %16.8f", defaultEnergy)); } return backboneEnergy; }
From source file:org.opendatakit.utilities.AbstractODKDatabaseUtilsTest.java
private List<Long> threadTest(final int threadCount, final String tableId, final String rowId, final String colPrefix, final OrderedColumns orderedColumns, final boolean useNewDB, final boolean multipleWrites, final int numOfMultiWrites) throws InterruptedException, ExecutionException { final UniqueIdGenerator domainObject = new UniqueIdGenerator(); Callable<Long> task = new Callable<Long>() { @Override// w w w . j ava2s . com public synchronized Long call() { Long origVal = domainObject.nextId(); int testVal = origVal.intValue(); String testCol = colPrefix + testVal; ContentValues cvValues = null; OdkConnectionInterface dbToUse = db; if (useNewDB) { DbHandle uniqueKey = new DbHandle(AbstractODKDatabaseUtilsTest.class.getSimpleName() + testVal + AndroidConnectFactory.INTERNAL_TYPE_SUFFIX); dbToUse = OdkConnectionFactorySingleton.getOdkConnectionFactoryInterface() .getConnection(getAppName(), uniqueKey); } try { if (multipleWrites) { for (int i = 1; i <= numOfMultiWrites; i++) { cvValues = new ContentValues(); cvValues.put(testCol, i); ODKDatabaseImplUtils.get().updateRowWithId(dbToUse, tableId, orderedColumns, cvValues, rowId, activeUser, RoleConsts.ADMIN_ROLES_LIST, currentLocale); try { Thread.sleep(0); } catch (Exception e) { e.printStackTrace(); } } } else { cvValues = new ContentValues(); cvValues.put(testCol, testVal); ODKDatabaseImplUtils.get().updateRowWithId(dbToUse, tableId, orderedColumns, cvValues, rowId, activeUser, RoleConsts.ADMIN_ROLES_LIST, currentLocale); } } catch (ActionNotAuthorizedException ex) { WebLogger.getLogger(dbToUse.getAppName()).printStackTrace(ex); throw new IllegalStateException(ex); } if (dbToUse != null && useNewDB) { dbToUse.releaseReference(); } return origVal; } }; List<Callable<Long>> tasks = Collections.nCopies(threadCount, task); ExecutorService executorService = Executors.newFixedThreadPool(threadCount); List<Future<Long>> futures = executorService.invokeAll(tasks); List<Long> resultList = new ArrayList<Long>(futures.size()); // Check for exceptions for (Future<Long> future : futures) { // Throws an exception if an exception was thrown by the task. resultList.add(future.get()); } // Validate the IDs assertEquals(threadCount, futures.size()); List<Long> expectedList = new ArrayList<Long>(threadCount); for (long i = 1; i <= threadCount; i++) { expectedList.add(i); } Collections.sort(resultList); assertEquals(expectedList, resultList); return resultList; }