Search in sources :

Example 1 with ForceFieldFilter

use of ffx.potential.parsers.ForceFieldFilter in project ffx by mjschnie.

the class PotentialsFileOpener method run.

/**
 * At present, parses the PDB, XYZ, INT, or ARC file from the constructor
 * and creates MolecularAssembly and properties objects.
 */
@Override
public void run() {
    int numFiles = allFiles.length;
    for (int i = 0; i < numFiles; i++) {
        File fileI = allFiles[i];
        Path pathI = allPaths[i];
        MolecularAssembly assembly = new MolecularAssembly(pathI.toString());
        assembly.setFile(fileI);
        CompositeConfiguration properties = Keyword.loadProperties(fileI);
        ForceFieldFilter 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();
            try {
                patchConfiguration.addProperty("propertyFile", fileI.getCanonicalPath());
            } catch (IOException e) {
                logger.log(Level.INFO, " Error loading {0}.", patch);
            }
            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));
            }
        }
        assembly.setForceField(forceField);
        if (new PDBFileFilter().acceptDeep(fileI)) {
            filter = new PDBFilter(fileI, assembly, forceField, properties);
        } else if (new XYZFileFilter().acceptDeep(fileI)) {
            filter = new XYZFilter(fileI, assembly, forceField, properties);
        } else if (new INTFileFilter().acceptDeep(fileI) || new ARCFileFilter().accept(fileI)) {
            filter = new INTFilter(fileI, assembly, forceField, properties);
        } else {
            throw new IllegalArgumentException(String.format(" File %s could not be recognized as a valid PDB, XYZ, INT, or ARC file.", pathI.toString()));
        }
        /* If on-open mutations requested, add them to filter. */
        if (mutationsToApply != null && !mutationsToApply.isEmpty()) {
            if (!(filter instanceof PDBFilter)) {
                throw new UnsupportedOperationException("Applying mutations during open only supported by PDB filter atm.");
            }
            ((PDBFilter) filter).mutate(mutationsToApply);
        }
        if (filter.readFile()) {
            if (!(filter instanceof PDBFilter)) {
                Utilities.biochemistry(assembly, filter.getAtomList());
            }
            filter.applyAtomProperties();
            assembly.finalize(true, forceField);
            // ForceFieldEnergy energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints());
            ForceFieldEnergy energy;
            if (nThreads > 0) {
                energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints(), nThreads);
            } else {
                energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints());
            }
            assembly.setPotential(energy);
            assemblies.add(assembly);
            propertyList.add(properties);
            if (filter instanceof PDBFilter) {
                PDBFilter pdbFilter = (PDBFilter) filter;
                List<Character> altLocs = pdbFilter.getAltLocs();
                if (altLocs.size() > 1 || altLocs.get(0) != ' ') {
                    StringBuilder altLocString = new StringBuilder("\n Alternate locations found [ ");
                    for (Character c : altLocs) {
                        // Do not report the root conformer.
                        if (c == ' ') {
                            continue;
                        }
                        altLocString.append(format("(%s) ", c));
                    }
                    altLocString.append("]\n");
                    logger.info(altLocString.toString());
                }
                /**
                 * Alternate conformers may have different chemistry, so
                 * they each need to be their own MolecularAssembly.
                 */
                for (Character c : altLocs) {
                    if (c.equals(' ') || c.equals('A')) {
                        continue;
                    }
                    MolecularAssembly newAssembly = new MolecularAssembly(pathI.toString());
                    newAssembly.setForceField(assembly.getForceField());
                    pdbFilter.setAltID(newAssembly, c);
                    pdbFilter.clearSegIDs();
                    if (pdbFilter.readFile()) {
                        String fileName = assembly.getFile().getAbsolutePath();
                        newAssembly.setName(FilenameUtils.getBaseName(fileName) + " " + c);
                        filter.applyAtomProperties();
                        newAssembly.finalize(true, assembly.getForceField());
                        // energy = ForceFieldEnergy.energyFactory(newAssembly, filter.getCoordRestraints());
                        if (nThreads > 0) {
                            energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints(), nThreads);
                        } else {
                            energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints());
                        }
                        newAssembly.setPotential(energy);
                        assemblies.add(newAssembly);
                    }
                }
            }
        } else {
            logger.warning(String.format(" Failed to read file %s", fileI.toString()));
        }
    }
    activeAssembly = assemblies.get(0);
    activeProperties = propertyList.get(0);
}
Also used : Path(java.nio.file.Path) PDBFileFilter(ffx.potential.parsers.PDBFileFilter) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ForceFieldFilter(ffx.potential.parsers.ForceFieldFilter) ARCFileFilter(ffx.potential.parsers.ARCFileFilter) ForceFieldEnergy(ffx.potential.ForceFieldEnergy) IOException(java.io.IOException) XYZFileFilter(ffx.potential.parsers.XYZFileFilter) MolecularAssembly(ffx.potential.MolecularAssembly) INTFileFilter(ffx.potential.parsers.INTFileFilter) ForceField(ffx.potential.parameters.ForceField) XYZFilter(ffx.potential.parsers.XYZFilter) File(java.io.File) PDBFilter(ffx.potential.parsers.PDBFilter) INTFilter(ffx.potential.parsers.INTFilter)

Example 2 with ForceFieldFilter

use of ffx.potential.parsers.ForceFieldFilter in project ffx by mjschnie.

the class MainPanel method openInit.

/**
 * Attempts to load the supplied file
 *
 * @param files Files to open
 * @param commandDescription Description of the command that created this
 * file.
 * @return a {@link java.lang.Thread} object.
 */
private UIFileOpener openInit(List<File> files, String commandDescription) {
    if (files == null) {
        return null;
    }
    File file = new File(FilenameUtils.normalize(files.get(0).getAbsolutePath()));
    // Set the Current Working Directory based on this file.
    setCWD(file.getParentFile());
    // Get "filename" from "filename.extension".
    String name = file.getName();
    String extension = FilenameUtils.getExtension(name);
    // Create the CompositeConfiguration properties.
    CompositeConfiguration properties = Keyword.loadProperties(file);
    forceFieldFilter = new ForceFieldFilter(properties);
    ForceField forceField = forceFieldFilter.parse();
    // Create an FFXSystem for this file.
    FFXSystem newSystem = new FFXSystem(file, commandDescription, properties);
    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);
    // Decide what parser to use.
    SystemFilter systemFilter = null;
    if (xyzFileFilter.acceptDeep(file)) {
        // Use the TINKER Cartesian Coordinate File Parser.
        systemFilter = new XYZFilter(files, newSystem, forceField, properties);
    } else if (intFileFilter.acceptDeep(file)) {
        // Use the TINKER Internal Coordinate File Parser.
        systemFilter = new INTFilter(files, newSystem, forceField, properties);
    } else {
        // Use the PDB File Parser.
        systemFilter = new PDBFilter(files, newSystem, forceField, properties);
    }
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    activeFilter = systemFilter;
    // return new UIFileOpener(systemFilter, this);
    UIFileOpener fileOpener = new UIFileOpener(systemFilter, this);
    if (fileOpenerThreads > 0) {
        fileOpener.setNThreads(fileOpenerThreads);
    }
    return fileOpener;
}
Also used : CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ForceFieldFilter(ffx.potential.parsers.ForceFieldFilter) ForceField(ffx.potential.parameters.ForceField) ForceFieldString(ffx.potential.parameters.ForceField.ForceFieldString) SystemFilter(ffx.potential.parsers.SystemFilter) XYZFilter(ffx.potential.parsers.XYZFilter) File(java.io.File) PDBFilter(ffx.potential.parsers.PDBFilter) INTFilter(ffx.potential.parsers.INTFilter)

Example 3 with ForceFieldFilter

use of ffx.potential.parsers.ForceFieldFilter in project ffx by mjschnie.

the class MainPanel method openFromPDB.

/**
 * Opens a file from the PDB
 */
public void openFromPDB() {
    if (openThread != null && openThread.isAlive()) {
        return;
    }
    String code = JOptionPane.showInputDialog("Enter the PDB Identifier (4 characters)", "");
    if (code == null) {
        return;
    }
    code = code.toLowerCase().trim();
    if (code == null || code.length() != 4) {
        return;
    }
    String fileName = code + ".pdb";
    String path = getPWD().getAbsolutePath();
    File pdbFile = new File(path + File.separatorChar + fileName);
    CompositeConfiguration properties = Keyword.loadProperties(pdbFile);
    forceFieldFilter = new ForceFieldFilter(properties);
    ForceField forceField = forceFieldFilter.parse();
    FFXSystem newSystem = new FFXSystem(pdbFile, "PDB", properties);
    newSystem.setForceField(forceField);
    if (!pdbFile.exists()) {
        String fromURL = pdbForID(code);
        pdbFile = downloadURL(fromURL);
        if (pdbFile == null || !pdbFile.exists()) {
            return;
        }
    } else {
        String message = String.format(" Reading the local copy of the PDB file %s.", pdbFile);
        logger.info(message);
    }
    PDBFilter pdbFilter = new PDBFilter(pdbFile, newSystem, forceField, properties);
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    UIFileOpener openFile = new UIFileOpener(pdbFilter, this);
    if (fileOpenerThreads > 0) {
        openFile.setNThreads(fileOpenerThreads);
    }
    openThread = new Thread(openFile);
    openThread.start();
    setPanel(GRAPHICS);
}
Also used : CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ForceFieldFilter(ffx.potential.parsers.ForceFieldFilter) ForceField(ffx.potential.parameters.ForceField) ForceFieldString(ffx.potential.parameters.ForceField.ForceFieldString) File(java.io.File) PDBFilter(ffx.potential.parsers.PDBFilter)

Example 4 with ForceFieldFilter

use of ffx.potential.parsers.ForceFieldFilter in project ffx by mjschnie.

the class MainPanel method openInit.

/**
 * Attempts to load the supplied file
 *
 * @param file File to open
 * @param commandDescription Description of the command that created this
 * file.
 * @return a {@link java.lang.Thread} object.
 */
private UIFileOpener openInit(File file, String commandDescription) {
    if (file == null || !file.isFile() || !file.canRead()) {
        return null;
    }
    file = new File(FilenameUtils.normalize(file.getAbsolutePath()));
    // Set the Current Working Directory based on this file.
    setCWD(file.getParentFile());
    // Get "filename" from "filename.extension".
    String name = file.getName();
    String extension = FilenameUtils.getExtension(name);
    /**
     * Run a Force Field X script.
     */
    if (extension.equalsIgnoreCase("ffx") || extension.equalsIgnoreCase("groovy")) {
        ModelingShell shell = getModelingShell();
        shell.runFFXScript(file);
        boolean shutDown = Boolean.parseBoolean(System.getProperty("ffx.shutDown", "true"));
        if (java.awt.GraphicsEnvironment.isHeadless() && shutDown) {
            exit();
        } else {
            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);
    SystemFilter systemFilter = null;
    // Decide what parser to use.
    if (xyzFileFilter.acceptDeep(file)) {
        // Use the TINKER Cartesian Coordinate File Parser.
        systemFilter = new XYZFilter(file, newSystem, forceField, properties);
    } else if (intFileFilter.acceptDeep(file)) {
        // Use the TINKER Internal Coordinate File Parser.
        systemFilter = new INTFilter(file, newSystem, forceField, properties);
    } else {
        // Use the PDB File Parser.
        systemFilter = new PDBFilter(file, newSystem, forceField, properties);
    }
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    activeFilter = systemFilter;
    UIFileOpener fileOpener = new UIFileOpener(systemFilter, this);
    if (fileOpenerThreads > 0) {
        fileOpener.setNThreads(fileOpenerThreads);
    }
    return fileOpener;
// return new UIFileOpener(systemFilter, this);
}
Also used : CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ForceFieldFilter(ffx.potential.parsers.ForceFieldFilter) ForceFieldString(ffx.potential.parameters.ForceField.ForceFieldString) ForceField(ffx.potential.parameters.ForceField) SystemFilter(ffx.potential.parsers.SystemFilter) XYZFilter(ffx.potential.parsers.XYZFilter) File(java.io.File) PDBFilter(ffx.potential.parsers.PDBFilter) INTFilter(ffx.potential.parsers.INTFilter)

Example 5 with ForceFieldFilter

use of ffx.potential.parsers.ForceFieldFilter 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

ForceField (ffx.potential.parameters.ForceField)8 ForceFieldFilter (ffx.potential.parsers.ForceFieldFilter)8 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)8 PDBFilter (ffx.potential.parsers.PDBFilter)6 File (java.io.File)6 ForceFieldEnergy (ffx.potential.ForceFieldEnergy)4 MolecularAssembly (ffx.potential.MolecularAssembly)4 ForceFieldString (ffx.potential.parameters.ForceField.ForceFieldString)4 INTFilter (ffx.potential.parsers.INTFilter)3 XYZFilter (ffx.potential.parsers.XYZFilter)3 ParallelTeam (edu.rit.pj.ParallelTeam)2 Crystal (ffx.crystal.Crystal)2 ReflectionList (ffx.crystal.ReflectionList)2 Resolution (ffx.crystal.Resolution)2 Atom (ffx.potential.bonded.Atom)2 BiojavaFilter (ffx.potential.parsers.BiojavaFilter)2 SystemFilter (ffx.potential.parsers.SystemFilter)2 Structure (org.biojava.bio.structure.Structure)2 HKL (ffx.crystal.HKL)1 ComplexNumber (ffx.numerics.ComplexNumber)1