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

📄 moleculebuilder.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            else            {                addAtom("O", currentMolecule.getAtom(addPos), 2.0, 0);            }        }        //Nitrile        else if (funGroupToken == "nitrile" )        {            addAtom("N", currentMolecule.getFirstAtom(), 3.0, 0);        }        //Benzene        else if (funGroupToken == "phenyl" )        {            Molecule benzene = MoleculeFactory.makeBenzene();            //Detect Aromacity in the benzene ring.            try            {                HueckelAromaticityDetector.detectAromaticity(benzene);            }            catch (Exception exc)            {//                logger.debug("No atom detected");            }            currentMolecule.add(benzene);                        Bond joiningBond;            //If functional group hasn't had a location specified:            if (addPos < 0)            {                joiningBond = new Bond(currentMolecule.getFirstAtom(), benzene.getFirstAtom());            }            else            {                joiningBond = new Bond(currentMolecule.getAtom(addPos), benzene.getFirstAtom());            }            currentMolecule.addBond(joiningBond);        }        else if (funGroupToken == "amino" )        {            //If functional group hasn't had a location specified:            if (addPos < 0)            {                addAtom("N", currentMolecule.getFirstAtom(), 1.0, 2);            }            else            {                addAtom("N", currentMolecule.getAtom(addPos), 1.0, 2);            }        }        //ORGANO METALLICS ADDED AS PREFIXES        else if (funGroupToken == "alumino" )        {            //If functional group hasn't had a location specified:            if (addPos < 0)            {                addAtom("Al", currentMolecule.getFirstAtom(), 1.0, 2);            }            else            {                addAtom("Al", currentMolecule.getAtom(addPos), 1.0, 2);            }        }        else if (funGroupToken == "litho" )        {            //If functional group hasn't had a location specified:            if (addPos < 0)            {                addAtom("Li", currentMolecule.getFirstAtom(), 1.0, 2);            }            else            {                addAtom("Li", currentMolecule.getAtom(addPos), 1.0, 2);            }        }        //PRIORITY SUBSTITUENTS        //FUNCTIONAL GROUPS WHICH MAY HAVE THEIR OWN SUBSTITUENTS        //Esters ("...oate")        else if (funGroupToken == "oate")        {            addAtom("O", endOfChain, 2.0, 0);            addAtom("O", endOfChain, 1.0, 0);            //Set the end of the chain to be built on for unspecified substituents.            endOfChain = currentMolecule.getLastAtom();        }        //Amines        else if (funGroupToken == "amine")        {            addAtom("N", endOfChain, 1.0, 1);                        //Set the end of the chain to be built on for unspecified substituents.            endOfChain = currentMolecule.getLastAtom();        }        //Amides        else if (funGroupToken =="amide")        {            addAtom("O", endOfChain, 2.0, 0);            addAtom("N", endOfChain, 1.0, 1);            //Set the end of the chain to be built on for unspecified substituents.            endOfChain = currentMolecule.getLastAtom();        }        //Ketones        else if (funGroupToken == "one")        {            addAtom("O", endOfChain, 2.0, 2);            //End of chain doesn't change in this case        }        //Organometals        else if (getMetalAtomicSymbol (funGroupToken) != null)        {            currentMolecule.addAtom (new Atom (getMetalAtomicSymbol (funGroupToken)));            endOfChain = currentMolecule.getLastAtom();        }        else        {//            logger.debug("Encountered unknown group: " + funGroupToken + " at " + addPos +//            "\nThe parser thinks this is valid but the molecule builder has no logic for it");        }    }        /**     * Translates a metal's name into it's atomic symbol.     *     * @param metalName The name of the metal, e.g. lead     * @return The given metal's atomic symbol e.g. Pb or null if none exist.     */    String getMetalAtomicSymbol (String metalName)    {        if (metalName == "aluminium")        {            return "Al";        }        else if (metalName == "magnesium" )        {            return "Mg";        }        else if (metalName == "gallium")        {            return "Ga";        }        else if (metalName == "indium")        {            return "In";        }        else if (metalName == "thallium")        {            return "Tl";        }        else if (metalName == "germanium")        {            return "Ge";        }        else if (metalName == "tin")        {            return "Sn";        }        else if (metalName == "lead")        {            return "Pb";        }        else if (metalName == "arsenic")        {            return "As";        }        else if (metalName == "antimony")        {            return "Sb";        }        else if (metalName == "bismuth")        {            return "Bi";        }                return null;    }        /**     * Adds an atom to the current molecule.     *     * @param newAtomType The atomic symbol for the atom.     * @param otherConnectingAtom An atom already in the molecule which     * the new one should connect to.     * @param bondOrder The order of the bond to use to join the two atoms.     * @param hydrogenCount The number of hydrogen atoms connected to this atom.     */    private void addAtom(String newAtomType, org.openscience.cdk.interfaces.IAtom otherConnectingAtom, double bondOrder, int hydrogenCount)    {        //Create the new atom and bond.        Atom newAtom = new Atom(newAtomType);        newAtom.setHydrogenCount(hydrogenCount);        Bond newBond = new Bond(newAtom, otherConnectingAtom, bondOrder);                //Add the new atom and bond to the molecule.        currentMolecule.addAtom(newAtom);        currentMolecule.addBond(newBond);    }        /**     * Adds other chains to the main chain connected at the specified atom.     *     * @param attachedSubstituents A vector of AttachedGroup's representing substituents.     */    private void addHeads(Vector attachedSubstituents)    {        Iterator substituentsIterator = attachedSubstituents.iterator();        while (substituentsIterator.hasNext())        {            AttachedGroup attachedSubstituent = (AttachedGroup) substituentsIterator.next();                        Iterator locationsIterator = attachedSubstituent.getLocations().iterator();            while (locationsIterator.hasNext())            {                Token locationToken = (Token) locationsIterator.next();                                int joinLocation = Integer.parseInt(locationToken.image) - 1;                org.openscience.cdk.interfaces.IAtom connectingAtom;                                //If join location wasn't specified we must be dealing with the "hack" which makes                //mainchains a substituent if a real substituent has already been parsed and interpreted as a main chain                if (joinLocation < 0)                {                    connectingAtom = endOfChain;                }                else                {                    connectingAtom = currentMolecule.getAtom(joinLocation);                }                                Molecule subChain = buildChain(attachedSubstituent.getLength(), false);                                Bond linkingBond = new Bond(subChain.getFirstAtom(), connectingAtom);                currentMolecule.addBond(linkingBond);                currentMolecule.add(subChain);            }        }    }        /**     * Start of the process of building a molecule from the parsed data. Passes the parsed     * tokens to other functions which build up the Molecule.     *     * @param mainChain The string representation of the length of the main chain.     * @param attachedSubstituents A vector of AttachedGroup's representing substituents.     * @param attachedGroups A vector of AttachedGroup's representing functional groups.     * @param isMainCyclic An indiacation of if the main chain is cyclic.     * @return The molecule as built from the parsed tokens.     */    protected Molecule buildMolecule(int mainChain, Vector attachedSubstituents    , Vector attachedGroups, boolean isMainCyclic, String name) throws    ParseException, CDKException    {        //Set up the molecle's name        currentMolecule.setID(name);        //Build the main chain        currentMolecule.add(buildChain(mainChain,isMainCyclic));                //Set the last atom here if a main chain has been built,         //if not rely on the functional group setting one of it's atoms as last        if (mainChain != 0) endOfChain = currentMolecule.getLastAtom();                //Add functional groups        buildFunGroups(attachedGroups);                //Add on further sub chains        addHeads(attachedSubstituents);                //Add the hydrogens to create a balanced molecule        HydrogenAdder adder = new HydrogenAdder();        adder.addImplicitHydrogensToSatisfyValency(currentMolecule);                        return currentMolecule;    }}

⌨️ 快捷键说明

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