use of org.biojava.bio.structure.StructureException in project ffx by mjschnie.
the class PDBFileMatcher method matchFile.
/**
* Interior code of file matching loop: intended to ensure consistency
* between sequential and parallel versions of code.
*
* @param currentFilePair
* @param filereader
* @param aligner
* @throws IOException
*/
private void matchFile(FileFilePair currentFilePair, PDBFileReader filereader, StructurePairAligner aligner) throws IOException {
Structure currentStructure = filereader.getStructure(currentFilePair.getMatchedFile());
currentFilePair.setStructure(currentStructure);
int numSources = sourceFiles.length;
for (int j = 0; j < numSources; j++) {
File currentSource = sourceFiles[j];
Structure sourceStructure = filereader.getStructure(currentSource);
try {
double rmsd = calculateRMSD(currentFilePair, sourceStructure, aligner);
currentFilePair.attemptReplace(currentSource, rmsd);
} catch (StructureException ex) {
logger.warning(String.format(" Error in calculating RMSD for match %s and source %s : %s", currentFilePair.getMatchedFile().getName(), currentSource.getName(), ex.toString()));
}
}
}
use of org.biojava.bio.structure.StructureException 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.StructureException in project ffx by mjschnie.
the class PDBFileMatcher method getMatchingAtom.
/**
* Finds atom1's match in structure2; uses atom1's residue number, atom
* type, and PDB serial number as a guess; if robustMatch is set true, will
* search all Atoms in structure2.
*
* @param atom1 An Atom
* @param structure2 A Structure to search
* @param searchAll Whether to search all Atoms in structure2.
* @return atom1's match in structure2
* @throws IllegalArgumentException If no match can be found.
*/
private Atom getMatchingAtom(Atom atom1, Structure structure2, boolean searchAll) throws IllegalArgumentException {
ResidueNumber res1 = atom1.getGroup().getResidueNumber();
String chainID = res1.getChainId();
Atom atom2 = null;
try {
Chain chain2 = structure2.getChainByPDB(chainID);
Group group2 = chain2.getGroupByPDB(res1);
try {
atom2 = group2.getAtom(atom1.getName());
} catch (StructureException ex) {
if (atom1.getName().equalsIgnoreCase("H")) {
atom2 = group2.getAtom("H1");
} else if (atom1.getName().equalsIgnoreCase("H1")) {
atom2 = group2.getAtom("H");
}
atom2 = group2.getAtom(atom1.getPDBserial());
}
} catch (StructureException ex) {
if (!searchAll) {
throw new IllegalArgumentException("Matching atom not found.");
}
for (Chain chain : structure2.getChains()) {
for (Group group : chain.getAtomGroups()) {
for (Atom atom : group.getAtoms()) {
if (compareAtoms(atom1, atom)) {
return atom2;
}
}
}
}
}
if (atom2 != null && compareAtoms(atom1, atom2)) {
return atom2;
}
throw new IllegalArgumentException("Matching atom not found.");
}
use of org.biojava.bio.structure.StructureException in project ffx by mjschnie.
the class SimplePDBMatcher method checkRMSD.
private double checkRMSD(Structure matchStructure, Structure sourceStructure, StructurePairAligner aligner, String matchName, String sourceName) {
double bestRMSD = Double.MAX_VALUE;
try {
aligner.align(matchStructure, sourceStructure);
AlternativeAlignment[] alignments = aligner.getAlignments();
for (AlternativeAlignment alignment : alignments) {
double alignRMSD = alignment.getRmsd();
bestRMSD = Math.min(alignRMSD, bestRMSD);
}
logger.info(String.format(" Minimum RMSD for match %s source %s: %11.7f", matchName, sourceName, bestRMSD));
} catch (StructureException ex) {
logger.warning(String.format(" Structure exception during match %s source file %s", matchName, sourceName));
}
return bestRMSD;
}
Aggregations