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;
}
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;
}
Aggregations