Search in sources :

Example 16 with CompositeConfiguration

use of org.apache.commons.configuration.CompositeConfiguration in project ffx by mjschnie.

the class XYZFilter method readPBC.

/**
 * Attempt to parse the String as unit cell parameters.
 *
 * @param data The String to parse.
 *
 * @return false if the first token in the String is an integer and true
 * otherwise.
 */
private static boolean readPBC(String data, MolecularAssembly activeMolecularAssembly) {
    if (firstTokenIsInteger(data)) {
        return false;
    }
    String[] tokens = data.trim().split(" +");
    if (tokens != null && tokens.length == 6) {
        CompositeConfiguration config = activeMolecularAssembly.getProperties();
        double a = Double.parseDouble(tokens[0]);
        double b = Double.parseDouble(tokens[1]);
        double c = Double.parseDouble(tokens[2]);
        double alpha = Double.parseDouble(tokens[3]);
        double beta = Double.parseDouble(tokens[4]);
        double gamma = Double.parseDouble(tokens[5]);
        config.setProperty("a-axis", a);
        config.setProperty("b-axis", b);
        config.setProperty("c-axis", c);
        config.setProperty("alpha", alpha);
        config.setProperty("beta", beta);
        config.setProperty("gamma", gamma);
        Crystal crystal = activeMolecularAssembly.getCrystal();
        if (crystal != null) {
            crystal.changeUnitCellParameters(a, b, c, alpha, beta, gamma);
        }
    }
    return true;
}
Also used : CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) Crystal(ffx.crystal.Crystal)

Example 17 with CompositeConfiguration

use of org.apache.commons.configuration.CompositeConfiguration in project ffx by mjschnie.

the class ForceFieldFilter method main.

/**
 * Parse a Force Field parameter file and echo the results with slashes.
 *
 * @param args an array of {@link java.lang.String} objects.
 * @throws java.lang.Exception if any.
 */
public static void main(String[] args) throws Exception {
    if (args == null || args.length < 1) {
        System.out.println("Usage: ForceFieldFilter <file.prm>");
        System.exit(-1);
    }
    CompositeConfiguration properties = Keyword.loadProperties(null);
    properties.setProperty("parameters", args[0]);
    ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
    ForceField forceField = forceFieldFilter.parse();
    if (forceField != null) {
        forceField.print();
    }
}
Also used : CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ForceField(ffx.potential.parameters.ForceField)

Example 18 with CompositeConfiguration

use of org.apache.commons.configuration.CompositeConfiguration in project ffx by mjschnie.

the class ForceFieldFilterTest method testParse.

/**
 * Test of parse method, of class ForceFieldFilter.
 */
@Test
public void testParse() {
    CompositeConfiguration properties = Keyword.loadProperties(null);
    ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
    ForceField forceField = forceFieldFilter.parse();
}
Also used : CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ForceField(ffx.potential.parameters.ForceField) Test(org.junit.Test)

Example 19 with CompositeConfiguration

use of org.apache.commons.configuration.CompositeConfiguration in project ninja by ninjaframework.

the class MessagesImpl method loadAllMessageFilesForRegisteredLanguages.

/**
 * Does all the loading of message files.
 *
 * Only registered messages in application.conf are loaded.
 */
private Map<String, Configuration> loadAllMessageFilesForRegisteredLanguages() {
    Map<String, Configuration> langToKeyAndValuesMappingMutable = Maps.newHashMap();
    // Load default messages:
    Configuration defaultLanguage = loadLanguageConfiguration("conf/messages.properties");
    // Everything else does not make much sense.
    if (defaultLanguage == null) {
        throw new RuntimeException("Did not find conf/messages.properties. Please add a default language file.");
    } else {
        langToKeyAndValuesMappingMutable.put("", defaultLanguage);
    }
    // Get the languages from the application configuration.
    String[] applicationLangs = ninjaProperties.getStringArray(NinjaConstant.applicationLanguages);
    // We'll use the default messages.properties file.
    if (applicationLangs == null) {
        return ImmutableMap.copyOf(langToKeyAndValuesMappingMutable);
    }
    // Load each language into the HashMap containing the languages:
    for (String lang : applicationLangs) {
        // First step: Load complete language eg. en-US
        Configuration configuration = loadLanguageConfiguration(String.format("conf/messages_%s.properties", lang));
        Configuration configurationLangOnly = null;
        // Overwritten by the default languages.
        if (lang.contains("-")) {
            // get the lang
            String langOnly = lang.split("-")[0];
            // And load the configuraion
            configurationLangOnly = loadLanguageConfiguration(String.format("conf/messages_%s.properties", langOnly));
        }
        // it should be there propably.
        if (configuration == null) {
            logger.info("Did not find conf/messages_{}.properties but it was specified in application.conf. Using default language instead.", lang);
        } else {
            // add new language, but combine with default language if stuff
            // is missing...
            CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
            // Add eg. "en-US"
            compositeConfiguration.addConfiguration(configuration);
            // Add eg. "en"
            if (configurationLangOnly != null) {
                compositeConfiguration.addConfiguration(configurationLangOnly);
            }
            // Add messages.conf (default pack)
            compositeConfiguration.addConfiguration(defaultLanguage);
            // and add the composed configuration to the hashmap with the
            // mapping.
            langToKeyAndValuesMappingMutable.put(lang, (Configuration) compositeConfiguration);
        }
    }
    return ImmutableMap.copyOf(langToKeyAndValuesMappingMutable);
}
Also used : Configuration(org.apache.commons.configuration.Configuration) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration)

Example 20 with CompositeConfiguration

use of org.apache.commons.configuration.CompositeConfiguration in project es6draft by anba.

the class Resources method loadConfiguration.

/**
 * Loads the configuration file.
 */
public static Configuration loadConfiguration(TestConfiguration config) {
    String file = config.file();
    String name = config.name();
    try {
        PropertiesConfiguration properties = new PropertiesConfiguration();
        // entries are mandatory unless an explicit default value was given
        properties.setThrowExceptionOnMissing(true);
        properties.setDelimiterParsingDisabled(true);
        properties.getInterpolator().setParentInterpolator(MISSING_VAR);
        properties.load(resource(file, Paths.get("")), "UTF-8");
        SystemConfiguration systemConfiguration = new SystemConfiguration();
        systemConfiguration.setDelimiterParsingDisabled(true);
        return new CompositeConfiguration(Arrays.asList(systemConfiguration, properties)).subset(name);
    } catch (ConfigurationException | IOException e) {
        throw new RuntimeException(e);
    } catch (NoSuchElementException e) {
        throw e;
    }
}
Also used : ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Aggregations

CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)89 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)46 Test (org.junit.Test)24 ClusterController (org.apache.whirr.ClusterController)22 Configuration (org.apache.commons.configuration.Configuration)21 File (java.io.File)17 Before (org.junit.Before)11 ForceField (ffx.potential.parameters.ForceField)10 ConfigurationException (org.apache.commons.configuration.ConfigurationException)9 HadoopProxy (org.apache.whirr.service.hadoop.HadoopProxy)9 BeforeClass (org.junit.BeforeClass)9 IOException (java.io.IOException)8 ClusterSpec (org.apache.whirr.ClusterSpec)8 MolecularAssembly (ffx.potential.MolecularAssembly)7 ForceFieldFilter (ffx.potential.parsers.ForceFieldFilter)7 PDBFilter (ffx.potential.parsers.PDBFilter)7 MapConfiguration (org.apache.commons.configuration.MapConfiguration)6 Crystal (ffx.crystal.Crystal)5 ReflectionList (ffx.crystal.ReflectionList)5 ForceFieldEnergy (ffx.potential.ForceFieldEnergy)5