Search in sources :

Example 1 with ForceFieldName

use of ffx.potential.parameters.ForceField.ForceFieldName 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)

Aggregations

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