📄 valencyhybridchecker.java
字号:
/** * Returns wether a bond is saturated. A bond is saturated if * <b>both</b> Atoms in the bond are saturated. */ public boolean isSaturated(IBond bond, IAtomContainer atomContainer) throws CDKException { logger.debug("isBondSaturated?: ", bond); IAtom[] atoms = BondManipulator.getAtomArray(bond); boolean isSaturated = true; for (int i=0; i<atoms.length; i++) { logger.debug("isSaturated(Bond, AC): atom I=", i); isSaturated = isSaturated && isSaturated(atoms[i], atomContainer); } logger.debug("isSaturated(Bond, AC): result=", isSaturated); return isSaturated; } /** * Determines of all atoms on the AtomContainer are saturated. */ public boolean isSaturated(IAtomContainer container) throws CDKException { return allSaturated(container); } public boolean allSaturated(IAtomContainer ac) throws CDKException { logger.debug("Are all atoms saturated?"); for (int f = 0; f < ac.getAtomCount(); f++) { if (!isSaturated(ac.getAtom(f), ac)) { return false; } } return true; } /** * Determines if the atom can be of type AtomType. That is, it sees if this * AtomType only differs in bond orders, or implicit hydrogen count. */ public boolean couldMatchAtomType(IAtom atom, double bondOrderSum, double maxBondOrder, IAtomType type) { logger.debug("couldMatchAtomType: ... matching atom ", atom, " vs ", type); int hcount = atom.getHydrogenCount(); int charge = atom.getFormalCharge(); if (charge == type.getFormalCharge()) { logger.debug("couldMatchAtomType: formal charge matches..."); if (atom.getHybridization() == type.getHybridization()) { logger.debug("couldMatchAtomType: hybridization is OK..."); if (bondOrderSum + hcount <= type.getBondOrderSum()) { logger.debug("couldMatchAtomType: bond order sum is OK..."); if (maxBondOrder <= type.getMaxBondOrder()) { logger.debug("couldMatchAtomType: max bond order is OK... We have a match!"); return true; } } else { logger.debug("couldMatchAtomType: no match", "" + (bondOrderSum + hcount), " > ", "" + type.getBondOrderSum()); } } } else { logger.debug("couldMatchAtomType: formal charge does NOT match..."); } logger.debug("couldMatchAtomType: No Match"); return false; } /** * Calculates the number of hydrogens that can be added to the given atom to fullfil * the atom's valency. It will return 0 for PseudoAtoms, and for atoms for which it * does not have an entry in the configuration file. */ public int calculateNumberOfImplicitHydrogens(IAtom atom, double bondOrderSum, double maxBondOrder, int neighbourCount) throws CDKException { int missingHydrogens = 0; if (atom instanceof IPseudoAtom) { logger.debug("don't figure it out... it simply does not lack H's"); return 0; } logger.debug("Calculating number of missing hydrogen atoms"); // get default atom IAtomType[] atomTypes = getAtomTypeFactory(atom.getBuilder()).getAtomTypes(atom.getSymbol()); if (atomTypes.length == 0) { logger.warn("Element not found in configuration file: ", atom); return 0; } logger.debug("Found atomtypes: ", atomTypes.length); for (int f = 0; f < atomTypes.length; f++) { IAtomType type = atomTypes[f]; if (couldMatchAtomType(atom, bondOrderSum, maxBondOrder, type)) { logger.debug("This type matches: ", type); int formalNeighbourCount = type.getFormalNeighbourCount(); if (type.getHybridization() == CDKConstants.HYBRIDIZATION_UNSET) { missingHydrogens = (int) (type.getBondOrderSum() - bondOrderSum); } else { switch (atom.getHybridization()) { case CDKConstants.HYBRIDIZATION_SP3: missingHydrogens = formalNeighbourCount - neighbourCount; break; case CDKConstants.HYBRIDIZATION_SP2: missingHydrogens = formalNeighbourCount - neighbourCount; break; case CDKConstants.HYBRIDIZATION_SP1: missingHydrogens = formalNeighbourCount - neighbourCount; break; default: missingHydrogens = (int) (type.getBondOrderSum() - bondOrderSum); } } break; } } logger.debug("missing hydrogens: ", missingHydrogens); return missingHydrogens; } /** * Checks wether an Atom is saturated by comparing it with known AtomTypes. * It returns true if the atom is an PseudoAtom and when the element is not in the list. */ public boolean isSaturated(IAtom atom, IAtomContainer container) throws CDKException { if (atom instanceof IPseudoAtom) { logger.debug("don't figure it out... it simply does not lack H's"); return true; } IAtomType[] atomTypes = getAtomTypeFactory(atom.getBuilder()).getAtomTypes(atom.getSymbol()); if (atomTypes.length == 0) { logger.warn("Missing entry in atom type list for ", atom.getSymbol()); return true; } double bondOrderSum = container.getBondOrderSum(atom); double maxBondOrder = container.getMaximumBondOrder(atom); int hcount = atom.getHydrogenCount(); int charge = atom.getFormalCharge(); logger.debug("Checking saturation of atom ", atom.getSymbol()); logger.debug("bondOrderSum: ", bondOrderSum); logger.debug("maxBondOrder: ", maxBondOrder); logger.debug("hcount: ", hcount); logger.debug("charge: ", charge); boolean elementPlusChargeMatches = false; for (int f = 0; f < atomTypes.length; f++) { IAtomType type = atomTypes[f]; if (couldMatchAtomType(atom, bondOrderSum, maxBondOrder, type)) { if (bondOrderSum + hcount == type.getBondOrderSum() && maxBondOrder <= type.getMaxBondOrder()) { logger.debug("We have a match: ", type); logger.debug("Atom is saturated: ", atom.getSymbol()); return true; } else { // ok, the element and charge matche, but unfulfilled elementPlusChargeMatches = true; } } // else: formal charges don't match } if (elementPlusChargeMatches) { logger.debug("No, atom is not saturated."); return false; } // ok, the found atom was not in the list throw new CDKException("The atom with element " + atom.getSymbol() + " and charge " + charge + " is not found."); } public int calculateNumberOfImplicitHydrogens(IAtom atom, IAtomContainer container) throws CDKException { return this.calculateNumberOfImplicitHydrogens(atom, container.getBondOrderSum(atom), container.getMaximumBondOrder(atom), container.getConnectedAtomsCount(atom) ); } protected AtomTypeFactory getAtomTypeFactory(IChemObjectBuilder builder) throws CDKException { if (structgenATF == null) { try { structgenATF = AtomTypeFactory.getInstance(atomTypeList, builder); } catch (Exception exception) { logger.debug(exception); throw new CDKException("Could not instantiate AtomTypeFactory!", exception); } } return structgenATF; } /** * Determines if the atom can be of type AtomType. */ public boolean couldMatchAtomType(IAtomContainer container, IAtom atom, IAtomType type) { double bondOrderSum = container.getBondOrderSum(atom); double maxBondOrder = container.getMaximumBondOrder(atom); return couldMatchAtomType(atom, bondOrderSum, maxBondOrder, type); } public void setInterrupted(boolean interrupted) { this.interrupted = interrupted; } public boolean isInterrupted() { return this.interrupted; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -