-
-
Save gilleain/f0861b94023e59370c16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tests; | |
import org.junit.Test; | |
import org.openscience.cdk.Atom; | |
import org.openscience.cdk.AtomContainer; | |
import org.openscience.cdk.geometry.cip.CIPTool; | |
import org.openscience.cdk.geometry.cip.CIPTool.CIP_CHIRALITY; | |
import org.openscience.cdk.interfaces.IAtom; | |
import org.openscience.cdk.interfaces.IAtomContainer; | |
import org.openscience.cdk.interfaces.IBond; | |
import org.openscience.cdk.interfaces.IStereoElement; | |
import org.openscience.cdk.interfaces.ITetrahedralChirality.Stereo; | |
import org.openscience.cdk.smiles.SmilesGenerator; | |
import org.openscience.cdk.stereo.TetrahedralChirality; | |
public class RingTests { | |
public IAtomContainer makeChiralRing(int ringSize, int oxygenOffset) { | |
IAtomContainer ring = new AtomContainer(); | |
for (int i = 0; i < ringSize; i++) { | |
ring.addAtom(new Atom("C")); | |
} | |
for (int j = 0; j < ringSize - 1; j++) { | |
ring.addBond(j, j + 1, IBond.Order.SINGLE); | |
} | |
ring.addBond(ringSize - 1, 0, IBond.Order.SINGLE); | |
ring.addAtom(new Atom("Cl")); | |
ring.addAtom(new Atom("F")); | |
ring.addBond(0, ringSize, IBond.Order.SINGLE); | |
ring.addBond(0, ringSize + 1, IBond.Order.SINGLE); | |
ring.addAtom(new Atom("O")); | |
ring.addBond(oxygenOffset, ringSize + 2, IBond.Order.SINGLE); | |
IAtom[] atoms = new IAtom[] { | |
ring.getAtom(ringSize), | |
ring.getAtom(ringSize + 1), | |
ring.getAtom(ringSize - 1), | |
ring.getAtom(1) | |
}; | |
ring.addStereoElement( | |
new TetrahedralChirality(ring.getAtom(0), atoms, Stereo.ANTI_CLOCKWISE) | |
); | |
return ring; | |
} | |
public void printOut(IAtomContainer atomContainer) { | |
for (IBond bond : atomContainer.bonds()) { | |
int ai = atomContainer.getAtomNumber(bond.getAtom(0)); | |
int bi = atomContainer.getAtomNumber(bond.getAtom(1)); | |
System.out.println(ai + " " + bi); | |
} | |
SmilesGenerator generator = new SmilesGenerator(); | |
String smiles = generator.createSMILES(atomContainer); | |
System.out.println(smiles); | |
} | |
public TetrahedralChirality getChiralityElement(IAtomContainer container) { | |
for (IStereoElement element : container.stereoElements()) { | |
return (TetrahedralChirality) element; | |
} | |
return null; | |
} | |
public void analyseChirality(IAtomContainer container) { | |
TetrahedralChirality stereoCenter = getChiralityElement(container); | |
CIP_CHIRALITY chirality = CIPTool.getCIPChirality(container, stereoCenter); | |
System.out.println(chirality); | |
} | |
@Test | |
public void threeRing() { | |
IAtomContainer threeRing = makeChiralRing(3, 1); | |
printOut(threeRing); | |
analyseChirality(threeRing); | |
} | |
@Test | |
public void fourRing() { | |
IAtomContainer fourRing = makeChiralRing(4, 1); | |
printOut(fourRing); | |
analyseChirality(fourRing); | |
} | |
@Test | |
public void fiveRing() { | |
IAtomContainer fiveRing = makeChiralRing(5, 1); | |
printOut(fiveRing); | |
analyseChirality(fiveRing); | |
} | |
@Test | |
public void sixRing() { | |
IAtomContainer sixRing = makeChiralRing(6, 1); | |
printOut(sixRing); | |
analyseChirality(sixRing); | |
} | |
@Test | |
public void sevenRing() { | |
IAtomContainer sevenRing = makeChiralRing(7, 1); | |
printOut(sevenRing); | |
analyseChirality(sevenRing); | |
} | |
@Test | |
public void fourRingOffset2() { | |
IAtomContainer fourTwoRing = makeChiralRing(4, 2); | |
printOut(fourTwoRing); | |
analyseChirality(fourTwoRing); | |
} | |
@Test | |
public void fiveRingOffset2() { | |
IAtomContainer fiveTwoRing = makeChiralRing(5, 2); | |
printOut(fiveTwoRing); | |
analyseChirality(fiveTwoRing); | |
} | |
@Test | |
public void sixRingOffset2() { | |
IAtomContainer sixTwoRing = makeChiralRing(6, 2); | |
printOut(sixTwoRing); | |
analyseChirality(sixTwoRing); | |
} | |
@Test | |
public void sevenRingOffset3() { | |
IAtomContainer sevenThreeRing = makeChiralRing(7, 3); | |
printOut(sevenThreeRing); | |
analyseChirality(sevenThreeRing); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment