Search in sources :

Example 1 with PDBFilter

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

the class Looptimizer method setOptimization.

public void setOptimization(boolean osrwOptimization, MolecularAssembly molAss) {
    this.osrwOptimization = osrwOptimization;
    this.molecularAssembly = molAss;
    File file = molecularAssembly.getFile();
    String fileName = FilenameUtils.removeExtension(file.getAbsolutePath());
    if (pdbFilter == null) {
        pdbFile = new File(fileName + "_opt.pdb");
        pdbFilter = new PDBFilter(new File(fileName + "_opt.pdb"), molecularAssembly, null, null);
    }
}
Also used : File(java.io.File) PDBFilter(ffx.potential.parsers.PDBFilter)

Example 2 with PDBFilter

use of ffx.potential.parsers.PDBFilter 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 3 with PDBFilter

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

the class GenerateRotamers method setVideo.

/**
 * Null file indicates to not write a video.
 * @param videoFile Filename for video or null
 */
public void setVideo(String videoFile) {
    if (videoFile != null) {
        File vidFile = new File(videoFile);
        if (vidFile.exists()) {
            for (int i = 0; i < 1000; i++) {
                vidFile = new File(String.format("%s_%d", videoFile, i));
                if (!vidFile.exists()) {
                    this.videoFile = vidFile;
                    writeVideo = true;
                    videoFilter = new PDBFilter(this.videoFile, mola, mola.getForceField(), null);
                    videoFilter.setLogWrites(false);
                    break;
                }
            }
            if (vidFile.exists()) {
                logger.warning(String.format(" Could not version video file %s", videoFile));
            }
        } else {
            this.videoFile = vidFile;
            writeVideo = true;
            videoFilter = new PDBFilter(this.videoFile, mola, mola.getForceField(), null);
            videoFilter.setLogWrites(false);
        }
    } else {
        writeVideo = false;
    }
}
Also used : File(java.io.File) PDBFilter(ffx.potential.parsers.PDBFilter)

Example 4 with PDBFilter

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

the class MolecularDynamics method assemblyInfo.

protected void assemblyInfo() {
    assemblies.stream().parallel().forEach((ainfo) -> {
        MolecularAssembly mola = ainfo.getAssembly();
        CompositeConfiguration aprops = ainfo.props;
        File file = mola.getFile();
        String filename = FilenameUtils.removeExtension(file.getAbsolutePath());
        File archFile = ainfo.archiveFile;
        if (archFile == null) {
            archFile = new File(filename + ".arc");
            ainfo.archiveFile = XYZFilter.version(archFile);
        }
        if (ainfo.pdbFile == null) {
            String extName = FilenameUtils.getExtension(file.getName());
            if (extName.toLowerCase().startsWith("pdb")) {
                ainfo.pdbFile = file;
            } else {
                ainfo.pdbFile = new File(filename + ".pdb");
            }
        }
        if (ainfo.xyzFilter == null) {
            ainfo.xyzFilter = new XYZFilter(file, mola, mola.getForceField(), aprops);
        }
        if (ainfo.pdbFilter == null) {
            ainfo.pdbFilter = new PDBFilter(ainfo.pdbFile, mola, mola.getForceField(), aprops);
        }
    });
}
Also used : MolecularAssembly(ffx.potential.MolecularAssembly) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) XYZFilter(ffx.potential.parsers.XYZFilter) File(java.io.File) PDBFilter(ffx.potential.parsers.PDBFilter)

Example 5 with PDBFilter

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

the class OSRW method writeTraversal.

/**
 * Save snapshots for each traversal of lambda.
 */
