use of org.biojava.bio.structure.io.PDBFileReader in project ffx by mjschnie.
the class SimplePDBMatcher method matchParallel.
public void matchParallel() {
try {
new ParallelTeam().execute(new ParallelRegion() {
@Override
public void run() throws Exception {
execute(0, sourceFiles.length, new IntegerForLoop() {
@Override
public void run(int lb, int ub) {
PDBFileReader reader = new PDBFileReader();
StructurePairAligner aligner = new StructurePairAligner();
for (int i = lb; i <= ub; i++) {
File matchFile = matchFiles[i];
try {
Structure matchStructure = reader.getStructure(matchFiles[i]);
String matchName = matchFile.getName();
matchedSources[i] = loopOverSources(reader, aligner, matchStructure, matchName);
} catch (IOException ex) {
logger.warning(String.format(" Matching failed for file %s", matchFile.getName()));
}
}
}
});
}
});
} catch (Exception ex) {
logger.severe(" Matching in parallel failed.");
}
for (int i = 0; i < matchFiles.length; i++) {
logger.info(String.format(" Match file %s best source: %s at %11.7f A", matchFiles[i].getName(), matchedSources[i].file.getName(), matchedSources[i].rmsd));
}
}
use of org.biojava.bio.structure.io.PDBFileReader in project ffx by mjschnie.
the class PDBFileMatcher method sequentialFixer.
private void sequentialFixer() {
PDBFileReader filereader = new PDBFileReader();
for (int i = 0; i < matchFilePairs.length; i++) {
Long fixTime = -System.nanoTime();
FileFilePair currentPair = matchFilePairs[i];
try {
fixFile(currentPair, filereader);
} catch (IOException ex) {
}
fixTime += System.nanoTime();
fixTimes[i] += fixTime;
}
}
use of org.biojava.bio.structure.io.PDBFileReader in project ffx by mjschnie.
the class ClusterStructures method clusterSequential.
/**
* Performs clustering
*
* @return Final clusters.
*/
private List<Cluster> clusterSequential() {
String[] names = new String[nFiles];
double[][] rmsdDistances = new double[nFiles][nFiles];
PDBFileReader fileReader = new PDBFileReader();
LinkageStrategy ls;
switch(algorithm) {
case CLINK:
ls = new CompleteLinkageStrategy();
break;
case SLINK:
ls = new SingleLinkageStrategy();
break;
case AV_LINK:
default:
ls = new AverageLinkageStrategy();
break;
}
for (int i = 0; i < nFiles; i++) {
// Ensure the diagonal is filled.
rmsdDistances[i][i] = 0.0;
names[i] = String.format("%d", i);
if (i >= cacheStart) {
try {
structureCache[i - cacheStart] = fileReader.getStructure(files[i]);
} catch (IOException ex) {
logger.severe(String.format(" Error in reading file %s: %s", files[i].getName(), ex.toString()));
}
}
}
StructurePairAligner aligner = new StructurePairAligner();
for (int i = 0; i < nFiles; i++) {
Structure structI = null;
try {
structI = accessStructure(i, fileReader);
} catch (IOException ex) {
logger.severe(String.format(" Error in reading file %s: %s", files[i].getName(), ex.toString()));
}
for (int j = i; j < nFiles; j++) {
Structure structJ = null;
try {
structJ = accessStructure(j, fileReader);
} catch (IOException ex) {
logger.severe(String.format(" Error in reading file %s: %s", files[j].getName(), ex.toString()));
}
try {
aligner.align(structI, structJ);
} catch (StructureException ex) {
logger.severe(String.format(" Exception aligning structures " + "%d and %d: %s", i, j, ex.toString()));
}
AlternativeAlignment[] alignments = aligner.getAlignments();
double minRMSD = alignments[0].getRmsd();
for (int k = 1; k < alignments.length; k++) {
double rmsdK = alignments[k].getRmsd();
minRMSD = rmsdK < minRMSD ? rmsdK : minRMSD;
}
rmsdDistances[i][j] = minRMSD;
rmsdDistances[j][i] = minRMSD;
}
}
ClusteringAlgorithm alg = new DefaultClusteringAlgorithm();
Cluster cluster = alg.performClustering(rmsdDistances, names, ls);
List<Cluster> subClusters;
int nClusters = 1;
if (numClusters > 0) {
subClusters = new ArrayList<>(Arrays.asList(cluster));
while (nClusters < numClusters) {
double maxDist = subClusters.get(0).getDistanceValue();
Cluster maxCluster = subClusters.get(0);
for (Cluster subcluster : subClusters) {
double dist = subcluster.getDistanceValue();
if (dist > maxDist) {
maxDist = dist;
maxCluster = subcluster;
}
}
List<Cluster> newClusters = maxCluster.getChildren();
nClusters += (newClusters.size() - 1);
subClusters.addAll(newClusters);
subClusters.remove(maxCluster);
}
logger.severe(" Num clusters not implemented yet.");
} else {
subClusters = getSubclusters(cluster, rmsdCutoff);
nClusters = subClusters.size();
}
assert nClusters == subClusters.size() : " nClusters != subClusters.size()";
return subClusters;
}
use of org.biojava.bio.structure.io.PDBFileReader in project ffx by mjschnie.
the class PDBFileMatcher method sequentialFileMatch.
private void sequentialFileMatch() {
PDBFileReader filereader = new PDBFileReader();
StructurePairAligner aligner = new StructurePairAligner();
// int numSources = sourceFiles.length;
try {
for (int i = 0; i < matchFilePairs.length; i++) {
Long iterTime = -System.nanoTime();
FileFilePair currentFilePair = matchFilePairs[i];
matchFile(currentFilePair, filereader, aligner);
iterationTimes[i] = iterTime + System.nanoTime();
}
} catch (IOException ex) {
logger.severe(String.format(" Exception matching files %s", ex.toString()));
}
}
use of org.biojava.bio.structure.io.PDBFileReader in project ffx by mjschnie.
the class SimplePDBMatcher method match.
public void match() {
PDBFileReader reader = new PDBFileReader();
StructurePairAligner aligner = new StructurePairAligner();
for (int i = 0; i < matchFiles.length; i++) {
File matchFile = matchFiles[i];
try {
Structure matchStructure = reader.getStructure(matchFile);
String matchName = matchFile.getName();
matchedSources[i] = loopOverSources(reader, aligner, matchStructure, matchName);
} catch (IOException ex) {
logger.warning(String.format(" Matching failed for file %s", matchFile.getName()));
}
}
for (int i = 0; i < matchFiles.length; i++) {
logger.info(String.format(" Match file %s best source: %s at %11.7f A", matchFiles[i].getName(), matchedSources[i].file.getName(), matchedSources[i].rmsd));
}
}
Aggregations