Search in sources :

Example 1 with IStereoElement

use of org.openscience.cdk.interfaces.IStereoElement in project ambit-mirror by ideaconsult.

the class SuppleAtomContainer method init.

protected void init() {
    atoms = new FilteredList<IAtom>();
    bonds = new FilteredList<IBond>();
    lonePairs = new ArrayList<ILonePair>();
    singleElectrons = new ArrayList<ISingleElectron>();
    int atomCount = getAtomCount();
    stereoElements = new HashSet<IStereoElement>(atomCount / 2);
    for (IStereoElement element : stereoElements()) {
        addStereoElement(element);
    }
}
Also used : ISingleElectron(org.openscience.cdk.interfaces.ISingleElectron) ILonePair(org.openscience.cdk.interfaces.ILonePair) IBond(org.openscience.cdk.interfaces.IBond) IAtom(org.openscience.cdk.interfaces.IAtom) IStereoElement(org.openscience.cdk.interfaces.IStereoElement)

Example 2 with IStereoElement

use of org.openscience.cdk.interfaces.IStereoElement in project ambit-mirror by ideaconsult.

the class SMIRKSManager method getCloneStructure.

IAtomContainer getCloneStructure(IAtomContainer target) throws Exception {
    IAtomContainer mol = new AtomContainer();
    IAtom[] newAtoms = new IAtom[target.getAtomCount()];
    IBond[] newBonds = new IBond[target.getBondCount()];
    // Clone atoms
    for (int i = 0; i < target.getAtomCount(); i++) {
        IAtom a = target.getAtom(i);
        IAtom a1 = cloneAtom(a);
        mol.addAtom(a1);
        newAtoms[i] = a1;
    }
    // Clone bonds
    for (int i = 0; i < target.getBondCount(); i++) {
        IBond b = target.getBond(i);
        IBond b1 = MoleculeTools.newBond(target.getBuilder());
        IAtom[] a01 = new IAtom[2];
        int ind0 = target.getAtomNumber(b.getAtom(0));
        int ind1 = target.getAtomNumber(b.getAtom(1));
        a01[0] = mol.getAtom(ind0);
        a01[1] = mol.getAtom(ind1);
        b1.setAtoms(a01);
        b1.setOrder(b.getOrder());
        boolean FlagArom = b.getFlag(CDKConstants.ISAROMATIC);
        b1.setFlag(CDKConstants.ISAROMATIC, FlagArom);
        mol.addBond(b1);
        newBonds[i] = b1;
    }
    // Clone stereo elements
    for (IStereoElement element : target.stereoElements()) {
        if (element instanceof DoubleBondStereochemistry) {
            DoubleBondStereochemistry dbs0 = (DoubleBondStereochemistry) element;
            DoubleBondStereochemistry dbs = StereoChemUtils.cloneDoubleBondStereochemistry(dbs0, target, mol, newAtoms, newBonds);
            if (dbs != null)
                mol.addStereoElement(dbs);
            continue;
        }
        if (element instanceof TetrahedralChirality) {
            TetrahedralChirality thc0 = (TetrahedralChirality) element;
            TetrahedralChirality thc = StereoChemUtils.cloneTetrahedralChirality(thc0, target, mol, newAtoms);
            if (thc != null)
                mol.addStereoElement(thc);
            continue;
        }
    // TODO handle ExtendedTetrahedral (... allene like chiral centers)
    }
    return mol;
}
Also used : TetrahedralChirality(org.openscience.cdk.stereo.TetrahedralChirality) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) DoubleBondStereochemistry(org.openscience.cdk.stereo.DoubleBondStereochemistry) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) IBond(org.openscience.cdk.interfaces.IBond) IAtom(org.openscience.cdk.interfaces.IAtom) IStereoElement(org.openscience.cdk.interfaces.IStereoElement)

Example 3 with IStereoElement

use of org.openscience.cdk.interfaces.IStereoElement in project ambit-mirror by ideaconsult.

the class SMIRKSManager method deleteAtomAndDoStereoTransformation.

void deleteAtomAndDoStereoTransformation(IAtom tAt, IAtomContainer target, List<IStereoElement> invalidatedStereoElements, Map<IStereoElement, StereoChange> stereoChanges) {
    // Preliminary store the elements that are to be changed by the atom deletion
    // and hence to be removed from the IAtomContainer object
    // by function removeAtomAndConnectedElectronContainers()
    List<IStereoElement> listSE = getStereoElementsToBeRemoved(tAt, target);
    target.removeAtomAndConnectedElectronContainers(tAt);
    // Check previously invalidated stereo elements
    if (!invalidatedStereoElements.isEmpty()) {
        List<IStereoElement> newInvEl = new ArrayList<IStereoElement>();
        for (IStereoElement stEl : invalidatedStereoElements) {
            if (StereoChemUtils.contains(stEl, tAt)) {
                StereoChange stChange = stereoChanges.get(stEl);
                stereoChanges.remove(stEl);
                // System.out.println("  ## handleStereoOnAtomDeletion");
                IStereoElement el = handleStereoOnAtomDeletion(tAt, target, stEl, stChange);
                // if el = null then the stereo element is for 'total removal'
                if (el != null) {
                    newInvEl.add(el);
                    stereoChanges.put(el, stChange);
                }
            } else
                // no change to the invalidated element
                newInvEl.add(stEl);
        }
        invalidatedStereoElements.clear();
        invalidatedStereoElements.addAll(newInvEl);
    }
    // Handle newly invalidated stereo elements
    if (!listSE.isEmpty()) {
        for (IStereoElement stEl : listSE) {
            StereoChange stChange = stereoChanges.get(stEl);
            stereoChanges.remove(stEl);
            // System.out.println("  >> handleStereoOnAtomDeletion");
            // System.out.println("  >> " + StereoChemUtils.stereoElement2String(stEl, target));
            // System.out.println("  >> StereoChange: " + stChange.toString(target));
            IStereoElement el = handleStereoOnAtomDeletion(tAt, target, stEl, stChange);
            // if el = null then the stereo element is for 'total removal'
            if (el != null) {
                invalidatedStereoElements.add(el);
                stereoChanges.put(el, stChange);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) IStereoElement(org.openscience.cdk.interfaces.IStereoElement)

Example 4 with IStereoElement

use of org.openscience.cdk.interfaces.IStereoElement in project ambit-mirror by ideaconsult.

the class SMIRKSManager method checkInvalidatedDBStereo.

public void checkInvalidatedDBStereo(IAtomContainer target, List<IStereoElement> invalidatedStereoElements, Map<IStereoElement, StereoChange> stereoChanges) {
    // This check is needed since it is possible that the double stereo element is
    // invalid but the stereo information is still present
    // This happens when the a ligand atom is deleted (i.e. the element is invalidated)
    // but there is another neighbor atom attached to the double bond which can be used
    // to restore the stereo information
    List<IStereoElement> restoredElements = new ArrayList<IStereoElement>();
    for (IStereoElement element : invalidatedStereoElements) {
        if (element instanceof DoubleBondStereochemistry) {
            DoubleBondStereochemistry dbsc = (DoubleBondStereochemistry) element;
            StereoChange stChange = stereoChanges.get(element);
            DoubleBondStereochemistry restored = StereoChemUtils.restoreDBStereo(target, dbsc, stChange);
            if (restored != null)
                restoredElements.add(restored);
        }
    }
    if (!restoredElements.isEmpty()) {
        List<IStereoElement> newStereo = new ArrayList<IStereoElement>();
        for (IStereoElement element : target.stereoElements()) newStereo.add(element);
        newStereo.addAll(restoredElements);
        target.setStereoElements(newStereo);
    }
}
Also used : DoubleBondStereochemistry(org.openscience.cdk.stereo.DoubleBondStereochemistry) ArrayList(java.util.ArrayList) IStereoElement(org.openscience.cdk.interfaces.IStereoElement)

Example 5 with IStereoElement

use of org.openscience.cdk.interfaces.IStereoElement in project ambit-mirror by ideaconsult.

the class IsomorphismTester method matchDoubleBondStereo.

boolean matchDoubleBondStereo(SMARTSBond bond, Node node) {
    DoubleBondStereoInfo dbsi = null;
    if (bond instanceof DoubleNonAromaticBond)
        dbsi = ((DoubleNonAromaticBond) bond).getStereoInfo();
    else if (bond instanceof DoubleBondAromaticityNotSpecified)
        dbsi = ((DoubleBondAromaticityNotSpecified) bond).getStereoInfo();
    else if (bond instanceof SmartsBondExpression)
        dbsi = ((SmartsBondExpression) bond).getStereoInfo();
    if (dbsi == null)
        // no stereo check is done;
        return true;
    int query_index0 = query.getAtomNumber(bond.getAtom(0));
    int query_index1 = query.getAtomNumber(bond.getAtom(1));
    int query_ligand0 = query.getAtomNumber(dbsi.ligand1);
    int query_ligand1 = query.getAtomNumber(dbsi.ligand2);
    IAtom targetAt0 = node.atoms[query_index0];
    IAtom targetAt1 = node.atoms[query_index1];
    IAtom targetLigand0 = node.atoms[query_ligand0];
    IAtom targetLigand1 = node.atoms[query_ligand1];
    // System.out.println("query double bond atoms: "+ query_index0 + " " +
    // query_index1);
    // System.out.println("query ligand atoms: "+ query_ligand0 + " " +
    // query_ligand1);
    // System.out.println("Target double bond atoms: "+
    // target.getAtomNumber(targetAt0) + " " + target.getAtomNumber(targetAt1));
    // System.out.println("Target ligand atoms: "+
    // target.getAtomNumber(targetLigand0) + " " +
    // target.getAtomNumber(targetLigand1));
    IBond targetBo = target.getBond(targetAt0, targetAt1);
    if (// this should never happen
    targetBo == null) {
        if (dbsi.conformation == DBStereo.OPPOSITE_OR_UNDEFINED || dbsi.conformation == DBStereo.TOGETHER_OR_UNDEFINED)
            return true;
        return false;
    }
    // Find target double bond stereo element
    DoubleBondStereochemistry element = null;
    for (IStereoElement el : target.stereoElements()) {
        if (el instanceof DoubleBondStereochemistry)
            if (((DoubleBondStereochemistry) el).getStereoBond() == targetBo) {
                element = (DoubleBondStereochemistry) el;
                break;
            }
    }
    if (element == null) {
        if (dbsi.conformation == DBStereo.OPPOSITE_OR_UNDEFINED || dbsi.conformation == DBStereo.TOGETHER_OR_UNDEFINED)
            return true;
        return false;
    }
    int nMatchedLigands = 0;
    IBond[] elementBonds = element.getBonds();
    if (elementBonds[0].contains(targetLigand0) || elementBonds[1].contains(targetLigand0))
        nMatchedLigands++;
    if (elementBonds[0].contains(targetLigand1) || elementBonds[1].contains(targetLigand1))
        nMatchedLigands++;
    if (nMatchedLigands == 1) {
        if (element.getStereo() == Conformation.OPPOSITE) {
            if ((dbsi.conformation == DBStereo.TOGETHER) || (dbsi.conformation == DBStereo.TOGETHER_OR_UNDEFINED))
                return true;
            else
                return false;
        } else {
            // element.getStereo() == Conformation.TOGETHER
            if ((dbsi.conformation == DBStereo.TOGETHER) || (dbsi.conformation == DBStereo.TOGETHER_OR_UNDEFINED))
                return false;
            else
                return true;
        }
    } else {
        if (element.getStereo() == Conformation.OPPOSITE) {
            if ((dbsi.conformation == DBStereo.TOGETHER) || (dbsi.conformation == DBStereo.TOGETHER_OR_UNDEFINED))
                return false;
            else
                return true;
        } else {
            // element.getStereo() == Conformation.TOGETHER
            if ((dbsi.conformation == DBStereo.TOGETHER) || (dbsi.conformation == DBStereo.TOGETHER_OR_UNDEFINED))
                return true;
            else
                return false;
        }
    }
}
Also used : DoubleBondStereochemistry(org.openscience.cdk.stereo.DoubleBondStereochemistry) IBond(org.openscience.cdk.interfaces.IBond) IAtom(org.openscience.cdk.interfaces.IAtom) IStereoElement(org.openscience.cdk.interfaces.IStereoElement)

Aggregations

IStereoElement (org.openscience.cdk.interfaces.IStereoElement)187 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)123 Test (org.junit.Test)107 IAtom (org.openscience.cdk.interfaces.IAtom)91 IBond (org.openscience.cdk.interfaces.IBond)54 ITetrahedralChirality (org.openscience.cdk.interfaces.ITetrahedralChirality)51 ArrayList (java.util.ArrayList)39 AtomContainer (org.openscience.cdk.silent.AtomContainer)35 Sgroup (org.openscience.cdk.sgroup.Sgroup)22 HashMap (java.util.HashMap)21 ExtendedTetrahedral (org.openscience.cdk.stereo.ExtendedTetrahedral)21 ISingleElectron (org.openscience.cdk.interfaces.ISingleElectron)20 IDoubleBondStereochemistry (org.openscience.cdk.interfaces.IDoubleBondStereochemistry)18 ILonePair (org.openscience.cdk.interfaces.ILonePair)18 DoubleBondStereochemistry (org.openscience.cdk.stereo.DoubleBondStereochemistry)18 TetrahedralChirality (org.openscience.cdk.stereo.TetrahedralChirality)18 IChemObjectBuilder (org.openscience.cdk.interfaces.IChemObjectBuilder)14 EdgeToBondMap (org.openscience.cdk.graph.GraphUtil.EdgeToBondMap)12 IChemObject (org.openscience.cdk.interfaces.IChemObject)12 Stereo (org.openscience.cdk.interfaces.ITetrahedralChirality.Stereo)8