Search in sources :

Example 1 with Structure

use of org.biojava.bio.structure.Structure 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));
    }
}
Also used : IntegerForLoop(edu.rit.pj.IntegerForLoop) PDBFileReader(org.biojava.bio.structure.io.PDBFileReader) ParallelTeam(edu.rit.pj.ParallelTeam) StructurePairAligner(org.biojava.bio.structure.align.StructurePairAligner) IOException(java.io.IOException) ParallelRegion(edu.rit.pj.ParallelRegion) Structure(org.biojava.bio.structure.Structure) File(java.io.File) IOException(java.io.IOException) StructureException(org.biojava.bio.structure.StructureException)

Example 2 with Structure

use of org.biojava.bio.structure.Structure in project ffx by mjschnie.

the class SimplePDBMatcher method loopOverSources.

private FileDoublePair loopOverSources(PDBFileReader reader, StructurePairAligner aligner, Structure matchStructure, String matchName) {
    File bestMatch = sourceFiles[0];
    double rmsd = Double.MAX_VALUE;
    for (File sourceFile : sourceFiles) {
        try {
            Structure sourceStructure = reader.getStructure(sourceFile);
            String sourceName = sourceFile.getName();
            double fileRMSD = checkRMSD(matchStructure, sourceStructure, aligner, matchName, sourceName);
            if (fileRMSD < rmsd) {
                bestMatch = sourceFile;
                rmsd = fileRMSD;
            }
        } catch (IOException ex) {
            logger.warning(String.format(" Source file %s could not be read", sourceFile.toString()));
        }
    }
    logger.info(String.format(" Minimum RMSD for file %s: $11.7f to file %s", matchName, rmsd, bestMatch.getName()));
    return new FileDoublePair(bestMatch, rmsd);
}
Also used : IOException(java.io.IOException) Structure(org.biojava.bio.structure.Structure) File(java.io.File)

Example 3 with Structure

use of org.biojava.bio.structure.Structure 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()));
        }
    }
}
Also used : StructureException(org.biojava.bio.structure.StructureException) Structure(org.biojava.bio.structure.Structure) File(java.io.File)

Example 4 with Structure

use of org.biojava.bio.structure.Structure 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;
}
Also used : DefaultClusteringAlgorithm(com.apporiented.algorithm.clustering.DefaultClusteringAlgorithm) ClusteringAlgorithm(com.apporiented.algorithm.clustering.ClusteringAlgorithm) StructurePairAligner(org.biojava.bio.structure.align.StructurePairAligner) Cluster(com.apporiented.algorithm.clustering.Cluster) IOException(java.io.IOException) SingleLinkageStrategy(com.apporiented.algorithm.clustering.SingleLinkageStrategy) PDBFileReader(org.biojava.bio.structure.io.PDBFileReader) StructureException(org.biojava.bio.structure.StructureException) DefaultClusteringAlgorithm(com.apporiented.algorithm.clustering.DefaultClusteringAlgorithm) AlternativeAlignment(org.biojava.bio.structure.align.pairwise.AlternativeAlignment) AverageLinkageStrategy(com.apporiented.algorithm.clustering.AverageLinkageStrategy) Structure(org.biojava.bio.structure.Structure) LinkageStrategy(com.apporiented.algorithm.clustering.LinkageStrategy) AverageLinkageStrategy(com.apporiented.algorithm.clustering.AverageLinkageStrategy) CompleteLinkageStrategy(com.apporiented.algorithm.clustering.CompleteLinkageStrategy) SingleLinkageStrategy(com.apporiented.algorithm.clustering.SingleLinkageStrategy) CompleteLinkageStrategy(com.apporiented.algorithm.clustering.CompleteLinkageStrategy)

Example 5 with Structure

use of org.biojava.bio.structure.Structure in project ffx by mjschnie.

the class MainPanel method convertInit.

/**
 * Attempts to load from the supplied data structure
 *
 * @param data Data structure to load from
 * @param file Source file
 * @param commandDescription Description of the command that created this
 * file.
 * @return A thread-based UIDataConverter
 */
private UIDataConverter convertInit(Object data, File file, String commandDescription) {
    if (data == null) {
        return null;
    }
    // Create the CompositeConfiguration properties.
    CompositeConfiguration properties = Keyword.loadProperties(file);
    // Create an FFXSystem for this file.
    FFXSystem newSystem = new FFXSystem(file, commandDescription, properties);
    // Create a Force Field.
    forceFieldFilter = new ForceFieldFilter(properties);
    ForceField forceField = forceFieldFilter.parse();
    String[] patches = properties.getStringArray("patch");
    for (String patch : patches) {
        logger.info(" Attempting to read force field patch from " + patch + ".");
        CompositeConfiguration patchConfiguration = new CompositeConfiguration();
        patchConfiguration.addProperty("parameters", patch);
        forceFieldFilter = new ForceFieldFilter(patchConfiguration);
        ForceField patchForceField = forceFieldFilter.parse();
        forceField.append(patchForceField);
        if (RotamerLibrary.addRotPatch(patch)) {
            logger.info(String.format(" Loaded rotamer definitions from patch %s.", patch));
        }
    }
    newSystem.setForceField(forceField);
    ConversionFilter convFilter = null;
    // Decide what parser to use.
    if (biojavaDataFilter.accept(data)) {
        convFilter = new BiojavaFilter((Structure) data, newSystem, forceField, properties);
    } else {
        throw new IllegalArgumentException("Not a recognized data structure.");
    }
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    activeConvFilter = convFilter;
    return new UIDataConverter(data, file, convFilter, this);
}
Also used : ConversionFilter(ffx.potential.parsers.ConversionFilter) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ForceFieldFilter(ffx.potential.parsers.ForceFieldFilter) ForceField(ffx.potential.parameters.ForceField) ForceFieldString(ffx.potential.parameters.ForceField.ForceFieldString) BiojavaFilter(ffx.potential.parsers.BiojavaFilter) Structure(org.biojava.bio.structure.Structure)

Aggregations

Structure (org.biojava.bio.structure.Structure)10 File (java.io.File)5 IOException (java.io.IOException)5 Atom (org.biojava.bio.structure.Atom)3 StructureException (org.biojava.bio.structure.StructureException)3 StructurePairAligner (org.biojava.bio.structure.align.StructurePairAligner)3 PDBFileReader (org.biojava.bio.structure.io.PDBFileReader)3 ForceField (ffx.potential.parameters.ForceField)2 BiojavaFilter (ffx.potential.parsers.BiojavaFilter)2 ForceFieldFilter (ffx.potential.parsers.ForceFieldFilter)2 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)2 AlternativeAlignment (org.biojava.bio.structure.align.pairwise.AlternativeAlignment)2 AverageLinkageStrategy (com.apporiented.algorithm.clustering.AverageLinkageStrategy)1 Cluster (com.apporiented.algorithm.clustering.Cluster)1 ClusteringAlgorithm (com.apporiented.algorithm.clustering.ClusteringAlgorithm)1 CompleteLinkageStrategy (com.apporiented.algorithm.clustering.CompleteLinkageStrategy)1 DefaultClusteringAlgorithm (com.apporiented.algorithm.clustering.DefaultClusteringAlgorithm)1 LinkageStrategy (com.apporiented.algorithm.clustering.LinkageStrategy)1 SingleLinkageStrategy (com.apporiented.algorithm.clustering.SingleLinkageStrategy)1 IntegerForLoop (edu.rit.pj.IntegerForLoop)1