Search in sources :

Example 1 with Order

use of org.openscience.cdk.interfaces.IBond.Order in project cdk by cdk.

the class CDKAtomTypeMatcher method perceiveOxygens.

private IAtomType perceiveOxygens(IAtomContainer atomContainer, IAtom atom, RingSearch searcher, List<IBond> connectedBonds) throws CDKException {
    if (hasOneSingleElectron(atomContainer, atom)) {
        return perceiveOxygenRadicals(atomContainer, atom);
    }
    // if hybridization is given, use that
    if (connectedBonds == null)
        connectedBonds = atomContainer.getConnectedBondsList(atom);
    if (hasHybridization(atom) && !isCharged(atom)) {
        if (atom.getHybridization() == Hybridization.SP2) {
            int connectedAtomsCount = connectedBonds.size();
            if (connectedAtomsCount == 1) {
                if (isCarboxylate(atomContainer, atom, connectedBonds)) {
                    IAtomType type = getAtomType("O.sp2.co2");
                    if (isAcceptable(atom, atomContainer, type, connectedBonds))
                        return type;
                } else {
                    IAtomType type = getAtomType("O.sp2");
                    if (isAcceptable(atom, atomContainer, type, connectedBonds))
                        return type;
                }
            } else if (connectedAtomsCount == 2) {
                IAtomType type = getAtomType("O.planar3");
                if (isAcceptable(atom, atomContainer, type, connectedBonds))
                    return type;
            }
        } else if (atom.getHybridization() == Hybridization.SP3) {
            IAtomType type = getAtomType("O.sp3");
            if (isAcceptable(atom, atomContainer, type, connectedBonds))
                return type;
        } else if (atom.getHybridization() == Hybridization.PLANAR3) {
            IAtomType type = getAtomType("O.planar3");
            if (isAcceptable(atom, atomContainer, type, connectedBonds))
                return type;
        }
    } else if (isCharged(atom)) {
        if (isCharge(atom, -1) && connectedBonds.size() <= 1) {
            if (isCarboxylate(atomContainer, atom, connectedBonds)) {
                IAtomType type = getAtomType("O.minus.co2");
                if (isAcceptable(atom, atomContainer, type, connectedBonds))
                    return type;
            } else {
                IAtomType type = getAtomType("O.minus");
                if (isAcceptable(atom, atomContainer, type, connectedBonds))
                    return type;
            }
        } else if (isCharge(atom, -2) && connectedBonds.size() == 0) {
            IAtomType type = getAtomType("O.minus2");
            if (isAcceptable(atom, atomContainer, type, connectedBonds))
                return type;
        } else if (isCharge(atom, +1)) {
            if (connectedBonds.size() == 0) {
                IAtomType type = getAtomType("O.plus");
                if (isAcceptable(atom, atomContainer, type, connectedBonds))
                    return type;
            }
            IBond.Order maxBondOrder = getMaximumBondOrder(connectedBonds);
            if (maxBondOrder == Order.DOUBLE) {
                IAtomType type = getAtomType("O.plus.sp2");
                if (isAcceptable(atom, atomContainer, type, connectedBonds))
                    return type;
            } else if (maxBondOrder == Order.TRIPLE) {
                IAtomType type = getAtomType("O.plus.sp1");
                if (isAcceptable(atom, atomContainer, type, connectedBonds))
                    return type;
            } else {
                IAtomType type = getAtomType("O.plus");
                if (isAcceptable(atom, atomContainer, type, connectedBonds))
                    return type;
            }
        }
        return null;
    } else if (connectedBonds.size() > 2) {
        // FIXME: I don't perceive carbons with more than 4 connections yet
        return null;
    } else if (connectedBonds.size() == 0) {
        IAtomType type = getAtomType("O.sp3");
        if (isAcceptable(atom, atomContainer, type, connectedBonds))
            return type;
    } else {
        // OK, use bond order info
        IBond.Order maxBondOrder = getMaximumBondOrder(connectedBonds);
        if (maxBondOrder == Order.DOUBLE) {
            if (isCarboxylate(atomContainer, atom, connectedBonds)) {
                IAtomType type = getAtomType("O.sp2.co2");
                if (isAcceptable(atom, atomContainer, type, connectedBonds))
                    return type;
            } else {
                IAtomType type = getAtomType("O.sp2");
                if (isAcceptable(atom, atomContainer, type, connectedBonds))
                    return type;
            }
        } else if (maxBondOrder == Order.SINGLE) {
            int explicitHydrogens = countExplicitHydrogens(atom, connectedBonds);
            int connectedHeavyAtoms = connectedBonds.size() - explicitHydrogens;
            if (connectedHeavyAtoms == 2) {
                // a O.sp3 which is expected to take part in an aromatic system
                if (bothNeighborsAreSp2(atom, atomContainer, connectedBonds) && isRingAtom(atom, atomContainer, searcher)) {
                    IAtomType type = getAtomType("O.planar3");
                    if (isAcceptable(atom, atomContainer, type, connectedBonds))
                        return type;
                }
                IAtomType type = getAtomType("O.sp3");
                if (isAcceptable(atom, atomContainer, type, connectedBonds))
                    return type;
            } else {
                IAtomType type = getAtomType("O.sp3");
                if (isAcceptable(atom, atomContainer, type, connectedBonds))
                    return type;
            }
        }
    }
    return null;
}
Also used : IAtomType(org.openscience.cdk.interfaces.IAtomType) Order(org.openscience.cdk.interfaces.IBond.Order)

Example 2 with Order

use of org.openscience.cdk.interfaces.IBond.Order in project cdk by cdk.

the class CDKAtomTypeMatcher method isAcceptable.

private boolean isAcceptable(IAtom atom, IAtomContainer container, IAtomType type, List<IBond> connectedBonds) {
    if (connectedBonds == null)
        connectedBonds = container.getConnectedBondsList(atom);
    if (mode == REQUIRE_EXPLICIT_HYDROGENS) {
        // make sure no implicit hydrogens were assumed
        int actualContainerCount = connectedBonds.size();
        int requiredContainerCount = type.getFormalNeighbourCount();
        if (actualContainerCount != requiredContainerCount)
            return false;
    } else if (atom.getImplicitHydrogenCount() != CDKConstants.UNSET) {
        // confirm correct neighbour count
        int connectedAtoms = connectedBonds.size();
        int hCount = atom.getImplicitHydrogenCount();
        int actualNeighbourCount = connectedAtoms + hCount;
        int requiredNeighbourCount = type.getFormalNeighbourCount();
        if (actualNeighbourCount > requiredNeighbourCount)
            return false;
    }
    // confirm correct bond orders
    IBond.Order typeOrder = type.getMaxBondOrder();
    if (typeOrder != null) {
        for (IBond bond : connectedBonds) {
            IBond.Order order = bond.getOrder();
            if (order != CDKConstants.UNSET && order != IBond.Order.UNSET) {
                if (BondManipulator.isHigherOrder(order, typeOrder))
                    return false;
            } else if (bond.getFlag(CDKConstants.SINGLE_OR_DOUBLE)) {
                if (typeOrder != IBond.Order.SINGLE && typeOrder != IBond.Order.DOUBLE)
                    return false;
            } else {
                return false;
            }
        }
    }
    // confirm correct valency
    if (type.getValency() != CDKConstants.UNSET) {
        double valence = container.getBondOrderSum(atom);
        if (atom.getImplicitHydrogenCount() != null && atom.getImplicitHydrogenCount() != 0)
            valence += atom.getImplicitHydrogenCount();
        if (valence > type.getValency())
            return false;
    }
    // confirm correct formal charge, really would be easier if we just used an int rather than an Integer :-)
    if (!chargeEqual(atom.getFormalCharge(), type.getFormalCharge())) {
        return false;
    }
    // confirm single electron count
    if (type.getProperty(CDKConstants.SINGLE_ELECTRON_COUNT) != null) {
        int count = countSingleElectrons(container, atom);
        if (count != type.getProperty(CDKConstants.SINGLE_ELECTRON_COUNT, Integer.class))
            return false;
    }
    return true;
}
Also used : IBond(org.openscience.cdk.interfaces.IBond) Order(org.openscience.cdk.interfaces.IBond.Order)

Example 3 with Order

use of org.openscience.cdk.interfaces.IBond.Order in project cdk by cdk.

the class SingleMapping method setTargetSingleAtomMap.

private void setTargetSingleAtomMap(boolean removeHydrogen) throws CDKException {
    int counter = 0;
    BondEnergies be = BondEnergies.getInstance();
    for (IAtom targetAtom : target.atoms()) {
        if ((removeHydrogen && targetAtom.getAtomicNumber() != IElement.H) || (!removeHydrogen)) {
            for (IAtom sourceAtoms : source.atoms()) {
                Map<IAtom, IAtom> mapAtoms = new HashMap<>();
                if (targetAtom.getAtomicNumber().equals(sourceAtoms.getAtomicNumber())) {
                    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!");
        }
    }
}
Also used : Order(org.openscience.cdk.interfaces.IBond.Order) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) BondEnergies(org.openscience.cdk.smsd.tools.BondEnergies) IBond(org.openscience.cdk.interfaces.IBond) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 4 with Order

use of org.openscience.cdk.interfaces.IBond.Order in project cdk by cdk.

the class SingleMapping method setSourceSingleAtomMap.

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.getAtomicNumber() != IElement.H) || (!removeHydrogen)) {
            for (IAtom targetAtom : target.atoms()) {
                Map<IAtom, IAtom> mapAtoms = new HashMap<>();
                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!");
        }
    }
}
Also used : Order(org.openscience.cdk.interfaces.IBond.Order) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) BondEnergies(org.openscience.cdk.smsd.tools.BondEnergies) IQueryAtom(org.openscience.cdk.isomorphism.matchers.IQueryAtom) IBond(org.openscience.cdk.interfaces.IBond) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 5 with Order

use of org.openscience.cdk.interfaces.IBond.Order in project cdk by cdk.

the class SingleMapping method setSourceSingleAtomMap.

private void setSourceSingleAtomMap(boolean removeHydrogen) throws CDKException {
    int counter = 0;
    BondEnergies be = BondEnergies.getInstance();
    for (IAtom sourceAtom : source.atoms()) {
        if ((removeHydrogen && sourceAtom.getAtomicNumber() != IElement.H) || (!removeHydrogen)) {
            for (IAtom targetAtom : target.atoms()) {
                Map<IAtom, IAtom> mapAtoms = new HashMap<>();
                if (sourceAtom.getAtomicNumber().equals(targetAtom.getAtomicNumber())) {
                    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!");
        }
    }
}
Also used : Order(org.openscience.cdk.interfaces.IBond.Order) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) BondEnergies(org.openscience.cdk.smsd.tools.BondEnergies) IBond(org.openscience.cdk.interfaces.IBond) IAtom(org.openscience.cdk.interfaces.IAtom)

Aggregations

Order (org.openscience.cdk.interfaces.IBond.Order)27 IBond (org.openscience.cdk.interfaces.IBond)15 IAtomType (org.openscience.cdk.interfaces.IAtomType)11 CDKException (org.openscience.cdk.exception.CDKException)10 IAtom (org.openscience.cdk.interfaces.IAtom)10 DescriptorValue (org.openscience.cdk.qsar.DescriptorValue)8 DoubleResult (org.openscience.cdk.qsar.result.DoubleResult)8 LonePairElectronChecker (org.openscience.cdk.tools.LonePairElectronChecker)7 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)3 BondEnergies (org.openscience.cdk.smsd.tools.BondEnergies)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 Test (org.junit.Test)2 Bond (org.openscience.cdk.Bond)2 BondEnergy (org.openscience.cdk.smsd.helper.BondEnergy)2 InchiAtom (io.github.dan2097.jnainchi.InchiAtom)1 InchiBond (io.github.dan2097.jnainchi.InchiBond)1 InchiBondStereo (io.github.dan2097.jnainchi.InchiBondStereo)1