/** * 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; }
/** * 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; }
/** * Determines if the atom can be of type AtomType. */ public boolean couldMatchAtomType(IAtomContainer atomContainer, IAtom atom, IAtomType atomType) { logger.debug(" ... matching atom ", atom.getSymbol(), " vs ", atomType); if (atomContainer.getBondOrderSum(atom) + atom.getImplicitHydrogenCount() < atomType.getBondOrderSum()) { logger.debug(" Match!"); return true; } logger.debug(" No Match"); return false; }
/** * Determines if the atom can be of type AtomType. */ public boolean couldMatchAtomType(IAtomContainer atomContainer, IAtom atom, IAtomType atomType) { logger.debug(" ... matching atom ", atom.getSymbol(), " vs ", atomType); if (atomContainer.getBondOrderSum(atom) + atom.getImplicitHydrogenCount() < atomType.getBondOrderSum()) { logger.debug(" Match!"); return true; } logger.debug(" No Match"); return false; }
/** * 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, IBond.Order maxBondOrder, IAtomType type) { logger.debug("couldMatchAtomType: ... matching atom ", atom, " vs ", type); int hcount = atom.getImplicitHydrogenCount(); 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 (!BondManipulator.isHigherOrder(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; }
/** * 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, IBond.Order maxBondOrder, IAtomType type) { logger.debug("couldMatchAtomType: ... matching atom ", atom, " vs ", type); int hcount = atom.getImplicitHydrogenCount(); 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 (!BondManipulator.isHigherOrder(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; }
@Test public void testSetBondOrderSum_Double() { IAtomType at = (IAtomType) newChemObject(); at.setBondOrderSum(4.0); Assert.assertEquals(4.0, at.getBondOrderSum(), 0.001); }
/** * Constructs an isotope by copying the symbol, atomic number, * flags, identifier, exact mass, natural abundance and mass * number from the given IIsotope. It does not copy the * listeners and properties. If the element is an instance of * IAtomType, then the maximum bond order, bond order sum, * van der Waals and covalent radii, formal charge, hybridization, * electron valency, formal neighbour count and atom type name * are copied too. * * @param element IIsotope to copy information from */ public AtomType(IElement element) { super(element); if (element instanceof IAtomType) { this.maxBondOrder = ((IAtomType) element).getMaxBondOrder(); this.bondOrderSum = ((IAtomType) element).getBondOrderSum(); this.covalentRadius = ((IAtomType) element).getCovalentRadius(); this.formalCharge = ((IAtomType) element).getFormalCharge(); this.hybridization = ((IAtomType) element).getHybridization(); this.electronValency = ((IAtomType) element).getValency(); this.formalNeighbourCount = ((IAtomType) element).getFormalNeighbourCount(); this.identifier = ((IAtomType) element).getAtomTypeName(); } }
/** * 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); }
/** * Constructs an isotope by copying the symbol, atomic number, * flags, identifier, exact mass, natural abundance and mass * number from the given IIsotope. It does not copy the * listeners and properties. If the element is an instanceof * IAtomType, then the maximum bond order, bond order sum, * van der Waals and covalent radii, formal charge, hybridization, * electron valency, formal neighbour count and atom type name * are copied too. * * @param element IIsotope to copy information from */ public AtomType(IElement element) { super(element); if (element instanceof IAtomType) { this.maxBondOrder = ((IAtomType) element).getMaxBondOrder(); this.bondOrderSum = ((IAtomType) element).getBondOrderSum(); this.covalentRadius = ((IAtomType) element).getCovalentRadius(); this.formalCharge = ((IAtomType) element).getFormalCharge(); this.hybridization = ((IAtomType) element).getHybridization(); this.electronValency = ((IAtomType) element).getValency(); this.formalNeighbourCount = ((IAtomType) element).getFormalNeighbourCount(); this.identifier = ((IAtomType) element).getAtomTypeName(); } }
/** * Constructs an isotope by copying the symbol, atomic number, * flags, identifier, exact mass, natural abundance and mass * number from the given IIsotope. It does not copy the * listeners and properties. If the element is an instance of * IAtomType, then the maximum bond order, bond order sum, * van der Waals and covalent radii, formal charge, hybridization, * electron valency, formal neighbour count and atom type name * are copied too. * * @param element IIsotope to copy information from */ public AtomType(IElement element) { super(element); if (element instanceof IAtomType) { this.maxBondOrder = ((IAtomType) element).getMaxBondOrder(); this.bondOrderSum = ((IAtomType) element).getBondOrderSum(); this.covalentRadius = ((IAtomType) element).getCovalentRadius(); this.formalCharge = ((IAtomType) element).getFormalCharge(); this.hybridization = ((IAtomType) element).getHybridization(); this.electronValency = ((IAtomType) element).getValency(); this.formalNeighbourCount = ((IAtomType) element).getFormalNeighbourCount(); this.identifier = ((IAtomType) element).getAtomTypeName(); } }
/** * Constructs an isotope by copying the symbol, atomic number, * flags, identifier, exact mass, natural abundance and mass * number from the given IIsotope. It does not copy the * listeners and properties. If the element is an instanceof * IAtomType, then the maximum bond order, bond order sum, * van der Waals and covalent radii, formal charge, hybridization, * electron valency, formal neighbour count and atom type name * are copied too. * * @param element IIsotope to copy information from */ public AtomType(IElement element) { super(element); if (element instanceof IAtomType) { this.maxBondOrder = ((IAtomType) element).getMaxBondOrder(); this.bondOrderSum = ((IAtomType) element).getBondOrderSum(); this.covalentRadius = ((IAtomType) element).getCovalentRadius(); this.formalCharge = ((IAtomType) element).getFormalCharge(); this.hybridization = ((IAtomType) element).getHybridization(); this.electronValency = ((IAtomType) element).getValency(); this.formalNeighbourCount = ((IAtomType) element).getFormalNeighbourCount(); this.identifier = ((IAtomType) element).getAtomTypeName(); } }
/** * Method to test the clone() method */ @Test public void testClone_IBondOrderSum() throws Exception { IAtomType at = (IAtomType) newChemObject(); at.setBondOrderSum(1.0); IAtomType clone = (IAtomType) at.clone(); at.setBondOrderSum(2.0); Assert.assertEquals(1.0, clone.getBondOrderSum(), 0.001); }
ImmutableAtomType(IAtomType type) { this.element = type.getSymbol(); this.atomicNumber = type.getAtomicNumber(); this.naturalAbundance = type.getNaturalAbundance(); this.exactMass = type.getExactMass(); this.massNumber = type.getMassNumber(); this.formalCharge = type.getFormalCharge(); this.hybridization = type.getHybridization(); this.formalNeighbourCount = type.getFormalNeighbourCount(); this.identifier = type.getAtomTypeName(); this.maxBondOrder = type.getMaxBondOrder(); this.bondOrderSum = type.getBondOrderSum(); this.covalentRadius = type.getCovalentRadius(); this.flags = (short)type.getFlagValue(); this.properties = Collections.unmodifiableMap(type.getProperties()); if (type.getValency() != null) { this.electronValency = type.getValency(); } else { Integer piBondCount = type.getProperty(CDKConstants.PI_BOND_COUNT, Integer.class); if (piBondCount != null && formalNeighbourCount != null) { this.electronValency = piBondCount + formalNeighbourCount; } else { this.electronValency = null; } } }
ImmutableAtomType(IAtomType type) { this.element = type.getSymbol(); this.atomicNumber = type.getAtomicNumber(); this.naturalAbundance = type.getNaturalAbundance(); this.exactMass = type.getExactMass(); this.massNumber = type.getMassNumber(); this.formalCharge = type.getFormalCharge(); this.hybridization = type.getHybridization(); this.formalNeighbourCount = type.getFormalNeighbourCount(); this.identifier = type.getAtomTypeName(); this.maxBondOrder = type.getMaxBondOrder(); this.bondOrderSum = type.getBondOrderSum(); this.covalentRadius = type.getCovalentRadius(); this.flags = (short)type.getFlagValue(); this.properties = Collections.unmodifiableMap(type.getProperties()); if (type.getValency() != null) { this.electronValency = type.getValency(); } else { Integer piBondCount = type.getProperty(CDKConstants.PI_BOND_COUNT, Integer.class); if (piBondCount != null && formalNeighbourCount != null) { this.electronValency = piBondCount + formalNeighbourCount; } else { this.electronValency = null; } } }
@Test public void testGetAtomType_String() throws Exception { IAtomType atomType = atf.getAtomType("C4"); Assert.assertNotNull(atomType); Assert.assertEquals("C", atomType.getSymbol()); Assert.assertEquals("C4", atomType.getAtomTypeName()); Assert.assertEquals(4.0, atomType.getBondOrderSum(), 0.001); Assert.assertEquals(IBond.Order.TRIPLE, atomType.getMaxBondOrder()); }
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 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; }