⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mdlv3000reader.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    String indexString = tokenizer.nextToken();                    bond.setID(indexString);                } catch (Exception exception) {                    String error = "Error while parsing bond index";                    logger.error(error);                    logger.debug(exception);                    throw new CDKException(error, exception);                }                // parse the order                try {                    String orderString = tokenizer.nextToken();                    int order = Integer.parseInt(orderString);                    if (order >= 4) {                        logger.warn("Query order types are not supported (yet). File a bug if you need it");                    } else {                        bond.setOrder((double)order);                    }                } catch (Exception exception) {                    String error = "Error while parsing bond index";                    logger.error(error);                    logger.debug(exception);                    throw new CDKException(error, exception);                }                // parse index atom 1                try {                    String indexAtom1String = tokenizer.nextToken();                    int indexAtom1 = Integer.parseInt(indexAtom1String);                    IAtom atom1 = readData.getAtom(indexAtom1 -1);                    bond.setAtom(atom1, 0);                } catch (Exception exception) {                    String error = "Error while parsing index atom 1 in bond";                    logger.error(error);                    logger.debug(exception);                    throw new CDKException(error, exception);                }                // parse index atom 2                try {                    String indexAtom2String = tokenizer.nextToken();                    int indexAtom2 = Integer.parseInt(indexAtom2String);                    IAtom atom2 = readData.getAtom(indexAtom2 -1);                    bond.setAtom(atom2, 1);                } catch (Exception exception) {                    String error = "Error while parsing index atom 2 in bond";                    logger.error(error);                    logger.debug(exception);                    throw new CDKException(error, exception);                }                // the rest are key=value fields                if (command.indexOf("=") != -1) {                    Hashtable options = parseOptions(exhaustStringTokenizer(tokenizer));                    Enumeration keys = options.keys();                    while (keys.hasMoreElements()) {                        String key = (String)keys.nextElement();                        String value = (String)options.get(key);                        try {                            if (key.equals("CFG")) {                                int configuration = Integer.parseInt(value);                                if (configuration == 0) {                                    bond.setStereo(CDKConstants.STEREO_BOND_NONE);                                } else if (configuration == 1) {                                    bond.setStereo(CDKConstants.STEREO_BOND_UP);                                } else if (configuration == 2) {                                    bond.setStereo(CDKConstants.STEREO_BOND_UNDEFINED);                                } else if (configuration == 3) {                                    bond.setStereo(CDKConstants.STEREO_BOND_DOWN);                                }                            } else {                                logger.warn("Not parsing key: " + key);                            }                        } catch (Exception exception) {                            String error = "Error while parsing key/value " + key + "=" +                            value + ": " + exception.getMessage();                            logger.error(error);                            logger.debug(exception);                            throw new CDKException(error, exception);                        }                    }                }                                // storing bond                readData.addBond(bond);                logger.debug("Added bond: " + bond);            }        }    }        /**     * Reads labels.     */    public void readSGroup(IAtomContainer readData) throws CDKException {        boolean foundEND = false;        while (isReady() && !foundEND) {            String command = readCommand();            if ("END SGROUP".equals(command)) {                foundEND = true;            } else {                logger.debug("Parsing Sgroup line: " + command);                StringTokenizer tokenizer = new StringTokenizer(command);                // parse the index                String indexString = tokenizer.nextToken();                logger.warn("Skipping external index: " + indexString);                // parse command type                String type = tokenizer.nextToken();                // parse the external index                String externalIndexString = tokenizer.nextToken();                logger.warn("Skipping external index: " + externalIndexString);                                // the rest are key=value fields                Hashtable options = new Hashtable();                if (command.indexOf("=") != -1) {                    options = parseOptions(exhaustStringTokenizer(tokenizer));                }                // now interpret line                if (type.startsWith("SUP")) {                    Enumeration keys = options.keys();                    int atomID = -1;                    String label = "";                    while (keys.hasMoreElements()) {                        String key = (String)keys.nextElement();                        String value = (String)options.get(key);                        try {                            if (key.equals("ATOMS")) {                                StringTokenizer atomsTokenizer = new StringTokenizer(value);                                Integer.parseInt(atomsTokenizer.nextToken()); // should be 1, int atomCount =                                 atomID = Integer.parseInt(atomsTokenizer.nextToken());                            } else if (key.equals("LABEL")) {                                label = value;                            } else {                                logger.warn("Not parsing key: " + key);                            }                        } catch (Exception exception) {                            String error = "Error while parsing key/value " + key + "=" +                            value + ": " + exception.getMessage();                            logger.error(error);                            logger.debug(exception);                            throw new CDKException(error, exception);                        }                        if (atomID != -1 && label.length() > 0) {                        	IAtom atom = readData.getAtom(atomID-1);                            if (!(atom instanceof IPseudoAtom)) {                                atom = readData.getBuilder().newPseudoAtom(atom);                            }                            ((IPseudoAtom)atom).setLabel(label);                            readData.setAtom(atomID-1, atom);                        }                    }                } else {                    logger.warn("Skipping unrecognized SGROUP type: " + type);                }            }        }    }                /**     * Reads the command on this line. If the line is continued on the next, that     * part is added.     *     * @return Returns the command on this line.     */    private String readCommand() throws CDKException {        String line = readLine();        if (line.startsWith("M  V30 ")) {            String command =  line.substring(7);            if (command.endsWith("-")) {                command = command.substring(0, command.length()-1);                command += readCommand();            }            return command;        } else {            throw new CDKException("Could not read MDL file: unexpected line: " + line);        }    }        private Hashtable parseOptions(String string) throws CDKException {        Hashtable keyValueTuples = new Hashtable();        while (string.length() >= 3) {            logger.debug("Matching remaining option string: " + string);            Matcher tuple1Matcher = keyValueTuple2.matcher(string);            if (tuple1Matcher.matches()) {                String key = tuple1Matcher.group(1);                String value = tuple1Matcher.group(2);                string = tuple1Matcher.group(3);                logger.debug("Found key: " + key);                logger.debug("Found value: " + value);                keyValueTuples.put(key, value);            } else {                Matcher tuple2Matcher = keyValueTuple.matcher(string);                if (tuple2Matcher.matches()) {                    String key = tuple2Matcher.group(1);                    String value = tuple2Matcher.group(2);                    string = tuple2Matcher.group(3);                    logger.debug("Found key: " + key);                    logger.debug("Found value: " + value);                    keyValueTuples.put(key, value);                } else {                    logger.warn("Quiting; could not parse: " + string + ".");                    string = "";                }            }        }        return keyValueTuples;    }        public String exhaustStringTokenizer(StringTokenizer tokenizer) {        StringBuffer buffer = new StringBuffer();        buffer.append(" ");        while (tokenizer.hasMoreTokens()) {            buffer.append(tokenizer.nextToken());            buffer.append(" ");        }        return buffer.toString();    }        public String readLine() throws CDKException {        String line = null;        try {            line = input.readLine();            logger.debug("read line: " + line);        } catch (Exception exception) {            String error = "Unexpected error while reading file: " + exception.getMessage();            logger.error(error);            logger.debug(exception);            throw new CDKException(error, exception);        }        return line;    }        public boolean isReady() throws CDKException {        try {            return input.ready();        } catch (Exception exception) {            String error = "Unexpected error while reading file: " + exception.getMessage();            logger.error(error);            logger.debug(exception);            throw new CDKException(error, exception);        }    }    private boolean isPseudoAtom(String element) {        if (element.equals("R#") || // a Rgroup            element.equals("Q") ||  // any atom but C and H            element.equals("A") ||  // any atom            element.equals("*")) {  // 'star' atom            return true;        }        return false;    }        public boolean accepts(IChemObject object) {        if (object instanceof IMolecule) {            return true;        }        return false;    }    public void close() throws IOException {        input.close();    }        private void initIOSettings() {    }        public IOSetting[] getIOSettings() {        return new IOSetting[0];    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -