Search in sources :

Example 1 with StringIOSetting

use of org.openscience.cdk.io.setting.StringIOSetting in project ambit-mirror by ideaconsult.

the class InteractiveIteratingMDLReader method next.

/* (non-Javadoc)
     * @see org.openscience.cdk.io.iterator.IteratingMDLReader#next()
     */
public IAtomContainer next() {
    Object o = super.next();
    if (o instanceof IChemObject) {
        Map properties = ((IChemObject) o).getProperties();
        if (properties.size() > 0) {
            fireIOSettingQuestion(new StringIOSetting("", Importance.MEDIUM, Property.IO_QUESTION.IO_START.toString(), ""));
            Iterator i = properties.keySet().iterator();
            while (i.hasNext()) {
                String name = i.next().toString();
                fireIOSettingQuestion(new StringIOSetting(name, Importance.MEDIUM, Property.IO_QUESTION.IO_TRANSLATE_NAME.toString(), name));
            }
            fireIOSettingQuestion(new StringIOSetting("", Importance.MEDIUM, Property.IO_QUESTION.IO_STOP.toString(), ""));
        }
        return (IAtomContainer) o;
    }
    return null;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IChemObject(org.openscience.cdk.interfaces.IChemObject) Iterator(java.util.Iterator) IChemObject(org.openscience.cdk.interfaces.IChemObject) StringIOSetting(org.openscience.cdk.io.setting.StringIOSetting) Map(java.util.Map)

Example 2 with StringIOSetting

use of org.openscience.cdk.io.setting.StringIOSetting in project ambit-mirror by ideaconsult.

the class IteratingDelimitedFileReaderComplexHeader method hasNext.

// TODO fix: returns false if a column without a header has some data
// (throws exception and the returns false)
/*
	 * (non-Javadoc)
	 * 
	 * @see java.util.Iterator#hasNext()
	 */
public boolean hasNext() {
    if (isHeaderEmpty()) {
        fireIOSettingQuestion(new StringIOSetting("", Importance.MEDIUM, Property.IO_QUESTION.IO_START.toString(), ""));
        processHeader(input);
        fireIOSettingQuestion(new StringIOSetting("", Importance.MEDIUM, Property.IO_QUESTION.IO_STOP.toString(), ""));
    }
    if (!nextAvailableIsKnown) {
        hasNext = false;
        // now try to parse the next Molecule
        try {
            if (input.ready()) {
                extractRowKeyAndData(input.readLine().trim());
                nextMolecule = null;
                if (inchiIndex >= 0)
                    try {
                        if (inchiFactory == null)
                            inchiFactory = InChIGeneratorFactory.getInstance();
                        InChIToStructure c = inchiFactory.getInChIToStructure(values[inchiIndex].toString(), SilentChemObjectBuilder.getInstance());
                        nextMolecule = c.getAtomContainer();
                    } catch (Exception x) {
                        nextMolecule = null;
                    }
                if ((nextMolecule == null) && (smilesIndex >= 0)) {
                    try {
                        if (values[smilesIndex] == null) {
                            nextMolecule = SilentChemObjectBuilder.getInstance().newInstance(IAtomContainer.class);
                        } else
                            nextMolecule = sp.parseSmiles(values[smilesIndex].toString());
                    } catch (InvalidSmilesException | ArrayIndexOutOfBoundsException x) {
                        // do not want to break if a record is faulty
                        logger.fine("Empty molecule!");
                        // just
                        nextMolecule = SilentChemObjectBuilder.getInstance().newInstance(IAtomContainer.class);
                        // create
                        nextMolecule.setProperty("SMILES", "Invalid SMILES");
                    }
                }
                if (nextMolecule == null)
                    nextMolecule = SilentChemObjectBuilder.getInstance().newInstance(IAtomContainer.class);
                for (int i = 0; i < values.length; i++) if (values[i] != null) {
                    String cas = casTransformer.process(values[i].toString());
                    if (CASProcessor.isValidFormat(cas)) {
                        // if (getHeaderColumn(i) instanceof Property)
                        // getHeaderColumn(i).setLabel(Property.CAS);
                        values[i] = cas;
                    }
                    // else if
                    // (EINECS.isValidFormat(values[i].toString()))
                    // getHeaderColumn(i).setLabel(Property.EC);
                    nextMolecule.setProperty(getHeaderColumn(i), values[i].toString().trim());
                } else
                    nextMolecule.removeProperty(getHeaderColumn(i));
                /*
					 * if (nextMolecule.getAtomCount() > 0) { hasNext = true; }
					 * else { hasNext = false; }
					 */
                hasNext = true;
            } else {
                hasNext = false;
            }
        } catch (Exception exception) {
            logger.log(Level.SEVERE, "Error while reading next molecule: ", exception);
            hasNext = true;
        }
        if (!hasNext)
            nextMolecule = null;
        nextAvailableIsKnown = true;
    }
    return hasNext;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InChIToStructure(org.openscience.cdk.inchi.InChIToStructure) StringIOSetting(org.openscience.cdk.io.setting.StringIOSetting) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) CDKException(org.openscience.cdk.exception.CDKException) IOException(java.io.IOException) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) NoSuchElementException(java.util.NoSuchElementException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 3 with StringIOSetting

use of org.openscience.cdk.io.setting.StringIOSetting in project ambit-mirror by ideaconsult.

the class IteratingFilesWithHeaderReader method addHeaderColumn.

protected void addHeaderColumn(String name) {
    header.add(createPropertyByColumnName(name));
    fireIOSettingQuestion(new StringIOSetting(name, Importance.MEDIUM, Property.IO_QUESTION.IO_TRANSLATE_NAME.toString(), name));
}
Also used : StringIOSetting(org.openscience.cdk.io.setting.StringIOSetting)

Example 4 with StringIOSetting

use of org.openscience.cdk.io.setting.StringIOSetting in project ambit-mirror by ideaconsult.

the class IteratingXLSReader method hasNext.

public boolean hasNext() {
    if (isHeaderEmpty()) {
        fireIOSettingQuestion(new StringIOSetting("", Importance.MEDIUM, Property.IO_QUESTION.IO_START.toString(), ""));
        processHeader();
        fireIOSettingQuestion(new StringIOSetting("", Importance.MEDIUM, Property.IO_QUESTION.IO_STOP.toString(), ""));
    }
    try {
        return iterator.hasNext();
    } catch (Exception x) {
        logger.log(Level.SEVERE, x.getMessage(), x);
        return false;
    }
}
Also used : StringIOSetting(org.openscience.cdk.io.setting.StringIOSetting) CDKException(org.openscience.cdk.exception.CDKException) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) IOException(java.io.IOException)

Example 5 with StringIOSetting

use of org.openscience.cdk.io.setting.StringIOSetting 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

StringIOSetting (org.openscience.cdk.io.setting.StringIOSetting)5 IOException (java.io.IOException)2 CDKException (org.openscience.cdk.exception.CDKException)2 InvalidSmilesException (org.openscience.cdk.exception.InvalidSmilesException)2 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 InChIToStructure (org.openscience.cdk.inchi.InChIToStructure)1 IChemObject (org.openscience.cdk.interfaces.IChemObject)1 BooleanIOSetting (org.openscience.cdk.io.setting.BooleanIOSetting)1 IntegerIOSetting (org.openscience.cdk.io.setting.IntegerIOSetting)1 OptionIOSetting (org.openscience.cdk.io.setting.OptionIOSetting)1