Search in sources :

Example 26 with Reaction

use of org.openscience.cdk.Reaction in project cdk by cdk.

the class AbstractReactionLabeller method labelReaction.

public IReaction labelReaction(IReaction reaction, ICanonicalMoleculeLabeller labeller) {
    System.out.println("labelling");
    IReaction canonReaction = new Reaction();
    Map<IAtomContainer, int[]> permutationMap = new HashMap<>();
    IAtomContainerSet canonicalProducts = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class);
    for (IAtomContainer product : reaction.getProducts().atomContainers()) {
        IAtomContainer canonicalForm = labeller.getCanonicalMolecule(product);
        if (fixAtomMappingCastType) {
            fixAtomMapping(canonicalForm);
        }
        IAtomContainer canonicalMolecule = canonicalForm.getBuilder().newInstance(IAtomContainer.class, canonicalForm);
        permutationMap.put(canonicalMolecule, labeller.getCanonicalPermutation(product));
        canonicalProducts.addAtomContainer(canonicalMolecule);
    }
    IAtomContainerSet canonicalReactants = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class);
    for (IAtomContainer reactant : reaction.getReactants().atomContainers()) {
        IAtomContainer canonicalForm = labeller.getCanonicalMolecule(reactant);
        if (fixAtomMappingCastType) {
            fixAtomMapping(canonicalForm);
        }
        IAtomContainer canonicalMolecule = canonicalForm.getBuilder().newInstance(IAtomContainer.class, canonicalForm);
        permutationMap.put(canonicalMolecule, labeller.getCanonicalPermutation(reactant));
        canonicalReactants.addAtomContainer(canonicalMolecule);
    }
    canonReaction.setProducts(canonicalProducts);
    canonReaction.setReactants(canonicalReactants);
    cloneAndSortMappings(reaction, canonReaction, permutationMap);
    return canonReaction;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) HashMap(java.util.HashMap) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IReaction(org.openscience.cdk.interfaces.IReaction) Reaction(org.openscience.cdk.Reaction) IReaction(org.openscience.cdk.interfaces.IReaction)

Example 27 with Reaction

use of org.openscience.cdk.Reaction in project cdk by cdk.

the class GeometryToolsTest method testShiftReactionVertical_IAtomContainer_Rectangle2D_Rectangle2D_double.

@Test
public void testShiftReactionVertical_IAtomContainer_Rectangle2D_Rectangle2D_double() throws Exception {
    IAtom atom1 = new Atom("C");
    atom1.setPoint2d(new Point2d(0, 1));
    IAtom atom2 = new Atom("C");
    atom2.setPoint2d(new Point2d(1, 0));
    IAtomContainer react1 = new AtomContainer();
    IReaction reaction = new Reaction();
    reaction.addReactant(react1);
    react1.addAtom(atom1);
    react1.addAtom(atom2);
    react1.addBond(0, 1, IBond.Order.SINGLE);
    IReaction reaction2 = (IReaction) reaction.clone();
    IAtomContainer react2 = reaction2.getReactants().getAtomContainer(0);
    // shift the second reaction up
    GeometryTools.shiftReactionVertical(reaction2, GeometryTools.getRectangle2D(react2), GeometryTools.getRectangle2D(react1), 1.0);
    // assert all coordinates of the second reaction moved up
    AtomContainerDiff.diff(react1, react2);
    LoggingToolFactory.createLoggingTool(getClass()).info("R1: " + GeometryTools.getRectangle2D(react1));
    LoggingToolFactory.createLoggingTool(getClass()).info("R2: " + GeometryTools.getRectangle2D(react2));
    for (int i = 0; i < 2; i++) {
        atom1 = react1.getAtom(0);
        atom2 = react2.getAtom(0);
        // so, x coordinates should be the same
        Assert.assertEquals(atom1.getPoint2d().x, atom2.getPoint2d().x, 0.0);
        // but, y coordinates should not
        Assert.assertTrue(atom1.getPoint2d().y < atom2.getPoint2d().y);
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) Point2d(javax.vecmath.Point2d) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) IReaction(org.openscience.cdk.interfaces.IReaction) Reaction(org.openscience.cdk.Reaction) IReaction(org.openscience.cdk.interfaces.IReaction) IAtom(org.openscience.cdk.interfaces.IAtom) IAtom(org.openscience.cdk.interfaces.IAtom) Atom(org.openscience.cdk.Atom) Test(org.junit.Test)

Example 28 with Reaction

use of org.openscience.cdk.Reaction in project cdk by cdk.

the class GeometryToolsTest method testGetBondLengthAverage_MultiReaction.

/**
 * Tests if the bond length average is calculated based on all
 * {@link IAtomContainer}s in the IReaction.
 */
@Test
public void testGetBondLengthAverage_MultiReaction() {
    IReaction reaction = new Reaction();
    // mol 1
    IAtom atom1 = new Atom("C");
    atom1.setPoint2d(new Point2d(0, 0));
    IAtom atom2 = new Atom("C");
    atom2.setPoint2d(new Point2d(1, 0));
    IAtomContainer acont = new AtomContainer();
    reaction.addReactant(acont);
    acont.addAtom(atom1);
    acont.addAtom(atom2);
    acont.addBond(0, 1, IBond.Order.SINGLE);
    // mol 2
    atom1 = new Atom("C");
    atom1.setPoint2d(new Point2d(0, 0));
    atom2 = new Atom("C");
    atom2.setPoint2d(new Point2d(3, 0));
    acont = new AtomContainer();
    reaction.addProduct(acont);
    acont.addAtom(atom1);
    acont.addAtom(atom2);
    acont.addBond(0, 1, IBond.Order.SINGLE);
    Assert.assertEquals(2.0, GeometryTools.getBondLengthAverage(reaction), 0.0);
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) Point2d(javax.vecmath.Point2d) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) IReaction(org.openscience.cdk.interfaces.IReaction) Reaction(org.openscience.cdk.Reaction) IReaction(org.openscience.cdk.interfaces.IReaction) IAtom(org.openscience.cdk.interfaces.IAtom) IAtom(org.openscience.cdk.interfaces.IAtom) Atom(org.openscience.cdk.Atom) Test(org.junit.Test)

Example 29 with Reaction

use of org.openscience.cdk.Reaction in project cdk by cdk.

the class ChemFileManipulatorTest method setUp.

@Before
public void setUp() {
    molecule1 = new AtomContainer();
    atomInMol1 = new Atom("Cl");
    molecule1.addAtom(atomInMol1);
    molecule1.addAtom(new Atom("Cl"));
    bondInMol1 = new Bond(atomInMol1, molecule1.getAtom(1));
    molecule1.addBond(bondInMol1);
    molecule2 = new AtomContainer();
    atomInMol2 = new Atom("O");
    atomInMol2.setImplicitHydrogenCount(2);
    molecule2.addAtom(atomInMol2);
    moleculeSet = new AtomContainerSet();
    moleculeSet.addAtomContainer(molecule1);
    moleculeSet.addAtomContainer(molecule2);
    reaction = new Reaction();
    reaction.addReactant(molecule1);
    reaction.addProduct(molecule2);
    reactionSet = new ReactionSet();
    reactionSet.addReaction(reaction);
    chemModel = new ChemModel();
    chemModel.setMoleculeSet(moleculeSet);
    chemModel.setReactionSet(reactionSet);
    chemSequence1 = new ChemSequence();
    chemSequence1.addChemModel(chemModel);
    chemSequence2 = new ChemSequence();
    chemFile = new ChemFile();
    chemFile.addChemSequence(chemSequence1);
    chemFile.addChemSequence(chemSequence2);
}
Also used : ChemSequence(org.openscience.cdk.ChemSequence) IChemSequence(org.openscience.cdk.interfaces.IChemSequence) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) ReactionSet(org.openscience.cdk.ReactionSet) ChemModel(org.openscience.cdk.ChemModel) IChemModel(org.openscience.cdk.interfaces.IChemModel) ChemFile(org.openscience.cdk.ChemFile) IChemFile(org.openscience.cdk.interfaces.IChemFile) Bond(org.openscience.cdk.Bond) IBond(org.openscience.cdk.interfaces.IBond) Reaction(org.openscience.cdk.Reaction) IReaction(org.openscience.cdk.interfaces.IReaction) IAtom(org.openscience.cdk.interfaces.IAtom) Atom(org.openscience.cdk.Atom) AtomContainerSet(org.openscience.cdk.AtomContainerSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) Before(org.junit.Before)

Example 30 with Reaction

use of org.openscience.cdk.Reaction in project cdk by cdk.

the class ChemModelManipulatorTest method testRemoveAtomAndConnectedElectronContainers_IChemModel_IAtom.

@Test
public void testRemoveAtomAndConnectedElectronContainers_IChemModel_IAtom() {
    IAtomContainer mol1 = new AtomContainer();
    IAtom atom1 = new Atom("Cl");
    mol1.addAtom(atom1);
    mol1.addAtom(new Atom("Cl"));
    IBond bond1 = new Bond(mol1.getAtom(0), mol1.getAtom(1));
    mol1.addBond(bond1);
    IAtomContainer mol2 = new AtomContainer();
    IAtom atom2 = new Atom("I");
    mol2.addAtom(atom2);
    mol2.addAtom(new Atom("I"));
    IBond bond2 = new Bond(mol2.getAtom(0), mol2.getAtom(1));
    mol2.addBond(bond2);
    IAtomContainerSet molSet = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class);
    molSet.addAtomContainer(mol1);
    IReaction r = new Reaction();
    r.addProduct(mol2);
    IReactionSet rSet = new ReactionSet();
    rSet.addReaction(r);
    IChemModel model = new ChemModel();
    model.setMoleculeSet(molSet);
    model.setReactionSet(rSet);
    IAtom otherAtom = new Atom("Cl");
    Assert.assertEquals(2, ChemModelManipulator.getBondCount(model));
    Assert.assertEquals(4, ChemModelManipulator.getAtomCount(model));
    ChemModelManipulator.removeAtomAndConnectedElectronContainers(model, otherAtom);
    Assert.assertEquals(2, ChemModelManipulator.getBondCount(model));
    Assert.assertEquals(4, ChemModelManipulator.getAtomCount(model));
    ChemModelManipulator.removeAtomAndConnectedElectronContainers(model, atom1);
    Assert.assertEquals(1, ChemModelManipulator.getBondCount(model));
    Assert.assertEquals(3, ChemModelManipulator.getAtomCount(model));
    ChemModelManipulator.removeAtomAndConnectedElectronContainers(model, atom2);
    Assert.assertEquals(0, ChemModelManipulator.getBondCount(model));
    Assert.assertEquals(2, ChemModelManipulator.getAtomCount(model));
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) IBond(org.openscience.cdk.interfaces.IBond) IChemModel(org.openscience.cdk.interfaces.IChemModel) Reaction(org.openscience.cdk.Reaction) IReaction(org.openscience.cdk.interfaces.IReaction) IAtom(org.openscience.cdk.interfaces.IAtom) Atom(org.openscience.cdk.Atom) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) ReactionSet(org.openscience.cdk.ReactionSet) ChemModel(org.openscience.cdk.ChemModel) IChemModel(org.openscience.cdk.interfaces.IChemModel) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IReaction(org.openscience.cdk.interfaces.IReaction) Bond(org.openscience.cdk.Bond) IBond(org.openscience.cdk.interfaces.IBond) IAtom(org.openscience.cdk.interfaces.IAtom) Test(org.junit.Test)

Aggregations

Reaction (org.openscience.cdk.Reaction)30 IReaction (org.openscience.cdk.interfaces.IReaction)28 Test (org.junit.Test)23 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)23 AtomContainer (org.openscience.cdk.AtomContainer)19 IAtom (org.openscience.cdk.interfaces.IAtom)16 Atom (org.openscience.cdk.Atom)15 InputStream (java.io.InputStream)12 Point2d (javax.vecmath.Point2d)8 ChemModel (org.openscience.cdk.ChemModel)8 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)8 SimpleChemObjectReaderTest (org.openscience.cdk.test.io.SimpleChemObjectReaderTest)8 IChemModel (org.openscience.cdk.interfaces.IChemModel)6 Bond (org.openscience.cdk.Bond)5 ReactionSet (org.openscience.cdk.ReactionSet)5 IBond (org.openscience.cdk.interfaces.IBond)5 IReactionSet (org.openscience.cdk.interfaces.IReactionSet)5 ChemFile (org.openscience.cdk.ChemFile)4 Before (org.junit.Before)3 IChemObject (org.openscience.cdk.interfaces.IChemObject)3