Search in sources :

Example 1 with OptionIOSetting

use of org.openscience.cdk.io.setting.OptionIOSetting in project cdk by cdk.

the class TextGUIListener method processIOSettingQuestion.

/**
 * Processes the IOSettings by listing the question, giving the options
 * and asking the user to provide their choice.
 *
 * <p>Note: if the input reader is <code>null</code>, then the method
 * does not wait for an answer, and takes the default.
 */
@Override
public void processIOSettingQuestion(IOSetting setting) {
    // post the question
    if (setting.getLevel().ordinal() <= this.level.ordinal()) {
        // output the option name
        this.out.print("[" + setting.getName() + "]: ");
        // post the question
        this.out.print(setting.getQuestion());
        if (setting instanceof BooleanIOSetting) {
            BooleanIOSetting boolSet = (BooleanIOSetting) setting;
            boolean set = boolSet.isSet();
            if (set) {
                this.out.print(" [Yn]");
            } else {
                this.out.print(" [yN]");
            }
        } else if (setting instanceof OptionIOSetting) {
            OptionIOSetting optionSet = (OptionIOSetting) setting;
            List<String> settings = optionSet.getOptions();
            for (int i = 0; i < settings.size(); i++) {
                this.out.println();
                String option = settings.get(i);
                this.out.print((i + 1) + ". " + option);
                if (option.equals(setting.getSetting())) {
                    this.out.print(" (Default)");
                }
            }
        } else {
            this.out.print(" [" + setting.getSetting() + "]");
        }
        this.out.println();
        this.out.flush();
        // get the answer, only if input != null
        if (this.in == null) {
        // don't really ask questions. This is intentional behaviour to
        // allow for listing all questions. The settings is now defaulted,
        // which is the intention too.
        } else {
            boolean gotAnswer = false;
            while (!gotAnswer) {
                try {
                    this.out.print("> ");
                    this.out.flush();
                    String answer = in.readLine();
                    if (answer.length() == 0) {
                    // pressed ENTER -> take default
                    } else if (setting instanceof OptionIOSetting) {
                        ((OptionIOSetting) setting).setSetting(Integer.parseInt(answer));
                    } else if (setting instanceof BooleanIOSetting) {
                        if (answer.equalsIgnoreCase("n") || answer.equalsIgnoreCase("no")) {
                            answer = "false";
                        }
                        if (answer.equalsIgnoreCase("y") || answer.equalsIgnoreCase("yes")) {
                            answer = "true";
                        }
                        setting.setSetting(answer);
                    } else {
                        setting.setSetting(answer);
                    }
                    gotAnswer = true;
                } catch (IOException exception) {
                    this.out.println("Cannot read from STDIN. Skipping question.");
                } catch (NumberFormatException exception) {
                    this.out.println("Answer is not a number.");
                } catch (CDKException exception) {
                    this.out.println();
                    this.out.println(exception);
                }
            }
        }
    }
}
Also used : BooleanIOSetting(org.openscience.cdk.io.setting.BooleanIOSetting) CDKException(org.openscience.cdk.exception.CDKException) List(java.util.List) IOException(java.io.IOException) OptionIOSetting(org.openscience.cdk.io.setting.OptionIOSetting)

Example 2 with OptionIOSetting

use of org.openscience.cdk.io.setting.OptionIOSetting in project cdk by cdk.

the class GaussianInputWriter method initIOSettings.

private void initIOSettings() {
    List<String> basisOptions = new ArrayList<>();
    basisOptions.add("6-31g");
    basisOptions.add("6-31g*");
    basisOptions.add("6-31g(d)");
    basisOptions.add("6-311g");
    basisOptions.add("6-311+g**");
    basis = new OptionIOSetting("Basis", IOSetting.Importance.MEDIUM, "Which basis set do you want to use?", basisOptions, "6-31g");
    List<String> methodOptions = new ArrayList<>();
    methodOptions.add("rb3lyp");
    methodOptions.add("b3lyp");
    methodOptions.add("rhf");
    method = new OptionIOSetting("Method", IOSetting.Importance.MEDIUM, "Which method do you want to use?", methodOptions, "b3lyp");
    List<String> commandOptions = new ArrayList<>();
    commandOptions.add("energy calculation");
    commandOptions.add("geometry optimization");
    commandOptions.add("IR frequency calculation");
    commandOptions.add("IR frequency calculation (with Raman)");
    command = addSetting(new OptionIOSetting("Command", IOSetting.Importance.HIGH, "What kind of job do you want to perform?", commandOptions, "energy calculation"));
    comment = addSetting(new StringIOSetting("Comment", IOSetting.Importance.LOW, "What comment should be put in the file?", "Created with CDK (http://cdk.sf.net/)"));
    memory = addSetting(new StringIOSetting("Memory", IOSetting.Importance.LOW, "How much memory do you want to use?", "unset"));
    shell = addSetting(new BooleanIOSetting("OpenShell", IOSetting.Importance.MEDIUM, "Should the calculation be open shell?", "false"));
    proccount = addSetting(new IntegerIOSetting("ProcessorCount", IOSetting.Importance.LOW, "How many processors should be used by Gaussian?", "1"));
    usecheckpoint = new BooleanIOSetting("UseCheckPointFile", IOSetting.Importance.LOW, "Should a check point file be saved?", "false");
}
Also used : BooleanIOSetting(org.openscience.cdk.io.setting.BooleanIOSetting) ArrayList(java.util.ArrayList) StringIOSetting(org.openscience.cdk.io.setting.StringIOSetting) IntegerIOSetting(org.openscience.cdk.io.setting.IntegerIOSetting) OptionIOSetting(org.openscience.cdk.io.setting.OptionIOSetting)

Aggregations

BooleanIOSetting (org.openscience.cdk.io.setting.BooleanIOSetting)2 OptionIOSetting (org.openscience.cdk.io.setting.OptionIOSetting)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CDKException (org.openscience.cdk.exception.CDKException)1 IntegerIOSetting (org.openscience.cdk.io.setting.IntegerIOSetting)1 StringIOSetting (org.openscience.cdk.io.setting.StringIOSetting)1