use of ffx.utilities.Keyword in project ffx by mjschnie.
the class ModelingPanel method loadCommand.
private void loadCommand() {
synchronized (this) {
// Force Field X Command
Element command;
// Command Options
NodeList options;
Element option;
// Option Values
NodeList values;
Element value;
// Options may be Conditional based on previous Option values (not
// always supplied)
NodeList conditionalList;
Element conditional;
// JobPanel GUI Components that change based on command
JPanel optionPanel;
// Clear the previous components
commandPanel.removeAll();
optionsTabbedPane.removeAll();
conditionals.clear();
String currentCommand = (String) currentCommandBox.getSelectedItem();
if (currentCommand == null) {
commandPanel.validate();
commandPanel.repaint();
return;
}
command = null;
for (int i = 0; i < commandList.getLength(); i++) {
command = (Element) commandList.item(i);
String name = command.getAttribute("name");
if (name.equalsIgnoreCase(currentCommand)) {
break;
}
}
int div = splitPane.getDividerLocation();
descriptTextArea.setText(currentCommand.toUpperCase() + ": " + command.getAttribute("description"));
splitPane.setBottomComponent(descriptScrollPane);
splitPane.setDividerLocation(div);
// The "action" tells Force Field X what to do when the
// command finishes
commandActions = command.getAttribute("action").trim();
// The "fileType" specifies what file types this command can execute
// on
String string = command.getAttribute("fileType").trim();
String[] types = string.split(" +");
commandFileTypes.clear();
for (String type : types) {
if (type.contains("XYZ")) {
commandFileTypes.add(FileType.XYZ);
}
if (type.contains("INT")) {
commandFileTypes.add(FileType.INT);
}
if (type.contains("ARC")) {
commandFileTypes.add(FileType.ARC);
}
if (type.contains("PDB")) {
commandFileTypes.add(FileType.PDB);
}
if (type.contains("ANY")) {
commandFileTypes.add(FileType.ANY);
}
}
// Determine what options are available for this command
options = command.getElementsByTagName("Option");
int length = options.getLength();
for (int i = 0; i < length; i++) {
// This Option will be enabled (isEnabled = true) unless a
// Conditional disables it
boolean isEnabled = true;
option = (Element) options.item(i);
conditionalList = option.getElementsByTagName("Conditional");
/*
* Currently, there can only be 0 or 1 Conditionals per Option
* There are three types of Conditionals implemented. 1.)
* Conditional on a previous Option, this option may be
* available 2.) Conditional on input for this option, a
* sub-option may be available 3.) Conditional on the presence
* of keywords, this option may be available
*/
if (conditionalList != null) {
conditional = (Element) conditionalList.item(0);
} else {
conditional = null;
}
// Get the command line flag
String flag = option.getAttribute("flag").trim();
// Get the description
String optionDescript = option.getAttribute("description");
JTextArea optionTextArea = new JTextArea(" " + optionDescript.trim());
optionTextArea.setEditable(false);
optionTextArea.setLineWrap(true);
optionTextArea.setWrapStyleWord(true);
optionTextArea.setBorder(etchedBorder);
// Get the default for this Option (if one exists)
String defaultOption = option.getAttribute("default");
// Option Panel
optionPanel = new JPanel(new BorderLayout());
optionPanel.add(optionTextArea, BorderLayout.NORTH);
String swing = option.getAttribute("gui");
JPanel optionValuesPanel = new JPanel(new FlowLayout());
optionValuesPanel.setBorder(etchedBorder);
ButtonGroup bg = null;
if (swing.equalsIgnoreCase("CHECKBOXES")) {
// CHECKBOXES allows selection of 1 or more values from a
// predefined set (Analyze, for example)
values = option.getElementsByTagName("Value");
for (int j = 0; j < values.getLength(); j++) {
value = (Element) values.item(j);
JCheckBox jcb = new JCheckBox(value.getAttribute("name"));
jcb.addMouseListener(this);
jcb.setName(flag);
if (defaultOption != null && jcb.getActionCommand().equalsIgnoreCase(defaultOption)) {
jcb.setSelected(true);
}
optionValuesPanel.add(jcb);
}
} else if (swing.equalsIgnoreCase("TEXTFIELD")) {
// TEXTFIELD takes an arbitrary String as input
JTextField jtf = new JTextField(20);
jtf.addMouseListener(this);
jtf.setName(flag);
if (defaultOption != null && defaultOption.equals("ATOMS")) {
FFXSystem sys = mainPanel.getHierarchy().getActive();
if (sys != null) {
jtf.setText("" + sys.getAtomList().size());
}
} else if (defaultOption != null) {
jtf.setText(defaultOption);
}
optionValuesPanel.add(jtf);
} else if (swing.equalsIgnoreCase("RADIOBUTTONS")) {
// RADIOBUTTONS allows one choice from a set of predifined
// values
bg = new ButtonGroup();
values = option.getElementsByTagName("Value");
for (int j = 0; j < values.getLength(); j++) {
value = (Element) values.item(j);
JRadioButton jrb = new JRadioButton(value.getAttribute("name"));
jrb.addMouseListener(this);
jrb.setName(flag);
bg.add(jrb);
if (defaultOption != null && jrb.getActionCommand().equalsIgnoreCase(defaultOption)) {
jrb.setSelected(true);
}
optionValuesPanel.add(jrb);
}
} else if (swing.equalsIgnoreCase("PROTEIN")) {
// Protein allows selection of amino acids for the protein
// builder
optionValuesPanel.setLayout(new BoxLayout(optionValuesPanel, BoxLayout.Y_AXIS));
optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
optionValuesPanel.add(getAminoAcidPanel());
optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
acidComboBox.removeAllItems();
JButton add = new JButton("Edit");
add.setActionCommand("PROTEIN");
add.addActionListener(this);
add.setAlignmentX(Button.CENTER_ALIGNMENT);
JPanel comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
comboPanel.add(acidTextField);
comboPanel.add(add);
optionValuesPanel.add(comboPanel);
optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
JButton remove = new JButton("Remove");
add.setMinimumSize(remove.getPreferredSize());
add.setPreferredSize(remove.getPreferredSize());
remove.setActionCommand("PROTEIN");
remove.addActionListener(this);
remove.setAlignmentX(Button.CENTER_ALIGNMENT);
comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
comboPanel.add(acidComboBox);
comboPanel.add(remove);
optionValuesPanel.add(comboPanel);
optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
optionValuesPanel.add(acidScrollPane);
optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
JButton reset = new JButton("Reset");
reset.setActionCommand("PROTEIN");
reset.addActionListener(this);
reset.setAlignmentX(Button.CENTER_ALIGNMENT);
optionValuesPanel.add(reset);
optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
acidTextArea.setText("");
acidTextField.setText("");
} else if (swing.equalsIgnoreCase("NUCLEIC")) {
// Nucleic allows selection of nucleic acids for the nucleic
// acid builder
optionValuesPanel.setLayout(new BoxLayout(optionValuesPanel, BoxLayout.Y_AXIS));
optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
optionValuesPanel.add(getNucleicAcidPanel());
optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
acidComboBox.removeAllItems();
JButton add = new JButton("Edit");
add.setActionCommand("NUCLEIC");
add.addActionListener(this);
add.setAlignmentX(Button.CENTER_ALIGNMENT);
JPanel comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
comboPanel.add(acidTextField);
comboPanel.add(add);
optionValuesPanel.add(comboPanel);
optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
JButton remove = new JButton("Remove");
add.setMinimumSize(remove.getPreferredSize());
add.setPreferredSize(remove.getPreferredSize());
remove.setActionCommand("NUCLEIC");
remove.addActionListener(this);
remove.setAlignmentX(Button.CENTER_ALIGNMENT);
comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
comboPanel.add(acidComboBox);
comboPanel.add(remove);
optionValuesPanel.add(comboPanel);
optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
optionValuesPanel.add(acidScrollPane);
optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
JButton button = new JButton("Reset");
button.setActionCommand("NUCLEIC");
button.addActionListener(this);
button.setAlignmentX(Button.CENTER_ALIGNMENT);
optionValuesPanel.add(button);
optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
acidTextArea.setText("");
acidTextField.setText("");
} else if (swing.equalsIgnoreCase("SYSTEMS")) {
// SYSTEMS allows selection of an open system
JComboBox<FFXSystem> jcb = new JComboBox<>(mainPanel.getHierarchy().getNonActiveSystems());
jcb.setSize(jcb.getMaximumSize());
jcb.addActionListener(this);
optionValuesPanel.add(jcb);
}
// Set up a Conditional for this Option
if (conditional != null) {
isEnabled = false;
String conditionalName = conditional.getAttribute("name");
String conditionalValues = conditional.getAttribute("value");
String cDescription = conditional.getAttribute("description");
String cpostProcess = conditional.getAttribute("postProcess");
if (conditionalName.toUpperCase().startsWith("KEYWORD")) {
optionPanel.setName(conditionalName);
String[] keywords = conditionalValues.split(" +");
if (activeSystem != null) {
Hashtable<String, Keyword> systemKeywords = activeSystem.getKeywords();
for (String key : keywords) {
if (systemKeywords.containsKey(key.toUpperCase())) {
isEnabled = true;
}
}
}
} else if (conditionalName.toUpperCase().startsWith("VALUE")) {
isEnabled = true;
// the conditional options can be disabled/enabled.
for (int j = 0; j < optionValuesPanel.getComponentCount(); j++) {
JToggleButton jtb = (JToggleButton) optionValuesPanel.getComponent(j);
jtb.addActionListener(this);
jtb.setActionCommand("Conditional");
}
JPanel condpanel = new JPanel();
condpanel.setBorder(etchedBorder);
JLabel condlabel = new JLabel(cDescription);
condlabel.setEnabled(false);
condlabel.setName(conditionalValues);
JTextField condtext = new JTextField(10);
condlabel.setLabelFor(condtext);
if (cpostProcess != null) {
condtext.setName(cpostProcess);
}
condtext.setEnabled(false);
condpanel.add(condlabel);
condpanel.add(condtext);
conditionals.add(condlabel);
optionPanel.add(condpanel, BorderLayout.SOUTH);
} else if (conditionalName.toUpperCase().startsWith("REFLECTION")) {
String[] condModifiers;
if (conditionalValues.equalsIgnoreCase("AltLoc")) {
condModifiers = activeSystem.getAltLocations();
if (condModifiers != null && condModifiers.length > 1) {
isEnabled = true;
bg = new ButtonGroup();
for (int j = 0; j < condModifiers.length; j++) {
JRadioButton jrbmi = new JRadioButton(condModifiers[j]);
jrbmi.addMouseListener(this);
bg.add(jrbmi);
optionValuesPanel.add(jrbmi);
if (j == 0) {
jrbmi.setSelected(true);
}
}
}
} else if (conditionalValues.equalsIgnoreCase("Chains")) {
condModifiers = activeSystem.getChainNames();
if (condModifiers != null && condModifiers.length > 0) {
isEnabled = true;
for (int j = 0; j < condModifiers.length; j++) {
JRadioButton jrbmi = new JRadioButton(condModifiers[j]);
jrbmi.addMouseListener(this);
bg.add(jrbmi);
optionValuesPanel.add(jrbmi, j);
}
}
}
}
}
optionPanel.add(optionValuesPanel, BorderLayout.CENTER);
optionPanel.setPreferredSize(optionPanel.getPreferredSize());
optionsTabbedPane.addTab(option.getAttribute("name"), optionPanel);
optionsTabbedPane.setEnabledAt(optionsTabbedPane.getTabCount() - 1, isEnabled);
}
}
optionsTabbedPane.setPreferredSize(optionsTabbedPane.getPreferredSize());
commandPanel.setLayout(borderLayout);
commandPanel.add(optionsTabbedPane, BorderLayout.CENTER);
commandPanel.validate();
commandPanel.repaint();
loadLogSettings();
statusLabel.setText(" " + createCommandInput());
}
use of ffx.utilities.Keyword in project ffx by mjschnie.
the class KeywordPanel method storeActive.
/**
* Store the KeywordPanel's current keyword content in the activeSystem.
*/
public void storeActive() {
synchronized (this) {
if (currentSystem == null) {
return;
}
// No changes
if (!KeywordComponent.isKeywordModified()) {
return;
}
Hashtable<String, Keyword> currentKeys = currentSystem.getKeywords();
Hashtable<String, Keyword> newKeys = new Hashtable<String, Keyword>();
for (KeywordComponent kc : keywordHashMap.values()) {
if (kc.isActive() == true) {
Keyword keywordData = null;
if (currentKeys != null) {
keywordData = currentKeys.get(kc.getKeyword());
}
if (keywordData == null) {
keywordData = new Keyword(kc.getKeyword());
} else {
keywordData.clear();
}
kc.getKeywordData(keywordData);
newKeys.put(kc.getKeyword(), keywordData);
}
}
Keyword comments = new Keyword("COMMENTS", commentStringBuffer.toString());
newKeys.put("COMMENTS", comments);
currentSystem.setKeywords(newKeys);
}
}
use of ffx.utilities.Keyword in project ffx by mjschnie.
the class KeywordPanel method configToKeywords.
private void configToKeywords(FFXSystem newSystem) {
CompositeConfiguration properties = newSystem.getProperties();
Hashtable<String, Keyword> keywordHash = new Hashtable<>();
// Create the "Comments" property.
Keyword keyword = new Keyword("COMMENTS");
keywordHash.put("COMMENTS", keyword);
// Loop over properties from the keyword file.
Configuration config = properties.getConfiguration(0);
if (config instanceof PropertiesConfiguration) {
PropertiesConfiguration prop = (PropertiesConfiguration) config;
Iterator<String> keys = prop.getKeys();
while (keys.hasNext()) {
String key = keys.next();
if (keywordHash.contains(key)) {
keyword = keywordHash.get(key);
keyword.append(prop.getStringArray(key));
} else {
String[] values = prop.getStringArray(key);
keyword = new Keyword(key, values);
keywordHash.put(key, keyword);
}
}
}
newSystem.setKeywords(keywordHash);
}
use of ffx.utilities.Keyword in project ffx by mjschnie.
the class KeywordPanel method loadActive.
/**
* <p>
* loadActive</p>
*
* @param newSystem a {@link ffx.ui.FFXSystem} object.
* @param newKeys a {@link java.util.Hashtable} object.
* @param newKeyFile a {@link java.io.File} object.
* @return a boolean.
*/
public boolean loadActive(FFXSystem newSystem, Hashtable<String, Keyword> newKeys, File newKeyFile) {
synchronized (this) {
// Store changes made to the current system (if any) first.
if (currentKeys != null && KeywordComponent.isKeywordModified()) {
if (currentSystem != null && currentSystem != newSystem) {
storeActive();
} else {
saveChanges();
}
}
// Clear previous values
keyClear();
// No keywords to load
if (newKeys == null || newKeys.size() == 0) {
return false;
}
currentSystem = newSystem;
currentKeyFile = newKeyFile;
currentKeys = newKeys;
fileOpen = true;
/*
* Keys to remove are those entries not recognized by the FFX
* Keyword Editor These keys are removed from the active System's
* keyword Hashtable and appended to the generic "Comments"
* KeywordData instance.
*/
ArrayList<String> keysToRemove = new ArrayList<>();
Keyword comments = currentKeys.get("COMMENTS");
for (Keyword keyword : currentKeys.values()) {
String label = keyword.getKeyword();
Vector<String> data = keyword.getEntries();
if (label.equals("COMMENTS")) {
continue;
}
KeywordComponent tk = keywordHashMap.get(label.toUpperCase());
// as a Comment
if (tk == null) {
keysToRemove.add(keyword.getKeyword());
if (data.isEmpty()) {
comments.append(label);
} else if (label.equalsIgnoreCase("MULTIPOLE")) {
int count = 5;
for (String entry : data) {
count++;
if (count > 5) {
comments.append(label + " " + entry);
count = 1;
} else {
comments.append(entry);
}
}
} else if (label.equalsIgnoreCase("TORTORS")) {
int points = 0;
int count = 0;
for (String entry : data) {
count++;
if (count > points) {
String[] res = entry.split(" +");
int xres = Integer.parseInt(res[5]);
int yres = Integer.parseInt(res[5]);
points = xres * yres;
comments.append(label + " " + entry);
count = 0;
} else {
comments.append(entry);
}
}
} else {
for (String entry : data) {
comments.append(label + " " + entry);
}
}
continue;
}
// doesn't have modifiers)
if (data.isEmpty()) {
tk.loadKeywordEntry(label);
}
// can be repeated)
for (String s : data) {
tk.loadKeywordEntry(s);
}
}
// Load up the Comments
Vector<String> entries = comments.getEntries();
if (entries != null) {
for (String s : entries) {
if (s.length() > 1) {
if (!groupHashMap.containsKey(s.substring(1).toUpperCase().trim())) {
commentStringBuffer.append(s).append("\n");
}
} else {
commentStringBuffer.append(s).append("\n");
}
}
}
// Keywords that aren't recognized have been turned into Comments
for (String k : keysToRemove) {
currentKeys.remove(k);
}
if (currentSystem != null) {
currentSystem.setKeywords(currentKeys);
currentSystem.setKeyFile(currentKeyFile);
}
loadKeywordGroup();
return true;
}
}
use of ffx.utilities.Keyword in project ffx by mjschnie.
the class MainPanel method createKeyFile.
/**
* <p>
* createKeyFile</p>
*
* @param system a {@link ffx.ui.FFXSystem} object.
* @return a boolean.
*/
public boolean createKeyFile(FFXSystem system) {
String message = new String("Please select a parameter file " + "and a TINKER Key file will be created.");
String params = (String) JOptionPane.showInputDialog(this, message, "Parameter File", JOptionPane.QUESTION_MESSAGE, null, keywordPanel.getParamFiles(), null);
if (params != null) {
if (params.equalsIgnoreCase("Use an existing TINKER Key file")) {
JFileChooser fc = resetFileChooser();
fc.setDialogTitle("Choose a KEY File");
fc.setCurrentDirectory(pwd);
fc.setSelectedFile(null);
fc.setFileFilter(keyFileFilter);
int result = fc.showOpenDialog(this);
if (result == JFileChooser.APPROVE_OPTION) {
File keyfile = fc.getSelectedFile();
if (keyfile.exists()) {
Hashtable<String, Keyword> keywordHash = KeyFilter.open(keyfile);
if (keywordHash != null) {
system.setKeywords(keywordHash);
} else {
return false;
}
system.setKeyFile(keyfile);
system.setForceField(null);
return true;
}
}
} else {
File tempFile = system.getFile();
if (tempFile.getParentFile().canWrite()) {
String path = system.getFile().getParent() + File.separatorChar;
String keyFileName = system.getName() + ".key";
File keyfile = new File(path + keyFileName);
try {
FileWriter fw = new FileWriter(keyfile);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("\n");
bw.write("# Force Field Selection\n");
String tempParm = keywordPanel.getParamPath(params);
if (tempParm.indexOf(" ") > 0) {
tempParm = "\"" + keywordPanel.getParamPath(params) + "\"";
}
bw.write("PARAMETERS " + tempParm + "\n");
bw.close();
fw.close();
Hashtable<String, Keyword> keywordHash = KeyFilter.open(keyfile);
if (keywordHash != null) {
system.setKeywords(keywordHash);
} else {
return false;
}
system.setKeyFile(keyfile);
system.setForceField(null);
return true;
} catch (Exception e) {
logger.warning("" + e);
message = new String("There was an error creating " + keyfile.getAbsolutePath());
JOptionPane.showMessageDialog(this, message);
}
} else {
message = new String("Could not create a Key file because " + pwd.getAbsolutePath() + " is not writable");
JOptionPane.showMessageDialog(this, message);
}
}
}
return false;
}
Aggregations