private void writeTraversal() {
    double heldTraversalLambda = 0.5;
    if (!traversalInHand.isEmpty()) {
        heldTraversalLambda = Double.parseDouble(traversalInHand.get(0).split(",")[0]);
        if ((lambda > 0.2 && traversalSnapshotTarget == 0) || (lambda < 0.8 && traversalSnapshotTarget == 1)) {
            int snapshotCounts = Integer.parseInt(traversalInHand.get(0).split(",")[1]);
            traversalInHand.remove(0);
            File fileToWrite;
            int numStructures;
            if (traversalSnapshotTarget == 0) {
                fileToWrite = lambdaZeroFile;
                numStructures = ++lambdaZeroStructures;
            } else {
                fileToWrite = lambdaOneFile;
                numStructures = ++lambdaOneStructures;
            }
            try {
                FileWriter fw = new FileWriter(fileToWrite, true);
                BufferedWriter bw = new BufferedWriter(fw);
                bw.write(String.format("MODEL        %d          L=%.4f  counts=%d", numStructures, heldTraversalLambda, snapshotCounts));
                for (int i = 0; i < 50; i++) {
                    bw.write(" ");
                }
                bw.newLine();
                for (int i = 0; i < traversalInHand.size(); i++) {
                    bw.write(traversalInHand.get(i));
                    bw.newLine();
                }
                bw.write(String.format("ENDMDL"));
                for (int i = 0; i < 75; i++) {
                    bw.write(" ");
                }
                bw.newLine();
                bw.close();
                logger.info(String.format(" Wrote traversal structure L=%.4f", heldTraversalLambda));
            } catch (Exception exception) {
                logger.warning(String.format("Exception writing to file: %s", fileToWrite.getName()));
            }
            heldTraversalLambda = 0.5;
            traversalInHand.clear();
            traversalSnapshotTarget = 1 - traversalSnapshotTarget;
        }
    }
    if (((lambda < 0.1 && traversalInHand.isEmpty()) || (lambda < heldTraversalLambda - 0.025 && !traversalInHand.isEmpty())) && (traversalSnapshotTarget == 0 || traversalSnapshotTarget == -1)) {
        if (lambdaZeroFilter == null) {
            lambdaZeroFilter = new PDBFilter(lambdaZeroFile, lambdaZeroAssembly, null, null);
            lambdaZeroFilter.setListMode(true);
        }
        lambdaZeroFilter.clearListOutput();
        lambdaZeroFilter.writeFileWithHeader(lambdaFile, format("%.4f,%d,", lambda, totalCounts));
        traversalInHand = lambdaZeroFilter.getListOutput();
        traversalSnapshotTarget = 0;
    } else if (((lambda > 0.9 && traversalInHand.isEmpty()) || (lambda > heldTraversalLambda + 0.025 && !traversalInHand.isEmpty())) && (traversalSnapshotTarget == 1 || traversalSnapshotTarget == -1)) {
        if (lambdaOneFilter == null) {
            lambdaOneFilter = new PDBFilter(lambdaOneFile, lambdaOneAssembly, null, null);
            lambdaOneFilter.setListMode(true);
        }
        lambdaOneFilter.clearListOutput();
        lambdaOneFilter.writeFileWithHeader(lambdaFile, format("%.4f,%d,", lambda, totalCounts));
        traversalInHand = lambdaOneFilter.getListOutput();
        traversalSnapshotTarget = 1;
    }
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) PDBFilter(ffx.potential.parsers.PDBFilter) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) FileNotFoundException(java.io.FileNotFoundException) BufferedWriter(java.io.BufferedWriter)

Aggregations

PDBFilter (ffx.potential.parsers.PDBFilter)33 File (java.io.File)29 IOException (java.io.IOException)7 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)7 ForceField (ffx.potential.parameters.ForceField)6 ForceFieldFilter (ffx.potential.parsers.ForceFieldFilter)6 Atom (ffx.potential.bonded.Atom)5 XYZFilter (ffx.potential.parsers.XYZFilter)5 Crystal (ffx.crystal.Crystal)4 ForceFieldEnergy (ffx.potential.ForceFieldEnergy)4 MolecularAssembly (ffx.potential.MolecularAssembly)4 Rotamer (ffx.potential.bonded.Rotamer)4 ForceFieldString (ffx.potential.parameters.ForceField.ForceFieldString)4 BufferedWriter (java.io.BufferedWriter)4 FileWriter (java.io.FileWriter)4 MultiResidue (ffx.potential.bonded.MultiResidue)3 NACorrectionException (ffx.potential.bonded.NACorrectionException)3 Residue (ffx.potential.bonded.Residue)3 ResidueState (ffx.potential.bonded.ResidueState)3 INTFilter (ffx.potential.parsers.INTFilter)3