/** * Returns the number of double bond equivalents in this molecule. * * @param formula The IMolecularFormula to calculate * @return The number of DBEs * @throws CDKException if DBE cannot be be evaluated * * @cdk.keyword DBE * @cdk.keyword double bond equivalent */ public static double getDBE(IMolecularFormula formula) throws CDKException { int valencies[] = new int[5]; IAtomContainer ac = getAtomContainer(formula); AtomTypeFactory factory = AtomTypeFactory.getInstance( "org/openscience/cdk/config/data/structgen_atomtypes.xml", ac.getBuilder()); for (int f = 0; f < ac.getAtomCount(); f++) { IAtomType[] types = factory.getAtomTypes(ac.getAtom(f).getSymbol()); if (types.length == 0) throw new CDKException( "Calculation of double bond equivalents not possible due to problems with element " + ac.getAtom(f).getSymbol()); // valencies[(int) (types[0].getBondOrderSum() + ac.getAtom(f).getFormalCharge())]++; valencies[types[0].getBondOrderSum().intValue()]++; } return 1 + (valencies[4]) + (valencies[3] / 2) - (valencies[1] / 2); }
private boolean createBondsWithRebondTool(IAtomContainer molecule) { RebondTool tool = new RebondTool(2.0, 0.5, 0.5); try { // configure atoms AtomTypeFactory factory = AtomTypeFactory.getInstance("org/openscience/cdk/config/data/jmol_atomtypes.txt", molecule.getBuilder()); for (IAtom atom : molecule.atoms()) { try { IAtomType[] types = factory.getAtomTypes(atom.getSymbol()); if (types.length > 0) { // just pick the first one AtomTypeManipulator.configure(atom, types[0]); } else { logger.warn("Could not configure atom with symbol: " + atom.getSymbol()); } } catch (Exception e) { logger.warn("Could not configure atom (but don't care): " + e.getMessage()); logger.debug(e); } } tool.rebond(molecule); } catch (Exception e) { logger.error("Could not rebond the polymer: " + e.getMessage()); logger.debug(e); } return true; }
private boolean createBondsWithRebondTool(IAtomContainer molecule) { RebondTool tool = new RebondTool(2.0, 0.5, 0.5); try { // configure atoms AtomTypeFactory factory = AtomTypeFactory.getInstance("org/openscience/cdk/config/data/jmol_atomtypes.txt", molecule.getBuilder()); for (IAtom atom : molecule.atoms()) { try { IAtomType[] types = factory.getAtomTypes(atom.getSymbol()); if (types.length > 0) { // just pick the first one AtomTypeManipulator.configure(atom, types[0]); } else { logger.warn("Could not configure atom with symbol: " + atom.getSymbol()); } } catch (Exception e) { logger.warn("Could not configure atom (but don't care): " + e.getMessage()); logger.debug(e); } } tool.rebond(molecule); } catch (Exception e) { logger.error("Could not rebond the polymer: " + e.getMessage()); logger.debug(e); } return true; }
/** * Returns the currently maximum formable bond order for this atom. * * @param atom The atom to be checked * @param ac The AtomContainer that provides the context * @return the currently maximum formable bond order for this atom */ public double getCurrentMaxBondOrder(IAtom atom, IAtomContainer ac) throws CDKException { IAtomType[] atomTypes = getAtomTypeFactory(atom.getBuilder()).getAtomTypes(atom.getSymbol()); if (atomTypes.length == 0) return 0; double bondOrderSum = ac.getBondOrderSum(atom); Integer hcount = atom.getImplicitHydrogenCount() == CDKConstants.UNSET ? 0 : atom.getImplicitHydrogenCount(); double max = 0; double current = 0; for (int f = 0; f < atomTypes.length; f++) { current = hcount + bondOrderSum; if (atomTypes[f].getBondOrderSum() - current > max) { max = atomTypes[f].getBondOrderSum() - current; } } return max; }
IAtomType[] types = factory.getAtomTypes(atom.getSymbol()); for (IAtomType type : types) { logger.debug(" ... matching atom ", atom, " vs ", type);
/** * Returns the currently maximum formable bond order for this atom. * * @param atom The atom to be checked * @param ac The AtomContainer that provides the context * @return the currently maximum formable bond order for this atom */ public double getCurrentMaxBondOrder(IAtom atom, IAtomContainer ac) throws CDKException { IAtomType[] atomTypes = getAtomTypeFactory(atom.getBuilder()).getAtomTypes(atom.getSymbol()); if (atomTypes.length == 0) return 0; double bondOrderSum = ac.getBondOrderSum(atom); Integer hcount = atom.getImplicitHydrogenCount() == CDKConstants.UNSET ? 0 : atom.getImplicitHydrogenCount(); double max = 0; double current = 0; for (int f = 0; f < atomTypes.length; f++) { current = hcount + bondOrderSum; if (atomTypes[f].getBondOrderSum() - current > max) { max = atomTypes[f].getBondOrderSum() - current; } } return max; }
@Test public void testGetAtomTypes_String() throws Exception { IAtomType[] atomTypes = atf.getAtomTypes("C"); Assert.assertNotNull(atomTypes); Assert.assertTrue(0 < atomTypes.length); Assert.assertEquals("C", atomTypes[0].getSymbol()); }
IAtomType[] types = factory.getAtomTypes(atom.getSymbol()); for (IAtomType type : types) { logger.debug(" ... matching atom ", atom, " vs ", type);
"org/openscience/cdk/dict/data/cdk-atom-types.owl", atom.getBuilder()); int bos = (int) molecule.getBondOrderSum(atom); 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: "
int hcount = atom.getImplicitHydrogenCount() == null ? 0 : atom.getImplicitHydrogenCount(); IAtomType[] types = factory.getAtomTypes(atom.getSymbol()); for (IAtomType type : types) { logger.debug(" ... matching atom ", atom, " vs ", type);
int hcount = atom.getImplicitHydrogenCount() == null ? 0 : atom.getImplicitHydrogenCount(); IAtomType[] types = factory.getAtomTypes(atom.getSymbol()); for (IAtomType type : types) { logger.debug(" ... matching atom ", atom, " vs ", type);
/** * Test if all elements up to and including Uranium have atom types. * * @throws Exception */ @Test public void testAllElementsRepresented() throws Exception { AtomTypeFactory factory = AtomTypeFactory.getInstance("org/openscience/cdk/dict/data/cdk-atom-types.owl", SilentChemObjectBuilder.getInstance()); Assert.assertTrue("Could not read the atom types", factory.getSize() != 0); String errorMessage = "Elements without atom type(s) defined in the XML:"; final int testUptoAtomicNumber = 36; // TODO: 92 ? int elementsMissingTypes = 0; for (int i = 1; i < testUptoAtomicNumber; i++) { String symbol = PeriodicTable.getSymbol(i); IAtomType[] expectedTypes = factory.getAtomTypes(symbol); if (expectedTypes.length == 0) { errorMessage += " " + symbol; elementsMissingTypes++; } } Assert.assertEquals(errorMessage, 0, elementsMissingTypes); }
IAtom partner = atoms[1]; logger.debug(" saturating bond: ", atom.getSymbol(), "-", partner.getSymbol()); IAtomType[] atomTypes1 = getAtomTypeFactory(bond.getBuilder()).getAtomTypes(atom.getSymbol()); IAtomType[] atomTypes2 = getAtomTypeFactory(bond.getBuilder()).getAtomTypes(partner.getSymbol()); for (int atCounter1 = 0; atCounter1 < atomTypes1.length; atCounter1++) { IAtomType aType1 = atomTypes1[atCounter1];
IAtom partner = atoms[1]; logger.debug(" saturating bond: ", atom.getSymbol(), "-", partner.getSymbol()); IAtomType[] atomTypes1 = getAtomTypeFactory(bond.getBuilder()).getAtomTypes(atom.getSymbol()); IAtomType[] atomTypes2 = getAtomTypeFactory(bond.getBuilder()).getAtomTypes(partner.getSymbol()); for (int atCounter1 = 0; atCounter1 < atomTypes1.length; atCounter1++) { IAtomType aType1 = atomTypes1[atCounter1];
public boolean hasPerfectConfiguration(IAtom atom, IAtomContainer ac) throws CDKException { double bondOrderSum = ac.getBondOrderSum(atom); IBond.Order maxBondOrder = ac.getMaximumBondOrder(atom); IAtomType[] atomTypes = getAtomTypeFactory(atom.getBuilder()).getAtomTypes(atom.getSymbol()); if (atomTypes.length == 0) return true; logger.debug("*** Checking for perfect configuration ***"); try { logger.debug("Checking configuration of atom " + ac.indexOf(atom)); logger.debug("Atom has bondOrderSum = " + bondOrderSum); logger.debug("Atom has max = " + bondOrderSum); } catch (Exception exc) { } for (int f = 0; f < atomTypes.length; f++) { if (bondOrderSum == atomTypes[f].getBondOrderSum() && maxBondOrder == atomTypes[f].getMaxBondOrder()) { try { logger.debug("Atom " + ac.indexOf(atom) + " has perfect configuration"); } catch (Exception exc) { } return true; } } try { logger.debug("*** Atom " + ac.indexOf(atom) + " has imperfect configuration ***"); } catch (Exception exc) { } return false; }
public boolean hasPerfectConfiguration(IAtom atom, IAtomContainer ac) throws CDKException { double bondOrderSum = ac.getBondOrderSum(atom); IBond.Order maxBondOrder = ac.getMaximumBondOrder(atom); IAtomType[] atomTypes = getAtomTypeFactory(atom.getBuilder()).getAtomTypes(atom.getSymbol()); if (atomTypes.length == 0) return true; logger.debug("*** Checking for perfect configuration ***"); try { logger.debug("Checking configuration of atom " + ac.indexOf(atom)); logger.debug("Atom has bondOrderSum = " + bondOrderSum); logger.debug("Atom has max = " + bondOrderSum); } catch (Exception exc) { } for (int f = 0; f < atomTypes.length; f++) { if (bondOrderSum == atomTypes[f].getBondOrderSum() && maxBondOrder == atomTypes[f].getMaxBondOrder()) { try { logger.debug("Atom " + ac.indexOf(atom) + " has perfect configuration"); } catch (Exception exc) { } return true; } } try { logger.debug("*** Atom " + ac.indexOf(atom) + " has imperfect configuration ***"); } catch (Exception exc) { } return false; }
/** * Checks if the current atom has exceeded its bond order sum value. * * @param atom The Atom to check * @param ac The atomcontainer context * @return oversaturated or not */ public boolean isOverSaturated(IAtom atom, IAtomContainer ac) throws CDKException { IAtomType[] atomTypes = getAtomTypeFactory(atom.getBuilder()).getAtomTypes(atom.getSymbol()); if (atomTypes.length == 0) return false; double bondOrderSum = ac.getBondOrderSum(atom); IBond.Order maxBondOrder = ac.getMaximumBondOrder(atom); Integer hcount = atom.getImplicitHydrogenCount() == CDKConstants.UNSET ? 0 : atom.getImplicitHydrogenCount(); Integer charge = atom.getFormalCharge() == CDKConstants.UNSET ? 0 : atom.getFormalCharge(); try { logger.debug("*** Checking saturation of atom " + ac.indexOf(atom) + " ***"); logger.debug("bondOrderSum: " + bondOrderSum); logger.debug("maxBondOrder: " + maxBondOrder); logger.debug("hcount: " + hcount); } catch (Exception exc) { } for (int f = 0; f < atomTypes.length; f++) { if (bondOrderSum - charge + hcount > atomTypes[f].getBondOrderSum()) { logger.debug("*** Good ! ***"); return true; } } logger.debug("*** Bad ! ***"); return false; }
/** * Checks if the current atom has exceeded its bond order sum value. * * @param atom The Atom to check * @param ac The atomcontainer context * @return oversaturated or not */ public boolean isOverSaturated(IAtom atom, IAtomContainer ac) throws CDKException { IAtomType[] atomTypes = getAtomTypeFactory(atom.getBuilder()).getAtomTypes(atom.getSymbol()); if (atomTypes.length == 0) return false; double bondOrderSum = ac.getBondOrderSum(atom); IBond.Order maxBondOrder = ac.getMaximumBondOrder(atom); Integer hcount = atom.getImplicitHydrogenCount() == CDKConstants.UNSET ? 0 : atom.getImplicitHydrogenCount(); Integer charge = atom.getFormalCharge() == CDKConstants.UNSET ? 0 : atom.getFormalCharge(); try { logger.debug("*** Checking saturation of atom " + ac.indexOf(atom) + " ***"); logger.debug("bondOrderSum: " + bondOrderSum); logger.debug("maxBondOrder: " + maxBondOrder); logger.debug("hcount: " + hcount); } catch (Exception exc) { } for (int f = 0; f < atomTypes.length; f++) { if (bondOrderSum - charge + hcount > atomTypes[f].getBondOrderSum()) { logger.debug("*** Good ! ***"); return true; } } logger.debug("*** Bad ! ***"); return false; }
/** * Checks whether an Atom is saturated by comparing it with known AtomTypes. */ @Override public boolean isSaturated(IAtom atom, IAtomContainer ac) throws CDKException { IAtomType[] atomTypes = getAtomTypeFactory(atom.getBuilder()).getAtomTypes(atom.getSymbol()); if (atomTypes.length == 0) return true; double bondOrderSum = ac.getBondOrderSum(atom); IBond.Order maxBondOrder = ac.getMaximumBondOrder(atom); Integer hcount = atom.getImplicitHydrogenCount() == CDKConstants.UNSET ? 0 : atom.getImplicitHydrogenCount(); Integer charge = atom.getFormalCharge() == CDKConstants.UNSET ? 0 : atom.getFormalCharge(); try { logger.debug("*** Checking saturation of atom ", atom.getSymbol(), "" + ac.indexOf(atom) + " ***"); logger.debug("bondOrderSum: " + bondOrderSum); logger.debug("maxBondOrder: " + maxBondOrder); logger.debug("hcount: " + hcount); } catch (Exception exc) { logger.debug(exc); } for (int f = 0; f < atomTypes.length; f++) { if (bondOrderSum - charge + hcount == atomTypes[f].getBondOrderSum() && !BondManipulator.isHigherOrder(maxBondOrder, atomTypes[f].getMaxBondOrder())) { logger.debug("*** Good ! ***"); return true; } } logger.debug("*** Bad ! ***"); return false; }
/** * Checks whether an Atom is saturated by comparing it with known AtomTypes. */ @Override public boolean isSaturated(IAtom atom, IAtomContainer ac) throws CDKException { IAtomType[] atomTypes = getAtomTypeFactory(atom.getBuilder()).getAtomTypes(atom.getSymbol()); if (atomTypes.length == 0) return true; double bondOrderSum = ac.getBondOrderSum(atom); IBond.Order maxBondOrder = ac.getMaximumBondOrder(atom); Integer hcount = atom.getImplicitHydrogenCount() == CDKConstants.UNSET ? 0 : atom.getImplicitHydrogenCount(); Integer charge = atom.getFormalCharge() == CDKConstants.UNSET ? 0 : atom.getFormalCharge(); try { logger.debug("*** Checking saturation of atom ", atom.getSymbol(), "" + ac.indexOf(atom) + " ***"); logger.debug("bondOrderSum: " + bondOrderSum); logger.debug("maxBondOrder: " + maxBondOrder); logger.debug("hcount: " + hcount); } catch (Exception exc) { logger.debug(exc); } for (int f = 0; f < atomTypes.length; f++) { if (bondOrderSum - charge + hcount == atomTypes[f].getBondOrderSum() && !BondManipulator.isHigherOrder(maxBondOrder, atomTypes[f].getMaxBondOrder())) { logger.debug("*** Good ! ***"); return true; } } logger.debug("*** Bad ! ***"); return false; }