Search in sources :

Example 1 with BiojavaFilter

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

the class UIDataConverter method convert.

/**
 * Converts the data structure to MolecularAssembly(s).
 */
public void convert() {
    if (timer) {
        startTimer();
    }
    FFXSystem ffxSystem = null;
    // Continue if the file was read in successfully.
    if (conversionFilter.convert()) {
        ffxSystem = (FFXSystem) conversionFilter.getActiveMolecularSystem();
        if (!(conversionFilter instanceof BiojavaFilter)) {
            Utilities.biochemistry(ffxSystem, conversionFilter.getAtomList());
        }
        conversionFilter.applyAtomProperties();
        // Add the system to the multiscale hierarchy.
        mainPanel.getHierarchy().addSystemNode(ffxSystem);
        ForceFieldEnergy energy = ForceFieldEnergy.energyFactory(ffxSystem, conversionFilter.getCoordRestraints());
        ffxSystem.setPotential(energy);
        mainPanel.getHierarchy().setActive(ffxSystem);
        // Check if there are alternate conformers
        if (conversionFilter instanceof BiojavaFilter) {
            BiojavaFilter biojFilter = (BiojavaFilter) conversionFilter;
            List<Character> altLocs = biojFilter.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(String.format("(%s) ", c));
                }
                altLocString.append("]\n");
                logger.info(altLocString.toString());
            }
            /**
             * Alternate conformers may have different chemistry, so they
             * each need to be their own FFX system.
             */
            for (Character c : altLocs) {
                if (c.equals(' ') || c.equals('A')) {
                    continue;
                }
                FFXSystem newSystem = new FFXSystem(ffxSystem.getFile(), "Alternate Location " + c, ffxSystem.getProperties());
                newSystem.setForceField(ffxSystem.getForceField());
                biojFilter.setAltID(newSystem, c);
                biojFilter.clearSegIDs();
                if (biojFilter.convert()) {
                    biojFilter.applyAtomProperties();
                    String fileName = ffxSystem.getFile().getAbsolutePath();
                    newSystem.setName(FilenameUtils.getBaseName(fileName) + " " + c);
                    mainPanel.getHierarchy().addSystemNode(newSystem);
                    energy = ForceFieldEnergy.energyFactory(newSystem, biojFilter.getCoordRestraints());
                    newSystem.setPotential(energy);
                }
            }
        }
    } else {
        logger.warning(String.format(" Failed to convert structure %s", dataStructure.toString()));
    }
    mainPanel.setCursor(Cursor.getDefaultCursor());
    if (timer) {
        stopTimer(ffxSystem);
    }
}
Also used : ForceFieldEnergy(ffx.potential.ForceFieldEnergy) BiojavaFilter(ffx.potential.parsers.BiojavaFilter)

Example 2 with BiojavaFilter

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

Example 3 with BiojavaFilter

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

the class PotentialsDataConverter method run.

/**
 * Converts the data structure to MolecularAssembly(s).
 */
@Override
public void run() {
    if (dataStructure == null || dataType.equals(Utilities.DataType.UNK)) {
        throw new IllegalArgumentException("Object passed was not recognized.");
    }
    assemblies = new ArrayList<>();
    propertyList = new ArrayList<>();
    switch(dataType) {
        case BIOJAVA:
            Structure struct = (Structure) dataStructure;
            String name = struct.getPDBCode();
            CompositeConfiguration properties = Keyword.loadProperties(file);
            MolecularAssembly assembly = new MolecularAssembly(name);
            assembly.setFile(file);
            ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
            ForceField forceField = forceFieldFilter.parse();
            assembly.setForceField(forceField);
            BiojavaFilter filter = new BiojavaFilter(struct, assembly, forceField, properties);
            if (filter.convert()) {
                filter.applyAtomProperties();
                assembly.finalize(true, forceField);
                ForceFieldEnergy energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints());
                assembly.setPotential(energy);
                assemblies.add(assembly);
                propertyList.add(properties);
                List<Character> altLocs = filter.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(name);
                    newAssembly.setForceField(assembly.getForceField());
                    filter.setAltID(newAssembly, c);
                    filter.clearSegIDs();
                    if (filter.convert()) {
                        String fileName = assembly.getFile().getAbsolutePath();
                        newAssembly.setName(FilenameUtils.getBaseName(fileName) + " " + c);
                        filter.applyAtomProperties();
                        newAssembly.finalize(true, assembly.getForceField());
                        energy = ForceFieldEnergy.energyFactory(newAssembly, filter.getCoordRestraints());
                        newAssembly.setPotential(energy);
                        assemblies.add(newAssembly);
                        properties.addConfiguration(properties);
                    }
                }
            } else {
                logger.warning(String.format(" Failed to convert structure %s", dataStructure.toString()));
            }
            activeAssembly = assembly;
            activeProperties = properties;
            break;
        case UNK:
        default:
            throw new IllegalArgumentException("Object passed was not recognized.");
    }
}
Also used : CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ForceFieldFilter(ffx.potential.parsers.ForceFieldFilter) ForceFieldEnergy(ffx.potential.ForceFieldEnergy) MolecularAssembly(ffx.potential.MolecularAssembly) ForceField(ffx.potential.parameters.ForceField) BiojavaFilter(ffx.potential.parsers.BiojavaFilter) Structure(org.biojava.bio.structure.Structure)

Aggregations

BiojavaFilter (ffx.potential.parsers.BiojavaFilter)3 ForceFieldEnergy (ffx.potential.ForceFieldEnergy)2 ForceField (ffx.potential.parameters.ForceField)2 ForceFieldFilter (ffx.potential.parsers.ForceFieldFilter)2 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)2 Structure (org.biojava.bio.structure.Structure)2 MolecularAssembly (ffx.potential.MolecularAssembly)1 ForceFieldString (ffx.potential.parameters.ForceField.ForceFieldString)1 ConversionFilter (ffx.potential.parsers.ConversionFilter)1