Search in sources :

Example 1 with ExtendedTetrahedral

use of org.openscience.cdk.stereo.ExtendedTetrahedral in project ambit-mirror by ideaconsult.

the class IsomorphismTester method getTargetChiralAtomStereo.

int getTargetChiralAtomStereo(SmartsAtomExpression atom, Node node) {
    int queryChiralCenter_index = query.getAtomNumber(atom);
    IAtom targetCenter = node.atoms[queryChiralCenter_index];
    if (atom.extChirInfo == null) {
        // Handle chiral stereo center
        TetrahedralChirality thc = findTargetChiralStereoElement(targetCenter);
        if (thc == null)
            return SmartsConst.ChC_Unspec;
        IAtom[] targetMatchedLigands = new IAtom[atom.stereoLigands.size()];
        for (int i = 0; i < targetMatchedLigands.length; i++) {
            int query_index = query.getAtomNumber(atom.stereoLigands.get(i));
            targetMatchedLigands[i] = node.atoms[query_index];
        }
        if (atom.hasImplicitHStereoLigand) {
            // The targetCenter must be within target ligands
            boolean FlagOK = false;
            for (int i = 0; i < targetMatchedLigands.length; i++) {
                if (targetMatchedLigands[i] == targetCenter) {
                    FlagOK = true;
                    break;
                }
            }
            if (!FlagOK)
                // This case should not occur if target stereo element is OK
                return SmartsConst.ChC_Unspec;
        }
        // ligands as defined in the target molecule.
        IAtom[] targetOriginalLigands = thc.getLigands();
        // (additional checks are done below as well)
        if (targetOriginalLigands == null)
            return SmartsConst.ChC_Unspec;
        if (targetOriginalLigands.length != 4)
            return SmartsConst.ChC_Unspec;
        // Determining the target ligands permutation as well as
        // checking the correctness of the target stereo element (there is a chance that
        // the target stereo element is no correct - in this case the result is
        // ChC_Unspec)
        // The query ligands order is considered to be the basic permutation (0,1,2,3)
        int[] targetPerm = new int[4];
        for (int i = 0; i < targetMatchedLigands.length; i++) {
            int pos = getLigandIndex(targetMatchedLigands[i], targetOriginalLigands);
            if (pos == -1)
                return SmartsConst.ChC_Unspec;
            // This means incorrect target ligands in the stereo element.
            // Neighbor to the targer center is matched which is not within
            // The stereo element ligang list.
            // This error should not appear but if present it is due to
            // incorrect target AtomContainer object
            targetPerm[i] = pos;
        }
        int nSwitches = ChiralPermutations.getNumOfPairSwitches(ChiralPermutations.basic4Permutation, targetPerm);
        if ((nSwitches % 2) == 0) {
            // relative stereo configurations are the same
            if (thc.getStereo() == ITetrahedralChirality.Stereo.ANTI_CLOCKWISE)
                return SmartsConst.ChC_AntiClock;
            else
                return SmartsConst.ChC_Clock;
        } else {
            // relative stereo configurations are different
            if (thc.getStereo() == ITetrahedralChirality.Stereo.ANTI_CLOCKWISE)
                return SmartsConst.ChC_Clock;
            else
                return SmartsConst.ChC_AntiClock;
        }
    } else {
        // Handle extended chirality
        ExtendedTetrahedral exth = findTargetExtendedTetrahedralElement(targetCenter);
        if (exth == null)
            return SmartsConst.ChC_Unspec;
        IAtom[] targetMatchedLigands = new IAtom[atom.stereoLigands.size()];
        for (int i = 0; i < targetMatchedLigands.length; i++) {
            int query_index = query.getAtomNumber(atom.stereoLigands.get(i));
            targetMatchedLigands[i] = node.atoms[query_index];
        }
        // peripherals (ligands) as defined in the target molecule.
        IAtom[] targetOriginalLigands = exth.peripherals();
        // (additional checks are done below as well)
        if (targetOriginalLigands == null)
            return SmartsConst.ChC_Unspec;
        if (targetOriginalLigands.length != 4)
            return SmartsConst.ChC_Unspec;
        // Determining the target ligands permutation as well as
        // checking the correctness of the target stereo element (there is a chance that
        // the target stereo element is no correct - in this case the result is
        // ChC_Unspec)
        // The query ligands order is considered to be the basic permutation (0,1,2,3)
        int[] targetPerm = new int[4];
        for (int i = 0; i < targetMatchedLigands.length; i++) {
            int pos = getLigandIndex(targetMatchedLigands[i], targetOriginalLigands);
            if (pos == -1)
                return SmartsConst.ChC_Unspec;
            // This means incorrect target ligands in the stereo element.
            // Neighbor to the targer center is matched which is not within
            // The stereo element ligang list.
            // This error should not appear but if present it is due to
            // incorrect target IAtomContainer object
            targetPerm[i] = pos;
        }
        int nSwitches = ChiralPermutations.getNumOfPairSwitches(ChiralPermutations.basic4Permutation, targetPerm);
        if ((nSwitches % 2) == 0) {
            // relative stereo configurations are the same
            if (exth.winding() == ITetrahedralChirality.Stereo.ANTI_CLOCKWISE)
                return SmartsConst.ChC_AntiClock;
            else
                return SmartsConst.ChC_Clock;
        } else {
            // relative stereo configurations are different
            if (exth.winding() == ITetrahedralChirality.Stereo.ANTI_CLOCKWISE)
                return SmartsConst.ChC_Clock;
            else
                return SmartsConst.ChC_AntiClock;
        }
    }
}
Also used : ITetrahedralChirality(org.openscience.cdk.interfaces.ITetrahedralChirality) TetrahedralChirality(org.openscience.cdk.stereo.TetrahedralChirality) ExtendedTetrahedral(org.openscience.cdk.stereo.ExtendedTetrahedral) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 2 with ExtendedTetrahedral

use of org.openscience.cdk.stereo.ExtendedTetrahedral in project cdk by cdk.

the class AtomContainerManipulator method convertImplicitToExplicitHydrogens.

/**
 * Adds explicit hydrogens (without coordinates) to the IAtomContainer,
 * equaling the number of set implicit hydrogens.
 *
 * @param atomContainer the atom container to consider
 * @cdk.keyword hydrogens, adding
 */
public static void convertImplicitToExplicitHydrogens(IAtomContainer atomContainer) {
    List<IAtom> hydrogens = new ArrayList<>();
    List<IBond> newBonds = new ArrayList<>();
    // store a single explicit hydrogen of each original neighbor
    Map<IAtom, IAtom> hNeighbor = new HashMap<>(2 * atomContainer.getAtomCount());
    for (IAtom atom : atomContainer.atoms()) {
        if (atom.getAtomicNumber() != IElement.H) {
            Integer hCount = atom.getImplicitHydrogenCount();
            if (hCount != null) {
                for (int i = 0; i < hCount; i++) {
                    IAtom hydrogen = atom.getBuilder().newInstance(IAtom.class, "H");
                    hydrogen.setAtomTypeName("H");
                    hydrogen.setImplicitHydrogenCount(0);
                    hydrogens.add(hydrogen);
                    newBonds.add(atom.getBuilder().newInstance(IBond.class, atom, hydrogen, Order.SINGLE));
                    if (hNeighbor.get(atom) == null)
                        hNeighbor.put(atom, hydrogen);
                }
                atom.setImplicitHydrogenCount(0);
            }
        }
    }
    for (IAtom atom : hydrogens) atomContainer.addAtom(atom);
    for (IBond bond : newBonds) atomContainer.addBond(bond);
    // update stereo elements with an implicit part
    List<IStereoElement> stereos = new ArrayList<>();
    for (IStereoElement stereo : atomContainer.stereoElements()) {
        if (stereo instanceof ITetrahedralChirality) {
            ITetrahedralChirality tc = (ITetrahedralChirality) stereo;
            IAtom focus = tc.getFocus();
            IAtom[] carriers = tc.getCarriers().toArray(new IAtom[4]);
            IAtom hydrogen = hNeighbor.get(focus);
            if (hydrogen != null) {
                replaceAtom(carriers, focus, hydrogen);
                TetrahedralChirality newStereo = new TetrahedralChirality(focus, carriers, tc.getStereo());
                newStereo.setGroupInfo(tc.getGroupInfo());
                stereos.add(newStereo);
            } else {
                stereos.add(stereo);
            }
        } else if (stereo instanceof ExtendedTetrahedral) {
            ExtendedTetrahedral tc = (ExtendedTetrahedral) stereo;
            IAtom focus = tc.getFocus();
            IAtom[] carriers = tc.getCarriers().toArray(new IAtom[4]);
            IAtom[] ends = ExtendedTetrahedral.findTerminalAtoms(atomContainer, focus);
            IAtom h1 = hNeighbor.get(ends[0]);
            IAtom h2 = hNeighbor.get(ends[1]);
            if (h1 != null || h2 != null) {
                if (h1 != null)
                    replaceAtom(carriers, ends[0], h1);
                if (h2 != null)
                    replaceAtom(carriers, ends[1], h2);
                stereos.add(new ExtendedTetrahedral(focus, carriers, tc.getConfigOrder()));
            } else {
                stereos.add(stereo);
            }
        } else {
            stereos.add(stereo);
        }
    }
    atomContainer.setStereoElements(stereos);
}
Also used : ITetrahedralChirality(org.openscience.cdk.interfaces.ITetrahedralChirality) TetrahedralChirality(org.openscience.cdk.stereo.TetrahedralChirality) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IBond(org.openscience.cdk.interfaces.IBond) ITetrahedralChirality(org.openscience.cdk.interfaces.ITetrahedralChirality) ExtendedTetrahedral(org.openscience.cdk.stereo.ExtendedTetrahedral) IAtom(org.openscience.cdk.interfaces.IAtom) IStereoElement(org.openscience.cdk.interfaces.IStereoElement)

Example 3 with ExtendedTetrahedral

use of org.openscience.cdk.stereo.ExtendedTetrahedral in project cdk by cdk.

the class InChIGeneratorTest method r_penta_2_3_diene_impl_h.

@Test
public void r_penta_2_3_diene_impl_h() throws Exception {
    IAtomContainer m = new AtomContainer(5, 4, 0, 0);
    m.addAtom(new Atom("CH3"));
    m.addAtom(new Atom("CH"));
    m.addAtom(new Atom("C"));
    m.addAtom(new Atom("CH"));
    m.addAtom(new Atom("CH3"));
    m.addBond(0, 1, IBond.Order.SINGLE);
    m.addBond(1, 2, IBond.Order.DOUBLE);
    m.addBond(2, 3, IBond.Order.DOUBLE);
    m.addBond(3, 4, IBond.Order.SINGLE);
    int[][] atoms = new int[][] { { 0, 1, 3, 4 }, { 1, 0, 3, 4 }, { 1, 0, 4, 3 }, { 0, 1, 4, 3 }, { 4, 3, 1, 0 }, { 4, 3, 0, 1 }, { 3, 4, 0, 1 }, { 3, 4, 1, 0 } };
    Stereo[] stereos = new Stereo[] { Stereo.ANTI_CLOCKWISE, Stereo.CLOCKWISE, Stereo.ANTI_CLOCKWISE, Stereo.CLOCKWISE, Stereo.ANTI_CLOCKWISE, Stereo.CLOCKWISE, Stereo.ANTI_CLOCKWISE, Stereo.CLOCKWISE };
    for (int i = 0; i < atoms.length; i++) {
        IStereoElement element = new ExtendedTetrahedral(m.getAtom(2), new IAtom[] { m.getAtom(atoms[i][0]), m.getAtom(atoms[i][1]), m.getAtom(atoms[i][2]), m.getAtom(atoms[i][3]) }, stereos[i]);
        m.setStereoElements(Collections.singletonList(element));
        InChIGenerator generator = getFactory().getInChIGenerator(m);
        assertThat(generator.getInchi(), is("InChI=1S/C5H8/c1-3-5-4-2/h3-4H,1-2H3/t5-/m0/s1"));
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) Stereo(org.openscience.cdk.interfaces.ITetrahedralChirality.Stereo) ExtendedTetrahedral(org.openscience.cdk.stereo.ExtendedTetrahedral) IAtom(org.openscience.cdk.interfaces.IAtom) Atom(org.openscience.cdk.Atom) IStereoElement(org.openscience.cdk.interfaces.IStereoElement) Test(org.junit.Test)

Example 4 with ExtendedTetrahedral

use of org.openscience.cdk.stereo.ExtendedTetrahedral in project cdk by cdk.

the class SmilesParserTest method extendedTetrahedral7.

@Test
public void extendedTetrahedral7() throws InvalidSmilesException {
    IAtomContainer mol = load("CC=C=C=[C@]=C=C=CC");
    for (IStereoElement se : mol.stereoElements()) {
        if (se instanceof ExtendedTetrahedral) {
            ExtendedTetrahedral et = (ExtendedTetrahedral) se;
            assertThat(et.getConfigOrder(), is(IStereoElement.LEFT));
            assertThat(et.getFocus(), is(mol.getAtom(4)));
            assertThat(et.getCarriers().toArray(new IAtom[4]), is(new IAtom[] { mol.getAtom(0), mol.getAtom(1), mol.getAtom(7), mol.getAtom(8) }));
        }
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ExtendedTetrahedral(org.openscience.cdk.stereo.ExtendedTetrahedral) IStereoElement(org.openscience.cdk.interfaces.IStereoElement) IAtom(org.openscience.cdk.interfaces.IAtom) Test(org.junit.Test)

Example 5 with ExtendedTetrahedral

use of org.openscience.cdk.stereo.ExtendedTetrahedral in project cdk by cdk.

the class CDKToBeamTest method r_penta_2_3_diene_expl_h.

@Test
public void r_penta_2_3_diene_expl_h() throws Exception {
    IAtomContainer m = new AtomContainer(5, 4, 0, 0);
    m.addAtom(new Atom("C"));
    m.addAtom(new Atom("C"));
    m.addAtom(new Atom("C"));
    m.addAtom(new Atom("C"));
    m.addAtom(new Atom("C"));
    m.addAtom(new Atom("H"));
    m.addAtom(new Atom("H"));
    m.addBond(0, 1, IBond.Order.SINGLE);
    m.addBond(1, 2, IBond.Order.DOUBLE);
    m.addBond(2, 3, IBond.Order.DOUBLE);
    m.addBond(3, 4, IBond.Order.SINGLE);
    m.addBond(1, 5, IBond.Order.SINGLE);
    m.addBond(3, 6, IBond.Order.SINGLE);
    int[][] atoms = new int[][] { { 0, 5, 6, 4 }, { 5, 0, 6, 4 }, { 5, 0, 4, 6 }, { 0, 5, 4, 6 }, { 4, 6, 5, 0 }, { 4, 6, 0, 5 }, { 6, 4, 0, 5 }, { 6, 4, 5, 0 } };
    Stereo[] stereos = new Stereo[] { Stereo.ANTI_CLOCKWISE, Stereo.CLOCKWISE, Stereo.ANTI_CLOCKWISE, Stereo.CLOCKWISE, Stereo.ANTI_CLOCKWISE, Stereo.CLOCKWISE, Stereo.ANTI_CLOCKWISE, Stereo.CLOCKWISE };
    for (int i = 0; i < atoms.length; i++) {
        IStereoElement element = new ExtendedTetrahedral(m.getAtom(2), new IAtom[] { m.getAtom(atoms[i][0]), m.getAtom(atoms[i][1]), m.getAtom(atoms[i][2]), m.getAtom(atoms[i][3]) }, stereos[i]);
        m.setStereoElements(Collections.singletonList(element));
        assertThat(convert(m, SmiFlavor.Stereo).toSmiles(), is("CC(=[C@@]=C(C)[H])[H]"));
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.silent.AtomContainer) Stereo(org.openscience.cdk.interfaces.ITetrahedralChirality.Stereo) ExtendedTetrahedral(org.openscience.cdk.stereo.ExtendedTetrahedral) PseudoAtom(org.openscience.cdk.silent.PseudoAtom) IAtom(org.openscience.cdk.interfaces.IAtom) Atom(org.openscience.cdk.silent.Atom) IStereoElement(org.openscience.cdk.interfaces.IStereoElement) Test(org.junit.Test)

Aggregations

ExtendedTetrahedral (org.openscience.cdk.stereo.ExtendedTetrahedral)24 IAtom (org.openscience.cdk.interfaces.IAtom)23 IStereoElement (org.openscience.cdk.interfaces.IStereoElement)21 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)17 Test (org.junit.Test)15 ITetrahedralChirality (org.openscience.cdk.interfaces.ITetrahedralChirality)8 IBond (org.openscience.cdk.interfaces.IBond)7 Stereo (org.openscience.cdk.interfaces.ITetrahedralChirality.Stereo)7 AtomContainer (org.openscience.cdk.silent.AtomContainer)6 HashMap (java.util.HashMap)5 TetrahedralChirality (org.openscience.cdk.stereo.TetrahedralChirality)5 Atom (org.openscience.cdk.Atom)4 AtomContainer (org.openscience.cdk.AtomContainer)4 IDoubleBondStereochemistry (org.openscience.cdk.interfaces.IDoubleBondStereochemistry)4 Atom (org.openscience.cdk.silent.Atom)4 PseudoAtom (org.openscience.cdk.silent.PseudoAtom)4 DoubleBondStereochemistry (org.openscience.cdk.stereo.DoubleBondStereochemistry)4 ArrayList (java.util.ArrayList)3 ExtendedCisTrans (org.openscience.cdk.stereo.ExtendedCisTrans)3 InchiAtom (io.github.dan2097.jnainchi.InchiAtom)2