Search in sources :

Example 1 with ForceFieldString

use of ffx.potential.parameters.ForceField.ForceFieldString in project ffx by mjschnie.

the class ForceFieldFilter method parse.

/**
 * <p>
 * parse</p>
 *
 * @return a {@link ffx.potential.parameters.ForceField} object.
 */
public ForceField parse() {
    try {
        if (forceFieldFile != null) {
            /**
             * Parse an external (ie. not in the FFX jar) parameter file.
             */
            if (!forceFieldFile.exists()) {
                logger.log(Level.INFO, " {0} does not exist.", forceFieldFile);
                return null;
            } else if (!forceFieldFile.canRead()) {
                logger.log(Level.INFO, " {0} can not be read.", forceFieldFile);
                return null;
            }
            parse(new FileInputStream(forceFieldFile));
        } else {
            /**
             * Parse an internal parameter file and add it to the composite
             * configuration.
             */
            String forceFieldString = properties.getString("forcefield", "AMOEBA-BIO-2009");
            ForceFieldName ff;
            try {
                ff = ForceField.ForceFieldName.valueOf(forceFieldString.toUpperCase().replace('-', '_'));
                logger.info(" Loading force field: " + ff.toString());
            } catch (Exception e) {
                logger.warning("Defaulting to force field: AMOEBA_BIO_2009");
                ff = ForceField.ForceFieldName.AMOEBA_BIO_2009;
            }
            URL url = ForceField.getForceFieldURL(ff);
            if (url != null) {
                forceField.forceFieldURL = url;
                try {
                    PropertiesConfiguration config = new PropertiesConfiguration(url);
                    properties.addConfiguration(config);
                } catch (ConfigurationException e) {
                    logger.warning(e.toString());
                }
            }
        }
        /**
         * Overwrite parameters of the forceFieldFile with those from the
         * CompositeConfiguration.
         */
        if (properties != null) {
            parse(properties);
        }
    // forceField.checkPolarizationTypes();
    } catch (FileNotFoundException e) {
        String message = "Exception parsing force field.";
        logger.log(Level.WARNING, message, e);
    }
    return forceField;
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) FileNotFoundException(java.io.FileNotFoundException) ForceFieldName(ffx.potential.parameters.ForceField.ForceFieldName) ForceFieldString(ffx.potential.parameters.ForceField.ForceFieldString) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) URL(java.net.URL)

Example 2 with ForceFieldString

use of ffx.potential.parameters.ForceField.ForceFieldString in project ffx by mjschnie.

the class ForceFieldFilter method parseKeyword.

private boolean parseKeyword(String[] tokens) {
    String keyword = toEnumForm(tokens[0]);
    try {
        // Parse Keywords with a String value.
        ForceFieldString ffString = ForceFieldString.valueOf(keyword);
        int len = tokens.length;
        if (len == 1) {
            forceField.addForceFieldString(ffString, null);
        } else if (len == 2) {
            forceField.addForceFieldString(ffString, tokens[1]);
        } else {
            StringBuilder stringBuilder = new StringBuilder(tokens[1]);
            for (int i = 2; i < len; i++) {
                stringBuilder.append(" ");
                stringBuilder.append(tokens[i]);
            }
            forceField.addForceFieldString(ffString, stringBuilder.toString());
        }
    } catch (Exception e) {
        try {
            // Parse Keywords with a Double value.
            ForceFieldDouble ffDouble = ForceFieldDouble.valueOf(keyword);
            double value = Double.parseDouble(tokens[1]);
            forceField.addForceFieldDouble(ffDouble, value);
        } catch (Exception e2) {
            try {
                // Parse Keywords with an Integer value.
                ForceFieldInteger ffInteger = ForceFieldInteger.valueOf(keyword);
                int value = Integer.parseInt(tokens[1]);
                forceField.addForceFieldInteger(ffInteger, value);
            } catch (Exception e3) {
                try {
                    // Parse Keywords with a Boolean value.
                    ForceFieldBoolean ffBoolean = ForceFieldBoolean.valueOf(keyword);
                    boolean value = true;
                    if (tokens.length > 1 && tokens[0].toUpperCase().endsWith("TERM")) {
                        /**
                         * Handle the token "ONLY" specially to shut off all
                         * other terms.
                         */
                        if (tokens[1].equalsIgnoreCase("ONLY")) {
                            for (ForceFieldBoolean term : ForceFieldBoolean.values()) {
                                if (term.toString().toUpperCase().endsWith("TERM")) {
                                    forceField.addForceFieldBoolean(term, false);
                                }
                            }
                        } else if (tokens[1].equalsIgnoreCase("NONE")) {
                            /**
                             * Legacy support for the "NONE" token.
                             */
                            value = false;
                        } else {
                            value = Boolean.parseBoolean(tokens[1]);
                        }
                    }
                    forceField.addForceFieldBoolean(ffBoolean, value);
                    forceField.log(keyword);
                } catch (Exception e4) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : ForceFieldInteger(ffx.potential.parameters.ForceField.ForceFieldInteger) ForceFieldBoolean(ffx.potential.parameters.ForceField.ForceFieldBoolean) ForceFieldString(ffx.potential.parameters.ForceField.ForceFieldString) ForceFieldString(ffx.potential.parameters.ForceField.ForceFieldString) ForceFieldDouble(ffx.potential.parameters.ForceField.ForceFieldDouble) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ConfigurationException(org.apache.commons.configuration.ConfigurationException)

Aggregations

ForceFieldString (ffx.potential.parameters.ForceField.ForceFieldString)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 ForceFieldBoolean (ffx.potential.parameters.ForceField.ForceFieldBoolean)1 ForceFieldDouble (ffx.potential.parameters.ForceField.ForceFieldDouble)1 ForceFieldInteger (ffx.potential.parameters.ForceField.ForceFieldInteger)1 ForceFieldName (ffx.potential.parameters.ForceField.ForceFieldName)1 FileInputStream (java.io.FileInputStream)1 URL (java.net.URL)1 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)1