📄 basicvalidator.java
字号:
report.addCDKError(isElementOrPseudo); } } return report; } // the Bond tests private ValidationReport validateStereoChemistry(Bond bond) { ValidationReport report = new ValidationReport(); ValidationTest bondStereo = new ValidationTest(bond, "Defining stereochemistry on bonds is not safe.", "Use atom based stereochemistry." ); if (bond.getStereo() != CDKConstants.STEREO_BOND_NONE) { report.addWarning(bondStereo); } else { report.addOK(bondStereo); } return report; } private ValidationReport validateMaxBondOrder(Bond bond) { ValidationReport report = new ValidationReport(); ValidationTest maxBO = new ValidationTest(bond, "Bond order exceeds the maximum for one of its atoms." ); try { AtomTypeFactory structgenATF = AtomTypeFactory.getInstance( "org/openscience/cdk/config/data/structgen_atomtypes.xml", bond.getBuilder() ); for (int i=0; i<bond.getAtomCount(); i++) { org.openscience.cdk.interfaces.IAtom atom = bond.getAtom(i); if (atom instanceof PseudoAtom) { // ok, all is fine; we don't know the properties of pseudo atoms break; } org.openscience.cdk.interfaces.IAtomType[] atomTypes = structgenATF.getAtomTypes(atom.getSymbol()); org.openscience.cdk.interfaces.IAtomType failedOn = null; boolean foundMatchingAtomType = false; for (int j=0; j<atomTypes.length; j++) { if (bond.getOrder() <= atomTypes[j].getMaxBondOrder()) { foundMatchingAtomType = true; } else { failedOn = atomTypes[j]; } } if (foundMatchingAtomType) { report.addOK(maxBO); } else { if (failedOn != null) { maxBO.setDetails( "Bond order exceeds the one allowed for atom " + atom.getSymbol() + " for which the maximum bond order is " + failedOn.getMaxBondOrder() ); } report.addError(maxBO); } } } catch (Exception exception) { logger.error("Error while performing atom bos validation"); logger.debug(exception); maxBO.setDetails("Error while performing atom bos validation: " + exception.toString()); report.addCDKError(maxBO); } return report; } // the Isotope tests public ValidationReport validateIsotopeExistence(IIsotope isotope) { ValidationReport report = new ValidationReport(); ValidationTest isotopeExists = new ValidationTest(isotope, "Isotope with this mass number is not known for this element." ); try { IsotopeFactory isotopeFac = IsotopeFactory.getInstance(isotope.getBuilder()); IIsotope[] isotopes = isotopeFac.getIsotopes(isotope.getSymbol()); if (isotope.getMassNumber() != 0) { boolean foundKnownIsotope = false; for (int i=0; i<isotopes.length; i++) { if (isotopes[i].getMassNumber() == isotope.getMassNumber()) { foundKnownIsotope = true; } } if (!foundKnownIsotope) { report.addError(isotopeExists); } else { report.addOK(isotopeExists); } } else { // isotopic number is not set report.addOK(isotopeExists); } } catch (Exception exception) { // too bad... } return report; } // the Molecule tests private ValidationReport validateBondOrderSum(org.openscience.cdk.interfaces.IAtom atom, Molecule molecule) { ValidationReport report = new ValidationReport(); ValidationTest checkBondSum = new ValidationTest(atom, "The atom's total bond order is too high." ); try { AtomTypeFactory structgenATF = AtomTypeFactory.getInstance( "org/openscience/cdk/config/data/valency_atomtypes.xml", atom.getBuilder() ); int bos = (int)molecule.getBondOrderSum(atom); org.openscience.cdk.interfaces.IAtomType[] atomTypes = structgenATF.getAtomTypes(atom.getSymbol()); if (atomTypes.length == 0) { checkBondSum.setDetails( "Cannot validate bond order sum for atom not in valency atom type list: " + atom.getSymbol() ); report.addWarning(checkBondSum); } else { org.openscience.cdk.interfaces.IAtomType failedOn = null; boolean foundMatchingAtomType = false; for (int j=0; j<atomTypes.length; j++) { org.openscience.cdk.interfaces.IAtomType type = atomTypes[j]; if (atom.getFormalCharge() == type.getFormalCharge()) { foundMatchingAtomType = true; if (bos == type.getBondOrderSum()) { // skip this atom type } else { failedOn = atomTypes[j]; } } } if (foundMatchingAtomType) { report.addOK(checkBondSum); } else { if (failedOn != null) { checkBondSum.setDetails( "Bond order exceeds the one allowed for atom " + atom.getSymbol() + " for which the total bond order is " + failedOn.getBondOrderSum() ); } report.addError(checkBondSum); } } } catch (Exception exception) { logger.error("Error while performing atom bos validation: ", exception.getMessage()); logger.debug(exception); } return report; } private ValidationReport validateAtomCountConservation(Reaction reaction, AtomContainer reactants, AtomContainer products) { ValidationReport report = new ValidationReport(); ValidationTest atomCount = new ValidationTest(reaction, "Atom count mismatch for reaction: the product side has a different atom count than the reactant side." ); if (reactants.getAtomCount() != products.getAtomCount()) { report.addError(atomCount); } else { report.addOK(atomCount); } return report; } private ValidationReport validateChargeConservation(Reaction reaction, AtomContainer reactants, AtomContainer products) { ValidationReport report = new ValidationReport(); ValidationTest chargeConservation = new ValidationTest(reaction, "Total formal charge is not preserved during the reaction" ); java.util.Iterator atoms1 = reactants.atoms(); int totalCharge1 = 0; while (atoms1.hasNext()) { totalCharge1 =+ ((IAtom)atoms1.next()).getFormalCharge(); } java.util.Iterator atoms2 = products.atoms(); int totalCharge2 = 0; while (atoms2.hasNext()) { totalCharge2 =+ ((IAtom)atoms2.next()).getFormalCharge(); } if (totalCharge1 != totalCharge2) { report.addError(chargeConservation); } else { report.addOK(chargeConservation); } return report; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -