private void setSourceSingleAtomMap(IQueryAtomContainer source, boolean removeHydrogen) throws CDKException { int counter = 0; BondEnergies be = BondEnergies.getInstance(); for (IAtom sourceAtom : source.atoms()) { IQueryAtom smartAtom = (IQueryAtom) sourceAtom; if ((removeHydrogen && !smartAtom.getSymbol().equals("H")) || (!removeHydrogen)) { for (IAtom targetAtom : target.atoms()) { Map<IAtom, IAtom> mapAtoms = new HashMap<IAtom, IAtom>(); if (smartAtom.matches(targetAtom)) { mapAtoms.put(sourceAtom, targetAtom); List<IBond> bonds = target.getConnectedBondsList(targetAtom); double totalOrder = 0; for (IBond bond : bonds) { Order order = bond.getOrder(); totalOrder += order.numeric() + be.getEnergies(bond); } if (!Objects.equals(targetAtom.getFormalCharge(), sourceAtom.getFormalCharge())) { totalOrder += 0.5; } connectedBondOrder.put(counter, totalOrder); mappings.add(counter++, mapAtoms); } } } else { System.err.println("Skippping Hydrogen mapping or This is not a single mapping case!"); } } }
if ((atomE.getSymbol().equals("O") && atomP.getSymbol().equals("P")) || (atomE.getSymbol().equals("P") && atomP.getSymbol().equals("O"))) { if (bond.getOrder().equals(SINGLE)) { IAtom oxygen = atomE.getSymbol().equals("O") ? atomE : atomP; List<IBond> neighbourBonds = container.getConnectedBondsList(oxygen);
/** * Returns bond energy for a bond type, given atoms and bond type * @param sourceAtom First bondEnergy * @param targetAtom Second bondEnergy * @param bondOrder (single, double etc) * @return bond energy */ public synchronized int getEnergies(String sourceAtom, String targetAtom, Order bondOrder) { int D_kJ_per_mol = -1; if (sourceAtom.equalsIgnoreCase("R")) { sourceAtom = "C"; } if (targetAtom.equalsIgnoreCase("R")) { targetAtom = "C"; } for (Map.Entry<Integer, BondEnergy> entry : bondEngergies.entrySet()) { BondEnergy bondEnergy = entry.getValue(); String atom1 = bondEnergy.getSymbolFirstAtom(); String atom2 = bondEnergy.getSymbolSecondAtom(); if ((atom1.equalsIgnoreCase(sourceAtom) && atom2.equalsIgnoreCase(targetAtom)) || (atom2.equalsIgnoreCase(sourceAtom) && atom1.equalsIgnoreCase(targetAtom))) { Order order = bondEnergy.getBondOrder(); if (order != null && bondOrder != null && order.compareTo(bondOrder) == 0) { D_kJ_per_mol = bondEnergy.getEnergy(); } } } return D_kJ_per_mol; }
/** * Returns bond energy for a bond type, given atoms and bond type * @param sourceAtom First bondEnergy * @param targetAtom Second bondEnergy * @param bondOrder (single, double etc) * @return bond energy */ public synchronized int getEnergies(String sourceAtom, String targetAtom, Order bondOrder) { int D_kJ_per_mol = -1; if (sourceAtom.equalsIgnoreCase("R")) { sourceAtom = "C"; } if (targetAtom.equalsIgnoreCase("R")) { targetAtom = "C"; } for (Map.Entry<Integer, BondEnergy> entry : bondEngergies.entrySet()) { BondEnergy bondEnergy = entry.getValue(); String atom1 = bondEnergy.getSymbolFirstAtom(); String atom2 = bondEnergy.getSymbolSecondAtom(); if ((atom1.equalsIgnoreCase(sourceAtom) && atom2.equalsIgnoreCase(targetAtom)) || (atom2.equalsIgnoreCase(sourceAtom) && atom1.equalsIgnoreCase(targetAtom))) { Order order = bondEnergy.getBondOrder(); if (order != null && bondOrder != null && order.compareTo(bondOrder) == 0) { D_kJ_per_mol = bondEnergy.getEnergy(); } } } return D_kJ_per_mol; }
/** * Returns bond energy for a bond type, given atoms and bond type * @param sourceAtom First bondEnergy * @param targetAtom Second bondEnergy * @param bondOrder (single, double etc) * @return bond energy */ public synchronized int getEnergies(String sourceAtom, String targetAtom, Order bondOrder) { int D_kJ_per_mol = -1; if (sourceAtom.equalsIgnoreCase("R")) { sourceAtom = "C"; } if (targetAtom.equalsIgnoreCase("R")) { targetAtom = "C"; } for (Map.Entry<Integer, BondEnergy> entry : bondEngergies.entrySet()) { BondEnergy bondEnergy = entry.getValue(); String atom1 = bondEnergy.getSymbolFirstAtom(); String atom2 = bondEnergy.getSymbolSecondAtom(); if ((atom1.equalsIgnoreCase(sourceAtom) && atom2.equalsIgnoreCase(targetAtom)) || (atom2.equalsIgnoreCase(sourceAtom) && atom1.equalsIgnoreCase(targetAtom))) { Order order = bondEnergy.getBondOrder(); if (order != null && bondOrder != null && order.compareTo(bondOrder) == 0) { D_kJ_per_mol = bondEnergy.getEnergy(); } } } return D_kJ_per_mol; }
/** * Internal - sets up the 'contribution' and 'dbs' vectors. These define how many pi electrons * an atom can contribute and provide a lookup of the double bonded neighbour. * * @param molecule structure representation * @param bonds edge to bond map lookup * @param graph adjacency list graph representation of structure * @param contribution vector of p electron contributions from each vertex * @param dbs vector of double-bond pairs, index stored double-bonded index */ private static void setupContributionAndDoubleBonds(IAtomContainer molecule, EdgeToBondMap bonds, int[][] graph, int[] contribution, int[] dbs) { // fill the contribution and dbs vectors for (int v = 0; v < graph.length; v++) { // hydrogens, valence, and connectivity int hyd = molecule.getAtom(v).getImplicitHydrogenCount(); int val = hyd; int con = hyd + graph[v].length; for (int w : graph[v]) { IBond bond = bonds.get(v, w); val += bond.getOrder().numeric(); if (bond.getOrder() == IBond.Order.DOUBLE) { dbs[v] = dbs[v] == -1 ? w : -2; } } contribution[v] = contribution(molecule.getAtom(v).getAtomicNumber(), con, val); } }
private void setTargetSingleAtomMap(boolean removeHydrogen) throws CDKException { int counter = 0; BondEnergies be = BondEnergies.getInstance(); for (IAtom targetAtom : target.atoms()) { if ((removeHydrogen && !targetAtom.getSymbol().equals("H")) || (!removeHydrogen)) { for (IAtom sourceAtoms : source.atoms()) { Map<IAtom, IAtom> mapAtoms = new HashMap<IAtom, IAtom>(); if (targetAtom.getSymbol().equalsIgnoreCase(sourceAtoms.getSymbol())) { mapAtoms.put(sourceAtoms, targetAtom); List<IBond> bonds = source.getConnectedBondsList(sourceAtoms); double totalOrder = 0; for (IBond bond : bonds) { Order order = bond.getOrder(); totalOrder += order.numeric() + be.getEnergies(bond); } if (!Objects.equals(sourceAtoms.getFormalCharge(), targetAtom.getFormalCharge())) { totalOrder += 0.5; } connectedBondOrder.put(counter, totalOrder); mappings.add(counter++, mapAtoms); } } } else { System.err.println("Skippping Hydrogen mapping or This is not a single mapping case!"); } } }
public static QueryAtomContainer createSymbolChargeIDQueryContainer(IAtomContainer container) { QueryAtomContainer queryContainer = new QueryAtomContainer(container.getBuilder()); for (int i = 0; i < container.getAtomCount(); i++) { queryContainer.addAtom(new SymbolChargeIDQueryAtom(container.getAtom(i))); } Iterator<IBond> bonds = container.bonds().iterator(); while (bonds.hasNext()) { IBond bond = bonds.next(); int index1 = container.indexOf(bond.getBegin()); int index2 = container.indexOf(bond.getEnd()); if (bond.isAromatic()) { QueryBond qbond = new QueryBond(queryContainer.getAtom(index1), queryContainer.getAtom(index2), Expr.Type.IS_AROMATIC); queryContainer.addBond(qbond); } else { QueryBond qbond = new QueryBond(queryContainer.getAtom(index1), queryContainer.getAtom(index2), Expr.Type.ORDER, bond.getOrder().numeric()); qbond.setOrder(bond.getOrder()); // backwards compatibility queryContainer.addBond(qbond); } } return queryContainer; }
/** * Test whether we accept atom and it's connected bonds for inclusion in a * double bond configuration. This method checks for query bonds (up/down) * as well as double bond counts. If there is more then one double bond in * the connect bonds then it cannot have Z/E configuration. * * @param atom a double bonded atom * @param bonds all bonds connected to the atom * @return whether the atom is accepted for configuration */ static boolean accept(IAtom atom, List<IBond> bonds) { int dbCount = 0; // not SP2 if (!IAtomType.Hybridization.SP2.equals(atom.getHybridization())) return false; // only have one neighbour (which is the other atom) -> this is no configurable if (bonds.size() == 1) return false; for (IBond bond : bonds) { // increment the number of double bonds if (DOUBLE.equals(bond.getOrder())) dbCount++; // up/down bonds sometimes used to indicate E/Z IBond.Stereo stereo = bond.getStereo(); if (IBond.Stereo.UP_OR_DOWN.equals(stereo) || IBond.Stereo.UP_OR_DOWN_INVERTED.equals(stereo)) return false; } // not cumulated return dbCount == 1; }
/** * Internal - sets up the 'contribution' and 'dbs' vectors. These define how many pi electrons * an atom can contribute and provide a lookup of the double bonded neighbour. * * @param molecule structure representation * @param bonds edge to bond map lookup * @param graph adjacency list graph representation of structure * @param contribution vector of p electron contributions from each vertex * @param dbs vector of double-bond pairs, index stored double-bonded index */ private static void setupContributionAndDoubleBonds(IAtomContainer molecule, EdgeToBondMap bonds, int[][] graph, int[] contribution, int[] dbs) { // fill the contribution and dbs vectors for (int v = 0; v < graph.length; v++) { // hydrogens, valence, and connectivity int hyd = molecule.getAtom(v).getImplicitHydrogenCount(); int val = hyd; int con = hyd + graph[v].length; for (int w : graph[v]) { IBond bond = bonds.get(v, w); val += bond.getOrder().numeric(); if (bond.getOrder() == IBond.Order.DOUBLE) { dbs[v] = dbs[v] == -1 ? w : -2; } } contribution[v] = contribution(molecule.getAtom(v).getAtomicNumber(), con, val); } }
public String toString(IAtomContainer atomContainer) { StringBuilder sb = new StringBuilder(); for (IAtom atom : atomContainer.atoms()) { sb.append(atom.getSymbol()); } sb.append(' '); List<Edge> edges = new ArrayList<Edge>(); for (IBond bond : atomContainer.bonds()) { IAtom a0 = bond.getBegin(); IAtom a1 = bond.getEnd(); int a0N = atomContainer.indexOf(a0); int a1N = atomContainer.indexOf(a1); String a0S = a0.getSymbol(); String a1S = a1.getSymbol(); int o = bond.getOrder().numeric(); if (a0N < a1N) { edges.add(new Edge(a0N, a1N, o, a0S, a1S)); } else { edges.add(new Edge(a1N, a0N, o, a1S, a0S)); } } Collections.sort(edges); sb.append(edges.toString()); return sb.toString(); }
/** * Create a stereo encoder for all potential 2D and 3D double bond stereo * configurations. * * @param container an atom container * @param graph adjacency list representation of the container * @return a new encoder for tetrahedral elements */ @Override public StereoEncoder create(IAtomContainer container, int[][] graph) { List<StereoEncoder> encoders = new ArrayList<StereoEncoder>(5); for (IBond bond : container.bonds()) { // if double bond and not E or Z query bond if (DOUBLE.equals(bond.getOrder()) && !E_OR_Z.equals(bond.getStereo())) { IAtom left = bond.getBegin(); IAtom right = bond.getEnd(); // skip -N=N- double bonds which exhibit inversion if (Integer.valueOf(7).equals(left.getAtomicNumber()) && Integer.valueOf(7).equals(right.getAtomicNumber())) continue; StereoEncoder encoder = newEncoder(container, left, right, right, left, graph); if (encoder != null) { encoders.add(encoder); } } } return encoders.isEmpty() ? StereoEncoder.EMPTY : new MultiStereoEncoder(encoders); }
/** * * @param ringBond * @param singleRings * @return */ public static int getNeighbourBondOrderCountFromRing(IBond ringBond, IRingSet singleRings) { int minValue = 9999; for (IAtomContainer ring : singleRings.atomContainers()) { int value = 0; if (ring.contains(ringBond.getAtom(0)) && ring.contains(ringBond.getAtom(1))) { for (IBond bond : ring.bonds()) { if (bond.contains(ringBond.getAtom(0)) || bond.contains(ringBond.getAtom(1))) { value += bond.getOrder().numeric(); } } } if (value < minValue) { minValue = value; } } return minValue; }
/** * {@inheritDoc} */ @Override public Order getMaximumBondOrder(IAtom atom) { IBond.Order max = null; for (IBond bond : bonds()) { if (!bond.contains(atom)) continue; if (max == null || bond.getOrder().numeric() > max.numeric()) { max = bond.getOrder(); } } if (max == null) { if (!contains(atom)) throw new NoSuchAtomException("Atom does not belong to this container!"); if (atom.getImplicitHydrogenCount() != null && atom.getImplicitHydrogenCount() > 0) max = Order.SINGLE; else max = Order.UNSET; } return max; }
/** * {@inheritDoc} */ @Override public Order getMaximumBondOrder(IAtom atom) { IBond.Order max = null; for (IBond bond : bonds()) { if (!bond.contains(atom)) continue; if (max == null || bond.getOrder().numeric() > max.numeric()) { max = bond.getOrder(); } } if (max == null) { if (!contains(atom)) throw new NoSuchAtomException("Atom does not belong to this container!"); if (atom.getImplicitHydrogenCount() != null && atom.getImplicitHydrogenCount() > 0) max = Order.SINGLE; else max = Order.UNSET; } return max; }
/** * {@inheritDoc} */ @Override public Order getMinimumBondOrder(IAtom atom) { IBond.Order min = null; for (IBond bond : bonds()) { if (!bond.contains(atom)) continue; if (min == null || bond.getOrder().numeric() < min.numeric()) { min = bond.getOrder(); } } if (min == null) { if (!contains(atom)) throw new NoSuchAtomException("Atom does not belong to this container!"); if (atom.getImplicitHydrogenCount() != null && atom.getImplicitHydrogenCount() > 0) min = Order.SINGLE; else min = Order.UNSET; } return min; }
/** * {@inheritDoc} */ @Override public Order getMaximumBondOrder(IAtom atom) { IBond.Order max = null; for (IBond bond : bonds()) { if (!bond.contains(atom)) continue; if (max == null || bond.getOrder().numeric() > max.numeric()) { max = bond.getOrder(); } } if (max == null) { if (!contains(atom)) throw new NoSuchAtomException("Atom does not belong to this container!"); if (atom.getImplicitHydrogenCount() != null && atom.getImplicitHydrogenCount() > 0) max = Order.SINGLE; else max = Order.UNSET; } return max; }
/** * {@inheritDoc} */ @Override public Order getMinimumBondOrder(IAtom atom) { IBond.Order min = null; for (IBond bond : bonds()) { if (!bond.contains(atom)) continue; if (min == null || bond.getOrder().numeric() < min.numeric()) { min = bond.getOrder(); } } if (min == null) { if (!contains(atom)) throw new NoSuchAtomException("Atom does not belong to this container!"); if (atom.getImplicitHydrogenCount() != null && atom.getImplicitHydrogenCount() > 0) min = Order.SINGLE; else min = Order.UNSET; } return min; }
@Override public boolean isSaturated(IAtom atom, IAtomContainer container) throws CDKException { IAtomType type = atomTypeList.getAtomType(atom.getAtomTypeName()); if (type == null) throw new CDKException("Atom type is not a recognized CDK atom type: " + atom.getAtomTypeName()); if (type.getFormalNeighbourCount() == CDKConstants.UNSET) throw new CDKException( "Atom type is too general; cannot decide the number of implicit hydrogen to add for: " + atom.getAtomTypeName()); if (type.getProperty(CDKConstants.PI_BOND_COUNT) == CDKConstants.UNSET) throw new CDKException("Atom type is too general; cannot determine the number of pi bonds for: " + atom.getAtomTypeName()); double bondOrderSum = container.getBondOrderSum(atom); IBond.Order maxBondOrder = container.getMaximumBondOrder(atom); Integer hcount = atom.getImplicitHydrogenCount() == CDKConstants.UNSET ? 0 : atom.getImplicitHydrogenCount(); int piBondCount = ((Integer) type.getProperty(CDKConstants.PI_BOND_COUNT)).intValue(); int formalNeighborCount = type.getFormalNeighbourCount().intValue(); int typeMaxBondOrder = piBondCount + 1; int typeBondOrderSum = formalNeighborCount + piBondCount; if (bondOrderSum + hcount == typeBondOrderSum && maxBondOrder.numeric() <= typeMaxBondOrder) { return true; } return false; }
/** * Returns bond energy for a bond type, given atoms and bond type * @param sourceAtom First bondEnergy * @param targetAtom Second bondEnergy * @param bondOrder (single, double etc) * @return bond energy */ public int getEnergies(String sourceAtom, String targetAtom, Order bondOrder) { int dKJPerMol = -1; for (Map.Entry<Integer, BondEnergy> entry : bondEngergies.entrySet()) { BondEnergy bondEnergy = entry.getValue(); String atom1 = bondEnergy.getSymbolFirstAtom(); String atom2 = bondEnergy.getSymbolSecondAtom(); if ((atom1.equalsIgnoreCase(sourceAtom) && atom2.equalsIgnoreCase(targetAtom)) || (atom2.equalsIgnoreCase(sourceAtom) && atom1.equalsIgnoreCase(targetAtom))) { Order order = bondEnergy.getBondOrder(); if (order.compareTo(bondOrder) == 0) { dKJPerMol = bondEnergy.getEnergy(); } } } return dKJPerMol; }