Search in sources :

Example 1 with ARCFileFilter

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

Aggregations

ForceFieldEnergy (ffx.potential.ForceFieldEnergy)1 MolecularAssembly (ffx.potential.MolecularAssembly)1 ForceField (ffx.potential.parameters.ForceField)1 ARCFileFilter (ffx.potential.parsers.ARCFileFilter)1 ForceFieldFilter (ffx.potential.parsers.ForceFieldFilter)1 INTFileFilter (ffx.potential.parsers.INTFileFilter)1 INTFilter (ffx.potential.parsers.INTFilter)1 PDBFileFilter (ffx.potential.parsers.PDBFileFilter)1 PDBFilter (ffx.potential.parsers.PDBFilter)1 XYZFileFilter (ffx.potential.parsers.XYZFileFilter)1 XYZFilter (ffx.potential.parsers.XYZFilter)1 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)1